OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" | 5 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 | 69 |
70 void BluetoothAdapter::AdapterCallback(const dbus::ObjectPath& adapter_path, | 70 void BluetoothAdapter::AdapterCallback(const dbus::ObjectPath& adapter_path, |
71 bool success) { | 71 bool success) { |
72 if (success) { | 72 if (success) { |
73 ChangeAdapter(adapter_path); | 73 ChangeAdapter(adapter_path); |
74 } else if (!object_path_.value().empty()) { | 74 } else if (!object_path_.value().empty()) { |
75 RemoveAdapter(); | 75 RemoveAdapter(); |
76 } | 76 } |
77 } | 77 } |
78 | 78 |
| 79 void BluetoothAdapter::AdapterCallbackToResultCallback( |
| 80 const ResultCallback& callback, |
| 81 const dbus::ObjectPath& adapter_path, |
| 82 bool success) { |
| 83 callback.Run(success); |
| 84 } |
| 85 |
79 void BluetoothAdapter::DefaultAdapterChanged( | 86 void BluetoothAdapter::DefaultAdapterChanged( |
80 const dbus::ObjectPath& adapter_path) { | 87 const dbus::ObjectPath& adapter_path) { |
81 if (track_default_) | 88 if (track_default_) |
82 ChangeAdapter(adapter_path); | 89 ChangeAdapter(adapter_path); |
83 } | 90 } |
84 | 91 |
85 void BluetoothAdapter::AdapterRemoved(const dbus::ObjectPath& adapter_path) { | 92 void BluetoothAdapter::AdapterRemoved(const dbus::ObjectPath& adapter_path) { |
86 if (adapter_path == object_path_) | 93 if (adapter_path == object_path_) |
87 RemoveAdapter(); | 94 RemoveAdapter(); |
88 } | 95 } |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 GetProperties(object_path_); | 251 GetProperties(object_path_); |
245 | 252 |
246 if (property_name == properties->powered.name()) { | 253 if (property_name == properties->powered.name()) { |
247 PoweredChanged(properties->powered.value()); | 254 PoweredChanged(properties->powered.value()); |
248 | 255 |
249 } else if (property_name == properties->discovering.name()) { | 256 } else if (property_name == properties->discovering.name()) { |
250 DiscoveringChanged(properties->discovering.value()); | 257 DiscoveringChanged(properties->discovering.value()); |
251 | 258 |
252 } else if (property_name == properties->devices.name()) { | 259 } else if (property_name == properties->devices.name()) { |
253 DevicesChanged(properties->devices.value()); | 260 DevicesChanged(properties->devices.value()); |
254 | |
255 } | 261 } |
256 } | 262 } |
257 | 263 |
258 void BluetoothAdapter::DevicePropertyChanged( | 264 void BluetoothAdapter::DevicePropertyChanged( |
259 const dbus::ObjectPath& device_path, | 265 const dbus::ObjectPath& device_path, |
260 const std::string& property_name) { | 266 const std::string& property_name) { |
261 UpdateDevice(device_path); | 267 UpdateDevice(device_path); |
262 } | 268 } |
263 | 269 |
264 void BluetoothAdapter::UpdateDevice(const dbus::ObjectPath& device_path) { | 270 void BluetoothAdapter::UpdateDevice(const dbus::ObjectPath& device_path) { |
265 BluetoothDeviceClient::Properties* properties = | 271 BluetoothDeviceClient::Properties* properties = |
266 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> | 272 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> |
267 GetProperties(device_path); | 273 GetProperties(device_path); |
268 | 274 |
269 // When we first see a device, we may not know the address yet and need to | 275 // When we first see a device, we may not know the address yet and need to |
270 // wait for the DevicePropertyChanged signal before adding the device. | 276 // wait for the DevicePropertyChanged signal before adding the device. |
271 const std::string address = properties->address.value(); | 277 const std::string address = properties->address.value(); |
272 if (address.empty()) | 278 if (address.empty()) |
273 return; | 279 return; |
274 | 280 |
275 // If the device is already known this may be just an update to properties, | 281 // If the device is already known this may be just an update to properties, |
276 // or it may be the device going from discovered to connected and gaining | 282 // or it may be the device going from discovered to connected and gaining |
277 // an object path. Update the existing object and notify observers. | 283 // an object path. Update the existing object and notify observers. |
278 DevicesMap::iterator iter = devices_.find(address); | 284 DevicesMap::iterator iter = devices_.find(address); |
279 if (iter != devices_.end()){ | 285 if (iter != devices_.end()) { |
280 BluetoothDevice* device = iter->second; | 286 BluetoothDevice* device = iter->second; |
281 | 287 |
282 if (!device->IsPaired()) | 288 if (!device->IsPaired()) |
283 device->SetObjectPath(device_path); | 289 device->SetObjectPath(device_path); |
284 device->Update(properties, true); | 290 device->Update(properties, true); |
285 | 291 |
286 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 292 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
287 DeviceChanged(this, device)); | 293 DeviceChanged(this, device)); |
288 return; | 294 return; |
289 } | 295 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 | 332 |
327 const BluetoothDevice* BluetoothAdapter::GetDevice( | 333 const BluetoothDevice* BluetoothAdapter::GetDevice( |
328 const std::string& address) const { | 334 const std::string& address) const { |
329 DevicesMap::const_iterator iter = devices_.find(address); | 335 DevicesMap::const_iterator iter = devices_.find(address); |
330 if (iter != devices_.end()) | 336 if (iter != devices_.end()) |
331 return iter->second; | 337 return iter->second; |
332 | 338 |
333 return NULL; | 339 return NULL; |
334 } | 340 } |
335 | 341 |
| 342 void BluetoothAdapter::ReadLocalOutOfBandPairingData( |
| 343 const OutOfBandPairingDataCallback& callback) const { |
| 344 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> |
| 345 ReadLocalOutOfBandPairingData(object_path_, callback); |
| 346 } |
| 347 |
| 348 void BluetoothAdapter::SetOutOfBandPairingData(const std::string& address, |
| 349 const chromeos::OutOfBandPairingData& data, |
| 350 const ResultCallback& callback) { |
| 351 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> |
| 352 AddRemoteOutOfBandPairingData( |
| 353 object_path_, |
| 354 address, |
| 355 data, |
| 356 base::Bind(&BluetoothAdapter::AdapterCallbackToResultCallback, |
| 357 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 358 } |
| 359 |
| 360 void BluetoothAdapter::ClearOutOfBandPairingData(const std::string& address, |
| 361 const ResultCallback& callback) { |
| 362 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> |
| 363 RemoveRemoteOutOfBandPairingData( |
| 364 object_path_, |
| 365 address, |
| 366 base::Bind(&BluetoothAdapter::AdapterCallbackToResultCallback, |
| 367 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 368 } |
| 369 |
336 void BluetoothAdapter::ClearDevices() { | 370 void BluetoothAdapter::ClearDevices() { |
337 for (DevicesMap::iterator iter = devices_.begin(); | 371 for (DevicesMap::iterator iter = devices_.begin(); |
338 iter != devices_.end(); ++iter) { | 372 iter != devices_.end(); ++iter) { |
339 BluetoothDevice* device = iter->second; | 373 BluetoothDevice* device = iter->second; |
340 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 374 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
341 DeviceRemoved(this, device)); | 375 DeviceRemoved(this, device)); |
342 | 376 |
343 delete device; | 377 delete device; |
344 } | 378 } |
345 devices_.clear(); | 379 devices_.clear(); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 } | 495 } |
462 | 496 |
463 // static | 497 // static |
464 BluetoothAdapter* BluetoothAdapter::Create(const std::string& address) { | 498 BluetoothAdapter* BluetoothAdapter::Create(const std::string& address) { |
465 BluetoothAdapter* adapter = new BluetoothAdapter; | 499 BluetoothAdapter* adapter = new BluetoothAdapter; |
466 adapter->FindAdapter(address); | 500 adapter->FindAdapter(address); |
467 return adapter; | 501 return adapter; |
468 } | 502 } |
469 | 503 |
470 } // namespace chromeos | 504 } // namespace chromeos |
OLD | NEW |