Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(610)

Side by Side Diff: device/bluetooth/bluez/bluetooth_device_bluez.cc

Issue 2751223002: bluetooth: Stop support of reconnecting devices not supporting pairing (Closed)
Patch Set: fix an unittest failure Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « device/bluetooth/bluez/bluetooth_bluez_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "device/bluetooth/bluez/bluetooth_device_bluez.h" 5 #include "device/bluetooth/bluez/bluetooth_device_bluez.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 // There isn't currently a good way to manage the ownership of a connection 247 // There isn't currently a good way to manage the ownership of a connection
248 // between Chrome and bluetoothd plugins/profiles. Until a proper reference 248 // between Chrome and bluetoothd plugins/profiles. Until a proper reference
249 // count is kept in bluetoothd, we might unwittingly kill a connection to a 249 // count is kept in bluetoothd, we might unwittingly kill a connection to a
250 // device the user is still interested in, e.g. a mouse. A device's paired 250 // device the user is still interested in, e.g. a mouse. A device's paired
251 // status is usually a good indication that the device is being used by other 251 // status is usually a good indication that the device is being used by other
252 // parts of the system and therefore we leak these connections. 252 // parts of the system and therefore we leak these connections.
253 // TODO(crbug.com/630586): Call disconnect for all devices. 253 // TODO(crbug.com/630586): Call disconnect for all devices.
254 254
255 // IsPaired() returns true if we've connected to the device before. So we 255 // IsPaired() returns true if we've connected to the device before. So we
256 // check the dbus property directly. 256 // check the dbus property directly.
257 // TODO(crbug.com/649651): Use IsPaired once it returns true only for paired 257 // TODO(crbug.com/649651): Use IsPaired once it returns true only for paired
ortuno 2017/03/28 02:09:26 You can also remove this TODO.
258 // devices. 258 // devices.
259 bluez::BluetoothDeviceClient::Properties* properties = 259 bluez::BluetoothDeviceClient::Properties* properties =
260 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( 260 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties(
261 object_path_); 261 object_path_);
262 DCHECK(properties); 262 DCHECK(properties);
263 263
264 if (properties->paired.value()) { 264 if (properties->paired.value()) {
265 LOG(WARNING) << "Leaking connection to paired device."; 265 LOG(WARNING) << "Leaking connection to paired device.";
266 return; 266 return;
267 } 267 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 else 326 else
327 return base::nullopt; 327 return base::nullopt;
328 } 328 }
329 329
330 bool BluetoothDeviceBlueZ::IsPaired() const { 330 bool BluetoothDeviceBlueZ::IsPaired() const {
331 bluez::BluetoothDeviceClient::Properties* properties = 331 bluez::BluetoothDeviceClient::Properties* properties =
332 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( 332 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties(
333 object_path_); 333 object_path_);
334 DCHECK(properties); 334 DCHECK(properties);
335 335
336 // Trusted devices are devices that don't support pairing but that the 336 // The Paired property reflects the successful pairing for BR/EDR/LE. The
337 // user has explicitly connected; it makes no sense for UI purposes to 337 // value of the Paired property is always false for the devices that don't
338 // treat them differently from each other. 338 // support pairing. Once a device is paired successfully, both Paired and
339 return properties->paired.value() || properties->trusted.value(); 339 // Trusted properties will be set to true.
340 return properties->paired.value();
340 } 341 }
341 342
342 bool BluetoothDeviceBlueZ::IsConnected() const { 343 bool BluetoothDeviceBlueZ::IsConnected() const {
343 bluez::BluetoothDeviceClient::Properties* properties = 344 bluez::BluetoothDeviceClient::Properties* properties =
344 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( 345 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties(
345 object_path_); 346 object_path_);
346 DCHECK(properties); 347 DCHECK(properties);
347 348
348 return properties->connected.value(); 349 return properties->connected.value();
349 } 350 }
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 void BluetoothDeviceBlueZ::Connect( 443 void BluetoothDeviceBlueZ::Connect(
443 BluetoothDevice::PairingDelegate* pairing_delegate, 444 BluetoothDevice::PairingDelegate* pairing_delegate,
444 const base::Closure& callback, 445 const base::Closure& callback,
445 const ConnectErrorCallback& error_callback) { 446 const ConnectErrorCallback& error_callback) {
446 if (num_connecting_calls_++ == 0) 447 if (num_connecting_calls_++ == 0)
447 adapter()->NotifyDeviceChanged(this); 448 adapter()->NotifyDeviceChanged(this);
448 449
449 VLOG(1) << object_path_.value() << ": Connecting, " << num_connecting_calls_ 450 VLOG(1) << object_path_.value() << ": Connecting, " << num_connecting_calls_
450 << " in progress"; 451 << " in progress";
451 452
452 if (IsPaired() || !pairing_delegate || !IsPairable()) { 453 if (IsPaired() || !pairing_delegate) {
453 // No need to pair, or unable to, skip straight to connection. 454 // No need to pair, or unable to, skip straight to connection.
454 ConnectInternal(false, callback, error_callback); 455 ConnectInternal(false, callback, error_callback);
455 } else { 456 } else {
456 // Initiate high-security connection with pairing. 457 // Initiate high-security connection with pairing.
457 BeginPairing(pairing_delegate); 458 BeginPairing(pairing_delegate);
458 459
459 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->Pair( 460 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->Pair(
460 object_path_, 461 object_path_,
461 base::Bind(&BluetoothDeviceBlueZ::OnPairDuringConnect, 462 base::Bind(&BluetoothDeviceBlueZ::OnPairDuringConnect,
462 weak_ptr_factory_.GetWeakPtr(), callback, error_callback), 463 weak_ptr_factory_.GetWeakPtr(), callback, error_callback),
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
953 void BluetoothDeviceBlueZ::OnForgetError(const ErrorCallback& error_callback, 954 void BluetoothDeviceBlueZ::OnForgetError(const ErrorCallback& error_callback,
954 const std::string& error_name, 955 const std::string& error_name,
955 const std::string& error_message) { 956 const std::string& error_message) {
956 LOG(WARNING) << object_path_.value() 957 LOG(WARNING) << object_path_.value()
957 << ": Failed to remove device: " << error_name << ": " 958 << ": Failed to remove device: " << error_name << ": "
958 << error_message; 959 << error_message;
959 error_callback.Run(); 960 error_callback.Run();
960 } 961 }
961 962
962 } // namespace bluez 963 } // namespace bluez
OLDNEW
« no previous file with comments | « device/bluetooth/bluez/bluetooth_bluez_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698