| 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/dbus/bluetooth_adapter_client.h" | 5 #include "chrome/browser/chromeos/dbus/bluetooth_adapter_client.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "chrome/browser/chromeos/dbus/bluetooth_manager_client.h" | 12 #include "chrome/browser/chromeos/dbus/bluetooth_manager_client.h" |
| 13 #include "chrome/browser/chromeos/system/runtime_environment.h" | 13 #include "chrome/browser/chromeos/system/runtime_environment.h" |
| 14 #include "dbus/bus.h" | 14 #include "dbus/bus.h" |
| 15 #include "dbus/message.h" | 15 #include "dbus/message.h" |
| 16 #include "dbus/object_path.h" | |
| 17 #include "dbus/object_proxy.h" | 16 #include "dbus/object_proxy.h" |
| 18 #include "third_party/cros_system_api/dbus/service_constants.h" | 17 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 19 | 18 |
| 20 namespace { | 19 namespace { |
| 21 | 20 |
| 22 // Utility function to convert an array of dbus dict_entry objects into a | 21 // Utility function to convert an array of dbus dict_entry objects into a |
| 23 // DictionaryValue object. | 22 // DictionaryValue object. |
| 24 // | 23 // |
| 25 // The dict_entry objects must have keys that are strings and values that are | 24 // The dict_entry objects must have keys that are strings and values that are |
| 26 // simple variants. | 25 // simple variants. |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 } | 135 } |
| 137 case dbus::Message::STRING: { | 136 case dbus::Message::STRING: { |
| 138 std::string value; | 137 std::string value; |
| 139 if (!variant_reader.PopString(&value)) { | 138 if (!variant_reader.PopString(&value)) { |
| 140 return false; | 139 return false; |
| 141 } | 140 } |
| 142 dictionary->SetString(key, value); | 141 dictionary->SetString(key, value); |
| 143 break; | 142 break; |
| 144 } | 143 } |
| 145 case dbus::Message::OBJECT_PATH: { | 144 case dbus::Message::OBJECT_PATH: { |
| 146 dbus::ObjectPath value; | 145 std::string value; |
| 147 if (!variant_reader.PopObjectPath(&value)) { | 146 if (!variant_reader.PopObjectPath(&value)) { |
| 148 return false; | 147 return false; |
| 149 } | 148 } |
| 150 dictionary->SetString(key, value.value()); | 149 dictionary->SetString(key, value); |
| 151 break; | 150 break; |
| 152 } | 151 } |
| 153 case dbus::Message::ARRAY: { | 152 case dbus::Message::ARRAY: { |
| 154 // Not yet supported. | 153 // Not yet supported. |
| 155 return false; | 154 return false; |
| 156 } | 155 } |
| 157 case dbus::Message::STRUCT: { | 156 case dbus::Message::STRUCT: { |
| 158 // Not yet supported. | 157 // Not yet supported. |
| 159 return false; | 158 return false; |
| 160 } | 159 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 } | 201 } |
| 203 | 202 |
| 204 // BluetoothAdapterClient override. | 203 // BluetoothAdapterClient override. |
| 205 virtual void RemoveObserver(BluetoothAdapterClient::Observer* observer) { | 204 virtual void RemoveObserver(BluetoothAdapterClient::Observer* observer) { |
| 206 VLOG(1) << "RemoveObserver"; | 205 VLOG(1) << "RemoveObserver"; |
| 207 DCHECK(observer); | 206 DCHECK(observer); |
| 208 observers_.RemoveObserver(observer); | 207 observers_.RemoveObserver(observer); |
| 209 } | 208 } |
| 210 | 209 |
| 211 // BluetoothAdapterClient override. | 210 // BluetoothAdapterClient override. |
| 212 virtual void StartDiscovery(const dbus::ObjectPath& object_path) { | 211 virtual void StartDiscovery(const std::string& object_path) { |
| 213 VLOG(1) << "StartDiscovery: " << object_path.value(); | 212 VLOG(1) << "StartDiscovery: " << object_path; |
| 214 | 213 |
| 215 dbus::MethodCall method_call( | 214 dbus::MethodCall method_call( |
| 216 bluetooth_adapter::kBluetoothAdapterInterface, | 215 bluetooth_adapter::kBluetoothAdapterInterface, |
| 217 bluetooth_adapter::kStartDiscovery); | 216 bluetooth_adapter::kStartDiscovery); |
| 218 | 217 |
| 219 dbus::ObjectProxy* adapter_proxy = GetObjectProxyForPath(object_path); | 218 dbus::ObjectProxy* adapter_proxy = GetObjectProxyForPath(object_path); |
| 220 | 219 |
| 221 adapter_proxy->CallMethod( | 220 adapter_proxy->CallMethod( |
| 222 &method_call, | 221 &method_call, |
| 223 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 222 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 224 base::Bind(&BluetoothAdapterClientImpl::OnStartDiscovery, | 223 base::Bind(&BluetoothAdapterClientImpl::OnStartDiscovery, |
| 225 weak_ptr_factory_.GetWeakPtr(), object_path)); | 224 weak_ptr_factory_.GetWeakPtr(), object_path)); |
| 226 } | 225 } |
| 227 | 226 |
| 228 // BluetoothAdapterClient override. | 227 // BluetoothAdapterClient override. |
| 229 virtual void StopDiscovery(const dbus::ObjectPath& object_path) { | 228 virtual void StopDiscovery(const std::string& object_path) { |
| 230 VLOG(1) << "StopDiscovery: " << object_path.value(); | 229 VLOG(1) << "StopDiscovery: " << object_path; |
| 231 | 230 |
| 232 dbus::MethodCall method_call( | 231 dbus::MethodCall method_call( |
| 233 bluetooth_adapter::kBluetoothAdapterInterface, | 232 bluetooth_adapter::kBluetoothAdapterInterface, |
| 234 bluetooth_adapter::kStopDiscovery); | 233 bluetooth_adapter::kStopDiscovery); |
| 235 | 234 |
| 236 dbus::ObjectProxy* adapter_proxy = GetObjectProxyForPath(object_path); | 235 dbus::ObjectProxy* adapter_proxy = GetObjectProxyForPath(object_path); |
| 237 | 236 |
| 238 adapter_proxy->CallMethod( | 237 adapter_proxy->CallMethod( |
| 239 &method_call, | 238 &method_call, |
| 240 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 239 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 241 base::Bind(&BluetoothAdapterClientImpl::OnStopDiscovery, | 240 base::Bind(&BluetoothAdapterClientImpl::OnStopDiscovery, |
| 242 weak_ptr_factory_.GetWeakPtr(), object_path)); | 241 weak_ptr_factory_.GetWeakPtr(), object_path)); |
| 243 } | 242 } |
| 244 | 243 |
| 245 private: | 244 private: |
| 246 // BluetoothManagerClient::Observer override. | 245 // BluetoothManagerClient::Observer override. |
| 247 virtual void AdapterAdded(const dbus::ObjectPath& object_path) OVERRIDE { | 246 virtual void AdapterAdded(const std::string& object_path) OVERRIDE { |
| 248 VLOG(1) << "AdapterAdded: " << object_path.value(); | 247 VLOG(1) << "AdapterAdded: " << object_path; |
| 249 } | 248 } |
| 250 | 249 |
| 251 // BluetoothManagerClient::Observer override. | 250 // BluetoothManagerClient::Observer override. |
| 252 virtual void AdapterRemoved(const dbus::ObjectPath& object_path) OVERRIDE { | 251 virtual void AdapterRemoved(const std::string& object_path) OVERRIDE { |
| 253 VLOG(1) << "AdapterRemoved: " << object_path.value(); | 252 VLOG(1) << "AdapterRemoved: " << object_path; |
| 254 RemoveObjectProxyForPath(object_path); | 253 RemoveObjectProxyForPath(object_path); |
| 255 } | 254 } |
| 256 | 255 |
| 257 // Ensures that we have a dbus object proxy for an adapter with dbus | 256 // Ensures that we have a dbus object proxy for an adapter with dbus |
| 258 // object path |object_path|, and if not, creates it and stores it in | 257 // object path |object_path|, and if not, creates it and stores it in |
| 259 // our |proxy_map_| map. | 258 // our |proxy_map_| map. |
| 260 dbus::ObjectProxy* GetObjectProxyForPath( | 259 dbus::ObjectProxy* GetObjectProxyForPath(const std::string& object_path) { |
| 261 const dbus::ObjectPath& object_path) { | 260 VLOG(1) << "GetObjectProxyForPath: " << object_path; |
| 262 VLOG(1) << "GetObjectProxyForPath: " << object_path.value(); | |
| 263 | 261 |
| 264 ProxyMap::iterator it = proxy_map_.find(object_path); | 262 ProxyMap::iterator it = proxy_map_.find(object_path); |
| 265 if (it != proxy_map_.end()) | 263 if (it != proxy_map_.end()) |
| 266 return it->second; | 264 return it->second; |
| 267 | 265 |
| 268 DCHECK(bus_); | 266 DCHECK(bus_); |
| 269 dbus::ObjectProxy* adapter_proxy = bus_->GetObjectProxy( | 267 dbus::ObjectProxy* adapter_proxy = bus_->GetObjectProxy( |
| 270 bluetooth_adapter::kBluetoothAdapterServiceName, object_path); | 268 bluetooth_adapter::kBluetoothAdapterServiceName, object_path); |
| 271 | 269 |
| 272 proxy_map_[object_path] = adapter_proxy; | 270 proxy_map_[object_path] = adapter_proxy; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 base::Bind(&BluetoothAdapterClientImpl::DeviceDisappearedReceived, | 307 base::Bind(&BluetoothAdapterClientImpl::DeviceDisappearedReceived, |
| 310 weak_ptr_factory_.GetWeakPtr(), object_path), | 308 weak_ptr_factory_.GetWeakPtr(), object_path), |
| 311 base::Bind(&BluetoothAdapterClientImpl::DeviceDisappearedConnected, | 309 base::Bind(&BluetoothAdapterClientImpl::DeviceDisappearedConnected, |
| 312 weak_ptr_factory_.GetWeakPtr(), object_path)); | 310 weak_ptr_factory_.GetWeakPtr(), object_path)); |
| 313 | 311 |
| 314 return adapter_proxy; | 312 return adapter_proxy; |
| 315 } | 313 } |
| 316 | 314 |
| 317 // Removes the dbus object proxy for the adapter with dbus object path | 315 // Removes the dbus object proxy for the adapter with dbus object path |
| 318 // |object_path| from our |proxy_map_| map. | 316 // |object_path| from our |proxy_map_| map. |
| 319 void RemoveObjectProxyForPath(const dbus::ObjectPath& object_path) { | 317 void RemoveObjectProxyForPath(const std::string& object_path) { |
| 320 VLOG(1) << "RemoveObjectProxyForPath: " << object_path.value(); | 318 VLOG(1) << "RemoveObjectProxyForPath: " << object_path; |
| 321 proxy_map_.erase(object_path); | 319 proxy_map_.erase(object_path); |
| 322 } | 320 } |
| 323 | 321 |
| 324 // Called by dbus:: when a DeviceCreated signal is received. | 322 // Called by dbus:: when a DeviceCreated signal is received. |
| 325 void DeviceCreatedReceived(const dbus::ObjectPath& object_path, | 323 void DeviceCreatedReceived(const std::string& object_path, |
| 326 dbus::Signal* signal) { | 324 dbus::Signal* signal) { |
| 327 DCHECK(signal); | 325 DCHECK(signal); |
| 328 dbus::MessageReader reader(signal); | 326 dbus::MessageReader reader(signal); |
| 329 dbus::ObjectPath device_path; | 327 std::string device_path; |
| 330 if (!reader.PopObjectPath(&device_path)) { | 328 if (!reader.PopObjectPath(&device_path)) { |
| 331 LOG(ERROR) << object_path.value() | 329 LOG(ERROR) << object_path |
| 332 << ": DeviceCreated signal has incorrect parameters: " | 330 << ": DeviceCreated signal has incorrect parameters: " |
| 333 << signal->ToString(); | 331 << signal->ToString(); |
| 334 return; | 332 return; |
| 335 } | 333 } |
| 336 VLOG(1) << object_path.value() << ": Device created: " | 334 VLOG(1) << object_path << ": Device created: " << device_path; |
| 337 << device_path.value(); | |
| 338 | 335 |
| 339 FOR_EACH_OBSERVER(BluetoothAdapterClient::Observer, observers_, | 336 FOR_EACH_OBSERVER(BluetoothAdapterClient::Observer, observers_, |
| 340 DeviceCreated(object_path, device_path)); | 337 DeviceCreated(object_path, device_path)); |
| 341 } | 338 } |
| 342 | 339 |
| 343 // Called by dbus:: when the DeviceCreated signal is initially connected. | 340 // Called by dbus:: when the DeviceCreated signal is initially connected. |
| 344 void DeviceCreatedConnected(const dbus::ObjectPath& object_path, | 341 void DeviceCreatedConnected(const std::string& object_path, |
| 345 const std::string& interface_name, | 342 const std::string& interface_name, |
| 346 const std::string& signal_name, | 343 const std::string& signal_name, |
| 347 bool success) { | 344 bool success) { |
| 348 LOG_IF(WARNING, !success) << object_path.value() | 345 LOG_IF(WARNING, !success) << object_path |
| 349 << ": Failed to connect to DeviceCreated signal."; | 346 << ": Failed to connect to DeviceCreated signal."; |
| 350 } | 347 } |
| 351 | 348 |
| 352 // Called by dbus:: when a DeviceRemoved signal is received. | 349 // Called by dbus:: when a DeviceRemoved signal is received. |
| 353 void DeviceRemovedReceived(const dbus::ObjectPath& object_path, | 350 void DeviceRemovedReceived(const std::string& object_path, |
| 354 dbus::Signal* signal) { | 351 dbus::Signal* signal) { |
| 355 DCHECK(signal); | 352 DCHECK(signal); |
| 356 dbus::MessageReader reader(signal); | 353 dbus::MessageReader reader(signal); |
| 357 dbus::ObjectPath device_path; | 354 std::string device_path; |
| 358 if (!reader.PopObjectPath(&device_path)) { | 355 if (!reader.PopObjectPath(&device_path)) { |
| 359 LOG(ERROR) << object_path.value() | 356 LOG(ERROR) << object_path |
| 360 << ": DeviceRemoved signal has incorrect parameters: " | 357 << ": DeviceRemoved signal has incorrect parameters: " |
| 361 << signal->ToString(); | 358 << signal->ToString(); |
| 362 return; | 359 return; |
| 363 } | 360 } |
| 364 VLOG(1) << object_path.value() << ": Device removed: " | 361 VLOG(1) << object_path << ": Device removed: " << device_path; |
| 365 << device_path.value(); | |
| 366 | 362 |
| 367 FOR_EACH_OBSERVER(BluetoothAdapterClient::Observer, observers_, | 363 FOR_EACH_OBSERVER(BluetoothAdapterClient::Observer, observers_, |
| 368 DeviceRemoved(object_path, device_path)); | 364 DeviceRemoved(object_path, device_path)); |
| 369 } | 365 } |
| 370 | 366 |
| 371 // Called by dbus:: when the DeviceRemoved signal is initially connected. | 367 // Called by dbus:: when the DeviceRemoved signal is initially connected. |
| 372 void DeviceRemovedConnected(const dbus::ObjectPath& object_path, | 368 void DeviceRemovedConnected(const std::string& object_path, |
| 373 const std::string& interface_name, | 369 const std::string& interface_name, |
| 374 const std::string& signal_name, | 370 const std::string& signal_name, |
| 375 bool success) { | 371 bool success) { |
| 376 LOG_IF(WARNING, !success) << object_path.value() | 372 LOG_IF(WARNING, !success) << object_path |
| 377 << ": Failed to connect to DeviceRemoved signal."; | 373 << ": Failed to connect to DeviceRemoved signal."; |
| 378 } | 374 } |
| 379 | 375 |
| 380 // Called by dbus:: when a PropertyChanged signal is received. | 376 // Called by dbus:: when a PropertyChanged signal is received. |
| 381 void PropertyChangedReceived(const dbus::ObjectPath& object_path, | 377 void PropertyChangedReceived(const std::string& object_path, |
| 382 dbus::Signal* signal) { | 378 dbus::Signal* signal) { |
| 383 DCHECK(signal); | 379 DCHECK(signal); |
| 384 dbus::MessageReader reader(signal); | 380 dbus::MessageReader reader(signal); |
| 385 std::string property_name; | 381 std::string property_name; |
| 386 if (!reader.PopString(&property_name)) { | 382 if (!reader.PopString(&property_name)) { |
| 387 LOG(ERROR) << object_path.value() | 383 LOG(ERROR) << object_path |
| 388 << ": PropertyChanged signal has incorrect parameters: " | 384 << ": PropertyChanged signal has incorrect parameters: " |
| 389 << signal->ToString(); | 385 << signal->ToString(); |
| 390 return; | 386 return; |
| 391 } | 387 } |
| 392 | 388 |
| 393 if (property_name != bluetooth_adapter::kDiscoveringProperty) { | 389 if (property_name != bluetooth_adapter::kDiscoveringProperty) { |
| 394 VLOG(1) << object_path.value() << ": PropertyChanged: " << property_name; | 390 VLOG(1) << object_path << ": PropertyChanged: " << property_name; |
| 395 // We don't care. | 391 // We don't care. |
| 396 return; | 392 return; |
| 397 } | 393 } |
| 398 | 394 |
| 399 bool discovering = false; | 395 bool discovering = false; |
| 400 if (!reader.PopVariantOfBool(&discovering)) { | 396 if (!reader.PopVariantOfBool(&discovering)) { |
| 401 LOG(ERROR) << object_path.value() | 397 LOG(ERROR) << object_path |
| 402 << ": PropertyChanged signal has incorrect parameters: " | 398 << ": PropertyChanged signal has incorrect parameters: " |
| 403 << signal->ToString(); | 399 << signal->ToString(); |
| 404 return; | 400 return; |
| 405 } | 401 } |
| 406 VLOG(1) << object_path.value() << ": PropertyChanged: Discovering = " | 402 VLOG(1) << object_path << ": PropertyChanged: Discovering = " |
| 407 << discovering; | 403 << discovering; |
| 408 | 404 |
| 409 FOR_EACH_OBSERVER(BluetoothAdapterClient::Observer, observers_, | 405 FOR_EACH_OBSERVER(BluetoothAdapterClient::Observer, observers_, |
| 410 DiscoveringPropertyChanged(object_path, discovering)); | 406 DiscoveringPropertyChanged(object_path, discovering)); |
| 411 } | 407 } |
| 412 | 408 |
| 413 // Called by dbus:: when the PropertyChanged signal is initially connected. | 409 // Called by dbus:: when the PropertyChanged signal is initially connected. |
| 414 void PropertyChangedConnected(const dbus::ObjectPath& object_path, | 410 void PropertyChangedConnected(const std::string& object_path, |
| 415 const std::string& interface_name, | 411 const std::string& interface_name, |
| 416 const std::string& signal_name, | 412 const std::string& signal_name, |
| 417 bool success) { | 413 bool success) { |
| 418 LOG_IF(WARNING, !success) | 414 LOG_IF(WARNING, !success) << object_path |
| 419 << object_path.value() | |
| 420 << ": Failed to connect to PropertyChanged signal."; | 415 << ": Failed to connect to PropertyChanged signal."; |
| 421 } | 416 } |
| 422 | 417 |
| 423 // Called by dbus:: when a DeviceFound signal is received. | 418 // Called by dbus:: when a DeviceFound signal is received. |
| 424 void DeviceFoundReceived(const dbus::ObjectPath& object_path, | 419 void DeviceFoundReceived(const std::string& object_path, |
| 425 dbus::Signal* signal) { | 420 dbus::Signal* signal) { |
| 426 DCHECK(signal); | 421 DCHECK(signal); |
| 427 dbus::MessageReader reader(signal); | 422 dbus::MessageReader reader(signal); |
| 428 std::string address; | 423 std::string address; |
| 429 if (!reader.PopString(&address)) { | 424 if (!reader.PopString(&address)) { |
| 430 LOG(ERROR) << object_path.value() | 425 LOG(ERROR) << object_path |
| 431 << ": DeviceFound signal has incorrect parameters: " | 426 << ": DeviceFound signal has incorrect parameters: " |
| 432 << signal->ToString(); | 427 << signal->ToString(); |
| 433 return; | 428 return; |
| 434 } | 429 } |
| 435 VLOG(1) << object_path.value() << ": Device found: " << address; | 430 VLOG(1) << object_path << ": Device found: " << address; |
| 436 | 431 |
| 437 DictionaryValue device_properties; | 432 DictionaryValue device_properties; |
| 438 if (!PopArrayOfDictEntries(&reader, signal, &device_properties)) { | 433 if (!PopArrayOfDictEntries(&reader, signal, &device_properties)) { |
| 439 LOG(ERROR) << object_path.value() | 434 LOG(ERROR) << object_path |
| 440 << ": DeviceFound signal has incorrect parameters: " | 435 << ": DeviceFound signal has incorrect parameters: " |
| 441 << signal->ToString(); | 436 << signal->ToString(); |
| 442 return; | 437 return; |
| 443 } | 438 } |
| 444 | 439 |
| 445 FOR_EACH_OBSERVER(BluetoothAdapterClient::Observer, observers_, | 440 FOR_EACH_OBSERVER(BluetoothAdapterClient::Observer, observers_, |
| 446 DeviceFound(object_path, address, device_properties)); | 441 DeviceFound(object_path, address, device_properties)); |
| 447 } | 442 } |
| 448 | 443 |
| 449 // Called by dbus:: when the DeviceFound signal is initially connected. | 444 // Called by dbus:: when the DeviceFound signal is initially connected. |
| 450 void DeviceFoundConnected(const dbus::ObjectPath& object_path, | 445 void DeviceFoundConnected(const std::string& object_path, |
| 451 const std::string& interface_name, | 446 const std::string& interface_name, |
| 452 const std::string& signal_name, | 447 const std::string& signal_name, |
| 453 bool success) { | 448 bool success) { |
| 454 LOG_IF(WARNING, !success) << object_path.value() | 449 LOG_IF(WARNING, !success) << object_path |
| 455 << ": Failed to connect to DeviceFound signal."; | 450 << ": Failed to connect to DeviceFound signal."; |
| 456 } | 451 } |
| 457 | 452 |
| 458 // Called by dbus:: when a DeviceDisappeared signal is received. | 453 // Called by dbus:: when a DeviceDisappeared signal is received. |
| 459 void DeviceDisappearedReceived(const dbus::ObjectPath& object_path, | 454 void DeviceDisappearedReceived(const std::string& object_path, |
| 460 dbus::Signal* signal) { | 455 dbus::Signal* signal) { |
| 461 DCHECK(signal); | 456 DCHECK(signal); |
| 462 dbus::MessageReader reader(signal); | 457 dbus::MessageReader reader(signal); |
| 463 std::string address; | 458 std::string address; |
| 464 if (!reader.PopString(&address)) { | 459 if (!reader.PopString(&address)) { |
| 465 LOG(ERROR) << object_path.value() | 460 LOG(ERROR) << object_path |
| 466 << ": DeviceDisappeared signal has incorrect parameters: " | 461 << ": DeviceDisappeared signal has incorrect parameters: " |
| 467 << signal->ToString(); | 462 << signal->ToString(); |
| 468 return; | 463 return; |
| 469 } | 464 } |
| 470 VLOG(1) << object_path.value() << ": Device disappeared: " << address; | 465 VLOG(1) << object_path << ": Device disappeared: " << address; |
| 471 FOR_EACH_OBSERVER(BluetoothAdapterClient::Observer, observers_, | 466 FOR_EACH_OBSERVER(BluetoothAdapterClient::Observer, observers_, |
| 472 DeviceDisappeared(object_path, address)); | 467 DeviceDisappeared(object_path, address)); |
| 473 } | 468 } |
| 474 | 469 |
| 475 // Called by dbus:: when the DeviceDisappeared signal is initially connected. | 470 // Called by dbus:: when the DeviceDisappeared signal is initially connected. |
| 476 void DeviceDisappearedConnected(const dbus::ObjectPath& object_path, | 471 void DeviceDisappearedConnected(const std::string& object_path, |
| 477 const std::string& interface_name, | 472 const std::string& interface_name, |
| 478 const std::string& signal_name, | 473 const std::string& signal_name, |
| 479 bool success) { | 474 bool success) { |
| 480 LOG_IF(WARNING, !success) | 475 LOG_IF(WARNING, !success) << object_path |
| 481 << object_path.value() | |
| 482 << ": Failed to connect to DeviceDisappeared signal."; | 476 << ": Failed to connect to DeviceDisappeared signal."; |
| 483 } | 477 } |
| 484 | 478 |
| 485 // Called when a response for StartDiscovery() is received. | 479 // Called when a response for StartDiscovery() is received. |
| 486 void OnStartDiscovery(const dbus::ObjectPath& object_path, | 480 void OnStartDiscovery(const std::string& object_path, |
| 487 dbus::Response* response) { | 481 dbus::Response* response) { |
| 488 VLOG(1) << "OnStartDiscovery: " << object_path.value(); | 482 VLOG(1) << "OnStartDiscovery: " << object_path; |
| 489 LOG_IF(WARNING, !response) << object_path.value() | 483 LOG_IF(WARNING, !response) << object_path << ": OnStartDiscovery: failed."; |
| 490 << ": OnStartDiscovery: failed."; | |
| 491 } | 484 } |
| 492 | 485 |
| 493 // Called when a response for StopDiscovery() is received. | 486 // Called when a response for StopDiscovery() is received. |
| 494 void OnStopDiscovery(const dbus::ObjectPath& object_path, | 487 void OnStopDiscovery(const std::string& object_path, |
| 495 dbus::Response* response) { | 488 dbus::Response* response) { |
| 496 VLOG(1) << "OnStopDiscovery: " << object_path.value(); | 489 VLOG(1) << "OnStopDiscovery: " << object_path; |
| 497 LOG_IF(WARNING, !response) << object_path.value() | 490 LOG_IF(WARNING, !response) << object_path << ": OnStopDiscovery: failed."; |
| 498 << ": OnStopDiscovery: failed."; | |
| 499 } | 491 } |
| 500 | 492 |
| 501 // Weak pointer factory for generating 'this' pointers that might live longer | 493 // Weak pointer factory for generating 'this' pointers that might live longer |
| 502 // than we do. | 494 // than we do. |
| 503 base::WeakPtrFactory<BluetoothAdapterClientImpl> weak_ptr_factory_; | 495 base::WeakPtrFactory<BluetoothAdapterClientImpl> weak_ptr_factory_; |
| 504 | 496 |
| 505 dbus::Bus* bus_; | 497 dbus::Bus* bus_; |
| 506 | 498 |
| 507 // We maintain a collection of dbus object proxies, one for each adapter. | 499 // We maintain a collection of dbus object proxies, one for each adapter. |
| 508 typedef std::map<const dbus::ObjectPath, dbus::ObjectProxy*> ProxyMap; | 500 typedef std::map<const std::string, dbus::ObjectProxy*> ProxyMap; |
| 509 ProxyMap proxy_map_; | 501 ProxyMap proxy_map_; |
| 510 | 502 |
| 511 // List of observers interested in event notifications from us. | 503 // List of observers interested in event notifications from us. |
| 512 ObserverList<BluetoothAdapterClient::Observer> observers_; | 504 ObserverList<BluetoothAdapterClient::Observer> observers_; |
| 513 | 505 |
| 514 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterClientImpl); | 506 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterClientImpl); |
| 515 }; | 507 }; |
| 516 | 508 |
| 517 // The BluetoothAdapterClient implementation used on Linux desktop, which does | 509 // The BluetoothAdapterClient implementation used on Linux desktop, which does |
| 518 // nothing. | 510 // nothing. |
| 519 class BluetoothAdapterClientStubImpl : public BluetoothAdapterClient { | 511 class BluetoothAdapterClientStubImpl : public BluetoothAdapterClient { |
| 520 public: | 512 public: |
| 521 // BluetoothAdapterClient override. | 513 // BluetoothAdapterClient override. |
| 522 virtual void AddObserver(Observer* observer) { | 514 virtual void AddObserver(Observer* observer) { |
| 523 VLOG(1) << "AddObserver"; | 515 VLOG(1) << "AddObserver"; |
| 524 } | 516 } |
| 525 | 517 |
| 526 // BluetoothAdapterClient override. | 518 // BluetoothAdapterClient override. |
| 527 virtual void RemoveObserver(Observer* observer) { | 519 virtual void RemoveObserver(Observer* observer) { |
| 528 VLOG(1) << "RemoveObserver"; | 520 VLOG(1) << "RemoveObserver"; |
| 529 } | 521 } |
| 530 | 522 |
| 531 // BluetoothAdapterClient override. | 523 // BluetoothAdapterClient override. |
| 532 virtual void StartDiscovery(const dbus::ObjectPath& object_path) { | 524 virtual void StartDiscovery(const std::string& object_path) { |
| 533 VLOG(1) << "StartDiscovery: " << object_path.value(); | 525 VLOG(1) << "StartDiscovery: " << object_path; |
| 534 } | 526 } |
| 535 | 527 |
| 536 // BluetoothAdapterClient override. | 528 // BluetoothAdapterClient override. |
| 537 virtual void StopDiscovery(const dbus::ObjectPath& object_path) { | 529 virtual void StopDiscovery(const std::string& object_path) { |
| 538 VLOG(1) << "StopDiscovery: " << object_path.value(); | 530 VLOG(1) << "StopDiscovery: " << object_path; |
| 539 } | 531 } |
| 540 }; | 532 }; |
| 541 | 533 |
| 542 BluetoothAdapterClient::BluetoothAdapterClient() { | 534 BluetoothAdapterClient::BluetoothAdapterClient() { |
| 543 } | 535 } |
| 544 | 536 |
| 545 BluetoothAdapterClient::~BluetoothAdapterClient() { | 537 BluetoothAdapterClient::~BluetoothAdapterClient() { |
| 546 } | 538 } |
| 547 | 539 |
| 548 BluetoothAdapterClient* BluetoothAdapterClient::Create( | 540 BluetoothAdapterClient* BluetoothAdapterClient::Create( |
| 549 dbus::Bus* bus, | 541 dbus::Bus* bus, |
| 550 BluetoothManagerClient* manager_client) { | 542 BluetoothManagerClient* manager_client) { |
| 551 if (system::runtime_environment::IsRunningOnChromeOS()) { | 543 if (system::runtime_environment::IsRunningOnChromeOS()) { |
| 552 return new BluetoothAdapterClientImpl(bus, manager_client); | 544 return new BluetoothAdapterClientImpl(bus, manager_client); |
| 553 } else { | 545 } else { |
| 554 return new BluetoothAdapterClientStubImpl(); | 546 return new BluetoothAdapterClientStubImpl(); |
| 555 } | 547 } |
| 556 } | 548 } |
| 557 | 549 |
| 558 } // namespace chromeos | 550 } // namespace chromeos |
| OLD | NEW |