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" |
11 #include "chrome/browser/chromeos/bluetooth/bluetooth_device.h" | 11 #include "chrome/browser/chromeos/bluetooth/bluetooth_device.h" |
12 #include "chromeos/dbus/bluetooth_adapter_client.h" | 12 #include "chromeos/dbus/bluetooth_adapter_client.h" |
13 #include "chromeos/dbus/bluetooth_device_client.h" | 13 #include "chromeos/dbus/bluetooth_device_client.h" |
14 #include "chromeos/dbus/bluetooth_manager_client.h" | 14 #include "chromeos/dbus/bluetooth_manager_client.h" |
15 #include "chromeos/dbus/bluetooth_out_of_band_client.h" | |
15 #include "chromeos/dbus/dbus_thread_manager.h" | 16 #include "chromeos/dbus/dbus_thread_manager.h" |
16 #include "dbus/object_path.h" | 17 #include "dbus/object_path.h" |
17 | 18 |
18 namespace chromeos { | 19 namespace chromeos { |
19 | 20 |
20 BluetoothAdapter::BluetoothAdapter() : weak_ptr_factory_(this), | 21 BluetoothAdapter::BluetoothAdapter() : weak_ptr_factory_(this), |
21 track_default_(false), | 22 track_default_(false), |
22 powered_(false), | 23 powered_(false), |
23 discovering_(false) { | 24 discovering_(false) { |
24 DBusThreadManager::Get()->GetBluetoothManagerClient()-> | 25 DBusThreadManager::Get()->GetBluetoothManagerClient()-> |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
244 GetProperties(object_path_); | 245 GetProperties(object_path_); |
245 | 246 |
246 if (property_name == properties->powered.name()) { | 247 if (property_name == properties->powered.name()) { |
247 PoweredChanged(properties->powered.value()); | 248 PoweredChanged(properties->powered.value()); |
248 | 249 |
249 } else if (property_name == properties->discovering.name()) { | 250 } else if (property_name == properties->discovering.name()) { |
250 DiscoveringChanged(properties->discovering.value()); | 251 DiscoveringChanged(properties->discovering.value()); |
251 | 252 |
252 } else if (property_name == properties->devices.name()) { | 253 } else if (property_name == properties->devices.name()) { |
253 DevicesChanged(properties->devices.value()); | 254 DevicesChanged(properties->devices.value()); |
254 | |
keybuk
2012/06/08 20:06:39
why removed?
bryeung
2012/06/14 15:31:07
not sure how that happened, fixed
| |
255 } | 255 } |
256 } | 256 } |
257 | 257 |
258 void BluetoothAdapter::DevicePropertyChanged( | 258 void BluetoothAdapter::DevicePropertyChanged( |
259 const dbus::ObjectPath& device_path, | 259 const dbus::ObjectPath& device_path, |
260 const std::string& property_name) { | 260 const std::string& property_name) { |
261 UpdateDevice(device_path); | 261 UpdateDevice(device_path); |
262 } | 262 } |
263 | 263 |
264 void BluetoothAdapter::UpdateDevice(const dbus::ObjectPath& device_path) { | 264 void BluetoothAdapter::UpdateDevice(const dbus::ObjectPath& device_path) { |
265 BluetoothDeviceClient::Properties* properties = | 265 BluetoothDeviceClient::Properties* properties = |
266 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> | 266 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> |
267 GetProperties(device_path); | 267 GetProperties(device_path); |
268 | 268 |
269 // When we first see a device, we may not know the address yet and need to | 269 // 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. | 270 // wait for the DevicePropertyChanged signal before adding the device. |
271 const std::string address = properties->address.value(); | 271 const std::string address = properties->address.value(); |
272 if (address.empty()) | 272 if (address.empty()) |
273 return; | 273 return; |
274 | 274 |
275 // If the device is already known this may be just an update to properties, | 275 // 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 | 276 // or it may be the device going from discovered to connected and gaining |
277 // an object path. Update the existing object and notify observers. | 277 // an object path. Update the existing object and notify observers. |
278 DevicesMap::iterator iter = devices_.find(address); | 278 DevicesMap::iterator iter = devices_.find(address); |
279 if (iter != devices_.end()){ | 279 if (iter != devices_.end()) { |
280 BluetoothDevice* device = iter->second; | 280 BluetoothDevice* device = iter->second; |
281 | 281 |
282 if (!device->IsPaired()) | 282 if (!device->IsPaired()) |
283 device->SetObjectPath(device_path); | 283 device->SetObjectPath(device_path); |
284 device->Update(properties, true); | 284 device->Update(properties, true); |
285 | 285 |
286 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 286 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
287 DeviceChanged(this, device)); | 287 DeviceChanged(this, device)); |
288 return; | 288 return; |
289 } | 289 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
326 | 326 |
327 const BluetoothDevice* BluetoothAdapter::GetDevice( | 327 const BluetoothDevice* BluetoothAdapter::GetDevice( |
328 const std::string& address) const { | 328 const std::string& address) const { |
329 DevicesMap::const_iterator iter = devices_.find(address); | 329 DevicesMap::const_iterator iter = devices_.find(address); |
330 if (iter != devices_.end()) | 330 if (iter != devices_.end()) |
331 return iter->second; | 331 return iter->second; |
332 | 332 |
333 return NULL; | 333 return NULL; |
334 } | 334 } |
335 | 335 |
336 void BluetoothAdapter::ReadLocalOutOfBandPairingData( | |
337 const BluetoothOutOfBandClient::DataCallback& callback) const { | |
338 DBusThreadManager::Get()->GetBluetoothOutOfBandClient()-> | |
339 ReadLocalData(object_path_, callback); | |
340 } | |
341 | |
342 void BluetoothAdapter::SetOutOfBandPairingData(const std::string& address, | |
343 const chromeos::BluetoothOutOfBandPairingData& data, | |
344 const chromeos::BluetoothOutOfBandClient::SuccessCallback& callback) { | |
345 DBusThreadManager::Get()->GetBluetoothOutOfBandClient()-> | |
346 AddRemoteData( | |
347 object_path_, | |
348 address, | |
349 data, | |
350 callback); | |
351 } | |
352 | |
353 void BluetoothAdapter::ClearOutOfBandPairingData(const std::string& address, | |
354 const chromeos::BluetoothOutOfBandClient::SuccessCallback& callback) { | |
355 DBusThreadManager::Get()->GetBluetoothOutOfBandClient()-> | |
356 RemoveRemoteData( | |
357 object_path_, | |
358 address, | |
359 callback); | |
360 } | |
361 | |
336 void BluetoothAdapter::ClearDevices() { | 362 void BluetoothAdapter::ClearDevices() { |
337 for (DevicesMap::iterator iter = devices_.begin(); | 363 for (DevicesMap::iterator iter = devices_.begin(); |
338 iter != devices_.end(); ++iter) { | 364 iter != devices_.end(); ++iter) { |
339 BluetoothDevice* device = iter->second; | 365 BluetoothDevice* device = iter->second; |
340 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 366 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
341 DeviceRemoved(this, device)); | 367 DeviceRemoved(this, device)); |
342 | 368 |
343 delete device; | 369 delete device; |
344 } | 370 } |
345 devices_.clear(); | 371 devices_.clear(); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
461 } | 487 } |
462 | 488 |
463 // static | 489 // static |
464 BluetoothAdapter* BluetoothAdapter::Create(const std::string& address) { | 490 BluetoothAdapter* BluetoothAdapter::Create(const std::string& address) { |
465 BluetoothAdapter* adapter = new BluetoothAdapter; | 491 BluetoothAdapter* adapter = new BluetoothAdapter; |
466 adapter->FindAdapter(address); | 492 adapter->FindAdapter(address); |
467 return adapter; | 493 return adapter; |
468 } | 494 } |
469 | 495 |
470 } // namespace chromeos | 496 } // namespace chromeos |
OLD | NEW |