| 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_bluez.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 "dbus/bus.h" | 14 #include "dbus/bus.h" |
| 15 #include "device/bluetooth/bluetooth_adapter_chromeos.h" | 15 #include "device/bluetooth/bluetooth_adapter_bluez.h" |
| 16 #include "device/bluetooth/bluetooth_gatt_connection_chromeos.h" | 16 #include "device/bluetooth/bluetooth_gatt_connection_bluez.h" |
| 17 #include "device/bluetooth/bluetooth_pairing_chromeos.h" | 17 #include "device/bluetooth/bluetooth_pairing_bluez.h" |
| 18 #include "device/bluetooth/bluetooth_remote_gatt_service_chromeos.h" | 18 #include "device/bluetooth/bluetooth_remote_gatt_service_bluez.h" |
| 19 #include "device/bluetooth/bluetooth_socket.h" | 19 #include "device/bluetooth/bluetooth_socket.h" |
| 20 #include "device/bluetooth/bluetooth_socket_chromeos.h" | 20 #include "device/bluetooth/bluetooth_socket_bluez.h" |
| 21 #include "device/bluetooth/bluetooth_socket_thread.h" | 21 #include "device/bluetooth/bluetooth_socket_thread.h" |
| 22 #include "device/bluetooth/bluetooth_uuid.h" | 22 #include "device/bluetooth/bluetooth_uuid.h" |
| 23 #include "device/bluetooth/dbus/bluetooth_adapter_client.h" | 23 #include "device/bluetooth/dbus/bluetooth_adapter_client.h" |
| 24 #include "device/bluetooth/dbus/bluetooth_device_client.h" | 24 #include "device/bluetooth/dbus/bluetooth_device_client.h" |
| 25 #include "device/bluetooth/dbus/bluetooth_gatt_service_client.h" | 25 #include "device/bluetooth/dbus/bluetooth_gatt_service_client.h" |
| 26 #include "device/bluetooth/dbus/bluetooth_input_client.h" | 26 #include "device/bluetooth/dbus/bluetooth_input_client.h" |
| 27 #include "device/bluetooth/dbus/bluez_dbus_manager.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; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 56 uint16* device_id) { | 56 uint16* device_id) { |
| 57 bluez::BluetoothDeviceClient::Properties* properties = | 57 bluez::BluetoothDeviceClient::Properties* properties = |
| 58 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( | 58 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
| 59 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", &vendor_value, |
| 67 &vendor_value, &product_value, &device_value) == 3) { | 67 &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", &vendor_value, |
| 70 &vendor_value, &product_value, &device_value) == 3) { | 70 &product_value, &device_value) == 3) { |
| 71 source_value = BluetoothDevice::VENDOR_ID_USB; | 71 source_value = BluetoothDevice::VENDOR_ID_USB; |
| 72 } else { | 72 } else { |
| 73 return; | 73 return; |
| 74 } | 74 } |
| 75 | 75 |
| 76 if (vendor_id_source != NULL) | 76 if (vendor_id_source != NULL) |
| 77 *vendor_id_source = source_value; | 77 *vendor_id_source = source_value; |
| 78 if (vendor_id != NULL) | 78 if (vendor_id != NULL) |
| 79 *vendor_id = vendor_value; | 79 *vendor_id = vendor_value; |
| 80 if (product_id != NULL) | 80 if (product_id != NULL) |
| (...skipping 23 matching lines...) Expand all Loading... |
| 104 case BluetoothDevice::ERROR_AUTH_TIMEOUT: | 104 case BluetoothDevice::ERROR_AUTH_TIMEOUT: |
| 105 pairing_result = UMA_PAIRING_RESULT_AUTH_TIMEOUT; | 105 pairing_result = UMA_PAIRING_RESULT_AUTH_TIMEOUT; |
| 106 break; | 106 break; |
| 107 case BluetoothDevice::ERROR_UNSUPPORTED_DEVICE: | 107 case BluetoothDevice::ERROR_UNSUPPORTED_DEVICE: |
| 108 pairing_result = UMA_PAIRING_RESULT_UNSUPPORTED_DEVICE; | 108 pairing_result = UMA_PAIRING_RESULT_UNSUPPORTED_DEVICE; |
| 109 break; | 109 break; |
| 110 default: | 110 default: |
| 111 pairing_result = UMA_PAIRING_RESULT_UNKNOWN_ERROR; | 111 pairing_result = UMA_PAIRING_RESULT_UNKNOWN_ERROR; |
| 112 } | 112 } |
| 113 | 113 |
| 114 UMA_HISTOGRAM_ENUMERATION("Bluetooth.PairingResult", | 114 UMA_HISTOGRAM_ENUMERATION("Bluetooth.PairingResult", pairing_result, |
| 115 pairing_result, | |
| 116 UMA_PAIRING_RESULT_COUNT); | 115 UMA_PAIRING_RESULT_COUNT); |
| 117 } | 116 } |
| 118 | 117 |
| 119 } // namespace | 118 } // namespace |
| 120 | 119 |
| 121 namespace chromeos { | 120 namespace bluez { |
| 122 | 121 |
| 123 BluetoothDeviceChromeOS::BluetoothDeviceChromeOS( | 122 BluetoothDeviceBlueZ::BluetoothDeviceBlueZ( |
| 124 BluetoothAdapterChromeOS* adapter, | 123 BluetoothAdapterBlueZ* adapter, |
| 125 const dbus::ObjectPath& object_path, | 124 const dbus::ObjectPath& object_path, |
| 126 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, | 125 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, |
| 127 scoped_refptr<device::BluetoothSocketThread> socket_thread) | 126 scoped_refptr<device::BluetoothSocketThread> socket_thread) |
| 128 : BluetoothDevice(adapter), | 127 : BluetoothDevice(adapter), |
| 129 object_path_(object_path), | 128 object_path_(object_path), |
| 130 num_connecting_calls_(0), | 129 num_connecting_calls_(0), |
| 131 connection_monitor_started_(false), | 130 connection_monitor_started_(false), |
| 132 ui_task_runner_(ui_task_runner), | 131 ui_task_runner_(ui_task_runner), |
| 133 socket_thread_(socket_thread), | 132 socket_thread_(socket_thread), |
| 134 weak_ptr_factory_(this) { | 133 weak_ptr_factory_(this) { |
| 135 bluez::BluezDBusManager::Get()->GetBluetoothGattServiceClient()->AddObserver( | 134 bluez::BluezDBusManager::Get()->GetBluetoothGattServiceClient()->AddObserver( |
| 136 this); | 135 this); |
| 137 | 136 |
| 138 // Add all known GATT services. | 137 // Add all known GATT services. |
| 139 const std::vector<dbus::ObjectPath> gatt_services = | 138 const std::vector<dbus::ObjectPath> gatt_services = |
| 140 bluez::BluezDBusManager::Get() | 139 bluez::BluezDBusManager::Get() |
| 141 ->GetBluetoothGattServiceClient() | 140 ->GetBluetoothGattServiceClient() |
| 142 ->GetServices(); | 141 ->GetServices(); |
| 143 for (std::vector<dbus::ObjectPath>::const_iterator it = gatt_services.begin(); | 142 for (std::vector<dbus::ObjectPath>::const_iterator it = gatt_services.begin(); |
| 144 it != gatt_services.end(); ++it) { | 143 it != gatt_services.end(); ++it) { |
| 145 GattServiceAdded(*it); | 144 GattServiceAdded(*it); |
| 146 } | 145 } |
| 147 } | 146 } |
| 148 | 147 |
| 149 BluetoothDeviceChromeOS::~BluetoothDeviceChromeOS() { | 148 BluetoothDeviceBlueZ::~BluetoothDeviceBlueZ() { |
| 150 bluez::BluezDBusManager::Get() | 149 bluez::BluezDBusManager::Get() |
| 151 ->GetBluetoothGattServiceClient() | 150 ->GetBluetoothGattServiceClient() |
| 152 ->RemoveObserver(this); | 151 ->RemoveObserver(this); |
| 153 | 152 |
| 154 // Copy the GATT services list here and clear the original so that when we | 153 // Copy the GATT services list here and clear the original so that when we |
| 155 // send GattServiceRemoved(), GetGattServices() returns no services. | 154 // send GattServiceRemoved(), GetGattServices() returns no services. |
| 156 GattServiceMap gatt_services = gatt_services_; | 155 GattServiceMap gatt_services = gatt_services_; |
| 157 gatt_services_.clear(); | 156 gatt_services_.clear(); |
| 158 for (GattServiceMap::iterator iter = gatt_services.begin(); | 157 for (GattServiceMap::iterator iter = gatt_services.begin(); |
| 159 iter != gatt_services.end(); ++iter) { | 158 iter != gatt_services.end(); ++iter) { |
| 160 DCHECK(adapter_); | 159 DCHECK(adapter_); |
| 161 adapter()->NotifyGattServiceRemoved( | 160 adapter()->NotifyGattServiceRemoved( |
| 162 static_cast<BluetoothRemoteGattServiceChromeOS*>(iter->second)); | 161 static_cast<BluetoothRemoteGattServiceBlueZ*>(iter->second)); |
| 163 delete iter->second; | 162 delete iter->second; |
| 164 } | 163 } |
| 165 } | 164 } |
| 166 | 165 |
| 167 uint32 BluetoothDeviceChromeOS::GetBluetoothClass() const { | 166 uint32 BluetoothDeviceBlueZ::GetBluetoothClass() const { |
| 168 bluez::BluetoothDeviceClient::Properties* properties = | 167 bluez::BluetoothDeviceClient::Properties* properties = |
| 169 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( | 168 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
| 170 object_path_); | 169 object_path_); |
| 171 DCHECK(properties); | 170 DCHECK(properties); |
| 172 | 171 |
| 173 return properties->bluetooth_class.value(); | 172 return properties->bluetooth_class.value(); |
| 174 } | 173 } |
| 175 | 174 |
| 176 std::string BluetoothDeviceChromeOS::GetDeviceName() const { | 175 std::string BluetoothDeviceBlueZ::GetDeviceName() const { |
| 177 bluez::BluetoothDeviceClient::Properties* properties = | 176 bluez::BluetoothDeviceClient::Properties* properties = |
| 178 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( | 177 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
| 179 object_path_); | 178 object_path_); |
| 180 DCHECK(properties); | 179 DCHECK(properties); |
| 181 | 180 |
| 182 return properties->alias.value(); | 181 return properties->alias.value(); |
| 183 } | 182 } |
| 184 | 183 |
| 185 void BluetoothDeviceChromeOS::CreateGattConnectionImpl() { | 184 void BluetoothDeviceBlueZ::CreateGattConnectionImpl() { |
| 186 // ChromeOS implementation does not use the default CreateGattConnection | 185 // BlueZ implementation does not use the default CreateGattConnection |
| 187 // implementation. | 186 // implementation. |
| 188 NOTIMPLEMENTED(); | 187 NOTIMPLEMENTED(); |
| 189 } | 188 } |
| 190 | 189 |
| 191 void BluetoothDeviceChromeOS::DisconnectGatt() { | 190 void BluetoothDeviceBlueZ::DisconnectGatt() { |
| 192 // ChromeOS implementation does not use the default CreateGattConnection | 191 // BlueZ implementation does not use the default CreateGattConnection |
| 193 // implementation. | 192 // implementation. |
| 194 NOTIMPLEMENTED(); | 193 NOTIMPLEMENTED(); |
| 195 } | 194 } |
| 196 | 195 |
| 197 std::string BluetoothDeviceChromeOS::GetAddress() const { | 196 std::string BluetoothDeviceBlueZ::GetAddress() const { |
| 198 bluez::BluetoothDeviceClient::Properties* properties = | 197 bluez::BluetoothDeviceClient::Properties* properties = |
| 199 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( | 198 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
| 200 object_path_); | 199 object_path_); |
| 201 DCHECK(properties); | 200 DCHECK(properties); |
| 202 | 201 |
| 203 return CanonicalizeAddress(properties->address.value()); | 202 return CanonicalizeAddress(properties->address.value()); |
| 204 } | 203 } |
| 205 | 204 |
| 206 BluetoothDevice::VendorIDSource | 205 BluetoothDevice::VendorIDSource BluetoothDeviceBlueZ::GetVendorIDSource() |
| 207 BluetoothDeviceChromeOS::GetVendorIDSource() const { | 206 const { |
| 208 VendorIDSource vendor_id_source = VENDOR_ID_UNKNOWN; | 207 VendorIDSource vendor_id_source = VENDOR_ID_UNKNOWN; |
| 209 ParseModalias(object_path_, &vendor_id_source, NULL, NULL, NULL); | 208 ParseModalias(object_path_, &vendor_id_source, NULL, NULL, NULL); |
| 210 return vendor_id_source; | 209 return vendor_id_source; |
| 211 } | 210 } |
| 212 | 211 |
| 213 uint16 BluetoothDeviceChromeOS::GetVendorID() const { | 212 uint16 BluetoothDeviceBlueZ::GetVendorID() const { |
| 214 uint16 vendor_id = 0; | 213 uint16 vendor_id = 0; |
| 215 ParseModalias(object_path_, NULL, &vendor_id, NULL, NULL); | 214 ParseModalias(object_path_, NULL, &vendor_id, NULL, NULL); |
| 216 return vendor_id; | 215 return vendor_id; |
| 217 } | 216 } |
| 218 | 217 |
| 219 uint16 BluetoothDeviceChromeOS::GetProductID() const { | 218 uint16 BluetoothDeviceBlueZ::GetProductID() const { |
| 220 uint16 product_id = 0; | 219 uint16 product_id = 0; |
| 221 ParseModalias(object_path_, NULL, NULL, &product_id, NULL); | 220 ParseModalias(object_path_, NULL, NULL, &product_id, NULL); |
| 222 return product_id; | 221 return product_id; |
| 223 } | 222 } |
| 224 | 223 |
| 225 uint16 BluetoothDeviceChromeOS::GetDeviceID() const { | 224 uint16 BluetoothDeviceBlueZ::GetDeviceID() const { |
| 226 uint16 device_id = 0; | 225 uint16 device_id = 0; |
| 227 ParseModalias(object_path_, NULL, NULL, NULL, &device_id); | 226 ParseModalias(object_path_, NULL, NULL, NULL, &device_id); |
| 228 return device_id; | 227 return device_id; |
| 229 } | 228 } |
| 230 | 229 |
| 231 bool BluetoothDeviceChromeOS::IsPaired() const { | 230 bool BluetoothDeviceBlueZ::IsPaired() const { |
| 232 bluez::BluetoothDeviceClient::Properties* properties = | 231 bluez::BluetoothDeviceClient::Properties* properties = |
| 233 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( | 232 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
| 234 object_path_); | 233 object_path_); |
| 235 DCHECK(properties); | 234 DCHECK(properties); |
| 236 | 235 |
| 237 // Trusted devices are devices that don't support pairing but that the | 236 // Trusted devices are devices that don't support pairing but that the |
| 238 // user has explicitly connected; it makes no sense for UI purposes to | 237 // user has explicitly connected; it makes no sense for UI purposes to |
| 239 // treat them differently from each other. | 238 // treat them differently from each other. |
| 240 return properties->paired.value() || properties->trusted.value(); | 239 return properties->paired.value() || properties->trusted.value(); |
| 241 } | 240 } |
| 242 | 241 |
| 243 bool BluetoothDeviceChromeOS::IsConnected() const { | 242 bool BluetoothDeviceBlueZ::IsConnected() const { |
| 244 bluez::BluetoothDeviceClient::Properties* properties = | 243 bluez::BluetoothDeviceClient::Properties* properties = |
| 245 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( | 244 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
| 246 object_path_); | 245 object_path_); |
| 247 DCHECK(properties); | 246 DCHECK(properties); |
| 248 | 247 |
| 249 return properties->connected.value(); | 248 return properties->connected.value(); |
| 250 } | 249 } |
| 251 | 250 |
| 252 bool BluetoothDeviceChromeOS::IsGattConnected() const { | 251 bool BluetoothDeviceBlueZ::IsGattConnected() const { |
| 253 NOTIMPLEMENTED(); | 252 NOTIMPLEMENTED(); |
| 254 return false; | 253 return false; |
| 255 } | 254 } |
| 256 | 255 |
| 257 bool BluetoothDeviceChromeOS::IsConnectable() const { | 256 bool BluetoothDeviceBlueZ::IsConnectable() const { |
| 258 bluez::BluetoothInputClient::Properties* input_properties = | 257 bluez::BluetoothInputClient::Properties* input_properties = |
| 259 bluez::BluezDBusManager::Get()->GetBluetoothInputClient()->GetProperties( | 258 bluez::BluezDBusManager::Get()->GetBluetoothInputClient()->GetProperties( |
| 260 object_path_); | 259 object_path_); |
| 261 // GetProperties returns NULL when the device does not implement the given | 260 // GetProperties returns NULL when the device does not implement the given |
| 262 // interface. Non HID devices are normally connectable. | 261 // interface. Non HID devices are normally connectable. |
| 263 if (!input_properties) | 262 if (!input_properties) |
| 264 return true; | 263 return true; |
| 265 | 264 |
| 266 return input_properties->reconnect_mode.value() != "device"; | 265 return input_properties->reconnect_mode.value() != "device"; |
| 267 } | 266 } |
| 268 | 267 |
| 269 bool BluetoothDeviceChromeOS::IsConnecting() const { | 268 bool BluetoothDeviceBlueZ::IsConnecting() const { |
| 270 return num_connecting_calls_ > 0; | 269 return num_connecting_calls_ > 0; |
| 271 } | 270 } |
| 272 | 271 |
| 273 BluetoothDeviceChromeOS::UUIDList BluetoothDeviceChromeOS::GetUUIDs() const { | 272 BluetoothDeviceBlueZ::UUIDList BluetoothDeviceBlueZ::GetUUIDs() const { |
| 274 bluez::BluetoothDeviceClient::Properties* properties = | 273 bluez::BluetoothDeviceClient::Properties* properties = |
| 275 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( | 274 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
| 276 object_path_); | 275 object_path_); |
| 277 DCHECK(properties); | 276 DCHECK(properties); |
| 278 | 277 |
| 279 std::vector<device::BluetoothUUID> uuids; | 278 std::vector<device::BluetoothUUID> uuids; |
| 280 const std::vector<std::string> &dbus_uuids = properties->uuids.value(); | 279 const std::vector<std::string>& dbus_uuids = properties->uuids.value(); |
| 281 for (std::vector<std::string>::const_iterator iter = dbus_uuids.begin(); | 280 for (std::vector<std::string>::const_iterator iter = dbus_uuids.begin(); |
| 282 iter != dbus_uuids.end(); ++iter) { | 281 iter != dbus_uuids.end(); ++iter) { |
| 283 device::BluetoothUUID uuid(*iter); | 282 device::BluetoothUUID uuid(*iter); |
| 284 DCHECK(uuid.IsValid()); | 283 DCHECK(uuid.IsValid()); |
| 285 uuids.push_back(uuid); | 284 uuids.push_back(uuid); |
| 286 } | 285 } |
| 287 return uuids; | 286 return uuids; |
| 288 } | 287 } |
| 289 | 288 |
| 290 int16 BluetoothDeviceChromeOS::GetInquiryRSSI() const { | 289 int16 BluetoothDeviceBlueZ::GetInquiryRSSI() const { |
| 291 bluez::BluetoothDeviceClient::Properties* properties = | 290 bluez::BluetoothDeviceClient::Properties* properties = |
| 292 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( | 291 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
| 293 object_path_); | 292 object_path_); |
| 294 DCHECK(properties); | 293 DCHECK(properties); |
| 295 | 294 |
| 296 if (!properties->rssi.is_valid()) | 295 if (!properties->rssi.is_valid()) |
| 297 return kUnknownPower; | 296 return kUnknownPower; |
| 298 | 297 |
| 299 return properties->rssi.value(); | 298 return properties->rssi.value(); |
| 300 } | 299 } |
| 301 | 300 |
| 302 int16 BluetoothDeviceChromeOS::GetInquiryTxPower() const { | 301 int16 BluetoothDeviceBlueZ::GetInquiryTxPower() const { |
| 303 bluez::BluetoothDeviceClient::Properties* properties = | 302 bluez::BluetoothDeviceClient::Properties* properties = |
| 304 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( | 303 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
| 305 object_path_); | 304 object_path_); |
| 306 DCHECK(properties); | 305 DCHECK(properties); |
| 307 | 306 |
| 308 if (!properties->tx_power.is_valid()) | 307 if (!properties->tx_power.is_valid()) |
| 309 return kUnknownPower; | 308 return kUnknownPower; |
| 310 | 309 |
| 311 return properties->tx_power.value(); | 310 return properties->tx_power.value(); |
| 312 } | 311 } |
| 313 | 312 |
| 314 bool BluetoothDeviceChromeOS::ExpectingPinCode() const { | 313 bool BluetoothDeviceBlueZ::ExpectingPinCode() const { |
| 315 return pairing_.get() && pairing_->ExpectingPinCode(); | 314 return pairing_.get() && pairing_->ExpectingPinCode(); |
| 316 } | 315 } |
| 317 | 316 |
| 318 bool BluetoothDeviceChromeOS::ExpectingPasskey() const { | 317 bool BluetoothDeviceBlueZ::ExpectingPasskey() const { |
| 319 return pairing_.get() && pairing_->ExpectingPasskey(); | 318 return pairing_.get() && pairing_->ExpectingPasskey(); |
| 320 } | 319 } |
| 321 | 320 |
| 322 bool BluetoothDeviceChromeOS::ExpectingConfirmation() const { | 321 bool BluetoothDeviceBlueZ::ExpectingConfirmation() const { |
| 323 return pairing_.get() && pairing_->ExpectingConfirmation(); | 322 return pairing_.get() && pairing_->ExpectingConfirmation(); |
| 324 } | 323 } |
| 325 | 324 |
| 326 void BluetoothDeviceChromeOS::GetConnectionInfo( | 325 void BluetoothDeviceBlueZ::GetConnectionInfo( |
| 327 const ConnectionInfoCallback& callback) { | 326 const ConnectionInfoCallback& callback) { |
| 328 // DBus method call should gracefully return an error if the device is not | 327 // DBus method call should gracefully return an error if the device is not |
| 329 // currently connected. | 328 // currently connected. |
| 330 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetConnInfo( | 329 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetConnInfo( |
| 331 object_path_, base::Bind(&BluetoothDeviceChromeOS::OnGetConnInfo, | 330 object_path_, base::Bind(&BluetoothDeviceBlueZ::OnGetConnInfo, |
| 332 weak_ptr_factory_.GetWeakPtr(), callback), | 331 weak_ptr_factory_.GetWeakPtr(), callback), |
| 333 base::Bind(&BluetoothDeviceChromeOS::OnGetConnInfoError, | 332 base::Bind(&BluetoothDeviceBlueZ::OnGetConnInfoError, |
| 334 weak_ptr_factory_.GetWeakPtr(), callback)); | 333 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 335 } | 334 } |
| 336 | 335 |
| 337 void BluetoothDeviceChromeOS::Connect( | 336 void BluetoothDeviceBlueZ::Connect( |
| 338 BluetoothDevice::PairingDelegate* pairing_delegate, | 337 BluetoothDevice::PairingDelegate* pairing_delegate, |
| 339 const base::Closure& callback, | 338 const base::Closure& callback, |
| 340 const ConnectErrorCallback& error_callback) { | 339 const ConnectErrorCallback& error_callback) { |
| 341 if (num_connecting_calls_++ == 0) | 340 if (num_connecting_calls_++ == 0) |
| 342 adapter()->NotifyDeviceChanged(this); | 341 adapter()->NotifyDeviceChanged(this); |
| 343 | 342 |
| 344 VLOG(1) << object_path_.value() << ": Connecting, " << num_connecting_calls_ | 343 VLOG(1) << object_path_.value() << ": Connecting, " << num_connecting_calls_ |
| 345 << " in progress"; | 344 << " in progress"; |
| 346 | 345 |
| 347 if (IsPaired() || !pairing_delegate || !IsPairable()) { | 346 if (IsPaired() || !pairing_delegate || !IsPairable()) { |
| 348 // No need to pair, or unable to, skip straight to connection. | 347 // No need to pair, or unable to, skip straight to connection. |
| 349 ConnectInternal(false, callback, error_callback); | 348 ConnectInternal(false, callback, error_callback); |
| 350 } else { | 349 } else { |
| 351 // Initiate high-security connection with pairing. | 350 // Initiate high-security connection with pairing. |
| 352 BeginPairing(pairing_delegate); | 351 BeginPairing(pairing_delegate); |
| 353 | 352 |
| 354 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->Pair( | 353 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->Pair( |
| 355 object_path_, | 354 object_path_, |
| 356 base::Bind(&BluetoothDeviceChromeOS::OnPair, | 355 base::Bind(&BluetoothDeviceBlueZ::OnPair, |
| 357 weak_ptr_factory_.GetWeakPtr(), callback, error_callback), | 356 weak_ptr_factory_.GetWeakPtr(), callback, error_callback), |
| 358 base::Bind(&BluetoothDeviceChromeOS::OnPairError, | 357 base::Bind(&BluetoothDeviceBlueZ::OnPairError, |
| 359 weak_ptr_factory_.GetWeakPtr(), error_callback)); | 358 weak_ptr_factory_.GetWeakPtr(), error_callback)); |
| 360 } | 359 } |
| 361 } | 360 } |
| 362 | 361 |
| 363 void BluetoothDeviceChromeOS::SetPinCode(const std::string& pincode) { | 362 void BluetoothDeviceBlueZ::SetPinCode(const std::string& pincode) { |
| 364 if (!pairing_.get()) | 363 if (!pairing_.get()) |
| 365 return; | 364 return; |
| 366 | 365 |
| 367 pairing_->SetPinCode(pincode); | 366 pairing_->SetPinCode(pincode); |
| 368 } | 367 } |
| 369 | 368 |
| 370 void BluetoothDeviceChromeOS::SetPasskey(uint32 passkey) { | 369 void BluetoothDeviceBlueZ::SetPasskey(uint32 passkey) { |
| 371 if (!pairing_.get()) | 370 if (!pairing_.get()) |
| 372 return; | 371 return; |
| 373 | 372 |
| 374 pairing_->SetPasskey(passkey); | 373 pairing_->SetPasskey(passkey); |
| 375 } | 374 } |
| 376 | 375 |
| 377 void BluetoothDeviceChromeOS::ConfirmPairing() { | 376 void BluetoothDeviceBlueZ::ConfirmPairing() { |
| 378 if (!pairing_.get()) | 377 if (!pairing_.get()) |
| 379 return; | 378 return; |
| 380 | 379 |
| 381 pairing_->ConfirmPairing(); | 380 pairing_->ConfirmPairing(); |
| 382 } | 381 } |
| 383 | 382 |
| 384 void BluetoothDeviceChromeOS::RejectPairing() { | 383 void BluetoothDeviceBlueZ::RejectPairing() { |
| 385 if (!pairing_.get()) | 384 if (!pairing_.get()) |
| 386 return; | 385 return; |
| 387 | 386 |
| 388 pairing_->RejectPairing(); | 387 pairing_->RejectPairing(); |
| 389 } | 388 } |
| 390 | 389 |
| 391 void BluetoothDeviceChromeOS::CancelPairing() { | 390 void BluetoothDeviceBlueZ::CancelPairing() { |
| 392 bool canceled = false; | 391 bool canceled = false; |
| 393 | 392 |
| 394 // If there is a callback in progress that we can reply to then use that | 393 // If there is a callback in progress that we can reply to then use that |
| 395 // to cancel the current pairing request. | 394 // to cancel the current pairing request. |
| 396 if (pairing_.get() && pairing_->CancelPairing()) | 395 if (pairing_.get() && pairing_->CancelPairing()) |
| 397 canceled = true; | 396 canceled = true; |
| 398 | 397 |
| 399 // If not we have to send an explicit CancelPairing() to the device instead. | 398 // If not we have to send an explicit CancelPairing() to the device instead. |
| 400 if (!canceled) { | 399 if (!canceled) { |
| 401 VLOG(1) << object_path_.value() << ": No pairing context or callback. " | 400 VLOG(1) << object_path_.value() << ": No pairing context or callback. " |
| 402 << "Sending explicit cancel"; | 401 << "Sending explicit cancel"; |
| 403 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->CancelPairing( | 402 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->CancelPairing( |
| 404 object_path_, base::Bind(&base::DoNothing), | 403 object_path_, base::Bind(&base::DoNothing), |
| 405 base::Bind(&BluetoothDeviceChromeOS::OnCancelPairingError, | 404 base::Bind(&BluetoothDeviceBlueZ::OnCancelPairingError, |
| 406 weak_ptr_factory_.GetWeakPtr())); | 405 weak_ptr_factory_.GetWeakPtr())); |
| 407 } | 406 } |
| 408 | 407 |
| 409 // Since there is no callback to this method it's possible that the pairing | 408 // Since there is no callback to this method it's possible that the pairing |
| 410 // delegate is going to be freed before things complete (indeed it's | 409 // delegate is going to be freed before things complete (indeed it's |
| 411 // documented that this is the method you should call while freeing the | 410 // documented that this is the method you should call while freeing the |
| 412 // pairing delegate), so clear our the context holding on to it. | 411 // pairing delegate), so clear our the context holding on to it. |
| 413 EndPairing(); | 412 EndPairing(); |
| 414 } | 413 } |
| 415 | 414 |
| 416 void BluetoothDeviceChromeOS::Disconnect(const base::Closure& callback, | 415 void BluetoothDeviceBlueZ::Disconnect(const base::Closure& callback, |
| 417 const ErrorCallback& error_callback) { | 416 const ErrorCallback& error_callback) { |
| 418 VLOG(1) << object_path_.value() << ": Disconnecting"; | 417 VLOG(1) << object_path_.value() << ": Disconnecting"; |
| 419 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->Disconnect( | 418 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->Disconnect( |
| 420 object_path_, base::Bind(&BluetoothDeviceChromeOS::OnDisconnect, | 419 object_path_, base::Bind(&BluetoothDeviceBlueZ::OnDisconnect, |
| 421 weak_ptr_factory_.GetWeakPtr(), callback), | 420 weak_ptr_factory_.GetWeakPtr(), callback), |
| 422 base::Bind(&BluetoothDeviceChromeOS::OnDisconnectError, | 421 base::Bind(&BluetoothDeviceBlueZ::OnDisconnectError, |
| 423 weak_ptr_factory_.GetWeakPtr(), error_callback)); | 422 weak_ptr_factory_.GetWeakPtr(), error_callback)); |
| 424 } | 423 } |
| 425 | 424 |
| 426 void BluetoothDeviceChromeOS::Forget(const ErrorCallback& error_callback) { | 425 void BluetoothDeviceBlueZ::Forget(const ErrorCallback& error_callback) { |
| 427 VLOG(1) << object_path_.value() << ": Removing device"; | 426 VLOG(1) << object_path_.value() << ": Removing device"; |
| 428 bluez::BluezDBusManager::Get()->GetBluetoothAdapterClient()->RemoveDevice( | 427 bluez::BluezDBusManager::Get()->GetBluetoothAdapterClient()->RemoveDevice( |
| 429 adapter()->object_path(), object_path_, base::Bind(&base::DoNothing), | 428 adapter()->object_path(), object_path_, base::Bind(&base::DoNothing), |
| 430 base::Bind(&BluetoothDeviceChromeOS::OnForgetError, | 429 base::Bind(&BluetoothDeviceBlueZ::OnForgetError, |
| 431 weak_ptr_factory_.GetWeakPtr(), error_callback)); | 430 weak_ptr_factory_.GetWeakPtr(), error_callback)); |
| 432 } | 431 } |
| 433 | 432 |
| 434 void BluetoothDeviceChromeOS::ConnectToService( | 433 void BluetoothDeviceBlueZ::ConnectToService( |
| 435 const BluetoothUUID& uuid, | 434 const BluetoothUUID& uuid, |
| 436 const ConnectToServiceCallback& callback, | 435 const ConnectToServiceCallback& callback, |
| 437 const ConnectToServiceErrorCallback& error_callback) { | 436 const ConnectToServiceErrorCallback& error_callback) { |
| 438 VLOG(1) << object_path_.value() << ": Connecting to service: " | 437 VLOG(1) << object_path_.value() |
| 439 << uuid.canonical_value(); | 438 << ": Connecting to service: " << uuid.canonical_value(); |
| 440 scoped_refptr<BluetoothSocketChromeOS> socket = | 439 scoped_refptr<BluetoothSocketBlueZ> socket = |
| 441 BluetoothSocketChromeOS::CreateBluetoothSocket( | 440 BluetoothSocketBlueZ::CreateBluetoothSocket(ui_task_runner_, |
| 442 ui_task_runner_, socket_thread_); | 441 socket_thread_); |
| 443 socket->Connect(this, uuid, BluetoothSocketChromeOS::SECURITY_LEVEL_MEDIUM, | 442 socket->Connect(this, uuid, BluetoothSocketBlueZ::SECURITY_LEVEL_MEDIUM, |
| 444 base::Bind(callback, socket), error_callback); | 443 base::Bind(callback, socket), error_callback); |
| 445 } | 444 } |
| 446 | 445 |
| 447 void BluetoothDeviceChromeOS::ConnectToServiceInsecurely( | 446 void BluetoothDeviceBlueZ::ConnectToServiceInsecurely( |
| 448 const BluetoothUUID& uuid, | 447 const BluetoothUUID& uuid, |
| 449 const ConnectToServiceCallback& callback, | 448 const ConnectToServiceCallback& callback, |
| 450 const ConnectToServiceErrorCallback& error_callback) { | 449 const ConnectToServiceErrorCallback& error_callback) { |
| 451 VLOG(1) << object_path_.value() << ": Connecting insecurely to service: " | 450 VLOG(1) << object_path_.value() |
| 452 << uuid.canonical_value(); | 451 << ": Connecting insecurely to service: " << uuid.canonical_value(); |
| 453 scoped_refptr<BluetoothSocketChromeOS> socket = | 452 scoped_refptr<BluetoothSocketBlueZ> socket = |
| 454 BluetoothSocketChromeOS::CreateBluetoothSocket( | 453 BluetoothSocketBlueZ::CreateBluetoothSocket(ui_task_runner_, |
| 455 ui_task_runner_, socket_thread_); | 454 socket_thread_); |
| 456 socket->Connect(this, uuid, BluetoothSocketChromeOS::SECURITY_LEVEL_LOW, | 455 socket->Connect(this, uuid, BluetoothSocketBlueZ::SECURITY_LEVEL_LOW, |
| 457 base::Bind(callback, socket), error_callback); | 456 base::Bind(callback, socket), error_callback); |
| 458 } | 457 } |
| 459 | 458 |
| 460 void BluetoothDeviceChromeOS::CreateGattConnection( | 459 void BluetoothDeviceBlueZ::CreateGattConnection( |
| 461 const GattConnectionCallback& callback, | 460 const GattConnectionCallback& callback, |
| 462 const ConnectErrorCallback& error_callback) { | 461 const ConnectErrorCallback& error_callback) { |
| 463 // TODO(sacomoto): Workaround to retrieve the connection for already connected | 462 // TODO(sacomoto): Workaround to retrieve the connection for already connected |
| 464 // devices. Currently, BluetoothGattConnection::Disconnect doesn't do | 463 // devices. Currently, BluetoothGattConnection::Disconnect doesn't do |
| 465 // anything, the unique underlying physical GATT connection is kept. This | 464 // anything, the unique underlying physical GATT connection is kept. This |
| 466 // should be removed once the correct behavour is implemented and the GATT | 465 // should be removed once the correct behavour is implemented and the GATT |
| 467 // connections are reference counted (see todo below). | 466 // connections are reference counted (see todo below). |
| 468 if (IsConnected()) { | 467 if (IsConnected()) { |
| 469 OnCreateGattConnection(callback); | 468 OnCreateGattConnection(callback); |
| 470 return; | 469 return; |
| 471 } | 470 } |
| 472 | 471 |
| 473 // TODO(armansito): Until there is a way to create a reference counted GATT | 472 // TODO(armansito): Until there is a way to create a reference counted GATT |
| 474 // connection in bluetoothd, simply do a regular connect. | 473 // connection in bluetoothd, simply do a regular connect. |
| 475 Connect(NULL, | 474 Connect(NULL, base::Bind(&BluetoothDeviceBlueZ::OnCreateGattConnection, |
| 476 base::Bind(&BluetoothDeviceChromeOS::OnCreateGattConnection, | 475 weak_ptr_factory_.GetWeakPtr(), callback), |
| 477 weak_ptr_factory_.GetWeakPtr(), | |
| 478 callback), | |
| 479 error_callback); | 476 error_callback); |
| 480 } | 477 } |
| 481 | 478 |
| 482 BluetoothPairingChromeOS* BluetoothDeviceChromeOS::BeginPairing( | 479 BluetoothPairingBlueZ* BluetoothDeviceBlueZ::BeginPairing( |
| 483 BluetoothDevice::PairingDelegate* pairing_delegate) { | 480 BluetoothDevice::PairingDelegate* pairing_delegate) { |
| 484 pairing_.reset(new BluetoothPairingChromeOS(this, pairing_delegate)); | 481 pairing_.reset(new BluetoothPairingBlueZ(this, pairing_delegate)); |
| 485 return pairing_.get(); | 482 return pairing_.get(); |
| 486 } | 483 } |
| 487 | 484 |
| 488 void BluetoothDeviceChromeOS::EndPairing() { | 485 void BluetoothDeviceBlueZ::EndPairing() { |
| 489 pairing_.reset(); | 486 pairing_.reset(); |
| 490 } | 487 } |
| 491 | 488 |
| 492 BluetoothPairingChromeOS* BluetoothDeviceChromeOS::GetPairing() const { | 489 BluetoothPairingBlueZ* BluetoothDeviceBlueZ::GetPairing() const { |
| 493 return pairing_.get(); | 490 return pairing_.get(); |
| 494 } | 491 } |
| 495 | 492 |
| 496 BluetoothAdapterChromeOS* BluetoothDeviceChromeOS::adapter() const { | 493 BluetoothAdapterBlueZ* BluetoothDeviceBlueZ::adapter() const { |
| 497 return static_cast<BluetoothAdapterChromeOS*>(adapter_); | 494 return static_cast<BluetoothAdapterBlueZ*>(adapter_); |
| 498 } | 495 } |
| 499 | 496 |
| 500 void BluetoothDeviceChromeOS::GattServiceAdded( | 497 void BluetoothDeviceBlueZ::GattServiceAdded( |
| 501 const dbus::ObjectPath& object_path) { | 498 const dbus::ObjectPath& object_path) { |
| 502 if (GetGattService(object_path.value())) { | 499 if (GetGattService(object_path.value())) { |
| 503 VLOG(1) << "Remote GATT service already exists: " << object_path.value(); | 500 VLOG(1) << "Remote GATT service already exists: " << object_path.value(); |
| 504 return; | 501 return; |
| 505 } | 502 } |
| 506 | 503 |
| 507 bluez::BluetoothGattServiceClient::Properties* properties = | 504 bluez::BluetoothGattServiceClient::Properties* properties = |
| 508 bluez::BluezDBusManager::Get() | 505 bluez::BluezDBusManager::Get() |
| 509 ->GetBluetoothGattServiceClient() | 506 ->GetBluetoothGattServiceClient() |
| 510 ->GetProperties(object_path); | 507 ->GetProperties(object_path); |
| 511 DCHECK(properties); | 508 DCHECK(properties); |
| 512 if (properties->device.value() != object_path_) { | 509 if (properties->device.value() != object_path_) { |
| 513 VLOG(2) << "Remote GATT service does not belong to this device."; | 510 VLOG(2) << "Remote GATT service does not belong to this device."; |
| 514 return; | 511 return; |
| 515 } | 512 } |
| 516 | 513 |
| 517 VLOG(1) << "Adding new remote GATT service for device: " << GetAddress(); | 514 VLOG(1) << "Adding new remote GATT service for device: " << GetAddress(); |
| 518 | 515 |
| 519 BluetoothRemoteGattServiceChromeOS* service = | 516 BluetoothRemoteGattServiceBlueZ* service = |
| 520 new BluetoothRemoteGattServiceChromeOS(adapter(), this, object_path); | 517 new BluetoothRemoteGattServiceBlueZ(adapter(), this, object_path); |
| 521 | 518 |
| 522 gatt_services_[service->GetIdentifier()] = service; | 519 gatt_services_[service->GetIdentifier()] = service; |
| 523 DCHECK(service->object_path() == object_path); | 520 DCHECK(service->object_path() == object_path); |
| 524 DCHECK(service->GetUUID().IsValid()); | 521 DCHECK(service->GetUUID().IsValid()); |
| 525 | 522 |
| 526 DCHECK(adapter_); | 523 DCHECK(adapter_); |
| 527 adapter()->NotifyGattServiceAdded(service); | 524 adapter()->NotifyGattServiceAdded(service); |
| 528 } | 525 } |
| 529 | 526 |
| 530 void BluetoothDeviceChromeOS::GattServiceRemoved( | 527 void BluetoothDeviceBlueZ::GattServiceRemoved( |
| 531 const dbus::ObjectPath& object_path) { | 528 const dbus::ObjectPath& object_path) { |
| 532 GattServiceMap::iterator iter = gatt_services_.find(object_path.value()); | 529 GattServiceMap::iterator iter = gatt_services_.find(object_path.value()); |
| 533 if (iter == gatt_services_.end()) { | 530 if (iter == gatt_services_.end()) { |
| 534 VLOG(3) << "Unknown GATT service removed: " << object_path.value(); | 531 VLOG(3) << "Unknown GATT service removed: " << object_path.value(); |
| 535 return; | 532 return; |
| 536 } | 533 } |
| 537 | 534 |
| 538 BluetoothRemoteGattServiceChromeOS* service = | 535 BluetoothRemoteGattServiceBlueZ* service = |
| 539 static_cast<BluetoothRemoteGattServiceChromeOS*>(iter->second); | 536 static_cast<BluetoothRemoteGattServiceBlueZ*>(iter->second); |
| 540 | 537 |
| 541 VLOG(1) << "Removing remote GATT service with UUID: '" | 538 VLOG(1) << "Removing remote GATT service with UUID: '" |
| 542 << service->GetUUID().canonical_value() | 539 << service->GetUUID().canonical_value() |
| 543 << "' from device: " << GetAddress(); | 540 << "' from device: " << GetAddress(); |
| 544 | 541 |
| 545 DCHECK(service->object_path() == object_path); | 542 DCHECK(service->object_path() == object_path); |
| 546 gatt_services_.erase(iter); | 543 gatt_services_.erase(iter); |
| 547 | 544 |
| 548 DCHECK(adapter_); | 545 DCHECK(adapter_); |
| 549 adapter()->NotifyGattServiceRemoved(service); | 546 adapter()->NotifyGattServiceRemoved(service); |
| 550 | 547 |
| 551 delete service; | 548 delete service; |
| 552 } | 549 } |
| 553 | 550 |
| 554 void BluetoothDeviceChromeOS::OnGetConnInfo( | 551 void BluetoothDeviceBlueZ::OnGetConnInfo(const ConnectionInfoCallback& callback, |
| 555 const ConnectionInfoCallback& callback, | 552 int16 rssi, |
| 556 int16 rssi, | 553 int16 transmit_power, |
| 557 int16 transmit_power, | 554 int16 max_transmit_power) { |
| 558 int16 max_transmit_power) { | |
| 559 callback.Run(ConnectionInfo(rssi, transmit_power, max_transmit_power)); | 555 callback.Run(ConnectionInfo(rssi, transmit_power, max_transmit_power)); |
| 560 } | 556 } |
| 561 | 557 |
| 562 void BluetoothDeviceChromeOS::OnGetConnInfoError( | 558 void BluetoothDeviceBlueZ::OnGetConnInfoError( |
| 563 const ConnectionInfoCallback& callback, | 559 const ConnectionInfoCallback& callback, |
| 564 const std::string& error_name, | 560 const std::string& error_name, |
| 565 const std::string& error_message) { | 561 const std::string& error_message) { |
| 566 LOG(WARNING) << object_path_.value() | 562 LOG(WARNING) << object_path_.value() |
| 567 << ": Failed to get connection info: " << error_name << ": " | 563 << ": Failed to get connection info: " << error_name << ": " |
| 568 << error_message; | 564 << error_message; |
| 569 callback.Run(ConnectionInfo()); | 565 callback.Run(ConnectionInfo()); |
| 570 } | 566 } |
| 571 | 567 |
| 572 void BluetoothDeviceChromeOS::ConnectInternal( | 568 void BluetoothDeviceBlueZ::ConnectInternal( |
| 573 bool after_pairing, | 569 bool after_pairing, |
| 574 const base::Closure& callback, | 570 const base::Closure& callback, |
| 575 const ConnectErrorCallback& error_callback) { | 571 const ConnectErrorCallback& error_callback) { |
| 576 VLOG(1) << object_path_.value() << ": Connecting"; | 572 VLOG(1) << object_path_.value() << ": Connecting"; |
| 577 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->Connect( | 573 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->Connect( |
| 578 object_path_, | 574 object_path_, |
| 579 base::Bind(&BluetoothDeviceChromeOS::OnConnect, | 575 base::Bind(&BluetoothDeviceBlueZ::OnConnect, |
| 580 weak_ptr_factory_.GetWeakPtr(), after_pairing, callback), | 576 weak_ptr_factory_.GetWeakPtr(), after_pairing, callback), |
| 581 base::Bind(&BluetoothDeviceChromeOS::OnConnectError, | 577 base::Bind(&BluetoothDeviceBlueZ::OnConnectError, |
| 582 weak_ptr_factory_.GetWeakPtr(), after_pairing, | 578 weak_ptr_factory_.GetWeakPtr(), after_pairing, |
| 583 error_callback)); | 579 error_callback)); |
| 584 } | 580 } |
| 585 | 581 |
| 586 void BluetoothDeviceChromeOS::OnConnect(bool after_pairing, | 582 void BluetoothDeviceBlueZ::OnConnect(bool after_pairing, |
| 587 const base::Closure& callback) { | 583 const base::Closure& callback) { |
| 588 if (--num_connecting_calls_ == 0) | 584 if (--num_connecting_calls_ == 0) |
| 589 adapter()->NotifyDeviceChanged(this); | 585 adapter()->NotifyDeviceChanged(this); |
| 590 | 586 |
| 591 DCHECK(num_connecting_calls_ >= 0); | 587 DCHECK(num_connecting_calls_ >= 0); |
| 592 VLOG(1) << object_path_.value() << ": Connected, " << num_connecting_calls_ | 588 VLOG(1) << object_path_.value() << ": Connected, " << num_connecting_calls_ |
| 593 << " still in progress"; | 589 << " still in progress"; |
| 594 | 590 |
| 595 SetTrusted(); | 591 SetTrusted(); |
| 596 | 592 |
| 597 if (after_pairing) | 593 if (after_pairing) |
| 598 UMA_HISTOGRAM_ENUMERATION("Bluetooth.PairingResult", | 594 UMA_HISTOGRAM_ENUMERATION("Bluetooth.PairingResult", |
| 599 UMA_PAIRING_RESULT_SUCCESS, | 595 UMA_PAIRING_RESULT_SUCCESS, |
| 600 UMA_PAIRING_RESULT_COUNT); | 596 UMA_PAIRING_RESULT_COUNT); |
| 601 | 597 |
| 602 callback.Run(); | 598 callback.Run(); |
| 603 } | 599 } |
| 604 | 600 |
| 605 void BluetoothDeviceChromeOS::OnCreateGattConnection( | 601 void BluetoothDeviceBlueZ::OnCreateGattConnection( |
| 606 const GattConnectionCallback& callback) { | 602 const GattConnectionCallback& callback) { |
| 607 scoped_ptr<device::BluetoothGattConnection> conn( | 603 scoped_ptr<device::BluetoothGattConnection> conn( |
| 608 new BluetoothGattConnectionChromeOS( | 604 new BluetoothGattConnectionBlueZ(adapter_, GetAddress(), object_path_)); |
| 609 adapter_, GetAddress(), object_path_)); | |
| 610 callback.Run(conn.Pass()); | 605 callback.Run(conn.Pass()); |
| 611 } | 606 } |
| 612 | 607 |
| 613 void BluetoothDeviceChromeOS::OnConnectError( | 608 void BluetoothDeviceBlueZ::OnConnectError( |
| 614 bool after_pairing, | 609 bool after_pairing, |
| 615 const ConnectErrorCallback& error_callback, | 610 const ConnectErrorCallback& error_callback, |
| 616 const std::string& error_name, | 611 const std::string& error_name, |
| 617 const std::string& error_message) { | 612 const std::string& error_message) { |
| 618 if (--num_connecting_calls_ == 0) | 613 if (--num_connecting_calls_ == 0) |
| 619 adapter()->NotifyDeviceChanged(this); | 614 adapter()->NotifyDeviceChanged(this); |
| 620 | 615 |
| 621 DCHECK(num_connecting_calls_ >= 0); | 616 DCHECK(num_connecting_calls_ >= 0); |
| 622 LOG(WARNING) << object_path_.value() << ": Failed to connect device: " | 617 LOG(WARNING) << object_path_.value() |
| 623 << error_name << ": " << error_message; | 618 << ": Failed to connect device: " << error_name << ": " |
| 619 << error_message; |
| 624 VLOG(1) << object_path_.value() << ": " << num_connecting_calls_ | 620 VLOG(1) << object_path_.value() << ": " << num_connecting_calls_ |
| 625 << " still in progress"; | 621 << " still in progress"; |
| 626 | 622 |
| 627 // Determine the error code from error_name. | 623 // Determine the error code from error_name. |
| 628 ConnectErrorCode error_code = ERROR_UNKNOWN; | 624 ConnectErrorCode error_code = ERROR_UNKNOWN; |
| 629 if (error_name == bluetooth_device::kErrorFailed) { | 625 if (error_name == bluetooth_device::kErrorFailed) { |
| 630 error_code = ERROR_FAILED; | 626 error_code = ERROR_FAILED; |
| 631 } else if (error_name == bluetooth_device::kErrorInProgress) { | 627 } else if (error_name == bluetooth_device::kErrorInProgress) { |
| 632 error_code = ERROR_INPROGRESS; | 628 error_code = ERROR_INPROGRESS; |
| 633 } else if (error_name == bluetooth_device::kErrorNotSupported) { | 629 } else if (error_name == bluetooth_device::kErrorNotSupported) { |
| 634 error_code = ERROR_UNSUPPORTED_DEVICE; | 630 error_code = ERROR_UNSUPPORTED_DEVICE; |
| 635 } | 631 } |
| 636 | 632 |
| 637 if (after_pairing) | 633 if (after_pairing) |
| 638 RecordPairingResult(error_code); | 634 RecordPairingResult(error_code); |
| 639 error_callback.Run(error_code); | 635 error_callback.Run(error_code); |
| 640 } | 636 } |
| 641 | 637 |
| 642 void BluetoothDeviceChromeOS::OnPair( | 638 void BluetoothDeviceBlueZ::OnPair(const base::Closure& callback, |
| 643 const base::Closure& callback, | 639 const ConnectErrorCallback& error_callback) { |
| 644 const ConnectErrorCallback& error_callback) { | |
| 645 VLOG(1) << object_path_.value() << ": Paired"; | 640 VLOG(1) << object_path_.value() << ": Paired"; |
| 646 | 641 |
| 647 EndPairing(); | 642 EndPairing(); |
| 648 | 643 |
| 649 ConnectInternal(true, callback, error_callback); | 644 ConnectInternal(true, callback, error_callback); |
| 650 } | 645 } |
| 651 | 646 |
| 652 void BluetoothDeviceChromeOS::OnPairError( | 647 void BluetoothDeviceBlueZ::OnPairError( |
| 653 const ConnectErrorCallback& error_callback, | 648 const ConnectErrorCallback& error_callback, |
| 654 const std::string& error_name, | 649 const std::string& error_name, |
| 655 const std::string& error_message) { | 650 const std::string& error_message) { |
| 656 if (--num_connecting_calls_ == 0) | 651 if (--num_connecting_calls_ == 0) |
| 657 adapter()->NotifyDeviceChanged(this); | 652 adapter()->NotifyDeviceChanged(this); |
| 658 | 653 |
| 659 DCHECK(num_connecting_calls_ >= 0); | 654 DCHECK(num_connecting_calls_ >= 0); |
| 660 LOG(WARNING) << object_path_.value() << ": Failed to pair device: " | 655 LOG(WARNING) << object_path_.value() |
| 661 << error_name << ": " << error_message; | 656 << ": Failed to pair device: " << error_name << ": " |
| 657 << error_message; |
| 662 VLOG(1) << object_path_.value() << ": " << num_connecting_calls_ | 658 VLOG(1) << object_path_.value() << ": " << num_connecting_calls_ |
| 663 << " still in progress"; | 659 << " still in progress"; |
| 664 | 660 |
| 665 EndPairing(); | 661 EndPairing(); |
| 666 | 662 |
| 667 // Determine the error code from error_name. | 663 // Determine the error code from error_name. |
| 668 ConnectErrorCode error_code = ERROR_UNKNOWN; | 664 ConnectErrorCode error_code = ERROR_UNKNOWN; |
| 669 if (error_name == bluetooth_device::kErrorConnectionAttemptFailed) { | 665 if (error_name == bluetooth_device::kErrorConnectionAttemptFailed) { |
| 670 error_code = ERROR_FAILED; | 666 error_code = ERROR_FAILED; |
| 671 } else if (error_name == bluetooth_device::kErrorFailed) { | 667 } else if (error_name == bluetooth_device::kErrorFailed) { |
| 672 error_code = ERROR_FAILED; | 668 error_code = ERROR_FAILED; |
| 673 } else if (error_name == bluetooth_device::kErrorAuthenticationFailed) { | 669 } else if (error_name == bluetooth_device::kErrorAuthenticationFailed) { |
| 674 error_code = ERROR_AUTH_FAILED; | 670 error_code = ERROR_AUTH_FAILED; |
| 675 } else if (error_name == bluetooth_device::kErrorAuthenticationCanceled) { | 671 } else if (error_name == bluetooth_device::kErrorAuthenticationCanceled) { |
| 676 error_code = ERROR_AUTH_CANCELED; | 672 error_code = ERROR_AUTH_CANCELED; |
| 677 } else if (error_name == bluetooth_device::kErrorAuthenticationRejected) { | 673 } else if (error_name == bluetooth_device::kErrorAuthenticationRejected) { |
| 678 error_code = ERROR_AUTH_REJECTED; | 674 error_code = ERROR_AUTH_REJECTED; |
| 679 } else if (error_name == bluetooth_device::kErrorAuthenticationTimeout) { | 675 } else if (error_name == bluetooth_device::kErrorAuthenticationTimeout) { |
| 680 error_code = ERROR_AUTH_TIMEOUT; | 676 error_code = ERROR_AUTH_TIMEOUT; |
| 681 } | 677 } |
| 682 | 678 |
| 683 RecordPairingResult(error_code); | 679 RecordPairingResult(error_code); |
| 684 error_callback.Run(error_code); | 680 error_callback.Run(error_code); |
| 685 } | 681 } |
| 686 | 682 |
| 687 void BluetoothDeviceChromeOS::OnCancelPairingError( | 683 void BluetoothDeviceBlueZ::OnCancelPairingError( |
| 688 const std::string& error_name, | 684 const std::string& error_name, |
| 689 const std::string& error_message) { | 685 const std::string& error_message) { |
| 690 LOG(WARNING) << object_path_.value() << ": Failed to cancel pairing: " | 686 LOG(WARNING) << object_path_.value() |
| 691 << error_name << ": " << error_message; | 687 << ": Failed to cancel pairing: " << error_name << ": " |
| 688 << error_message; |
| 692 } | 689 } |
| 693 | 690 |
| 694 void BluetoothDeviceChromeOS::SetTrusted() { | 691 void BluetoothDeviceBlueZ::SetTrusted() { |
| 695 // Unconditionally send the property change, rather than checking the value | 692 // Unconditionally send the property change, rather than checking the value |
| 696 // first; there's no harm in doing this and it solves any race conditions | 693 // first; there's no harm in doing this and it solves any race conditions |
| 697 // with the property becoming true or false and this call happening before | 694 // with the property becoming true or false and this call happening before |
| 698 // we get the D-Bus signal about the earlier change. | 695 // we get the D-Bus signal about the earlier change. |
| 699 bluez::BluezDBusManager::Get() | 696 bluez::BluezDBusManager::Get() |
| 700 ->GetBluetoothDeviceClient() | 697 ->GetBluetoothDeviceClient() |
| 701 ->GetProperties(object_path_) | 698 ->GetProperties(object_path_) |
| 702 ->trusted.Set(true, base::Bind(&BluetoothDeviceChromeOS::OnSetTrusted, | 699 ->trusted.Set(true, base::Bind(&BluetoothDeviceBlueZ::OnSetTrusted, |
| 703 weak_ptr_factory_.GetWeakPtr())); | 700 weak_ptr_factory_.GetWeakPtr())); |
| 704 } | 701 } |
| 705 | 702 |
| 706 void BluetoothDeviceChromeOS::OnSetTrusted(bool success) { | 703 void BluetoothDeviceBlueZ::OnSetTrusted(bool success) { |
| 707 LOG_IF(WARNING, !success) << object_path_.value() | 704 LOG_IF(WARNING, !success) << object_path_.value() |
| 708 << ": Failed to set device as trusted"; | 705 << ": Failed to set device as trusted"; |
| 709 } | 706 } |
| 710 | 707 |
| 711 void BluetoothDeviceChromeOS::OnDisconnect(const base::Closure& callback) { | 708 void BluetoothDeviceBlueZ::OnDisconnect(const base::Closure& callback) { |
| 712 VLOG(1) << object_path_.value() << ": Disconnected"; | 709 VLOG(1) << object_path_.value() << ": Disconnected"; |
| 713 callback.Run(); | 710 callback.Run(); |
| 714 } | 711 } |
| 715 | 712 |
| 716 void BluetoothDeviceChromeOS::OnDisconnectError( | 713 void BluetoothDeviceBlueZ::OnDisconnectError( |
| 717 const ErrorCallback& error_callback, | 714 const ErrorCallback& error_callback, |
| 718 const std::string& error_name, | 715 const std::string& error_name, |
| 719 const std::string& error_message) { | 716 const std::string& error_message) { |
| 720 LOG(WARNING) << object_path_.value() << ": Failed to disconnect device: " | 717 LOG(WARNING) << object_path_.value() |
| 721 << error_name << ": " << error_message; | 718 << ": Failed to disconnect device: " << error_name << ": " |
| 719 << error_message; |
| 722 error_callback.Run(); | 720 error_callback.Run(); |
| 723 } | 721 } |
| 724 | 722 |
| 725 void BluetoothDeviceChromeOS::OnForgetError( | 723 void BluetoothDeviceBlueZ::OnForgetError(const ErrorCallback& error_callback, |
| 726 const ErrorCallback& error_callback, | 724 const std::string& error_name, |
| 727 const std::string& error_name, | 725 const std::string& error_message) { |
| 728 const std::string& error_message) { | 726 LOG(WARNING) << object_path_.value() |
| 729 LOG(WARNING) << object_path_.value() << ": Failed to remove device: " | 727 << ": Failed to remove device: " << error_name << ": " |
| 730 << error_name << ": " << error_message; | 728 << error_message; |
| 731 error_callback.Run(); | 729 error_callback.Run(); |
| 732 } | 730 } |
| 733 | 731 |
| 734 } // namespace chromeos | 732 } // namespace bluez |
| OLD | NEW |