| 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_device_client.h" | 5 #include "chrome/browser/chromeos/dbus/bluetooth_device_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_adapter_client.h" | 12 #include "chrome/browser/chromeos/dbus/bluetooth_adapter_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" |
| 16 #include "dbus/object_proxy.h" | 17 #include "dbus/object_proxy.h" |
| 17 #include "third_party/cros_system_api/dbus/service_constants.h" | 18 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 18 | 19 |
| 19 namespace chromeos { | 20 namespace chromeos { |
| 20 | 21 |
| 21 // The BluetoothDeviceClient implementation used in production. | 22 // The BluetoothDeviceClient implementation used in production. |
| 22 class BluetoothDeviceClientImpl: public BluetoothDeviceClient, | 23 class BluetoothDeviceClientImpl: public BluetoothDeviceClient, |
| 23 private BluetoothAdapterClient::Observer { | 24 private BluetoothAdapterClient::Observer { |
| 24 public: | 25 public: |
| 25 BluetoothDeviceClientImpl(dbus::Bus* bus, | 26 BluetoothDeviceClientImpl(dbus::Bus* bus, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 46 // BluetoothDeviceClient override. | 47 // BluetoothDeviceClient override. |
| 47 virtual void RemoveObserver(BluetoothDeviceClient::Observer* observer) | 48 virtual void RemoveObserver(BluetoothDeviceClient::Observer* observer) |
| 48 OVERRIDE { | 49 OVERRIDE { |
| 49 VLOG(1) << "RemoveObserver"; | 50 VLOG(1) << "RemoveObserver"; |
| 50 DCHECK(observer); | 51 DCHECK(observer); |
| 51 observers_.RemoveObserver(observer); | 52 observers_.RemoveObserver(observer); |
| 52 } | 53 } |
| 53 | 54 |
| 54 private: | 55 private: |
| 55 // BluetoothAdapterClient::Observer override. | 56 // BluetoothAdapterClient::Observer override. |
| 56 virtual void DeviceCreated(const std::string& adapter_path, | 57 virtual void DeviceCreated(const dbus::ObjectPath& adapter_path, |
| 57 const std::string& object_path) OVERRIDE { | 58 const dbus::ObjectPath& object_path) OVERRIDE { |
| 58 VLOG(1) << "DeviceCreated: " << object_path; | 59 VLOG(1) << "DeviceCreated: " << object_path.value(); |
| 59 } | 60 } |
| 60 | 61 |
| 61 // BluetoothAdapterClient::Observer override. | 62 // BluetoothAdapterClient::Observer override. |
| 62 virtual void DeviceRemoved(const std::string& adapter_path, | 63 virtual void DeviceRemoved(const dbus::ObjectPath& adapter_path, |
| 63 const std::string& object_path) OVERRIDE { | 64 const dbus::ObjectPath& object_path) OVERRIDE { |
| 64 VLOG(1) << "DeviceRemoved: " << object_path; | 65 VLOG(1) << "DeviceRemoved: " << object_path.value(); |
| 65 RemoveObjectProxyForPath(object_path); | 66 RemoveObjectProxyForPath(object_path); |
| 66 } | 67 } |
| 67 | 68 |
| 68 // Ensures that we have a dbus object proxy for a device with dbus | 69 // Ensures that we have a dbus object proxy for a device with dbus |
| 69 // object path |object_path|, and if not, creates it stores it in | 70 // object path |object_path|, and if not, creates it stores it in |
| 70 // our |proxy_map_| map. | 71 // our |proxy_map_| map. |
| 71 dbus::ObjectProxy* GetObjectProxyForPath(const std::string& object_path) { | 72 dbus::ObjectProxy* GetObjectProxyForPath( |
| 72 VLOG(1) << "GetObjectProxyForPath: " << object_path; | 73 const dbus::ObjectPath& object_path) { |
| 74 VLOG(1) << "GetObjectProxyForPath: " << object_path.value(); |
| 73 | 75 |
| 74 ProxyMap::iterator it = proxy_map_.find(object_path); | 76 ProxyMap::iterator it = proxy_map_.find(object_path); |
| 75 if (it != proxy_map_.end()) | 77 if (it != proxy_map_.end()) |
| 76 return it->second; | 78 return it->second; |
| 77 | 79 |
| 78 DCHECK(bus_); | 80 DCHECK(bus_); |
| 79 dbus::ObjectProxy* device_proxy = bus_->GetObjectProxy( | 81 dbus::ObjectProxy* device_proxy = bus_->GetObjectProxy( |
| 80 bluetooth_device::kBluetoothDeviceServiceName, object_path); | 82 bluetooth_device::kBluetoothDeviceServiceName, object_path); |
| 81 | 83 |
| 82 proxy_map_[object_path] = device_proxy; | 84 proxy_map_[object_path] = device_proxy; |
| 83 | 85 |
| 84 return device_proxy; | 86 return device_proxy; |
| 85 } | 87 } |
| 86 | 88 |
| 87 // Removes the dbus object proxy for the device with dbus object path | 89 // Removes the dbus object proxy for the device with dbus object path |
| 88 // |object_path| from our |proxy_map_| map. | 90 // |object_path| from our |proxy_map_| map. |
| 89 void RemoveObjectProxyForPath(const std::string& object_path) { | 91 void RemoveObjectProxyForPath(const dbus::ObjectPath& object_path) { |
| 90 VLOG(1) << "RemoveObjectProxyForPath: " << object_path; | 92 VLOG(1) << "RemoveObjectProxyForPath: " << object_path.value(); |
| 91 proxy_map_.erase(object_path); | 93 proxy_map_.erase(object_path); |
| 92 } | 94 } |
| 93 | 95 |
| 94 // Weak pointer factory for generating 'this' pointers that might live longer | 96 // Weak pointer factory for generating 'this' pointers that might live longer |
| 95 // than we do. | 97 // than we do. |
| 96 base::WeakPtrFactory<BluetoothDeviceClientImpl> weak_ptr_factory_; | 98 base::WeakPtrFactory<BluetoothDeviceClientImpl> weak_ptr_factory_; |
| 97 | 99 |
| 98 dbus::Bus* bus_; | 100 dbus::Bus* bus_; |
| 99 | 101 |
| 100 // We maintain a collection of dbus object proxies, one for each device. | 102 // We maintain a collection of dbus object proxies, one for each device. |
| 101 typedef std::map<const std::string, dbus::ObjectProxy*> ProxyMap; | 103 typedef std::map<const dbus::ObjectPath, dbus::ObjectProxy*> ProxyMap; |
| 102 ProxyMap proxy_map_; | 104 ProxyMap proxy_map_; |
| 103 | 105 |
| 104 // List of observers interested in event notifications from us. | 106 // List of observers interested in event notifications from us. |
| 105 ObserverList<BluetoothDeviceClient::Observer> observers_; | 107 ObserverList<BluetoothDeviceClient::Observer> observers_; |
| 106 | 108 |
| 107 DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceClientImpl); | 109 DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceClientImpl); |
| 108 }; | 110 }; |
| 109 | 111 |
| 110 // The BluetoothDeviceClient implementation used on Linux desktop, which does | 112 // The BluetoothDeviceClient implementation used on Linux desktop, which does |
| 111 // nothing. | 113 // nothing. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 132 dbus::Bus* bus, | 134 dbus::Bus* bus, |
| 133 BluetoothAdapterClient* adapter_client) { | 135 BluetoothAdapterClient* adapter_client) { |
| 134 if (system::runtime_environment::IsRunningOnChromeOS()) { | 136 if (system::runtime_environment::IsRunningOnChromeOS()) { |
| 135 return new BluetoothDeviceClientImpl(bus, adapter_client); | 137 return new BluetoothDeviceClientImpl(bus, adapter_client); |
| 136 } else { | 138 } else { |
| 137 return new BluetoothDeviceClientStubImpl(); | 139 return new BluetoothDeviceClientStubImpl(); |
| 138 } | 140 } |
| 139 } | 141 } |
| 140 | 142 |
| 141 } // namespace chromeos | 143 } // namespace chromeos |
| OLD | NEW |