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 #ifndef CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_ |
6 #define CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
15 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" | |
16 #include "chromeos/dbus/bluetooth_adapter_client.h" | 15 #include "chromeos/dbus/bluetooth_adapter_client.h" |
17 #include "chromeos/dbus/bluetooth_device_client.h" | 16 #include "chromeos/dbus/bluetooth_device_client.h" |
18 #include "chromeos/dbus/bluetooth_manager_client.h" | 17 #include "chromeos/dbus/bluetooth_manager_client.h" |
19 #include "dbus/object_path.h" | 18 #include "dbus/object_path.h" |
19 #include "device/bluetooth/bluetooth_adapter.h" | |
20 | |
21 namespace device { | |
22 | |
23 class BluetoothAdapterFactory; | |
24 class MockBluetoothAdapter; | |
25 struct BluetoothOutOfBandPairingData; | |
26 | |
27 } // namespace device | |
20 | 28 |
21 namespace chromeos { | 29 namespace chromeos { |
22 | 30 |
23 class BluetoothDeviceChromeOs; | 31 class BluetoothDeviceChromeOs; |
24 | 32 |
25 struct BluetoothOutOfBandPairingData; | |
26 | |
27 // The BluetoothAdapterChromeOs class is an implementation of BluetoothAdapter | 33 // The BluetoothAdapterChromeOs class is an implementation of BluetoothAdapter |
28 // for Chrome OS platform. | 34 // for Chrome OS platform. |
29 class BluetoothAdapterChromeOs : public BluetoothAdapter, | 35 class BluetoothAdapterChromeOs |
tfarina
2012/10/20 02:08:42
This class should have probably be named Bluetooth
| |
30 public BluetoothManagerClient::Observer, | 36 : public device::BluetoothAdapter, |
31 public BluetoothAdapterClient::Observer, | 37 public BluetoothManagerClient::Observer, |
32 public BluetoothDeviceClient::Observer { | 38 public BluetoothAdapterClient::Observer, |
39 public BluetoothDeviceClient::Observer { | |
33 public: | 40 public: |
34 // BluetoothAdapter override | 41 // BluetoothAdapter override |
35 virtual void AddObserver(BluetoothAdapter::Observer* observer) OVERRIDE; | 42 virtual void AddObserver( |
36 virtual void RemoveObserver(BluetoothAdapter::Observer* observer) OVERRIDE; | 43 device::BluetoothAdapter::Observer* observer) OVERRIDE; |
44 virtual void RemoveObserver( | |
45 device::BluetoothAdapter::Observer* observer) OVERRIDE; | |
37 virtual bool IsPresent() const OVERRIDE; | 46 virtual bool IsPresent() const OVERRIDE; |
38 virtual bool IsPowered() const OVERRIDE; | 47 virtual bool IsPowered() const OVERRIDE; |
39 virtual void SetPowered( | 48 virtual void SetPowered( |
40 bool powered, | 49 bool powered, |
41 const base::Closure& callback, | 50 const base::Closure& callback, |
42 const ErrorCallback& error_callback) OVERRIDE; | 51 const ErrorCallback& error_callback) OVERRIDE; |
43 virtual bool IsDiscovering() const OVERRIDE; | 52 virtual bool IsDiscovering() const OVERRIDE; |
44 virtual void SetDiscovering( | 53 virtual void SetDiscovering( |
45 bool discovering, | 54 bool discovering, |
46 const base::Closure& callback, | 55 const base::Closure& callback, |
47 const ErrorCallback& error_callback) OVERRIDE; | 56 const ErrorCallback& error_callback) OVERRIDE; |
48 virtual ConstDeviceList GetDevices() const OVERRIDE; | 57 virtual ConstDeviceList GetDevices() const OVERRIDE; |
49 virtual BluetoothDevice* GetDevice(const std::string& address) OVERRIDE; | 58 virtual device::BluetoothDevice* GetDevice( |
50 virtual const BluetoothDevice* GetDevice( | 59 const std::string& address) OVERRIDE; |
60 virtual const device::BluetoothDevice* GetDevice( | |
51 const std::string& address) const OVERRIDE; | 61 const std::string& address) const OVERRIDE; |
52 virtual void ReadLocalOutOfBandPairingData( | 62 virtual void ReadLocalOutOfBandPairingData( |
53 const BluetoothOutOfBandPairingDataCallback& callback, | 63 const device::BluetoothAdapter::BluetoothOutOfBandPairingDataCallback& |
64 callback, | |
54 const ErrorCallback& error_callback) OVERRIDE; | 65 const ErrorCallback& error_callback) OVERRIDE; |
55 | 66 |
56 private: | 67 private: |
57 friend class BluetoothAdapterFactory; | |
58 friend class BluetoothDeviceChromeOs; | 68 friend class BluetoothDeviceChromeOs; |
59 friend class MockBluetoothAdapter; | 69 friend class device::BluetoothAdapterFactory; |
70 friend class device::MockBluetoothAdapter; | |
60 | 71 |
61 BluetoothAdapterChromeOs(); | 72 BluetoothAdapterChromeOs(); |
62 virtual ~BluetoothAdapterChromeOs(); | 73 virtual ~BluetoothAdapterChromeOs(); |
63 | 74 |
64 // Obtains the default adapter object path from the Bluetooth Daemon | 75 // Obtains the default adapter object path from the Bluetooth Daemon |
65 // and tracks future changes to it. | 76 // and tracks future changes to it. |
66 void TrackDefaultAdapter(); | 77 void TrackDefaultAdapter(); |
67 | 78 |
68 // Obtains the object paht for the adapter named by |address| from the | 79 // Obtains the object paht for the adapter named by |address| from the |
69 // Bluetooth Daemon. | 80 // Bluetooth Daemon. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
118 const ErrorCallback& error_callback, | 129 const ErrorCallback& error_callback, |
119 const dbus::ObjectPath& adapter_path, | 130 const dbus::ObjectPath& adapter_path, |
120 bool success); | 131 bool success); |
121 | 132 |
122 // Updates the tracked state of the adapter's discovering state to | 133 // Updates the tracked state of the adapter's discovering state to |
123 // |discovering| and notifies observers. Called on receipt of a property | 134 // |discovering| and notifies observers. Called on receipt of a property |
124 // changed signal, and directly using values obtained from properties. | 135 // changed signal, and directly using values obtained from properties. |
125 void DiscoveringChanged(bool discovering); | 136 void DiscoveringChanged(bool discovering); |
126 | 137 |
127 // Called by dbus:: in response to the ReadLocalData method call. | 138 // Called by dbus:: in response to the ReadLocalData method call. |
128 void OnReadLocalData(const BluetoothOutOfBandPairingDataCallback& callback, | 139 void OnReadLocalData( |
129 const ErrorCallback& error_callback, | 140 const device::BluetoothAdapter::BluetoothOutOfBandPairingDataCallback& |
130 const BluetoothOutOfBandPairingData& data, | 141 callback, |
131 bool success); | 142 const ErrorCallback& error_callback, |
143 const device::BluetoothOutOfBandPairingData& data, | |
144 bool success); | |
132 | 145 |
133 // BluetoothAdapterClient::Observer override. | 146 // BluetoothAdapterClient::Observer override. |
134 // | 147 // |
135 // Called when the adapter with object path |adapter_path| has a | 148 // Called when the adapter with object path |adapter_path| has a |
136 // change in value of the property named |property_name|. | 149 // change in value of the property named |property_name|. |
137 virtual void AdapterPropertyChanged(const dbus::ObjectPath& adapter_path, | 150 virtual void AdapterPropertyChanged(const dbus::ObjectPath& adapter_path, |
138 const std::string& property_name) | 151 const std::string& property_name) |
139 OVERRIDE; | 152 OVERRIDE; |
140 | 153 |
141 // BluetoothDeviceClient::Observer override. | 154 // BluetoothDeviceClient::Observer override. |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
193 | 206 |
194 // BluetoothAdapterClient::Observer override. | 207 // BluetoothAdapterClient::Observer override. |
195 // | 208 // |
196 // Called when the adapter with object path |object_path| can no | 209 // Called when the adapter with object path |object_path| can no |
197 // longer communicate with the discovered removed device with | 210 // longer communicate with the discovered removed device with |
198 // address |address|. | 211 // address |address|. |
199 virtual void DeviceDisappeared(const dbus::ObjectPath& object_path, | 212 virtual void DeviceDisappeared(const dbus::ObjectPath& object_path, |
200 const std::string& address) OVERRIDE; | 213 const std::string& address) OVERRIDE; |
201 | 214 |
202 // List of observers interested in event notifications from us. | 215 // List of observers interested in event notifications from us. |
203 ObserverList<BluetoothAdapter::Observer> observers_; | 216 ObserverList<device::BluetoothAdapter::Observer> observers_; |
204 | 217 |
205 // Object path of adapter for this instance, this is fixed at creation time | 218 // Object path of adapter for this instance, this is fixed at creation time |
206 // unless |track_default_| is true in which case we update it to always | 219 // unless |track_default_| is true in which case we update it to always |
207 // point at the default adapter. | 220 // point at the default adapter. |
208 bool track_default_; | 221 bool track_default_; |
209 dbus::ObjectPath object_path_; | 222 dbus::ObjectPath object_path_; |
210 | 223 |
211 // Tracked adapter state, cached locally so we only send change notifications | 224 // Tracked adapter state, cached locally so we only send change notifications |
212 // to observers on a genuine change. | 225 // to observers on a genuine change. |
213 bool powered_; | 226 bool powered_; |
214 bool discovering_; | 227 bool discovering_; |
215 | 228 |
216 // Devices paired with, connected to, discovered by, or visible to the | 229 // Devices paired with, connected to, discovered by, or visible to the |
217 // adapter. The key is the Bluetooth address of the device and the value | 230 // adapter. The key is the Bluetooth address of the device and the value |
218 // is the BluetoothDeviceChromeOs object whose lifetime is managed by the | 231 // is the BluetoothDeviceChromeOs object whose lifetime is managed by the |
219 // adapter instance. | 232 // adapter instance. |
220 typedef std::map<const std::string, BluetoothDeviceChromeOs*> DevicesMap; | 233 typedef std::map<const std::string, BluetoothDeviceChromeOs*> DevicesMap; |
221 DevicesMap devices_; | 234 DevicesMap devices_; |
222 | 235 |
223 // Note: This should remain the last member so it'll be destroyed and | 236 // Note: This should remain the last member so it'll be destroyed and |
224 // invalidate its weak pointers before any other members are destroyed. | 237 // invalidate its weak pointers before any other members are destroyed. |
225 base::WeakPtrFactory<BluetoothAdapterChromeOs> weak_ptr_factory_; | 238 base::WeakPtrFactory<BluetoothAdapterChromeOs> weak_ptr_factory_; |
226 | 239 |
227 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterChromeOs); | 240 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterChromeOs); |
228 }; | 241 }; |
229 | 242 |
230 } // namespace chromeos | 243 } // namespace chromeos |
231 | 244 |
232 #endif // CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_ | 245 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_ |
OLD | NEW |