| 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/bluetooth_device_chromeos.h" | 5 #include "device/bluetooth/bluetooth_device_chromeos.h" |
| 6 | 6 |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "chromeos/dbus/bluetooth_adapter_client.h" | |
| 15 #include "chromeos/dbus/bluetooth_device_client.h" | |
| 16 #include "chromeos/dbus/bluetooth_gatt_service_client.h" | |
| 17 #include "chromeos/dbus/bluetooth_input_client.h" | |
| 18 #include "chromeos/dbus/dbus_thread_manager.h" | |
| 19 #include "dbus/bus.h" | 14 #include "dbus/bus.h" |
| 20 #include "device/bluetooth/bluetooth_adapter_chromeos.h" | 15 #include "device/bluetooth/bluetooth_adapter_chromeos.h" |
| 21 #include "device/bluetooth/bluetooth_gatt_connection_chromeos.h" | 16 #include "device/bluetooth/bluetooth_gatt_connection_chromeos.h" |
| 22 #include "device/bluetooth/bluetooth_pairing_chromeos.h" | 17 #include "device/bluetooth/bluetooth_pairing_chromeos.h" |
| 23 #include "device/bluetooth/bluetooth_remote_gatt_service_chromeos.h" | 18 #include "device/bluetooth/bluetooth_remote_gatt_service_chromeos.h" |
| 24 #include "device/bluetooth/bluetooth_socket.h" | 19 #include "device/bluetooth/bluetooth_socket.h" |
| 25 #include "device/bluetooth/bluetooth_socket_chromeos.h" | 20 #include "device/bluetooth/bluetooth_socket_chromeos.h" |
| 26 #include "device/bluetooth/bluetooth_socket_thread.h" | 21 #include "device/bluetooth/bluetooth_socket_thread.h" |
| 27 #include "device/bluetooth/bluetooth_uuid.h" | 22 #include "device/bluetooth/bluetooth_uuid.h" |
| 23 #include "device/bluetooth/dbus/bluetooth_adapter_client.h" |
| 24 #include "device/bluetooth/dbus/bluetooth_device_client.h" |
| 25 #include "device/bluetooth/dbus/bluetooth_gatt_service_client.h" |
| 26 #include "device/bluetooth/dbus/bluetooth_input_client.h" |
| 27 #include "device/bluetooth/dbus/bluez_dbus_manager.h" |
| 28 #include "third_party/cros_system_api/dbus/service_constants.h" | 28 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 29 | 29 |
| 30 using device::BluetoothDevice; | 30 using device::BluetoothDevice; |
| 31 using device::BluetoothSocket; | 31 using device::BluetoothSocket; |
| 32 using device::BluetoothUUID; | 32 using device::BluetoothUUID; |
| 33 | 33 |
| 34 namespace { | 34 namespace { |
| 35 | 35 |
| 36 // Histogram enumerations for pairing results. | 36 // Histogram enumerations for pairing results. |
| 37 enum UMAPairingResult { | 37 enum UMAPairingResult { |
| 38 UMA_PAIRING_RESULT_SUCCESS, | 38 UMA_PAIRING_RESULT_SUCCESS, |
| 39 UMA_PAIRING_RESULT_INPROGRESS, | 39 UMA_PAIRING_RESULT_INPROGRESS, |
| 40 UMA_PAIRING_RESULT_FAILED, | 40 UMA_PAIRING_RESULT_FAILED, |
| 41 UMA_PAIRING_RESULT_AUTH_FAILED, | 41 UMA_PAIRING_RESULT_AUTH_FAILED, |
| 42 UMA_PAIRING_RESULT_AUTH_CANCELED, | 42 UMA_PAIRING_RESULT_AUTH_CANCELED, |
| 43 UMA_PAIRING_RESULT_AUTH_REJECTED, | 43 UMA_PAIRING_RESULT_AUTH_REJECTED, |
| 44 UMA_PAIRING_RESULT_AUTH_TIMEOUT, | 44 UMA_PAIRING_RESULT_AUTH_TIMEOUT, |
| 45 UMA_PAIRING_RESULT_UNSUPPORTED_DEVICE, | 45 UMA_PAIRING_RESULT_UNSUPPORTED_DEVICE, |
| 46 UMA_PAIRING_RESULT_UNKNOWN_ERROR, | 46 UMA_PAIRING_RESULT_UNKNOWN_ERROR, |
| 47 // NOTE: Add new pairing results immediately above this line. Make sure to | 47 // NOTE: Add new pairing results immediately above this line. Make sure to |
| 48 // update the enum list in tools/histogram/histograms.xml accordinly. | 48 // update the enum list in tools/histogram/histograms.xml accordinly. |
| 49 UMA_PAIRING_RESULT_COUNT | 49 UMA_PAIRING_RESULT_COUNT |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 void ParseModalias(const dbus::ObjectPath& object_path, | 52 void ParseModalias(const dbus::ObjectPath& object_path, |
| 53 BluetoothDevice::VendorIDSource* vendor_id_source, | 53 BluetoothDevice::VendorIDSource* vendor_id_source, |
| 54 uint16* vendor_id, | 54 uint16* vendor_id, |
| 55 uint16* product_id, | 55 uint16* product_id, |
| 56 uint16* device_id) { | 56 uint16* device_id) { |
| 57 chromeos::BluetoothDeviceClient::Properties* properties = | 57 bluez::BluetoothDeviceClient::Properties* properties = |
| 58 chromeos::DBusThreadManager::Get()->GetBluetoothDeviceClient()-> | 58 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
| 59 GetProperties(object_path); | 59 object_path); |
| 60 DCHECK(properties); | 60 DCHECK(properties); |
| 61 | 61 |
| 62 std::string modalias = properties->modalias.value(); | 62 std::string modalias = properties->modalias.value(); |
| 63 BluetoothDevice::VendorIDSource source_value; | 63 BluetoothDevice::VendorIDSource source_value; |
| 64 int vendor_value, product_value, device_value; | 64 int vendor_value, product_value, device_value; |
| 65 | 65 |
| 66 if (sscanf(modalias.c_str(), "bluetooth:v%04xp%04xd%04x", | 66 if (sscanf(modalias.c_str(), "bluetooth:v%04xp%04xd%04x", |
| 67 &vendor_value, &product_value, &device_value) == 3) { | 67 &vendor_value, &product_value, &device_value) == 3) { |
| 68 source_value = BluetoothDevice::VENDOR_ID_BLUETOOTH; | 68 source_value = BluetoothDevice::VENDOR_ID_BLUETOOTH; |
| 69 } else if (sscanf(modalias.c_str(), "usb:v%04xp%04xd%04x", | 69 } else if (sscanf(modalias.c_str(), "usb:v%04xp%04xd%04x", |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 const dbus::ObjectPath& object_path, | 125 const dbus::ObjectPath& object_path, |
| 126 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, | 126 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, |
| 127 scoped_refptr<device::BluetoothSocketThread> socket_thread) | 127 scoped_refptr<device::BluetoothSocketThread> socket_thread) |
| 128 : BluetoothDevice(adapter), | 128 : BluetoothDevice(adapter), |
| 129 object_path_(object_path), | 129 object_path_(object_path), |
| 130 num_connecting_calls_(0), | 130 num_connecting_calls_(0), |
| 131 connection_monitor_started_(false), | 131 connection_monitor_started_(false), |
| 132 ui_task_runner_(ui_task_runner), | 132 ui_task_runner_(ui_task_runner), |
| 133 socket_thread_(socket_thread), | 133 socket_thread_(socket_thread), |
| 134 weak_ptr_factory_(this) { | 134 weak_ptr_factory_(this) { |
| 135 DBusThreadManager::Get()->GetBluetoothGattServiceClient()->AddObserver(this); | 135 bluez::BluezDBusManager::Get()->GetBluetoothGattServiceClient()->AddObserver( |
| 136 this); |
| 136 | 137 |
| 137 // Add all known GATT services. | 138 // Add all known GATT services. |
| 138 const std::vector<dbus::ObjectPath> gatt_services = | 139 const std::vector<dbus::ObjectPath> gatt_services = |
| 139 DBusThreadManager::Get()->GetBluetoothGattServiceClient()->GetServices(); | 140 bluez::BluezDBusManager::Get() |
| 141 ->GetBluetoothGattServiceClient() |
| 142 ->GetServices(); |
| 140 for (std::vector<dbus::ObjectPath>::const_iterator it = gatt_services.begin(); | 143 for (std::vector<dbus::ObjectPath>::const_iterator it = gatt_services.begin(); |
| 141 it != gatt_services.end(); ++it) { | 144 it != gatt_services.end(); ++it) { |
| 142 GattServiceAdded(*it); | 145 GattServiceAdded(*it); |
| 143 } | 146 } |
| 144 } | 147 } |
| 145 | 148 |
| 146 BluetoothDeviceChromeOS::~BluetoothDeviceChromeOS() { | 149 BluetoothDeviceChromeOS::~BluetoothDeviceChromeOS() { |
| 147 DBusThreadManager::Get()->GetBluetoothGattServiceClient()-> | 150 bluez::BluezDBusManager::Get() |
| 148 RemoveObserver(this); | 151 ->GetBluetoothGattServiceClient() |
| 152 ->RemoveObserver(this); |
| 149 | 153 |
| 150 // Copy the GATT services list here and clear the original so that when we | 154 // Copy the GATT services list here and clear the original so that when we |
| 151 // send GattServiceRemoved(), GetGattServices() returns no services. | 155 // send GattServiceRemoved(), GetGattServices() returns no services. |
| 152 GattServiceMap gatt_services = gatt_services_; | 156 GattServiceMap gatt_services = gatt_services_; |
| 153 gatt_services_.clear(); | 157 gatt_services_.clear(); |
| 154 for (GattServiceMap::iterator iter = gatt_services.begin(); | 158 for (GattServiceMap::iterator iter = gatt_services.begin(); |
| 155 iter != gatt_services.end(); ++iter) { | 159 iter != gatt_services.end(); ++iter) { |
| 156 DCHECK(adapter_); | 160 DCHECK(adapter_); |
| 157 adapter()->NotifyGattServiceRemoved( | 161 adapter()->NotifyGattServiceRemoved( |
| 158 static_cast<BluetoothRemoteGattServiceChromeOS*>(iter->second)); | 162 static_cast<BluetoothRemoteGattServiceChromeOS*>(iter->second)); |
| 159 delete iter->second; | 163 delete iter->second; |
| 160 } | 164 } |
| 161 } | 165 } |
| 162 | 166 |
| 163 uint32 BluetoothDeviceChromeOS::GetBluetoothClass() const { | 167 uint32 BluetoothDeviceChromeOS::GetBluetoothClass() const { |
| 164 BluetoothDeviceClient::Properties* properties = | 168 bluez::BluetoothDeviceClient::Properties* properties = |
| 165 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> | 169 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
| 166 GetProperties(object_path_); | 170 object_path_); |
| 167 DCHECK(properties); | 171 DCHECK(properties); |
| 168 | 172 |
| 169 return properties->bluetooth_class.value(); | 173 return properties->bluetooth_class.value(); |
| 170 } | 174 } |
| 171 | 175 |
| 172 std::string BluetoothDeviceChromeOS::GetDeviceName() const { | 176 std::string BluetoothDeviceChromeOS::GetDeviceName() const { |
| 173 BluetoothDeviceClient::Properties* properties = | 177 bluez::BluetoothDeviceClient::Properties* properties = |
| 174 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> | 178 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
| 175 GetProperties(object_path_); | 179 object_path_); |
| 176 DCHECK(properties); | 180 DCHECK(properties); |
| 177 | 181 |
| 178 return properties->alias.value(); | 182 return properties->alias.value(); |
| 179 } | 183 } |
| 180 | 184 |
| 181 std::string BluetoothDeviceChromeOS::GetAddress() const { | 185 std::string BluetoothDeviceChromeOS::GetAddress() const { |
| 182 BluetoothDeviceClient::Properties* properties = | 186 bluez::BluetoothDeviceClient::Properties* properties = |
| 183 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> | 187 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
| 184 GetProperties(object_path_); | 188 object_path_); |
| 185 DCHECK(properties); | 189 DCHECK(properties); |
| 186 | 190 |
| 187 return CanonicalizeAddress(properties->address.value()); | 191 return CanonicalizeAddress(properties->address.value()); |
| 188 } | 192 } |
| 189 | 193 |
| 190 BluetoothDevice::VendorIDSource | 194 BluetoothDevice::VendorIDSource |
| 191 BluetoothDeviceChromeOS::GetVendorIDSource() const { | 195 BluetoothDeviceChromeOS::GetVendorIDSource() const { |
| 192 VendorIDSource vendor_id_source = VENDOR_ID_UNKNOWN; | 196 VendorIDSource vendor_id_source = VENDOR_ID_UNKNOWN; |
| 193 ParseModalias(object_path_, &vendor_id_source, NULL, NULL, NULL); | 197 ParseModalias(object_path_, &vendor_id_source, NULL, NULL, NULL); |
| 194 return vendor_id_source; | 198 return vendor_id_source; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 206 return product_id; | 210 return product_id; |
| 207 } | 211 } |
| 208 | 212 |
| 209 uint16 BluetoothDeviceChromeOS::GetDeviceID() const { | 213 uint16 BluetoothDeviceChromeOS::GetDeviceID() const { |
| 210 uint16 device_id = 0; | 214 uint16 device_id = 0; |
| 211 ParseModalias(object_path_, NULL, NULL, NULL, &device_id); | 215 ParseModalias(object_path_, NULL, NULL, NULL, &device_id); |
| 212 return device_id; | 216 return device_id; |
| 213 } | 217 } |
| 214 | 218 |
| 215 bool BluetoothDeviceChromeOS::IsPaired() const { | 219 bool BluetoothDeviceChromeOS::IsPaired() const { |
| 216 BluetoothDeviceClient::Properties* properties = | 220 bluez::BluetoothDeviceClient::Properties* properties = |
| 217 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> | 221 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
| 218 GetProperties(object_path_); | 222 object_path_); |
| 219 DCHECK(properties); | 223 DCHECK(properties); |
| 220 | 224 |
| 221 // Trusted devices are devices that don't support pairing but that the | 225 // Trusted devices are devices that don't support pairing but that the |
| 222 // user has explicitly connected; it makes no sense for UI purposes to | 226 // user has explicitly connected; it makes no sense for UI purposes to |
| 223 // treat them differently from each other. | 227 // treat them differently from each other. |
| 224 return properties->paired.value() || properties->trusted.value(); | 228 return properties->paired.value() || properties->trusted.value(); |
| 225 } | 229 } |
| 226 | 230 |
| 227 bool BluetoothDeviceChromeOS::IsConnected() const { | 231 bool BluetoothDeviceChromeOS::IsConnected() const { |
| 228 BluetoothDeviceClient::Properties* properties = | 232 bluez::BluetoothDeviceClient::Properties* properties = |
| 229 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> | 233 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
| 230 GetProperties(object_path_); | 234 object_path_); |
| 231 DCHECK(properties); | 235 DCHECK(properties); |
| 232 | 236 |
| 233 return properties->connected.value(); | 237 return properties->connected.value(); |
| 234 } | 238 } |
| 235 | 239 |
| 236 bool BluetoothDeviceChromeOS::IsConnectable() const { | 240 bool BluetoothDeviceChromeOS::IsConnectable() const { |
| 237 BluetoothInputClient::Properties* input_properties = | 241 bluez::BluetoothInputClient::Properties* input_properties = |
| 238 DBusThreadManager::Get()->GetBluetoothInputClient()-> | 242 bluez::BluezDBusManager::Get()->GetBluetoothInputClient()->GetProperties( |
| 239 GetProperties(object_path_); | 243 object_path_); |
| 240 // GetProperties returns NULL when the device does not implement the given | 244 // GetProperties returns NULL when the device does not implement the given |
| 241 // interface. Non HID devices are normally connectable. | 245 // interface. Non HID devices are normally connectable. |
| 242 if (!input_properties) | 246 if (!input_properties) |
| 243 return true; | 247 return true; |
| 244 | 248 |
| 245 return input_properties->reconnect_mode.value() != "device"; | 249 return input_properties->reconnect_mode.value() != "device"; |
| 246 } | 250 } |
| 247 | 251 |
| 248 bool BluetoothDeviceChromeOS::IsConnecting() const { | 252 bool BluetoothDeviceChromeOS::IsConnecting() const { |
| 249 return num_connecting_calls_ > 0; | 253 return num_connecting_calls_ > 0; |
| 250 } | 254 } |
| 251 | 255 |
| 252 BluetoothDeviceChromeOS::UUIDList BluetoothDeviceChromeOS::GetUUIDs() const { | 256 BluetoothDeviceChromeOS::UUIDList BluetoothDeviceChromeOS::GetUUIDs() const { |
| 253 BluetoothDeviceClient::Properties* properties = | 257 bluez::BluetoothDeviceClient::Properties* properties = |
| 254 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> | 258 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
| 255 GetProperties(object_path_); | 259 object_path_); |
| 256 DCHECK(properties); | 260 DCHECK(properties); |
| 257 | 261 |
| 258 std::vector<device::BluetoothUUID> uuids; | 262 std::vector<device::BluetoothUUID> uuids; |
| 259 const std::vector<std::string> &dbus_uuids = properties->uuids.value(); | 263 const std::vector<std::string> &dbus_uuids = properties->uuids.value(); |
| 260 for (std::vector<std::string>::const_iterator iter = dbus_uuids.begin(); | 264 for (std::vector<std::string>::const_iterator iter = dbus_uuids.begin(); |
| 261 iter != dbus_uuids.end(); ++iter) { | 265 iter != dbus_uuids.end(); ++iter) { |
| 262 device::BluetoothUUID uuid(*iter); | 266 device::BluetoothUUID uuid(*iter); |
| 263 DCHECK(uuid.IsValid()); | 267 DCHECK(uuid.IsValid()); |
| 264 uuids.push_back(uuid); | 268 uuids.push_back(uuid); |
| 265 } | 269 } |
| 266 return uuids; | 270 return uuids; |
| 267 } | 271 } |
| 268 | 272 |
| 269 int16 BluetoothDeviceChromeOS::GetInquiryRSSI() const { | 273 int16 BluetoothDeviceChromeOS::GetInquiryRSSI() const { |
| 270 BluetoothDeviceClient::Properties* properties = | 274 bluez::BluetoothDeviceClient::Properties* properties = |
| 271 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> | 275 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
| 272 GetProperties(object_path_); | 276 object_path_); |
| 273 DCHECK(properties); | 277 DCHECK(properties); |
| 274 | 278 |
| 275 if (!properties->rssi.is_valid()) | 279 if (!properties->rssi.is_valid()) |
| 276 return kUnknownPower; | 280 return kUnknownPower; |
| 277 | 281 |
| 278 return properties->rssi.value(); | 282 return properties->rssi.value(); |
| 279 } | 283 } |
| 280 | 284 |
| 281 int16 BluetoothDeviceChromeOS::GetInquiryTxPower() const { | 285 int16 BluetoothDeviceChromeOS::GetInquiryTxPower() const { |
| 282 BluetoothDeviceClient::Properties* properties = | 286 bluez::BluetoothDeviceClient::Properties* properties = |
| 283 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> | 287 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
| 284 GetProperties(object_path_); | 288 object_path_); |
| 285 DCHECK(properties); | 289 DCHECK(properties); |
| 286 | 290 |
| 287 if (!properties->tx_power.is_valid()) | 291 if (!properties->tx_power.is_valid()) |
| 288 return kUnknownPower; | 292 return kUnknownPower; |
| 289 | 293 |
| 290 return properties->tx_power.value(); | 294 return properties->tx_power.value(); |
| 291 } | 295 } |
| 292 | 296 |
| 293 bool BluetoothDeviceChromeOS::ExpectingPinCode() const { | 297 bool BluetoothDeviceChromeOS::ExpectingPinCode() const { |
| 294 return pairing_.get() && pairing_->ExpectingPinCode(); | 298 return pairing_.get() && pairing_->ExpectingPinCode(); |
| 295 } | 299 } |
| 296 | 300 |
| 297 bool BluetoothDeviceChromeOS::ExpectingPasskey() const { | 301 bool BluetoothDeviceChromeOS::ExpectingPasskey() const { |
| 298 return pairing_.get() && pairing_->ExpectingPasskey(); | 302 return pairing_.get() && pairing_->ExpectingPasskey(); |
| 299 } | 303 } |
| 300 | 304 |
| 301 bool BluetoothDeviceChromeOS::ExpectingConfirmation() const { | 305 bool BluetoothDeviceChromeOS::ExpectingConfirmation() const { |
| 302 return pairing_.get() && pairing_->ExpectingConfirmation(); | 306 return pairing_.get() && pairing_->ExpectingConfirmation(); |
| 303 } | 307 } |
| 304 | 308 |
| 305 void BluetoothDeviceChromeOS::GetConnectionInfo( | 309 void BluetoothDeviceChromeOS::GetConnectionInfo( |
| 306 const ConnectionInfoCallback& callback) { | 310 const ConnectionInfoCallback& callback) { |
| 307 // DBus method call should gracefully return an error if the device is not | 311 // DBus method call should gracefully return an error if the device is not |
| 308 // currently connected. | 312 // currently connected. |
| 309 DBusThreadManager::Get()->GetBluetoothDeviceClient()->GetConnInfo( | 313 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetConnInfo( |
| 310 object_path_, base::Bind(&BluetoothDeviceChromeOS::OnGetConnInfo, | 314 object_path_, base::Bind(&BluetoothDeviceChromeOS::OnGetConnInfo, |
| 311 weak_ptr_factory_.GetWeakPtr(), callback), | 315 weak_ptr_factory_.GetWeakPtr(), callback), |
| 312 base::Bind(&BluetoothDeviceChromeOS::OnGetConnInfoError, | 316 base::Bind(&BluetoothDeviceChromeOS::OnGetConnInfoError, |
| 313 weak_ptr_factory_.GetWeakPtr(), callback)); | 317 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 314 } | 318 } |
| 315 | 319 |
| 316 void BluetoothDeviceChromeOS::Connect( | 320 void BluetoothDeviceChromeOS::Connect( |
| 317 BluetoothDevice::PairingDelegate* pairing_delegate, | 321 BluetoothDevice::PairingDelegate* pairing_delegate, |
| 318 const base::Closure& callback, | 322 const base::Closure& callback, |
| 319 const ConnectErrorCallback& error_callback) { | 323 const ConnectErrorCallback& error_callback) { |
| 320 if (num_connecting_calls_++ == 0) | 324 if (num_connecting_calls_++ == 0) |
| 321 adapter()->NotifyDeviceChanged(this); | 325 adapter()->NotifyDeviceChanged(this); |
| 322 | 326 |
| 323 VLOG(1) << object_path_.value() << ": Connecting, " << num_connecting_calls_ | 327 VLOG(1) << object_path_.value() << ": Connecting, " << num_connecting_calls_ |
| 324 << " in progress"; | 328 << " in progress"; |
| 325 | 329 |
| 326 if (IsPaired() || !pairing_delegate || !IsPairable()) { | 330 if (IsPaired() || !pairing_delegate || !IsPairable()) { |
| 327 // No need to pair, or unable to, skip straight to connection. | 331 // No need to pair, or unable to, skip straight to connection. |
| 328 ConnectInternal(false, callback, error_callback); | 332 ConnectInternal(false, callback, error_callback); |
| 329 } else { | 333 } else { |
| 330 // Initiate high-security connection with pairing. | 334 // Initiate high-security connection with pairing. |
| 331 BeginPairing(pairing_delegate); | 335 BeginPairing(pairing_delegate); |
| 332 | 336 |
| 333 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> | 337 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->Pair( |
| 334 Pair(object_path_, | 338 object_path_, |
| 335 base::Bind(&BluetoothDeviceChromeOS::OnPair, | 339 base::Bind(&BluetoothDeviceChromeOS::OnPair, |
| 336 weak_ptr_factory_.GetWeakPtr(), | 340 weak_ptr_factory_.GetWeakPtr(), callback, error_callback), |
| 337 callback, error_callback), | 341 base::Bind(&BluetoothDeviceChromeOS::OnPairError, |
| 338 base::Bind(&BluetoothDeviceChromeOS::OnPairError, | 342 weak_ptr_factory_.GetWeakPtr(), error_callback)); |
| 339 weak_ptr_factory_.GetWeakPtr(), | |
| 340 error_callback)); | |
| 341 } | 343 } |
| 342 } | 344 } |
| 343 | 345 |
| 344 void BluetoothDeviceChromeOS::SetPinCode(const std::string& pincode) { | 346 void BluetoothDeviceChromeOS::SetPinCode(const std::string& pincode) { |
| 345 if (!pairing_.get()) | 347 if (!pairing_.get()) |
| 346 return; | 348 return; |
| 347 | 349 |
| 348 pairing_->SetPinCode(pincode); | 350 pairing_->SetPinCode(pincode); |
| 349 } | 351 } |
| 350 | 352 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 374 | 376 |
| 375 // If there is a callback in progress that we can reply to then use that | 377 // If there is a callback in progress that we can reply to then use that |
| 376 // to cancel the current pairing request. | 378 // to cancel the current pairing request. |
| 377 if (pairing_.get() && pairing_->CancelPairing()) | 379 if (pairing_.get() && pairing_->CancelPairing()) |
| 378 canceled = true; | 380 canceled = true; |
| 379 | 381 |
| 380 // If not we have to send an explicit CancelPairing() to the device instead. | 382 // If not we have to send an explicit CancelPairing() to the device instead. |
| 381 if (!canceled) { | 383 if (!canceled) { |
| 382 VLOG(1) << object_path_.value() << ": No pairing context or callback. " | 384 VLOG(1) << object_path_.value() << ": No pairing context or callback. " |
| 383 << "Sending explicit cancel"; | 385 << "Sending explicit cancel"; |
| 384 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> | 386 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->CancelPairing( |
| 385 CancelPairing( | 387 object_path_, base::Bind(&base::DoNothing), |
| 386 object_path_, | 388 base::Bind(&BluetoothDeviceChromeOS::OnCancelPairingError, |
| 387 base::Bind(&base::DoNothing), | 389 weak_ptr_factory_.GetWeakPtr())); |
| 388 base::Bind(&BluetoothDeviceChromeOS::OnCancelPairingError, | |
| 389 weak_ptr_factory_.GetWeakPtr())); | |
| 390 } | 390 } |
| 391 | 391 |
| 392 // Since there is no callback to this method it's possible that the pairing | 392 // Since there is no callback to this method it's possible that the pairing |
| 393 // delegate is going to be freed before things complete (indeed it's | 393 // delegate is going to be freed before things complete (indeed it's |
| 394 // documented that this is the method you should call while freeing the | 394 // documented that this is the method you should call while freeing the |
| 395 // pairing delegate), so clear our the context holding on to it. | 395 // pairing delegate), so clear our the context holding on to it. |
| 396 EndPairing(); | 396 EndPairing(); |
| 397 } | 397 } |
| 398 | 398 |
| 399 void BluetoothDeviceChromeOS::Disconnect(const base::Closure& callback, | 399 void BluetoothDeviceChromeOS::Disconnect(const base::Closure& callback, |
| 400 const ErrorCallback& error_callback) { | 400 const ErrorCallback& error_callback) { |
| 401 VLOG(1) << object_path_.value() << ": Disconnecting"; | 401 VLOG(1) << object_path_.value() << ": Disconnecting"; |
| 402 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> | 402 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->Disconnect( |
| 403 Disconnect( | 403 object_path_, base::Bind(&BluetoothDeviceChromeOS::OnDisconnect, |
| 404 object_path_, | 404 weak_ptr_factory_.GetWeakPtr(), callback), |
| 405 base::Bind(&BluetoothDeviceChromeOS::OnDisconnect, | 405 base::Bind(&BluetoothDeviceChromeOS::OnDisconnectError, |
| 406 weak_ptr_factory_.GetWeakPtr(), | 406 weak_ptr_factory_.GetWeakPtr(), error_callback)); |
| 407 callback), | |
| 408 base::Bind(&BluetoothDeviceChromeOS::OnDisconnectError, | |
| 409 weak_ptr_factory_.GetWeakPtr(), | |
| 410 error_callback)); | |
| 411 } | 407 } |
| 412 | 408 |
| 413 void BluetoothDeviceChromeOS::Forget(const ErrorCallback& error_callback) { | 409 void BluetoothDeviceChromeOS::Forget(const ErrorCallback& error_callback) { |
| 414 VLOG(1) << object_path_.value() << ": Removing device"; | 410 VLOG(1) << object_path_.value() << ": Removing device"; |
| 415 DBusThreadManager::Get()->GetBluetoothAdapterClient()->RemoveDevice( | 411 bluez::BluezDBusManager::Get()->GetBluetoothAdapterClient()->RemoveDevice( |
| 416 adapter()->object_path(), object_path_, base::Bind(&base::DoNothing), | 412 adapter()->object_path(), object_path_, base::Bind(&base::DoNothing), |
| 417 base::Bind(&BluetoothDeviceChromeOS::OnForgetError, | 413 base::Bind(&BluetoothDeviceChromeOS::OnForgetError, |
| 418 weak_ptr_factory_.GetWeakPtr(), error_callback)); | 414 weak_ptr_factory_.GetWeakPtr(), error_callback)); |
| 419 } | 415 } |
| 420 | 416 |
| 421 void BluetoothDeviceChromeOS::ConnectToService( | 417 void BluetoothDeviceChromeOS::ConnectToService( |
| 422 const BluetoothUUID& uuid, | 418 const BluetoothUUID& uuid, |
| 423 const ConnectToServiceCallback& callback, | 419 const ConnectToServiceCallback& callback, |
| 424 const ConnectToServiceErrorCallback& error_callback) { | 420 const ConnectToServiceErrorCallback& error_callback) { |
| 425 VLOG(1) << object_path_.value() << ": Connecting to service: " | 421 VLOG(1) << object_path_.value() << ": Connecting to service: " |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 return static_cast<BluetoothAdapterChromeOS*>(adapter_); | 480 return static_cast<BluetoothAdapterChromeOS*>(adapter_); |
| 485 } | 481 } |
| 486 | 482 |
| 487 void BluetoothDeviceChromeOS::GattServiceAdded( | 483 void BluetoothDeviceChromeOS::GattServiceAdded( |
| 488 const dbus::ObjectPath& object_path) { | 484 const dbus::ObjectPath& object_path) { |
| 489 if (GetGattService(object_path.value())) { | 485 if (GetGattService(object_path.value())) { |
| 490 VLOG(1) << "Remote GATT service already exists: " << object_path.value(); | 486 VLOG(1) << "Remote GATT service already exists: " << object_path.value(); |
| 491 return; | 487 return; |
| 492 } | 488 } |
| 493 | 489 |
| 494 BluetoothGattServiceClient::Properties* properties = | 490 bluez::BluetoothGattServiceClient::Properties* properties = |
| 495 DBusThreadManager::Get()->GetBluetoothGattServiceClient()-> | 491 bluez::BluezDBusManager::Get() |
| 496 GetProperties(object_path); | 492 ->GetBluetoothGattServiceClient() |
| 493 ->GetProperties(object_path); |
| 497 DCHECK(properties); | 494 DCHECK(properties); |
| 498 if (properties->device.value() != object_path_) { | 495 if (properties->device.value() != object_path_) { |
| 499 VLOG(2) << "Remote GATT service does not belong to this device."; | 496 VLOG(2) << "Remote GATT service does not belong to this device."; |
| 500 return; | 497 return; |
| 501 } | 498 } |
| 502 | 499 |
| 503 VLOG(1) << "Adding new remote GATT service for device: " << GetAddress(); | 500 VLOG(1) << "Adding new remote GATT service for device: " << GetAddress(); |
| 504 | 501 |
| 505 BluetoothRemoteGattServiceChromeOS* service = | 502 BluetoothRemoteGattServiceChromeOS* service = |
| 506 new BluetoothRemoteGattServiceChromeOS(adapter(), this, object_path); | 503 new BluetoothRemoteGattServiceChromeOS(adapter(), this, object_path); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 << ": Failed to get connection info: " << error_name << ": " | 547 << ": Failed to get connection info: " << error_name << ": " |
| 551 << error_message; | 548 << error_message; |
| 552 callback.Run(ConnectionInfo()); | 549 callback.Run(ConnectionInfo()); |
| 553 } | 550 } |
| 554 | 551 |
| 555 void BluetoothDeviceChromeOS::ConnectInternal( | 552 void BluetoothDeviceChromeOS::ConnectInternal( |
| 556 bool after_pairing, | 553 bool after_pairing, |
| 557 const base::Closure& callback, | 554 const base::Closure& callback, |
| 558 const ConnectErrorCallback& error_callback) { | 555 const ConnectErrorCallback& error_callback) { |
| 559 VLOG(1) << object_path_.value() << ": Connecting"; | 556 VLOG(1) << object_path_.value() << ": Connecting"; |
| 560 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> | 557 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->Connect( |
| 561 Connect( | 558 object_path_, |
| 562 object_path_, | 559 base::Bind(&BluetoothDeviceChromeOS::OnConnect, |
| 563 base::Bind(&BluetoothDeviceChromeOS::OnConnect, | 560 weak_ptr_factory_.GetWeakPtr(), after_pairing, callback), |
| 564 weak_ptr_factory_.GetWeakPtr(), | 561 base::Bind(&BluetoothDeviceChromeOS::OnConnectError, |
| 565 after_pairing, | 562 weak_ptr_factory_.GetWeakPtr(), after_pairing, |
| 566 callback), | 563 error_callback)); |
| 567 base::Bind(&BluetoothDeviceChromeOS::OnConnectError, | |
| 568 weak_ptr_factory_.GetWeakPtr(), | |
| 569 after_pairing, | |
| 570 error_callback)); | |
| 571 } | 564 } |
| 572 | 565 |
| 573 void BluetoothDeviceChromeOS::OnConnect(bool after_pairing, | 566 void BluetoothDeviceChromeOS::OnConnect(bool after_pairing, |
| 574 const base::Closure& callback) { | 567 const base::Closure& callback) { |
| 575 if (--num_connecting_calls_ == 0) | 568 if (--num_connecting_calls_ == 0) |
| 576 adapter()->NotifyDeviceChanged(this); | 569 adapter()->NotifyDeviceChanged(this); |
| 577 | 570 |
| 578 DCHECK(num_connecting_calls_ >= 0); | 571 DCHECK(num_connecting_calls_ >= 0); |
| 579 VLOG(1) << object_path_.value() << ": Connected, " << num_connecting_calls_ | 572 VLOG(1) << object_path_.value() << ": Connected, " << num_connecting_calls_ |
| 580 << " still in progress"; | 573 << " still in progress"; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 const std::string& error_message) { | 669 const std::string& error_message) { |
| 677 LOG(WARNING) << object_path_.value() << ": Failed to cancel pairing: " | 670 LOG(WARNING) << object_path_.value() << ": Failed to cancel pairing: " |
| 678 << error_name << ": " << error_message; | 671 << error_name << ": " << error_message; |
| 679 } | 672 } |
| 680 | 673 |
| 681 void BluetoothDeviceChromeOS::SetTrusted() { | 674 void BluetoothDeviceChromeOS::SetTrusted() { |
| 682 // Unconditionally send the property change, rather than checking the value | 675 // Unconditionally send the property change, rather than checking the value |
| 683 // first; there's no harm in doing this and it solves any race conditions | 676 // first; there's no harm in doing this and it solves any race conditions |
| 684 // with the property becoming true or false and this call happening before | 677 // with the property becoming true or false and this call happening before |
| 685 // we get the D-Bus signal about the earlier change. | 678 // we get the D-Bus signal about the earlier change. |
| 686 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> | 679 bluez::BluezDBusManager::Get() |
| 687 GetProperties(object_path_)->trusted.Set( | 680 ->GetBluetoothDeviceClient() |
| 688 true, | 681 ->GetProperties(object_path_) |
| 689 base::Bind(&BluetoothDeviceChromeOS::OnSetTrusted, | 682 ->trusted.Set(true, base::Bind(&BluetoothDeviceChromeOS::OnSetTrusted, |
| 690 weak_ptr_factory_.GetWeakPtr())); | 683 weak_ptr_factory_.GetWeakPtr())); |
| 691 } | 684 } |
| 692 | 685 |
| 693 void BluetoothDeviceChromeOS::OnSetTrusted(bool success) { | 686 void BluetoothDeviceChromeOS::OnSetTrusted(bool success) { |
| 694 LOG_IF(WARNING, !success) << object_path_.value() | 687 LOG_IF(WARNING, !success) << object_path_.value() |
| 695 << ": Failed to set device as trusted"; | 688 << ": Failed to set device as trusted"; |
| 696 } | 689 } |
| 697 | 690 |
| 698 void BluetoothDeviceChromeOS::OnDisconnect(const base::Closure& callback) { | 691 void BluetoothDeviceChromeOS::OnDisconnect(const base::Closure& callback) { |
| 699 VLOG(1) << object_path_.value() << ": Disconnected"; | 692 VLOG(1) << object_path_.value() << ": Disconnected"; |
| 700 callback.Run(); | 693 callback.Run(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 712 void BluetoothDeviceChromeOS::OnForgetError( | 705 void BluetoothDeviceChromeOS::OnForgetError( |
| 713 const ErrorCallback& error_callback, | 706 const ErrorCallback& error_callback, |
| 714 const std::string& error_name, | 707 const std::string& error_name, |
| 715 const std::string& error_message) { | 708 const std::string& error_message) { |
| 716 LOG(WARNING) << object_path_.value() << ": Failed to remove device: " | 709 LOG(WARNING) << object_path_.value() << ": Failed to remove device: " |
| 717 << error_name << ": " << error_message; | 710 << error_name << ": " << error_message; |
| 718 error_callback.Run(); | 711 error_callback.Run(); |
| 719 } | 712 } |
| 720 | 713 |
| 721 } // namespace chromeos | 714 } // namespace chromeos |
| OLD | NEW |