OLD | NEW |
---|---|
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 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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/BLE. The |
rkc
2017/03/15 22:49:01
nit: BR/EDR/LE
| |
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, the Trusted |
dmitrygr
2017/03/15 22:39:50
You mean "Paired" property?
| |
339 return properties->paired.value() || properties->trusted.value(); | 339 // property 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 Loading... | |
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 Loading... | |
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 |
OLD | NEW |