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

Side by Side Diff: chrome/browser/chromeos/bluetooth/bluetooth_adapter_chromeos.h

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

Powered by Google App Engine
This is Rietveld 408576698