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

Side by Side Diff: device/bluetooth/bluetooth_device_chromeos.cc

Issue 1347193004: Refactor DBusThreadManager to split away BT clients. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "device/bluetooth/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
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 void BluetoothDeviceChromeOS::CreateGattConnectionImpl() { 185 void BluetoothDeviceChromeOS::CreateGattConnectionImpl() {
182 // ChromeOS implementation does not use the default CreateGattConnection 186 // ChromeOS implementation does not use the default CreateGattConnection
183 // implementation. 187 // implementation.
184 NOTIMPLEMENTED(); 188 NOTIMPLEMENTED();
185 } 189 }
186 190
187 void BluetoothDeviceChromeOS::DisconnectGatt() { 191 void BluetoothDeviceChromeOS::DisconnectGatt() {
188 // ChromeOS implementation does not use the default CreateGattConnection 192 // ChromeOS implementation does not use the default CreateGattConnection
189 // implementation. 193 // implementation.
190 NOTIMPLEMENTED(); 194 NOTIMPLEMENTED();
191 } 195 }
192 196
193 std::string BluetoothDeviceChromeOS::GetAddress() const { 197 std::string BluetoothDeviceChromeOS::GetAddress() const {
194 BluetoothDeviceClient::Properties* properties = 198 bluez::BluetoothDeviceClient::Properties* properties =
195 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> 199 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties(
196 GetProperties(object_path_); 200 object_path_);
197 DCHECK(properties); 201 DCHECK(properties);
198 202
199 return CanonicalizeAddress(properties->address.value()); 203 return CanonicalizeAddress(properties->address.value());
200 } 204 }
201 205
202 BluetoothDevice::VendorIDSource 206 BluetoothDevice::VendorIDSource
203 BluetoothDeviceChromeOS::GetVendorIDSource() const { 207 BluetoothDeviceChromeOS::GetVendorIDSource() const {
204 VendorIDSource vendor_id_source = VENDOR_ID_UNKNOWN; 208 VendorIDSource vendor_id_source = VENDOR_ID_UNKNOWN;
205 ParseModalias(object_path_, &vendor_id_source, NULL, NULL, NULL); 209 ParseModalias(object_path_, &vendor_id_source, NULL, NULL, NULL);
206 return vendor_id_source; 210 return vendor_id_source;
(...skipping 11 matching lines...) Expand all
218 return product_id; 222 return product_id;
219 } 223 }
220 224
221 uint16 BluetoothDeviceChromeOS::GetDeviceID() const { 225 uint16 BluetoothDeviceChromeOS::GetDeviceID() const {
222 uint16 device_id = 0; 226 uint16 device_id = 0;
223 ParseModalias(object_path_, NULL, NULL, NULL, &device_id); 227 ParseModalias(object_path_, NULL, NULL, NULL, &device_id);
224 return device_id; 228 return device_id;
225 } 229 }
226 230
227 bool BluetoothDeviceChromeOS::IsPaired() const { 231 bool BluetoothDeviceChromeOS::IsPaired() 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 // Trusted devices are devices that don't support pairing but that the 237 // Trusted devices are devices that don't support pairing but that the
234 // user has explicitly connected; it makes no sense for UI purposes to 238 // user has explicitly connected; it makes no sense for UI purposes to
235 // treat them differently from each other. 239 // treat them differently from each other.
236 return properties->paired.value() || properties->trusted.value(); 240 return properties->paired.value() || properties->trusted.value();
237 } 241 }
238 242
239 bool BluetoothDeviceChromeOS::IsConnected() const { 243 bool BluetoothDeviceChromeOS::IsConnected() const {
240 BluetoothDeviceClient::Properties* properties = 244 bluez::BluetoothDeviceClient::Properties* properties =
241 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> 245 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties(
242 GetProperties(object_path_); 246 object_path_);
243 DCHECK(properties); 247 DCHECK(properties);
244 248
245 return properties->connected.value(); 249 return properties->connected.value();
246 } 250 }
247 251
248 bool BluetoothDeviceChromeOS::IsGattConnected() const { 252 bool BluetoothDeviceChromeOS::IsGattConnected() const {
249 NOTIMPLEMENTED(); 253 NOTIMPLEMENTED();
250 return false; 254 return false;
251 } 255 }
252 256
253 bool BluetoothDeviceChromeOS::IsConnectable() const { 257 bool BluetoothDeviceChromeOS::IsConnectable() const {
254 BluetoothInputClient::Properties* input_properties = 258 bluez::BluetoothInputClient::Properties* input_properties =
255 DBusThreadManager::Get()->GetBluetoothInputClient()-> 259 bluez::BluezDBusManager::Get()->GetBluetoothInputClient()->GetProperties(
256 GetProperties(object_path_); 260 object_path_);
257 // GetProperties returns NULL when the device does not implement the given 261 // GetProperties returns NULL when the device does not implement the given
258 // interface. Non HID devices are normally connectable. 262 // interface. Non HID devices are normally connectable.
259 if (!input_properties) 263 if (!input_properties)
260 return true; 264 return true;
261 265
262 return input_properties->reconnect_mode.value() != "device"; 266 return input_properties->reconnect_mode.value() != "device";
263 } 267 }
264 268
265 bool BluetoothDeviceChromeOS::IsConnecting() const { 269 bool BluetoothDeviceChromeOS::IsConnecting() const {
266 return num_connecting_calls_ > 0; 270 return num_connecting_calls_ > 0;
267 } 271 }
268 272
269 BluetoothDeviceChromeOS::UUIDList BluetoothDeviceChromeOS::GetUUIDs() const { 273 BluetoothDeviceChromeOS::UUIDList BluetoothDeviceChromeOS::GetUUIDs() 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 std::vector<device::BluetoothUUID> uuids; 279 std::vector<device::BluetoothUUID> uuids;
276 const std::vector<std::string> &dbus_uuids = properties->uuids.value(); 280 const std::vector<std::string> &dbus_uuids = properties->uuids.value();
277 for (std::vector<std::string>::const_iterator iter = dbus_uuids.begin(); 281 for (std::vector<std::string>::const_iterator iter = dbus_uuids.begin();
278 iter != dbus_uuids.end(); ++iter) { 282 iter != dbus_uuids.end(); ++iter) {
279 device::BluetoothUUID uuid(*iter); 283 device::BluetoothUUID uuid(*iter);
280 DCHECK(uuid.IsValid()); 284 DCHECK(uuid.IsValid());
281 uuids.push_back(uuid); 285 uuids.push_back(uuid);
282 } 286 }
283 return uuids; 287 return uuids;
284 } 288 }
285 289
286 int16 BluetoothDeviceChromeOS::GetInquiryRSSI() const { 290 int16 BluetoothDeviceChromeOS::GetInquiryRSSI() const {
287 BluetoothDeviceClient::Properties* properties = 291 bluez::BluetoothDeviceClient::Properties* properties =
288 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> 292 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties(
289 GetProperties(object_path_); 293 object_path_);
290 DCHECK(properties); 294 DCHECK(properties);
291 295
292 if (!properties->rssi.is_valid()) 296 if (!properties->rssi.is_valid())
293 return kUnknownPower; 297 return kUnknownPower;
294 298
295 return properties->rssi.value(); 299 return properties->rssi.value();
296 } 300 }
297 301
298 int16 BluetoothDeviceChromeOS::GetInquiryTxPower() const { 302 int16 BluetoothDeviceChromeOS::GetInquiryTxPower() const {
299 BluetoothDeviceClient::Properties* properties = 303 bluez::BluetoothDeviceClient::Properties* properties =
300 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> 304 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties(
301 GetProperties(object_path_); 305 object_path_);
302 DCHECK(properties); 306 DCHECK(properties);
303 307
304 if (!properties->tx_power.is_valid()) 308 if (!properties->tx_power.is_valid())
305 return kUnknownPower; 309 return kUnknownPower;
306 310
307 return properties->tx_power.value(); 311 return properties->tx_power.value();
308 } 312 }
309 313
310 bool BluetoothDeviceChromeOS::ExpectingPinCode() const { 314 bool BluetoothDeviceChromeOS::ExpectingPinCode() const {
311 return pairing_.get() && pairing_->ExpectingPinCode(); 315 return pairing_.get() && pairing_->ExpectingPinCode();
312 } 316 }
313 317
314 bool BluetoothDeviceChromeOS::ExpectingPasskey() const { 318 bool BluetoothDeviceChromeOS::ExpectingPasskey() const {
315 return pairing_.get() && pairing_->ExpectingPasskey(); 319 return pairing_.get() && pairing_->ExpectingPasskey();
316 } 320 }
317 321
318 bool BluetoothDeviceChromeOS::ExpectingConfirmation() const { 322 bool BluetoothDeviceChromeOS::ExpectingConfirmation() const {
319 return pairing_.get() && pairing_->ExpectingConfirmation(); 323 return pairing_.get() && pairing_->ExpectingConfirmation();
320 } 324 }
321 325
322 void BluetoothDeviceChromeOS::GetConnectionInfo( 326 void BluetoothDeviceChromeOS::GetConnectionInfo(
323 const ConnectionInfoCallback& callback) { 327 const ConnectionInfoCallback& callback) {
324 // DBus method call should gracefully return an error if the device is not 328 // DBus method call should gracefully return an error if the device is not
325 // currently connected. 329 // currently connected.
326 DBusThreadManager::Get()->GetBluetoothDeviceClient()->GetConnInfo( 330 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetConnInfo(
327 object_path_, base::Bind(&BluetoothDeviceChromeOS::OnGetConnInfo, 331 object_path_, base::Bind(&BluetoothDeviceChromeOS::OnGetConnInfo,
328 weak_ptr_factory_.GetWeakPtr(), callback), 332 weak_ptr_factory_.GetWeakPtr(), callback),
329 base::Bind(&BluetoothDeviceChromeOS::OnGetConnInfoError, 333 base::Bind(&BluetoothDeviceChromeOS::OnGetConnInfoError,
330 weak_ptr_factory_.GetWeakPtr(), callback)); 334 weak_ptr_factory_.GetWeakPtr(), callback));
331 } 335 }
332 336
333 void BluetoothDeviceChromeOS::Connect( 337 void BluetoothDeviceChromeOS::Connect(
334 BluetoothDevice::PairingDelegate* pairing_delegate, 338 BluetoothDevice::PairingDelegate* pairing_delegate,
335 const base::Closure& callback, 339 const base::Closure& callback,
336 const ConnectErrorCallback& error_callback) { 340 const ConnectErrorCallback& error_callback) {
337 if (num_connecting_calls_++ == 0) 341 if (num_connecting_calls_++ == 0)
338 adapter()->NotifyDeviceChanged(this); 342 adapter()->NotifyDeviceChanged(this);
339 343
340 VLOG(1) << object_path_.value() << ": Connecting, " << num_connecting_calls_ 344 VLOG(1) << object_path_.value() << ": Connecting, " << num_connecting_calls_
341 << " in progress"; 345 << " in progress";
342 346
343 if (IsPaired() || !pairing_delegate || !IsPairable()) { 347 if (IsPaired() || !pairing_delegate || !IsPairable()) {
344 // No need to pair, or unable to, skip straight to connection. 348 // No need to pair, or unable to, skip straight to connection.
345 ConnectInternal(false, callback, error_callback); 349 ConnectInternal(false, callback, error_callback);
346 } else { 350 } else {
347 // Initiate high-security connection with pairing. 351 // Initiate high-security connection with pairing.
348 BeginPairing(pairing_delegate); 352 BeginPairing(pairing_delegate);
349 353
350 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> 354 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->Pair(
351 Pair(object_path_, 355 object_path_,
352 base::Bind(&BluetoothDeviceChromeOS::OnPair, 356 base::Bind(&BluetoothDeviceChromeOS::OnPair,
353 weak_ptr_factory_.GetWeakPtr(), 357 weak_ptr_factory_.GetWeakPtr(), callback, error_callback),
354 callback, error_callback), 358 base::Bind(&BluetoothDeviceChromeOS::OnPairError,
355 base::Bind(&BluetoothDeviceChromeOS::OnPairError, 359 weak_ptr_factory_.GetWeakPtr(), error_callback));
356 weak_ptr_factory_.GetWeakPtr(),
357 error_callback));
358 } 360 }
359 } 361 }
360 362
361 void BluetoothDeviceChromeOS::SetPinCode(const std::string& pincode) { 363 void BluetoothDeviceChromeOS::SetPinCode(const std::string& pincode) {
362 if (!pairing_.get()) 364 if (!pairing_.get())
363 return; 365 return;
364 366
365 pairing_->SetPinCode(pincode); 367 pairing_->SetPinCode(pincode);
366 } 368 }
367 369
(...skipping 23 matching lines...) Expand all
391 393
392 // If there is a callback in progress that we can reply to then use that 394 // If there is a callback in progress that we can reply to then use that
393 // to cancel the current pairing request. 395 // to cancel the current pairing request.
394 if (pairing_.get() && pairing_->CancelPairing()) 396 if (pairing_.get() && pairing_->CancelPairing())
395 canceled = true; 397 canceled = true;
396 398
397 // If not we have to send an explicit CancelPairing() to the device instead. 399 // If not we have to send an explicit CancelPairing() to the device instead.
398 if (!canceled) { 400 if (!canceled) {
399 VLOG(1) << object_path_.value() << ": No pairing context or callback. " 401 VLOG(1) << object_path_.value() << ": No pairing context or callback. "
400 << "Sending explicit cancel"; 402 << "Sending explicit cancel";
401 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> 403 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->CancelPairing(
402 CancelPairing( 404 object_path_, base::Bind(&base::DoNothing),
403 object_path_, 405 base::Bind(&BluetoothDeviceChromeOS::OnCancelPairingError,
404 base::Bind(&base::DoNothing), 406 weak_ptr_factory_.GetWeakPtr()));
405 base::Bind(&BluetoothDeviceChromeOS::OnCancelPairingError,
406 weak_ptr_factory_.GetWeakPtr()));
407 } 407 }
408 408
409 // Since there is no callback to this method it's possible that the pairing 409 // 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 410 // 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 411 // documented that this is the method you should call while freeing the
412 // pairing delegate), so clear our the context holding on to it. 412 // pairing delegate), so clear our the context holding on to it.
413 EndPairing(); 413 EndPairing();
414 } 414 }
415 415
416 void BluetoothDeviceChromeOS::Disconnect(const base::Closure& callback, 416 void BluetoothDeviceChromeOS::Disconnect(const base::Closure& callback,
417 const ErrorCallback& error_callback) { 417 const ErrorCallback& error_callback) {
418 VLOG(1) << object_path_.value() << ": Disconnecting"; 418 VLOG(1) << object_path_.value() << ": Disconnecting";
419 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> 419 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->Disconnect(
420 Disconnect( 420 object_path_, base::Bind(&BluetoothDeviceChromeOS::OnDisconnect,
421 object_path_, 421 weak_ptr_factory_.GetWeakPtr(), callback),
422 base::Bind(&BluetoothDeviceChromeOS::OnDisconnect, 422 base::Bind(&BluetoothDeviceChromeOS::OnDisconnectError,
423 weak_ptr_factory_.GetWeakPtr(), 423 weak_ptr_factory_.GetWeakPtr(), error_callback));
424 callback),
425 base::Bind(&BluetoothDeviceChromeOS::OnDisconnectError,
426 weak_ptr_factory_.GetWeakPtr(),
427 error_callback));
428 } 424 }
429 425
430 void BluetoothDeviceChromeOS::Forget(const ErrorCallback& error_callback) { 426 void BluetoothDeviceChromeOS::Forget(const ErrorCallback& error_callback) {
431 VLOG(1) << object_path_.value() << ": Removing device"; 427 VLOG(1) << object_path_.value() << ": Removing device";
432 DBusThreadManager::Get()->GetBluetoothAdapterClient()->RemoveDevice( 428 bluez::BluezDBusManager::Get()->GetBluetoothAdapterClient()->RemoveDevice(
433 adapter()->object_path(), object_path_, base::Bind(&base::DoNothing), 429 adapter()->object_path(), object_path_, base::Bind(&base::DoNothing),
434 base::Bind(&BluetoothDeviceChromeOS::OnForgetError, 430 base::Bind(&BluetoothDeviceChromeOS::OnForgetError,
435 weak_ptr_factory_.GetWeakPtr(), error_callback)); 431 weak_ptr_factory_.GetWeakPtr(), error_callback));
436 } 432 }
437 433
438 void BluetoothDeviceChromeOS::ConnectToService( 434 void BluetoothDeviceChromeOS::ConnectToService(
439 const BluetoothUUID& uuid, 435 const BluetoothUUID& uuid,
440 const ConnectToServiceCallback& callback, 436 const ConnectToServiceCallback& callback,
441 const ConnectToServiceErrorCallback& error_callback) { 437 const ConnectToServiceErrorCallback& error_callback) {
442 VLOG(1) << object_path_.value() << ": Connecting to service: " 438 VLOG(1) << object_path_.value() << ": Connecting to service: "
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 return static_cast<BluetoothAdapterChromeOS*>(adapter_); 497 return static_cast<BluetoothAdapterChromeOS*>(adapter_);
502 } 498 }
503 499
504 void BluetoothDeviceChromeOS::GattServiceAdded( 500 void BluetoothDeviceChromeOS::GattServiceAdded(
505 const dbus::ObjectPath& object_path) { 501 const dbus::ObjectPath& object_path) {
506 if (GetGattService(object_path.value())) { 502 if (GetGattService(object_path.value())) {
507 VLOG(1) << "Remote GATT service already exists: " << object_path.value(); 503 VLOG(1) << "Remote GATT service already exists: " << object_path.value();
508 return; 504 return;
509 } 505 }
510 506
511 BluetoothGattServiceClient::Properties* properties = 507 bluez::BluetoothGattServiceClient::Properties* properties =
512 DBusThreadManager::Get()->GetBluetoothGattServiceClient()-> 508 bluez::BluezDBusManager::Get()
513 GetProperties(object_path); 509 ->GetBluetoothGattServiceClient()
510 ->GetProperties(object_path);
514 DCHECK(properties); 511 DCHECK(properties);
515 if (properties->device.value() != object_path_) { 512 if (properties->device.value() != object_path_) {
516 VLOG(2) << "Remote GATT service does not belong to this device."; 513 VLOG(2) << "Remote GATT service does not belong to this device.";
517 return; 514 return;
518 } 515 }
519 516
520 VLOG(1) << "Adding new remote GATT service for device: " << GetAddress(); 517 VLOG(1) << "Adding new remote GATT service for device: " << GetAddress();
521 518
522 BluetoothRemoteGattServiceChromeOS* service = 519 BluetoothRemoteGattServiceChromeOS* service =
523 new BluetoothRemoteGattServiceChromeOS(adapter(), this, object_path); 520 new BluetoothRemoteGattServiceChromeOS(adapter(), this, object_path);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 << ": Failed to get connection info: " << error_name << ": " 567 << ": Failed to get connection info: " << error_name << ": "
571 << error_message; 568 << error_message;
572 callback.Run(ConnectionInfo()); 569 callback.Run(ConnectionInfo());
573 } 570 }
574 571
575 void BluetoothDeviceChromeOS::ConnectInternal( 572 void BluetoothDeviceChromeOS::ConnectInternal(
576 bool after_pairing, 573 bool after_pairing,
577 const base::Closure& callback, 574 const base::Closure& callback,
578 const ConnectErrorCallback& error_callback) { 575 const ConnectErrorCallback& error_callback) {
579 VLOG(1) << object_path_.value() << ": Connecting"; 576 VLOG(1) << object_path_.value() << ": Connecting";
580 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> 577 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->Connect(
581 Connect( 578 object_path_,
582 object_path_, 579 base::Bind(&BluetoothDeviceChromeOS::OnConnect,
583 base::Bind(&BluetoothDeviceChromeOS::OnConnect, 580 weak_ptr_factory_.GetWeakPtr(), after_pairing, callback),
584 weak_ptr_factory_.GetWeakPtr(), 581 base::Bind(&BluetoothDeviceChromeOS::OnConnectError,
585 after_pairing, 582 weak_ptr_factory_.GetWeakPtr(), after_pairing,
586 callback), 583 error_callback));
587 base::Bind(&BluetoothDeviceChromeOS::OnConnectError,
588 weak_ptr_factory_.GetWeakPtr(),
589 after_pairing,
590 error_callback));
591 } 584 }
592 585
593 void BluetoothDeviceChromeOS::OnConnect(bool after_pairing, 586 void BluetoothDeviceChromeOS::OnConnect(bool after_pairing,
594 const base::Closure& callback) { 587 const base::Closure& callback) {
595 if (--num_connecting_calls_ == 0) 588 if (--num_connecting_calls_ == 0)
596 adapter()->NotifyDeviceChanged(this); 589 adapter()->NotifyDeviceChanged(this);
597 590
598 DCHECK(num_connecting_calls_ >= 0); 591 DCHECK(num_connecting_calls_ >= 0);
599 VLOG(1) << object_path_.value() << ": Connected, " << num_connecting_calls_ 592 VLOG(1) << object_path_.value() << ": Connected, " << num_connecting_calls_
600 << " still in progress"; 593 << " still in progress";
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 const std::string& error_message) { 689 const std::string& error_message) {
697 LOG(WARNING) << object_path_.value() << ": Failed to cancel pairing: " 690 LOG(WARNING) << object_path_.value() << ": Failed to cancel pairing: "
698 << error_name << ": " << error_message; 691 << error_name << ": " << error_message;
699 } 692 }
700 693
701 void BluetoothDeviceChromeOS::SetTrusted() { 694 void BluetoothDeviceChromeOS::SetTrusted() {
702 // Unconditionally send the property change, rather than checking the value 695 // Unconditionally send the property change, rather than checking the value
703 // first; there's no harm in doing this and it solves any race conditions 696 // first; there's no harm in doing this and it solves any race conditions
704 // with the property becoming true or false and this call happening before 697 // with the property becoming true or false and this call happening before
705 // we get the D-Bus signal about the earlier change. 698 // we get the D-Bus signal about the earlier change.
706 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> 699 bluez::BluezDBusManager::Get()
707 GetProperties(object_path_)->trusted.Set( 700 ->GetBluetoothDeviceClient()
708 true, 701 ->GetProperties(object_path_)
709 base::Bind(&BluetoothDeviceChromeOS::OnSetTrusted, 702 ->trusted.Set(true, base::Bind(&BluetoothDeviceChromeOS::OnSetTrusted,
710 weak_ptr_factory_.GetWeakPtr())); 703 weak_ptr_factory_.GetWeakPtr()));
711 } 704 }
712 705
713 void BluetoothDeviceChromeOS::OnSetTrusted(bool success) { 706 void BluetoothDeviceChromeOS::OnSetTrusted(bool success) {
714 LOG_IF(WARNING, !success) << object_path_.value() 707 LOG_IF(WARNING, !success) << object_path_.value()
715 << ": Failed to set device as trusted"; 708 << ": Failed to set device as trusted";
716 } 709 }
717 710
718 void BluetoothDeviceChromeOS::OnDisconnect(const base::Closure& callback) { 711 void BluetoothDeviceChromeOS::OnDisconnect(const base::Closure& callback) {
719 VLOG(1) << object_path_.value() << ": Disconnected"; 712 VLOG(1) << object_path_.value() << ": Disconnected";
720 callback.Run(); 713 callback.Run();
(...skipping 11 matching lines...) Expand all
732 void BluetoothDeviceChromeOS::OnForgetError( 725 void BluetoothDeviceChromeOS::OnForgetError(
733 const ErrorCallback& error_callback, 726 const ErrorCallback& error_callback,
734 const std::string& error_name, 727 const std::string& error_name,
735 const std::string& error_message) { 728 const std::string& error_message) {
736 LOG(WARNING) << object_path_.value() << ": Failed to remove device: " 729 LOG(WARNING) << object_path_.value() << ": Failed to remove device: "
737 << error_name << ": " << error_message; 730 << error_name << ": " << error_message;
738 error_callback.Run(); 731 error_callback.Run();
739 } 732 }
740 733
741 } // namespace chromeos 734 } // namespace chromeos
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_device_chromeos.h ('k') | device/bluetooth/bluetooth_gatt_chromeos_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698