Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Side by Side Diff: device/bluetooth/bluetooth_adapter_chromeos.h

Issue 15020009: Bluetooth: remove legacy backend (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/basictypes.h"
12 #include "base/callback.h"
13 #include "base/observer_list.h"
14 #include "chromeos/dbus/bluetooth_adapter_client.h"
15 #include "chromeos/dbus/bluetooth_device_client.h"
16 #include "chromeos/dbus/bluetooth_manager_client.h"
17 #include "dbus/object_path.h"
18 #include "device/bluetooth/bluetooth_adapter.h"
19
20 namespace device {
21
22 class BluetoothAdapterFactory;
23 class MockBluetoothAdapter;
24 struct BluetoothOutOfBandPairingData;
25
26 } // namespace device
27
28 namespace chromeos {
29
30 class BluetoothDeviceChromeOS;
31
32 // The BluetoothAdapterChromeOS class is an implementation of BluetoothAdapter
33 // for Chrome OS platform.
34 class BluetoothAdapterChromeOS
35 : public device::BluetoothAdapter,
36 public BluetoothManagerClient::Observer,
37 public BluetoothAdapterClient::Observer,
38 public BluetoothDeviceClient::Observer {
39 public:
40 // BluetoothAdapter override
41 virtual void AddObserver(
42 device::BluetoothAdapter::Observer* observer) OVERRIDE;
43 virtual void RemoveObserver(
44 device::BluetoothAdapter::Observer* observer) OVERRIDE;
45 virtual std::string GetAddress() const OVERRIDE;
46 virtual std::string GetName() const OVERRIDE;
47 virtual bool IsInitialized() const OVERRIDE;
48 virtual bool IsPresent() const OVERRIDE;
49 virtual bool IsPowered() const OVERRIDE;
50 virtual void SetPowered(
51 bool powered,
52 const base::Closure& callback,
53 const ErrorCallback& error_callback) OVERRIDE;
54 virtual bool IsDiscovering() const OVERRIDE;
55 virtual void StartDiscovering(
56 const base::Closure& callback,
57 const ErrorCallback& error_callback) OVERRIDE;
58 virtual void StopDiscovering(
59 const base::Closure& callback,
60 const ErrorCallback& error_callback) OVERRIDE;
61 virtual void ReadLocalOutOfBandPairingData(
62 const device::BluetoothAdapter::BluetoothOutOfBandPairingDataCallback&
63 callback,
64 const ErrorCallback& error_callback) OVERRIDE;
65
66 private:
67 friend class BluetoothDeviceChromeOS;
68 friend class device::BluetoothAdapterFactory;
69 friend class device::MockBluetoothAdapter;
70
71 BluetoothAdapterChromeOS();
72 virtual ~BluetoothAdapterChromeOS();
73
74 // Called by dbus:: in response to the method call sent by DefaultAdapter().
75 // |object_path| will contain the dbus object path of the requested adapter
76 // when |success| is true.
77 void AdapterCallback(const dbus::ObjectPath& adapter_path, bool success);
78
79 // BluetoothManagerClient::Observer override.
80 //
81 // Called when the default local bluetooth adapter changes.
82 // |object_path| is the dbus object path of the new default adapter.
83 // Not called if all adapters are removed.
84 virtual void DefaultAdapterChanged(const dbus::ObjectPath& adapter_path)
85 OVERRIDE;
86
87 // BluetoothManagerClient::Observer override.
88 //
89 // Called when a local bluetooth adapter is removed.
90 // |object_path| is the dbus object path of the adapter.
91 virtual void AdapterRemoved(const dbus::ObjectPath& adapter_path) OVERRIDE;
92
93 // Changes the tracked adapter to the dbus object path |adapter_path|,
94 // clearing information from the previously tracked adapter and updating
95 // to the new adapter.
96 void ChangeAdapter(const dbus::ObjectPath& adapter_path);
97
98 // Clears the tracked adapter information.
99 void RemoveAdapter();
100
101 // Called by dbus:: in response to the method call send by SetPowered().
102 // |callback| and |error_callback| are the callbacks passed to SetPowered().
103 void OnSetPowered(const base::Closure& callback,
104 const ErrorCallback& error_callback,
105 bool success);
106
107 // Updates the tracked state of the adapter's radio power to |powered|
108 // and notifies observers. Called on receipt of a property changed signal,
109 // and directly using values obtained from properties.
110 void PoweredChanged(bool powered);
111
112 // Notifies observers of a change in the device |device|. Used to signal
113 // changes initiated from the BluetoothDeviceChromeOS itself.
114 void NotifyDeviceChanged(BluetoothDeviceChromeOS* device);
115
116 // Called by BluetoothAdapterClient in response to the method call sent
117 // by StartDiscovering(), |callback| and |error_callback| are the callbacks
118 // provided to that method.
119 void OnStartDiscovery(const base::Closure& callback,
120 const ErrorCallback& error_callback,
121 const dbus::ObjectPath& adapter_path,
122 bool success);
123
124 // Called by BluetoothAdapterClient in response to the method call sent
125 // by StopDiscovering(), |callback| and |error_callback| are the callbacks
126 // provided to that method.
127 void OnStopDiscovery(const base::Closure& callback,
128 const ErrorCallback& error_callback,
129 const dbus::ObjectPath& adapter_path,
130 bool success);
131
132 // Updates the tracked state of the adapter's discovering state to
133 // |discovering| and notifies observers. Called on receipt of a property
134 // changed signal, and directly using values obtained from properties.
135 void DiscoveringChanged(bool discovering);
136
137 // Called by dbus:: in response to the ReadLocalData method call.
138 void OnReadLocalData(
139 const device::BluetoothAdapter::BluetoothOutOfBandPairingDataCallback&
140 callback,
141 const ErrorCallback& error_callback,
142 const device::BluetoothOutOfBandPairingData& data,
143 bool success);
144
145 // BluetoothAdapterClient::Observer override.
146 //
147 // Called when the adapter with object path |adapter_path| has a
148 // change in value of the property named |property_name|.
149 virtual void AdapterPropertyChanged(const dbus::ObjectPath& adapter_path,
150 const std::string& property_name)
151 OVERRIDE;
152
153 // BluetoothDeviceClient::Observer override.
154 //
155 // Called when the device with object path |device_path| has a
156 // change in value of the property named |property_name|.
157 virtual void DevicePropertyChanged(const dbus::ObjectPath& device_path,
158 const std::string& property_name)
159 OVERRIDE;
160
161 // Updates information on the device with object path |device_path|,
162 // adding it to the |devices_| map if not already present.
163 void UpdateDevice(const dbus::ObjectPath& device_path);
164
165 // Clears the |devices_| list, notifying obsevers of the device removal.
166 void ClearDevices();
167
168 // BluetoothAdapterClient::Observer override.
169 //
170 // Called when the adapter with object path |object_path| has a
171 // new known device with object path |object_path|.
172 virtual void DeviceCreated(const dbus::ObjectPath& adapter_path,
173 const dbus::ObjectPath& device_path) OVERRIDE;
174
175 // BluetoothAdapterClient::Observer override.
176 //
177 // Called when the adapter with object path |object_path| removes
178 // the known device with object path |object_path|.
179 virtual void DeviceRemoved(const dbus::ObjectPath& adapter_path,
180 const dbus::ObjectPath& device_path) OVERRIDE;
181
182 // Updates the adapter |devices_| list, adding or updating devices using
183 // the object paths in the|devices| list. This doesn't remove devices,
184 // relying instead on the DeviceRemoved() signal for that. Called on
185 // receipt of a property changed signal, and directly using values obtained
186 // from properties.
187 void DevicesChanged(const std::vector<dbus::ObjectPath>& devices);
188
189 // Clears discovered devices from the |devices_| list, notifying
190 // observers, and leaving only those devices with a dbus object path.
191 void ClearDiscoveredDevices();
192
193 // BluetoothAdapterClient::Observer override.
194 //
195 // Called when the adapter with object path |object_path| discovers
196 // a new remote device with address |address| and properties
197 // |properties|, there is no device object path until connected.
198 //
199 // |properties| supports only value() calls, not Get() or Set(), and
200 // should be copied if needed.
201 virtual void DeviceFound(
202 const dbus::ObjectPath& adapter_path,
203 const std::string& address,
204 const BluetoothDeviceClient::Properties& properties) OVERRIDE;
205
206 // BluetoothAdapterClient::Observer override.
207 //
208 // Called when the adapter with object path |object_path| can no
209 // longer communicate with the discovered removed device with
210 // address |address|.
211 virtual void DeviceDisappeared(const dbus::ObjectPath& object_path,
212 const std::string& address) OVERRIDE;
213
214 // List of observers interested in event notifications from us.
215 ObserverList<device::BluetoothAdapter::Observer> observers_;
216
217 // Object path of adapter for this instance, we update it to always
218 // point at the default adapter.
219 dbus::ObjectPath object_path_;
220
221 // Tracked adapter state, cached locally so we only send change notifications
222 // to observers on a genuine change.
223 std::string address_;
224 std::string name_;
225 bool powered_;
226 bool discovering_;
227
228 // Count of callers to StartDiscovering() and StopDiscovering(), used to
229 // track whether to clear the discovered devices list on start.
230 int discovering_count_;
231
232 // Note: This should remain the last member so it'll be destroyed and
233 // invalidate its weak pointers before any other members are destroyed.
234 base::WeakPtrFactory<BluetoothAdapterChromeOS> weak_ptr_factory_;
235
236 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterChromeOS);
237 };
238
239 } // namespace chromeos
240
241 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_
OLDNEW
« no previous file with comments | « chromeos/dbus/mock_dbus_thread_manager_without_gmock.cc ('k') | device/bluetooth/bluetooth_adapter_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698