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 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 bool BluetoothDeviceBlueZ::IsGattServicesDiscoveryComplete() const { | 229 bool BluetoothDeviceBlueZ::IsGattServicesDiscoveryComplete() const { |
230 bluez::BluetoothDeviceClient::Properties* properties = | 230 bluez::BluetoothDeviceClient::Properties* properties = |
231 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( | 231 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
232 object_path_); | 232 object_path_); |
233 DCHECK(properties); | 233 DCHECK(properties); |
234 | 234 |
235 return properties->services_resolved.value(); | 235 return properties->services_resolved.value(); |
236 } | 236 } |
237 | 237 |
238 void BluetoothDeviceBlueZ::DisconnectGatt() { | 238 void BluetoothDeviceBlueZ::DisconnectGatt() { |
| 239 // There isn't currently a good way to manage the ownership of a connection |
| 240 // between Chrome and bluetoothd plugins/profiles. Until a proper reference |
| 241 // count is kept in bluetoothd, we might unwittingly kill a connection to a |
| 242 // device the user is still interested in, e.g. a mouse. A device's paired |
| 243 // status is usually a good indication that the device is being used by other |
| 244 // parts of the system and therefore we leak these connections. |
| 245 // TODO(crbug.com/630586): Call disconnect for all devices. |
| 246 |
| 247 // IsPaired() returns true if we've connected to the device before. So we |
| 248 // check the dbus property directly. |
| 249 // TODO(crbug.com/649651): Use IsPaired once it returns true only for paired |
| 250 // devices. |
| 251 bluez::BluetoothDeviceClient::Properties* properties = |
| 252 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
| 253 object_path_); |
| 254 DCHECK(properties); |
| 255 |
| 256 if (properties->paired.value()) { |
| 257 LOG(WARNING) << "Leaking connection to paired device."; |
| 258 return; |
| 259 } |
| 260 |
239 Disconnect(base::Bind(&base::DoNothing), base::Bind(&base::DoNothing)); | 261 Disconnect(base::Bind(&base::DoNothing), base::Bind(&base::DoNothing)); |
240 } | 262 } |
241 | 263 |
242 std::string BluetoothDeviceBlueZ::GetAddress() const { | 264 std::string BluetoothDeviceBlueZ::GetAddress() const { |
243 bluez::BluetoothDeviceClient::Properties* properties = | 265 bluez::BluetoothDeviceClient::Properties* properties = |
244 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( | 266 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
245 object_path_); | 267 object_path_); |
246 DCHECK(properties); | 268 DCHECK(properties); |
247 | 269 |
248 return CanonicalizeAddress(properties->address.value()); | 270 return CanonicalizeAddress(properties->address.value()); |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 // TODO(sacomoto): Workaround to retrieve the connection for already connected | 572 // TODO(sacomoto): Workaround to retrieve the connection for already connected |
551 // devices. Currently, BluetoothGattConnection::Disconnect doesn't do | 573 // devices. Currently, BluetoothGattConnection::Disconnect doesn't do |
552 // anything, the unique underlying physical GATT connection is kept. This | 574 // anything, the unique underlying physical GATT connection is kept. This |
553 // should be removed once the correct behavour is implemented and the GATT | 575 // should be removed once the correct behavour is implemented and the GATT |
554 // connections are reference counted (see todo below). | 576 // connections are reference counted (see todo below). |
555 if (IsConnected()) { | 577 if (IsConnected()) { |
556 OnCreateGattConnection(callback); | 578 OnCreateGattConnection(callback); |
557 return; | 579 return; |
558 } | 580 } |
559 | 581 |
560 // TODO(armansito): Until there is a way to create a reference counted GATT | 582 // TODO(crbug.com/630586): Until there is a way to create a reference counted |
561 // connection in bluetoothd, simply do a regular connect. | 583 // GATT connection in bluetoothd, simply do a regular connect. |
562 Connect(NULL, base::Bind(&BluetoothDeviceBlueZ::OnCreateGattConnection, | 584 Connect(NULL, base::Bind(&BluetoothDeviceBlueZ::OnCreateGattConnection, |
563 weak_ptr_factory_.GetWeakPtr(), callback), | 585 weak_ptr_factory_.GetWeakPtr(), callback), |
564 error_callback); | 586 error_callback); |
565 } | 587 } |
566 | 588 |
567 void BluetoothDeviceBlueZ::GetServiceRecords( | 589 void BluetoothDeviceBlueZ::GetServiceRecords( |
568 const GetServiceRecordsCallback& callback, | 590 const GetServiceRecordsCallback& callback, |
569 const GetServiceRecordsErrorCallback& error_callback) { | 591 const GetServiceRecordsErrorCallback& error_callback) { |
570 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetServiceRecords( | 592 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetServiceRecords( |
571 object_path_, callback, | 593 object_path_, callback, |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
879 void BluetoothDeviceBlueZ::OnForgetError(const ErrorCallback& error_callback, | 901 void BluetoothDeviceBlueZ::OnForgetError(const ErrorCallback& error_callback, |
880 const std::string& error_name, | 902 const std::string& error_name, |
881 const std::string& error_message) { | 903 const std::string& error_message) { |
882 LOG(WARNING) << object_path_.value() | 904 LOG(WARNING) << object_path_.value() |
883 << ": Failed to remove device: " << error_name << ": " | 905 << ": Failed to remove device: " << error_name << ": " |
884 << error_message; | 906 << error_message; |
885 error_callback.Run(); | 907 error_callback.Run(); |
886 } | 908 } |
887 | 909 |
888 } // namespace bluez | 910 } // namespace bluez |
OLD | NEW |