| 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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 void BluetoothAdapter::DiscoveringChanged(bool discovering) { | 240 void BluetoothAdapter::DiscoveringChanged(bool discovering) { |
| 240 if (discovering == discovering_) | 241 if (discovering == discovering_) |
| 241 return; | 242 return; |
| 242 | 243 |
| 243 discovering_ = discovering; | 244 discovering_ = discovering; |
| 244 | 245 |
| 245 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 246 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 246 AdapterDiscoveringChanged(this, discovering_)); | 247 AdapterDiscoveringChanged(this, discovering_)); |
| 247 } | 248 } |
| 248 | 249 |
| 250 void BluetoothAdapter::OnReadLocalData( |
| 251 const BluetoothOutOfBandPairingDataCallback& callback, |
| 252 const ErrorCallback& error_callback, |
| 253 const BluetoothOutOfBandPairingData& data, |
| 254 bool success) { |
| 255 if (success) |
| 256 callback.Run(data); |
| 257 else |
| 258 error_callback.Run(); |
| 259 } |
| 260 |
| 249 void BluetoothAdapter::AdapterPropertyChanged( | 261 void BluetoothAdapter::AdapterPropertyChanged( |
| 250 const dbus::ObjectPath& adapter_path, | 262 const dbus::ObjectPath& adapter_path, |
| 251 const std::string& property_name) { | 263 const std::string& property_name) { |
| 252 if (adapter_path != object_path_) | 264 if (adapter_path != object_path_) |
| 253 return; | 265 return; |
| 254 | 266 |
| 255 BluetoothAdapterClient::Properties* properties = | 267 BluetoothAdapterClient::Properties* properties = |
| 256 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> | 268 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> |
| 257 GetProperties(object_path_); | 269 GetProperties(object_path_); |
| 258 | 270 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 282 // When we first see a device, we may not know the address yet and need to | 294 // When we first see a device, we may not know the address yet and need to |
| 283 // wait for the DevicePropertyChanged signal before adding the device. | 295 // wait for the DevicePropertyChanged signal before adding the device. |
| 284 const std::string address = properties->address.value(); | 296 const std::string address = properties->address.value(); |
| 285 if (address.empty()) | 297 if (address.empty()) |
| 286 return; | 298 return; |
| 287 | 299 |
| 288 // If the device is already known this may be just an update to properties, | 300 // If the device is already known this may be just an update to properties, |
| 289 // or it may be the device going from discovered to connected and gaining | 301 // or it may be the device going from discovered to connected and gaining |
| 290 // an object path. Update the existing object and notify observers. | 302 // an object path. Update the existing object and notify observers. |
| 291 DevicesMap::iterator iter = devices_.find(address); | 303 DevicesMap::iterator iter = devices_.find(address); |
| 292 if (iter != devices_.end()){ | 304 if (iter != devices_.end()) { |
| 293 BluetoothDevice* device = iter->second; | 305 BluetoothDevice* device = iter->second; |
| 294 | 306 |
| 295 if (!device->IsPaired()) | 307 if (!device->IsPaired()) |
| 296 device->SetObjectPath(device_path); | 308 device->SetObjectPath(device_path); |
| 297 device->Update(properties, true); | 309 device->Update(properties, true); |
| 298 | 310 |
| 299 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 311 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 300 DeviceChanged(this, device)); | 312 DeviceChanged(this, device)); |
| 301 return; | 313 return; |
| 302 } | 314 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 | 351 |
| 340 const BluetoothDevice* BluetoothAdapter::GetDevice( | 352 const BluetoothDevice* BluetoothAdapter::GetDevice( |
| 341 const std::string& address) const { | 353 const std::string& address) const { |
| 342 DevicesMap::const_iterator iter = devices_.find(address); | 354 DevicesMap::const_iterator iter = devices_.find(address); |
| 343 if (iter != devices_.end()) | 355 if (iter != devices_.end()) |
| 344 return iter->second; | 356 return iter->second; |
| 345 | 357 |
| 346 return NULL; | 358 return NULL; |
| 347 } | 359 } |
| 348 | 360 |
| 361 void BluetoothAdapter::ReadLocalOutOfBandPairingData( |
| 362 const BluetoothOutOfBandPairingDataCallback& callback, |
| 363 const ErrorCallback& error_callback) { |
| 364 DBusThreadManager::Get()->GetBluetoothOutOfBandClient()-> |
| 365 ReadLocalData(object_path_, |
| 366 base::Bind(&BluetoothAdapter::OnReadLocalData, |
| 367 weak_ptr_factory_.GetWeakPtr(), |
| 368 callback, |
| 369 error_callback)); |
| 370 } |
| 371 |
| 349 void BluetoothAdapter::ClearDevices() { | 372 void BluetoothAdapter::ClearDevices() { |
| 350 for (DevicesMap::iterator iter = devices_.begin(); | 373 for (DevicesMap::iterator iter = devices_.begin(); |
| 351 iter != devices_.end(); ++iter) { | 374 iter != devices_.end(); ++iter) { |
| 352 BluetoothDevice* device = iter->second; | 375 BluetoothDevice* device = iter->second; |
| 353 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 376 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 354 DeviceRemoved(this, device)); | 377 DeviceRemoved(this, device)); |
| 355 | 378 |
| 356 delete device; | 379 delete device; |
| 357 } | 380 } |
| 358 devices_.clear(); | 381 devices_.clear(); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 } | 497 } |
| 475 | 498 |
| 476 // static | 499 // static |
| 477 BluetoothAdapter* BluetoothAdapter::Create(const std::string& address) { | 500 BluetoothAdapter* BluetoothAdapter::Create(const std::string& address) { |
| 478 BluetoothAdapter* adapter = new BluetoothAdapter; | 501 BluetoothAdapter* adapter = new BluetoothAdapter; |
| 479 adapter->FindAdapter(address); | 502 adapter->FindAdapter(address); |
| 480 return adapter; | 503 return adapter; |
| 481 } | 504 } |
| 482 | 505 |
| 483 } // namespace chromeos | 506 } // namespace chromeos |
| OLD | NEW |