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

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

Issue 10899037: Refactoring bluetooth API code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rename to BluetoothAdapterChromeOs Created 8 years, 3 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
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_DEVICE_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_DEVICE_H_
6 #define CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_DEVICE_H_ 6 #define CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_DEVICE_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector>
10 9
11 #include "base/basictypes.h"
12 #include "base/callback.h" 10 #include "base/callback.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/scoped_vector.h"
15 #include "base/memory/weak_ptr.h"
16 #include "base/string16.h" 11 #include "base/string16.h"
17 #include "chromeos/dbus/bluetooth_agent_service_provider.h" 12 #include "base/memory/ref_counted.h"
18 #include "chromeos/dbus/bluetooth_device_client.h"
19 #include "chromeos/dbus/bluetooth_out_of_band_client.h"
20 #include "dbus/object_path.h"
21 13
22 namespace chromeos { 14 namespace chromeos {
23 15
24 class BluetoothAdapter;
25 class BluetoothServiceRecord; 16 class BluetoothServiceRecord;
26 class BluetoothSocket; 17 class BluetoothSocket;
27 18
28 // The BluetoothDevice class represents a remote Bluetooth device, both 19 struct BluetoothOutOfBandPairingData;
20
21 // The BluetoothDevice represents a remote Bluetooth device, both
keybuk 2012/09/17 22:19:43 nit: drop "The " since " class" is also dropped?
youngki 2012/09/18 18:19:56 Done.
29 // its properties and capabilities as discovered by a local adapter and 22 // its properties and capabilities as discovered by a local adapter and
30 // actions that may be performed on the remove device such as pairing, 23 // actions that may be performed on the remove device such as pairing,
31 // connection and disconnection. 24 // connection and disconnection.
32 // 25 //
33 // The class is instantiated and managed by the BluetoothAdapter class 26 // The class is instantiated and managed by the BluetoothAdapter class
34 // and pointers should only be obtained from that class and not cached, 27 // and pointers should only be obtained from that class and not cached,
35 // instead use the address() method as a unique key for a device. 28 // instead use the address() method as a unique key for a device.
36 // 29 //
37 // Since the lifecycle of BluetoothDevice instances is managed by 30 // Since the lifecycle of BluetoothDevice instances is managed by
38 // BluetoothAdapter, that class rather than this provides observer methods 31 // BluetoothAdapter, that class rather than this provides observer methods
39 // for devices coming and going, as well as properties being updated. 32 // for devices coming and going, as well as properties being updated.
40 class BluetoothDevice : public BluetoothDeviceClient::Observer, 33 class BluetoothDevice {
41 public BluetoothAgentServiceProvider::Delegate {
42 public: 34 public:
43 // Possible values that may be returned by GetDeviceType(), representing
44 // different types of bluetooth device that we support or are aware of
45 // decoded from the bluetooth class information.
46 enum DeviceType {
47 DEVICE_UNKNOWN,
48 DEVICE_COMPUTER,
49 DEVICE_PHONE,
50 DEVICE_MODEM,
51 DEVICE_PERIPHERAL,
52 DEVICE_JOYSTICK,
53 DEVICE_GAMEPAD,
54 DEVICE_KEYBOARD,
55 DEVICE_MOUSE,
56 DEVICE_TABLET,
57 DEVICE_KEYBOARD_MOUSE_COMBO
58 };
keybuk 2012/09/17 22:19:43 Why did this enum go away? This is the return type
youngki 2012/09/18 18:19:56 Done.
59
60 // Interface for observing changes from bluetooth devices. 35 // Interface for observing changes from bluetooth devices.
61 class Observer { 36 class Observer {
62 public: 37 public:
63 virtual ~Observer() {} 38 virtual ~Observer() {}
64 39
65 // TODO(keybuk): add observers for pairing and connection. 40 // TODO(keybuk): add observers for pairing and connection.
66 }; 41 };
67 42
68 // Interface for negotiating pairing of bluetooth devices. 43 // Interface for negotiating pairing of bluetooth devices.
69 class PairingDelegate { 44 class PairingDelegate {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 // This method will be called when any previous DisplayPinCode(), 108 // This method will be called when any previous DisplayPinCode(),
134 // DisplayPasskey() or ConfirmPasskey() request should be concluded 109 // DisplayPasskey() or ConfirmPasskey() request should be concluded
135 // and removed from the user. 110 // and removed from the user.
136 virtual void DismissDisplayOrConfirm() = 0; 111 virtual void DismissDisplayOrConfirm() = 0;
137 }; 112 };
138 113
139 virtual ~BluetoothDevice(); 114 virtual ~BluetoothDevice();
140 115
141 // Returns the Bluetooth of address the device. This should be used as 116 // Returns the Bluetooth of address the device. This should be used as
142 // a unique key to identify the device and copied where needed. 117 // a unique key to identify the device and copied where needed.
143 virtual const std::string& address() const; 118 virtual const std::string& address() const = 0;
144 119
145 // Returns the name of the device suitable for displaying, this may 120 // Returns the name of the device suitable for displaying, this may
146 // be a synthesied string containing the address and localized type name 121 // be a synthesied string containing the address and localized type name
147 // if the device has no obtained name. 122 // if the device has no obtained name.
148 virtual string16 GetName() const; 123 virtual string16 GetName() const = 0;
149
150 // Returns the type of the device, limited to those we support or are
151 // aware of, by decoding the bluetooth class information. The returned
152 // values are unique, and do not overlap, so DEVICE_KEYBOARD is not also
153 // DEVICE_PERIPHERAL.
154 DeviceType GetDeviceType() const;
keybuk 2012/09/17 22:19:43 This needs to be part of the public interface!
youngki 2012/09/18 18:19:56 Done.
155
156 // Returns a localized string containing the device's bluetooth address and
157 // a device type for display when |name_| is empty.
158 string16 GetAddressWithLocalizedDeviceTypeName() const;
159
160 // Indicates whether the class of this device is supported by Chrome OS.
161 bool IsSupported() const;
keybuk 2012/09/17 22:19:43 ok for these to go, since they're internal to the
youngki 2012/09/18 18:19:56 Acknowledged.
162 124
163 // Indicates whether the device is paired to the adapter, whether or not 125 // Indicates whether the device is paired to the adapter, whether or not
164 // that pairing is permanent or temporary. 126 // that pairing is permanent or temporary.
165 virtual bool IsPaired() const; 127 virtual bool IsPaired() const = 0;
166
167 // Indicates whether the device is visible to the adapter, this is not
168 // mutually exclusive to being paired.
169 bool IsVisible() const { return visible_; }
keybuk 2012/09/17 22:19:43 This needs to be part of the public interface!
youngki 2012/09/18 18:19:56 Done.
170 128
171 // Indicates whether the device is bonded to the adapter, bonding is 129 // Indicates whether the device is bonded to the adapter, bonding is
172 // formed by pairing and exchanging high-security link keys so that 130 // formed by pairing and exchanging high-security link keys so that
173 // connections may be encrypted. 131 // connections may be encrypted.
174 virtual bool IsBonded() const; 132 virtual bool IsBonded() const = 0;
175 133
176 // Indicates whether the device is currently connected to the adapter 134 // Indicates whether the device is currently connected to the adapter
177 // and at least one service available for use. 135 // and at least one service available for use.
178 virtual bool IsConnected() const; 136 virtual bool IsConnected() const = 0;
179
180 // Returns the services (as UUID strings) that this device provides.
181 typedef std::vector<std::string> ServiceList;
182 const ServiceList& GetServices() const { return service_uuids_; }
keybuk 2012/09/17 22:19:43 This needs to be part of the public interface!
youngki 2012/09/18 18:19:56 Done.
183 137
184 // The ErrorCallback is used for methods that can fail in which case it 138 // The ErrorCallback is used for methods that can fail in which case it
185 // is called, in the success case the callback is simply not called. 139 // is called, in the success case the callback is simply not called.
186 typedef base::Callback<void()> ErrorCallback; 140 typedef base::Callback<void()> ErrorCallback;
187 141
188 // Returns the services (as BluetoothServiceRecord objects) that this device 142 // Returns the services (as BluetoothServiceRecord objects) that this device
189 // provides. 143 // provides.
190 typedef ScopedVector<BluetoothServiceRecord> ServiceRecordList; 144 typedef ScopedVector<BluetoothServiceRecord> ServiceRecordList;
191 typedef base::Callback<void(const ServiceRecordList&)> ServiceRecordsCallback; 145 typedef base::Callback<void(const ServiceRecordList&)> ServiceRecordsCallback;
192 void GetServiceRecords(const ServiceRecordsCallback& callback, 146 virtual void GetServiceRecords(const ServiceRecordsCallback& callback,
193 const ErrorCallback& error_callback); 147 const ErrorCallback& error_callback) = 0;
194 148
195 // Indicates whether this device provides the given service. |uuid| should 149 // Indicates whether this device provides the given service. |uuid| should
196 // be in canonical form (see bluetooth_utils::CanonicalUuid). 150 // be in canonical form (see bluetooth_utils::CanonicalUuid).
197 virtual bool ProvidesServiceWithUUID(const std::string& uuid) const; 151 virtual bool ProvidesServiceWithUUID(const std::string& uuid) const = 0;
198 152
199 // The ProvidesServiceCallback is used by ProvidesServiceWithName to indicate 153 // The ProvidesServiceCallback is used by ProvidesServiceWithName to indicate
200 // whether or not a matching service was found. 154 // whether or not a matching service was found.
201 typedef base::Callback<void(bool)> ProvidesServiceCallback; 155 typedef base::Callback<void(bool)> ProvidesServiceCallback;
202 156
203 // Indicates whether this device provides the given service. 157 // Indicates whether this device provides the given service.
204 virtual void ProvidesServiceWithName(const std::string& name, 158 virtual void ProvidesServiceWithName(
205 const ProvidesServiceCallback& callback); 159 const std::string& name,
160 const ProvidesServiceCallback& callback) = 0;
206 161
207 // Indicates whether the device is currently pairing and expecting a 162 // Indicates whether the device is currently pairing and expecting a
208 // PIN Code to be returned. 163 // PIN Code to be returned.
209 bool ExpectingPinCode() const { return !pincode_callback_.is_null(); } 164 virtual bool ExpectingPinCode() const = 0;
210 165
211 // Indicates whether the device is currently pairing and expecting a 166 // Indicates whether the device is currently pairing and expecting a
212 // Passkey to be returned. 167 // Passkey to be returned.
213 bool ExpectingPasskey() const { return !passkey_callback_.is_null(); } 168 virtual bool ExpectingPasskey() const = 0;
214 169
215 // Indicates whether the device is currently pairing and expecting 170 // SocketCallback is used by ConnectToService to return a BluetoothSocket to
216 // confirmation of a displayed passkey. 171 // the caller, or NULL if there was an error. The socket will remain open
217 bool ExpectingConfirmation() const { 172 // until the last reference to the returned BluetoothSocket is released.
218 return !confirmation_callback_.is_null(); 173 typedef base::Callback<void(scoped_refptr<BluetoothSocket>)>
219 } 174 SocketCallback;
keybuk 2012/09/17 22:19:43 This needs to be part of the public interface!
youngki 2012/09/18 18:19:56 Done.
220 175
221 // Initiates a connection to the device, pairing first if necessary. 176 // Initiates a connection to the device, pairing first if necessary.
222 // 177 //
223 // Method calls will be made on the supplied object |pairing_delegate| 178 // Method calls will be made on the supplied object |pairing_delegate|
224 // to indicate what display, and in response should make method calls 179 // to indicate what display, and in response should make method calls
225 // back to the device object. Not all devices require user responses 180 // back to the device object. Not all devices require user responses
226 // during pairing, so it is normal for |pairing_delegate| to receive no 181 // during pairing, so it is normal for |pairing_delegate| to receive no
227 // calls. To explicitly force a low-security connection without bonding, 182 // calls. To explicitly force a low-security connection without bonding,
228 // pass NULL, though this is ignored if the device is already paired. 183 // pass NULL, though this is ignored if the device is already paired.
229 // 184 //
230 // If the request fails, |error_callback| will be called; otherwise, 185 // If the request fails, |error_callback| will be called; otherwise,
231 // |callback| is called when the request is complete. 186 // |callback| is called when the request is complete.
232 void Connect(PairingDelegate* pairing_delegate, 187 virtual void Connect(PairingDelegate* pairing_delegate,
233 const base::Closure& callback, 188 const base::Closure& callback,
234 const ErrorCallback& error_callback); 189 const ErrorCallback& error_callback) = 0;
235 190
236 // Sends the PIN code |pincode| to the remote device during pairing. 191 // Sends the PIN code |pincode| to the remote device during pairing.
237 // 192 //
238 // PIN Codes are generally required for Bluetooth 2.0 and earlier devices 193 // PIN Codes are generally required for Bluetooth 2.0 and earlier devices
239 // for which there is no automatic pairing or special handling. 194 // for which there is no automatic pairing or special handling.
240 void SetPinCode(const std::string& pincode); 195 virtual void SetPinCode(const std::string& pincode) = 0;
241 196
242 // Sends the Passkey |passkey| to the remote device during pairing. 197 // Sends the Passkey |passkey| to the remote device during pairing.
243 // 198 //
244 // Passkeys are generally required for Bluetooth 2.1 and later devices 199 // Passkeys are generally required for Bluetooth 2.1 and later devices
245 // which cannot provide input or display on their own, and don't accept 200 // which cannot provide input or display on their own, and don't accept
246 // passkey-less pairing, and are a numeric in the range 0-999999. 201 // passkey-less pairing, and are a numeric in the range 0-999999.
247 void SetPasskey(uint32 passkey); 202 virtual void SetPasskey(uint32 passkey) = 0;
248 203
249 // Confirms to the remote device during pairing that a passkey provided by 204 // Confirms to the remote device during pairing that a passkey provided by
250 // the ConfirmPasskey() delegate call is displayed on both devices. 205 // the ConfirmPasskey() delegate call is displayed on both devices.
251 void ConfirmPairing(); 206 virtual void ConfirmPairing() = 0;
252 207
253 // Rejects a pairing or connection request from a remote device. 208 // Rejects a pairing or connection request from a remote device.
254 void RejectPairing(); 209 virtual void RejectPairing() = 0;
255 210
256 // Cancels a pairing or connection attempt to a remote device. 211 // Cancels a pairing or connection attempt to a remote device.
257 void CancelPairing(); 212 virtual void CancelPairing() = 0;
258 213
259 // Disconnects the device, terminating the low-level ACL connection 214 // Disconnects the device, terminating the low-level ACL connection
260 // and any application connections using it. Link keys and other pairing 215 // and any application connections using it. Link keys and other pairing
261 // information are not discarded, and the device object is not deleted. 216 // information are not discarded, and the device object is not deleted.
262 // If the request fails, |error_callback| will be called; otherwise, 217 // If the request fails, |error_callback| will be called; otherwise,
263 // |callback| is called when the request is complete. 218 // |callback| is called when the request is complete.
264 void Disconnect(const base::Closure& callback, 219 virtual void Disconnect(const base::Closure& callback,
265 const ErrorCallback& error_callback); 220 const ErrorCallback& error_callback) = 0;
266 221
267 // Disconnects the device, terminating the low-level ACL connection 222 // Disconnects the device, terminating the low-level ACL connection
268 // and any application connections using it, and then discards link keys 223 // and any application connections using it, and then discards link keys
269 // and other pairing information. The device object remainds valid until 224 // and other pairing information. The device object remainds valid until
270 // returing from the calling function, after which it should be assumed to 225 // returing from the calling function, after which it should be assumed to
271 // have been deleted. If the request fails, |error_callback| will be called. 226 // have been deleted. If the request fails, |error_callback| will be called.
272 // There is no callback for success beause this object is often deleted 227 // There is no callback for success beause this object is often deleted
273 // before that callback would be called. 228 // before that callback would be called.
274 void Forget(const ErrorCallback& error_callback); 229 virtual void Forget(const ErrorCallback& error_callback) = 0;
275
276 // SocketCallback is used by ConnectToService to return a BluetoothSocket
277 // to the caller, or NULL if there was an error. The socket will remain open
278 // until the last reference to the returned BluetoothSocket is released.
279 typedef base::Callback<void(scoped_refptr<BluetoothSocket>)> SocketCallback;
280 230
281 // Attempts to open a socket to a service matching |uuid| on this device. If 231 // Attempts to open a socket to a service matching |uuid| on this device. If
282 // the connection is successful, |callback| is called with a BluetoothSocket. 232 // the connection is successful, |callback| is called with a BluetoothSocket.
283 // Otherwise |callback| is called with NULL. The socket is closed as soon as 233 // Otherwise |callback| is called with NULL. The socket is closed as soon as
284 // all references to the BluetoothSocket are released. Note that the 234 // all references to the BluetoothSocket are released. Note that the
285 // BluetoothSocket object can outlive both this BluetoothDevice and the 235 // BluetoothSocket object can outlive both this BluetoothDevice and the
286 // BluetoothAdapter for this device. 236 // BluetoothAdapter for this device.
287 void ConnectToService(const std::string& service_uuid, 237 virtual void ConnectToService(const std::string& service_uuid,
288 const SocketCallback& callback); 238 const SocketCallback& callback) = 0;
289 239
290 // Sets the Out Of Band pairing data for this device to |data|. Exactly one 240 // Sets the Out Of Band pairing data for this device to |data|. Exactly one
291 // of |callback| or |error_callback| will be run. 241 // of |callback| or |error_callback| will be run.
292 virtual void SetOutOfBandPairingData( 242 virtual void SetOutOfBandPairingData(
293 const chromeos::BluetoothOutOfBandPairingData& data, 243 const BluetoothOutOfBandPairingData& data,
294 const base::Closure& callback, 244 const base::Closure& callback,
295 const ErrorCallback& error_callback); 245 const ErrorCallback& error_callback) = 0;
296 246
297 // Clears the Out Of Band pairing data for this device. Exactly one of 247 // Clears the Out Of Band pairing data for this device. Exactly one of
298 // |callback| or |error_callback| will be run. 248 // |callback| or |error_callback| will be run.
299 virtual void ClearOutOfBandPairingData( 249 virtual void ClearOutOfBandPairingData(
300 const base::Closure& callback, 250 const base::Closure& callback,
301 const ErrorCallback& error_callback); 251 const ErrorCallback& error_callback) = 0;
302 252
303 private: 253 protected:
304 friend class BluetoothAdapter; 254 // Possible values that may be returned by GetDeviceType(), representing
305 friend class MockBluetoothDevice; 255 // different types of bluetooth device that we support or are aware of
256 // decoded from the bluetooth class information.
257 enum DeviceType {
258 DEVICE_UNKNOWN,
259 DEVICE_COMPUTER,
260 DEVICE_PHONE,
261 DEVICE_MODEM,
262 DEVICE_PERIPHERAL,
263 DEVICE_JOYSTICK,
264 DEVICE_GAMEPAD,
265 DEVICE_KEYBOARD,
266 DEVICE_MOUSE,
267 DEVICE_TABLET,
268 DEVICE_KEYBOARD_MOUSE_COMBO
269 };
306 270
307 explicit BluetoothDevice(BluetoothAdapter* adapter); 271 BluetoothDevice();
308 272
309 // Sets the dbus object path for the device to |object_path|, indicating 273 // Returns the type of the device, limited to those we support or are
310 // that the device has gone from being discovered to paired or bonded. 274 // aware of, by decoding the bluetooth class information. The returned
311 void SetObjectPath(const dbus::ObjectPath& object_path); 275 // values are unique, and do not overlap, so DEVICE_KEYBOARD is not also
312 276 // DEVICE_PERIPHERAL.
313 // Removes the dbus object path from the device, indicating that the 277 DeviceType GetDeviceType() const;
keybuk 2012/09/17 22:19:43 should be public: not protected: this may be used
youngki 2012/09/18 18:19:56 Done.
314 // device is no longer paired or bonded, but perhaps still visible.
315 void RemoveObjectPath();
316
317 // Sets whether the device is visible to the owning adapter to |visible|.
318 void SetVisible(bool visible) { visible_ = visible; }
319
320 // Updates device information from the properties in |properties|, device
321 // state properties such as |paired_| and |connected_| are ignored unless
322 // |update_state| is true.
323 void Update(const BluetoothDeviceClient::Properties* properties,
324 bool update_state);
325
326 // Called by BluetoothAdapterClient when a call to CreateDevice() or
327 // CreatePairedDevice() succeeds, provides the new object path for the remote
328 // device in |device_path|. |callback| and |error_callback| are the callbacks
329 // provided to Connect().
330 void ConnectCallback(const base::Closure& callback,
331 const ErrorCallback& error_callback,
332 const dbus::ObjectPath& device_path);
333
334 // Called by BluetoothAdapterClient when a call to CreateDevice() or
335 // CreatePairedDevice() fails with the error named |error_name| and
336 // optional message |error_message|, |error_callback| is the callback
337 // provided to Connect().
338 void ConnectErrorCallback(const ErrorCallback& error_callback,
339 const std::string& error_name,
340 const std::string& error_message);
341
342 // Called by BluetoothAdapterClient when a call to DiscoverServices()
343 // completes. |callback| and |error_callback| are the callbacks provided to
344 // GetServiceRecords.
345 void CollectServiceRecordsCallback(
346 const ServiceRecordsCallback& callback,
347 const ErrorCallback& error_callback,
348 const dbus::ObjectPath& device_path,
349 const BluetoothDeviceClient::ServiceMap& service_map,
350 bool success);
351
352 // Called by BluetoothProperty when the call to Set() for the Trusted
353 // property completes. |success| indicates whether or not the request
354 // succeeded, |callback| and |error_callback| are the callbacks provided to
355 // Connect().
356 void OnSetTrusted(const base::Closure& callback,
357 const ErrorCallback& error_callback,
358 bool success);
359
360 // Connect application-level protocols of the device to the system, called
361 // on a successful connection or to reconnect to a device that is already
362 // paired or previously connected. |error_callback| is called on failure.
363 // Otherwise, |callback| is called when the request is complete.
364 void ConnectApplications(const base::Closure& callback,
365 const ErrorCallback& error_callback);
366
367 // Called by IntrospectableClient when a call to Introspect() completes.
368 // |success| indicates whether or not the request succeeded, |callback| and
369 // |error_callback| are the callbacks provided to ConnectApplications(),
370 // |service_name| and |device_path| specify the remote object being
371 // introspected and |xml_data| contains the XML-formatted protocol data.
372 void OnIntrospect(const base::Closure& callback,
373 const ErrorCallback& error_callback,
374 const std::string& service_name,
375 const dbus::ObjectPath& device_path,
376 const std::string& xml_data, bool success);
377
378 // Called by BluetoothInputClient when the call to Connect() succeeds.
379 // |error_callback| is the callback provided to ConnectApplications(),
380 // |interface_name| specifies the interface being connected and
381 // |device_path| the remote object path.
382 void OnConnect(const base::Closure& callback,
383 const std::string& interface_name,
384 const dbus::ObjectPath& device_path);
385
386 // Called by BluetoothInputClient when the call to Connect() fails.
387 // |error_callback| is the callback provided to ConnectApplications(),
388 // |interface_name| specifies the interface being connected,
389 // |device_path| the remote object path,
390 // |error_name| the error name and |error_message| the optional message.
391 void OnConnectError(const ErrorCallback& error_callback,
392 const std::string& interface_name,
393 const dbus::ObjectPath& device_path,
394 const std::string& error_name,
395 const std::string& error_message);
396
397 // Called by BluetoothDeviceClient when a call to Disconnect() completes,
398 // |success| indicates whether or not the request succeeded, |callback| and
399 // |error_callback| are the callbacks provided to Disconnect() and
400 // |device_path| is the device disconnected.
401 void DisconnectCallback(const base::Closure& callback,
402 const ErrorCallback& error_callback,
403 const dbus::ObjectPath& device_path, bool success);
404
405 // Called by BluetoothAdapterClient when a call to RemoveDevice() completes,
406 // |success| indicates whether or not the request succeeded, |error_callback|
407 // is the callback provided to Forget() and |adapter_path| is the d-bus
408 // object path of the adapter that performed the removal.
409 void ForgetCallback(const ErrorCallback& error_callback,
410 const dbus::ObjectPath& adapter_path, bool success);
411
412 // Called if the call to GetServiceRecords from ProvidesServiceWithName fails.
413 void SearchServicesForNameErrorCallback(
414 const ProvidesServiceCallback& callback);
415
416 // Called by GetServiceRecords with the list of BluetoothServiceRecords to
417 // search for |name|. |callback| is the callback from
418 // ProvidesServiceWithName.
419 void SearchServicesForNameCallback(
420 const std::string& name,
421 const ProvidesServiceCallback& callback,
422 const ServiceRecordList& list);
423
424 // Called if the call to GetServiceRecords from Connect fails.
425 void GetServiceRecordsForConnectErrorCallback(
426 const SocketCallback& callback);
427
428 // Called by GetServiceRecords with the list of BluetoothServiceRecords.
429 // Connections are attempted to each service in the list matching
430 // |service_uuid|, and the socket from the first successful connection is
431 // passed to |callback|.
432 void GetServiceRecordsForConnectCallback(
433 const std::string& service_uuid,
434 const SocketCallback& callback,
435 const ServiceRecordList& list);
436
437 // Called by BlueoothDeviceClient in response to the AddRemoteData and
438 // RemoveRemoteData method calls.
439 void OnRemoteDataCallback(const base::Closure& callback,
440 const ErrorCallback& error_callback,
441 bool success);
442
443 // BluetoothDeviceClient::Observer override.
444 //
445 // Called when the device with object path |object_path| is about
446 // to be disconnected, giving a chance for application layers to
447 // shut down cleanly.
448 virtual void DisconnectRequested(
449 const dbus::ObjectPath& object_path) OVERRIDE;
450
451 // BluetoothAgentServiceProvider::Delegate override.
452 //
453 // This method will be called when the agent is unregistered from the
454 // Bluetooth daemon, generally at the end of a pairing request. It may be
455 // used to perform cleanup tasks.
456 virtual void Release() OVERRIDE;
457
458 // BluetoothAgentServiceProvider::Delegate override.
459 //
460 // This method will be called when the Bluetooth daemon requires a
461 // PIN Code for authentication of the device with object path |device_path|,
462 // the agent should obtain the code from the user and call |callback|
463 // to provide it, or indicate rejection or cancellation of the request.
464 //
465 // PIN Codes are generally required for Bluetooth 2.0 and earlier devices
466 // for which there is no automatic pairing or special handling.
467 virtual void RequestPinCode(const dbus::ObjectPath& device_path,
468 const PinCodeCallback& callback) OVERRIDE;
469
470 // BluetoothAgentServiceProvider::Delegate override.
471 //
472 // This method will be called when the Bluetooth daemon requires a
473 // Passkey for authentication of the device with object path |device_path|,
474 // the agent should obtain the passkey from the user (a numeric in the
475 // range 0-999999) and call |callback| to provide it, or indicate
476 // rejection or cancellation of the request.
477 //
478 // Passkeys are generally required for Bluetooth 2.1 and later devices
479 // which cannot provide input or display on their own, and don't accept
480 // passkey-less pairing.
481 virtual void RequestPasskey(const dbus::ObjectPath& device_path,
482 const PasskeyCallback& callback) OVERRIDE;
483
484 // BluetoothAgentServiceProvider::Delegate override.
485 //
486 // This method will be called when the Bluetooth daemon requires that the
487 // user enter the PIN code |pincode| into the device with object path
488 // |device_path| so that it may be authenticated. The Cancel() method
489 // will be called to dismiss the display once pairing is complete or
490 // cancelled.
491 //
492 // This is used for Bluetooth 2.0 and earlier keyboard devices, the
493 // |pincode| will always be a six-digit numeric in the range 000000-999999
494 // for compatibilty with later specifications.
495 virtual void DisplayPinCode(const dbus::ObjectPath& device_path,
496 const std::string& pincode) OVERRIDE;
497
498 // BluetoothAgentServiceProvider::Delegate override.
499 //
500 // This method will be called when the Bluetooth daemon requires that the
501 // user enter the Passkey |passkey| into the device with object path
502 // |device_path| so that it may be authenticated. The Cancel() method
503 // will be called to dismiss the display once pairing is complete or
504 // cancelled.
505 //
506 // This is used for Bluetooth 2.1 and later devices that support input
507 // but not display, such as keyboards. The Passkey is a numeric in the
508 // range 0-999999 and should be always presented zero-padded to six
509 // digits.
510 virtual void DisplayPasskey(const dbus::ObjectPath& device_path,
511 uint32 passkey) OVERRIDE;
512
513 // BluetoothAgentServiceProvider::Delegate override.
514 //
515 // This method will be called when the Bluetooth daemon requires that the
516 // user confirm that the Passkey |passkey| is displayed on the screen
517 // of the device with object path |object_path| so that it may be
518 // authentication. The agent should display to the user and ask for
519 // confirmation, then call |callback| to provide their response (success,
520 // rejected or cancelled).
521 //
522 // This is used for Bluetooth 2.1 and later devices that support display,
523 // such as other computers or phones. The Passkey is a numeric in the
524 // range 0-999999 and should be always present zero-padded to six
525 // digits.
526 virtual void RequestConfirmation(
527 const dbus::ObjectPath& device_path,
528 uint32 passkey,
529 const ConfirmationCallback& callback) OVERRIDE;
530
531 // BluetoothAgentServiceProvider::Delegate override.
532 //
533 // This method will be called when the Bluetooth daemon requires that the
534 // user confirm that the device with object path |object_path| is
535 // authorized to connect to the service with UUID |uuid|. The agent should
536 // confirm with the user and call |callback| to provide their response
537 // (success, rejected or cancelled).
538 virtual void Authorize(const dbus::ObjectPath& device_path,
539 const std::string& uuid,
540 const ConfirmationCallback& callback) OVERRIDE;
541
542 // BluetoothAgentServiceProvider::Delegate override.
543 //
544 // This method will be called when the Bluetooth daemon requires that the
545 // user confirm that the device adapter may switch to mode |mode|. The
546 // agent should confirm with the user and call |callback| to provide
547 // their response (success, rejected or cancelled).
548 virtual void ConfirmModeChange(Mode mode,
549 const ConfirmationCallback& callback) OVERRIDE;
550
551 // BluetoothAgentServiceProvider::Delegate override.
552 //
553 // This method will be called by the Bluetooth daemon to indicate that
554 // the request failed before a reply was returned from the device.
555 virtual void Cancel() OVERRIDE;
556
557 // Creates a new BluetoothDevice object bound to the adapter |adapter|.
558 static BluetoothDevice* Create(BluetoothAdapter* adapter);
559
560 // The adapter that owns this device instance.
561 BluetoothAdapter* adapter_;
562
563 // The dbus object path of the device, will be empty if the device has only
564 // been discovered and not yet paired with.
565 dbus::ObjectPath object_path_;
566
567 // The Bluetooth address of the device.
568 std::string address_;
569
570 // The name of the device, as supplied by the remote device.
571 std::string name_;
572 278
573 // The Bluetooth class of the device, a bitmask that may be decoded using 279 // The Bluetooth class of the device, a bitmask that may be decoded using
574 // https://www.bluetooth.org/Technical/AssignedNumbers/baseband.htm 280 // https://www.bluetooth.org/Technical/AssignedNumbers/baseband.htm
575 uint32 bluetooth_class_; 281 uint32 bluetooth_class_;
576
577 // Tracked device state, updated by the adapter managing the lifecyle of
578 // the device.
579 bool visible_;
580 bool bonded_;
581 bool connected_;
582
583 // The services (identified by UUIDs) that this device provides.
584 std::vector<std::string> service_uuids_;
585
586 // During pairing this is set to an object that we don't own, but on which
587 // we can make method calls to request, display or confirm PIN Codes and
588 // Passkeys. Generally it is the object that owns this one.
589 PairingDelegate* pairing_delegate_;
590
591 // During pairing this is set to an instance of a D-Bus agent object
592 // intialized with our own class as its delegate.
593 scoped_ptr<BluetoothAgentServiceProvider> agent_;
594
595 // During pairing these callbacks are set to those provided by method calls
596 // made on us by |agent_| and are called by our own method calls such as
597 // SetPinCode() and SetPasskey().
598 PinCodeCallback pincode_callback_;
599 PasskeyCallback passkey_callback_;
600 ConfirmationCallback confirmation_callback_;
601
602 // Used to keep track of pending application connection requests.
603 int connecting_applications_counter_;
604
605 // Note: This should remain the last member so it'll be destroyed and
606 // invalidate its weak pointers before any other members are destroyed.
607 base::WeakPtrFactory<BluetoothDevice> weak_ptr_factory_;
608
609 DISALLOW_COPY_AND_ASSIGN(BluetoothDevice);
610 }; 282 };
611 283
612 } // namespace chromeos 284 } // namespace chromeos
613 285
614 #endif // CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_DEVICE_H_ 286 #endif // CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_DEVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698