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

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: Fixing styles and tess. 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;
29 // its properties and capabilities as discovered by a local adapter and 20
30 // actions that may be performed on the remove device such as pairing, 21 // The BluetoothDevice represents a remote Bluetooth device, both its properties
31 // connection and disconnection. 22 // and capabilities as discovered by a local adapter and actions that
32 // 23 // may be performed on the remove device such as pairing, connection and
33 // The class is instantiated and managed by the BluetoothAdapter class 24 // disconnection.
34 // and pointers should only be obtained from that class and not cached, 25 class BluetoothDevice {
35 // instead use the address() method as a unique key for a device.
36 //
37 // Since the lifecycle of BluetoothDevice instances is managed by
38 // BluetoothAdapter, that class rather than this provides observer methods
39 // for devices coming and going, as well as properties being updated.
keybuk 2012/09/13 23:57:30 Again, why have you removed all of this documentat
youngki 2012/09/17 21:53:02 I originally put them into BluetoothDeviceDBus.h.
40 class BluetoothDevice : public BluetoothDeviceClient::Observer,
41 public BluetoothAgentServiceProvider::Delegate {
42 public: 26 public:
43 // Possible values that may be returned by GetDeviceType(), representing 27 // Possible values that may be returned by GetDeviceType(), representing
44 // different types of bluetooth device that we support or are aware of 28 // different types of bluetooth device that we support or are aware of
45 // decoded from the bluetooth class information. 29 // decoded from the bluetooth class information.
46 enum DeviceType { 30 enum DeviceType {
47 DEVICE_UNKNOWN, 31 DEVICE_UNKNOWN,
48 DEVICE_COMPUTER, 32 DEVICE_COMPUTER,
49 DEVICE_PHONE, 33 DEVICE_PHONE,
50 DEVICE_MODEM, 34 DEVICE_MODEM,
51 DEVICE_PERIPHERAL, 35 DEVICE_PERIPHERAL,
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 // digits. 113 // digits.
130 virtual void ConfirmPasskey(BluetoothDevice* device, 114 virtual void ConfirmPasskey(BluetoothDevice* device,
131 uint32 passkey) = 0; 115 uint32 passkey) = 0;
132 116
133 // This method will be called when any previous DisplayPinCode(), 117 // This method will be called when any previous DisplayPinCode(),
134 // DisplayPasskey() or ConfirmPasskey() request should be concluded 118 // DisplayPasskey() or ConfirmPasskey() request should be concluded
135 // and removed from the user. 119 // and removed from the user.
136 virtual void DismissDisplayOrConfirm() = 0; 120 virtual void DismissDisplayOrConfirm() = 0;
137 }; 121 };
138 122
139 virtual ~BluetoothDevice(); 123 virtual ~BluetoothDevice() {}
140 124
141 // Returns the Bluetooth of address the device. This should be used as 125 // Returns the Bluetooth of address the device. This should be used as
142 // a unique key to identify the device and copied where needed. 126 // a unique key to identify the device and copied where needed.
143 virtual const std::string& address() const; 127 virtual const std::string& address() const = 0;
144 128
145 // Returns the name of the device suitable for displaying, this may 129 // Returns the name of the device suitable for displaying, this may
146 // be a synthesied string containing the address and localized type name 130 // be a synthesied string containing the address and localized type name
147 // if the device has no obtained name. 131 // if the device has no obtained name.
148 virtual string16 GetName() const; 132 virtual string16 GetName() const = 0;
149 133
150 // Returns the type of the device, limited to those we support or are 134 // Returns the type of the device, limited to those we support or are
151 // aware of, by decoding the bluetooth class information. The returned 135 // aware of, by decoding the bluetooth class information. The returned
152 // values are unique, and do not overlap, so DEVICE_KEYBOARD is not also 136 // values are unique, and do not overlap, so DEVICE_KEYBOARD is not also
153 // DEVICE_PERIPHERAL. 137 // DEVICE_PERIPHERAL.
154 DeviceType GetDeviceType() const; 138 virtual DeviceType GetDeviceType() const = 0;
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;
keybuk 2012/09/13 23:57:30 Why has this method gone?
youngki 2012/09/17 21:53:02 This function is only used by its implementation b
159
160 // Indicates whether the class of this device is supported by Chrome OS.
161 bool IsSupported() const;
keybuk 2012/09/13 23:57:30 Likewise, why has this method gone?
youngki 2012/09/17 21:53:02 This function is only used by bluetooth_adapter_ch
162 139
163 // Indicates whether the device is paired to the adapter, whether or not 140 // Indicates whether the device is paired to the adapter, whether or not
164 // that pairing is permanent or temporary. 141 // that pairing is permanent or temporary.
165 virtual bool IsPaired() const; 142 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/13 23:57:30 Why has this method gone?
youngki 2012/09/17 21:53:02 This function is only used by bluetooth_adapter_ch
170 143
171 // Indicates whether the device is bonded to the adapter, bonding is 144 // Indicates whether the device is bonded to the adapter, bonding is
172 // formed by pairing and exchanging high-security link keys so that 145 // formed by pairing and exchanging high-security link keys so that
173 // connections may be encrypted. 146 // connections may be encrypted.
174 virtual bool IsBonded() const; 147 virtual bool IsBonded() const = 0;
175 148
176 // Indicates whether the device is currently connected to the adapter 149 // Indicates whether the device is currently connected to the adapter
177 // and at least one service available for use. 150 // and at least one service available for use.
178 virtual bool IsConnected() const; 151 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/13 23:57:30 Why has this method gone?
youngki 2012/09/17 21:53:02 This function is only used by bluetooth_adapter_ch
183 152
184 // The ErrorCallback is used for methods that can fail in which case it 153 // 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. 154 // is called, in the success case the callback is simply not called.
186 typedef base::Callback<void()> ErrorCallback; 155 typedef base::Callback<void()> ErrorCallback;
187 156
188 // Returns the services (as BluetoothServiceRecord objects) that this device 157 // Returns the services (as BluetoothServiceRecord objects) that this device
189 // provides. 158 // provides.
190 typedef ScopedVector<BluetoothServiceRecord> ServiceRecordList; 159 typedef ScopedVector<BluetoothServiceRecord> ServiceRecordList;
191 typedef base::Callback<void(const ServiceRecordList&)> ServiceRecordsCallback; 160 typedef base::Callback<void(const ServiceRecordList&)> ServiceRecordsCallback;
192 void GetServiceRecords(const ServiceRecordsCallback& callback, 161 virtual void GetServiceRecords(const ServiceRecordsCallback& callback,
193 const ErrorCallback& error_callback); 162 const ErrorCallback& error_callback) = 0;
194 163
195 // Indicates whether this device provides the given service. |uuid| should 164 // Indicates whether this device provides the given service. |uuid| should
196 // be in canonical form (see bluetooth_utils::CanonicalUuid). 165 // be in canonical form (see bluetooth_utils::CanonicalUuid).
197 virtual bool ProvidesServiceWithUUID(const std::string& uuid) const; 166 virtual bool ProvidesServiceWithUUID(const std::string& uuid) const = 0;
198 167
199 // The ProvidesServiceCallback is used by ProvidesServiceWithName to indicate 168 // The ProvidesServiceCallback is used by ProvidesServiceWithName to indicate
200 // whether or not a matching service was found. 169 // whether or not a matching service was found.
201 typedef base::Callback<void(bool)> ProvidesServiceCallback; 170 typedef base::Callback<void(bool)> ProvidesServiceCallback;
202 171
203 // Indicates whether this device provides the given service. 172 // Indicates whether this device provides the given service.
204 virtual void ProvidesServiceWithName(const std::string& name, 173 virtual void ProvidesServiceWithName(
205 const ProvidesServiceCallback& callback); 174 const std::string& name,
175 const ProvidesServiceCallback& callback) = 0;
206 176
207 // Indicates whether the device is currently pairing and expecting a 177 // SocketCallback is used by ConnectToService to return a BluetoothSocket to
208 // PIN Code to be returned. 178 // the caller, or NULL if there was an error. The socket will remain open
keybuk 2012/09/13 23:57:30 All of these methods need to be part of BluetoothD
youngki 2012/09/17 21:53:02 Done.
209 bool ExpectingPinCode() const { return !pincode_callback_.is_null(); }
bryeung 2012/09/13 19:52:57 I think the pairing stuff belongs in the interface
youngki 2012/09/17 21:53:02 Done.
210
211 // Indicates whether the device is currently pairing and expecting a
212 // Passkey to be returned.
213 bool ExpectingPasskey() const { return !passkey_callback_.is_null(); }
214
215 // Indicates whether the device is currently pairing and expecting
216 // confirmation of a displayed passkey.
217 bool ExpectingConfirmation() const {
218 return !confirmation_callback_.is_null();
219 }
220
221 // Initiates a connection to the device, pairing first if necessary.
222 //
223 // Method calls will be made on the supplied object |pairing_delegate|
224 // to indicate what display, and in response should make method calls
225 // back to the device object. Not all devices require user responses
226 // during pairing, so it is normal for |pairing_delegate| to receive no
227 // calls. To explicitly force a low-security connection without bonding,
228 // pass NULL, though this is ignored if the device is already paired.
229 //
230 // If the request fails, |error_callback| will be called; otherwise,
231 // |callback| is called when the request is complete.
232 void Connect(PairingDelegate* pairing_delegate,
233 const base::Closure& callback,
234 const ErrorCallback& error_callback);
235
236 // Sends the PIN code |pincode| to the remote device during pairing.
237 //
238 // PIN Codes are generally required for Bluetooth 2.0 and earlier devices
239 // for which there is no automatic pairing or special handling.
240 void SetPinCode(const std::string& pincode);
241
242 // Sends the Passkey |passkey| to the remote device during pairing.
243 //
244 // 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
246 // passkey-less pairing, and are a numeric in the range 0-999999.
247 void SetPasskey(uint32 passkey);
248
249 // Confirms to the remote device during pairing that a passkey provided by
250 // the ConfirmPasskey() delegate call is displayed on both devices.
251 void ConfirmPairing();
252
253 // Rejects a pairing or connection request from a remote device.
254 void RejectPairing();
255
256 // Cancels a pairing or connection attempt to a remote device.
257 void CancelPairing();
258
259 // Disconnects the device, terminating the low-level ACL connection
260 // and any application connections using it. Link keys and other pairing
261 // information are not discarded, and the device object is not deleted.
262 // If the request fails, |error_callback| will be called; otherwise,
263 // |callback| is called when the request is complete.
264 void Disconnect(const base::Closure& callback,
265 const ErrorCallback& error_callback);
266
267 // Disconnects the device, terminating the low-level ACL connection
268 // and any application connections using it, and then discards link keys
269 // and other pairing information. The device object remainds valid until
270 // 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.
272 // There is no callback for success beause this object is often deleted
273 // before that callback would be called.
274 void Forget(const ErrorCallback& error_callback);
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. 179 // until the last reference to the returned BluetoothSocket is released.
279 typedef base::Callback<void(scoped_refptr<BluetoothSocket>)> SocketCallback; 180 typedef base::Callback<void(scoped_refptr<BluetoothSocket>)>
181 SocketCallback;
280 182
281 // Attempts to open a socket to a service matching |uuid| on this device. If 183 // 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. 184 // the connection is successful, |callback| is called with a BluetoothSocket.
283 // Otherwise |callback| is called with NULL. The socket is closed as soon as 185 // Otherwise |callback| is called with NULL. The socket is closed as soon as
284 // all references to the BluetoothSocket are released. Note that the 186 // all references to the BluetoothSocket are released. Note that the
285 // BluetoothSocket object can outlive both this BluetoothDevice and the 187 // BluetoothSocket object can outlive both this BluetoothDeviceDBus and the
bryeung 2012/09/13 19:52:57 should not be referencing BluetoothDeviceDBus
youngki 2012/09/17 21:53:02 Done.
286 // BluetoothAdapter for this device. 188 // BluetoothAdapterDBus for this device.
287 void ConnectToService(const std::string& service_uuid, 189 virtual void ConnectToService(const std::string& service_uuid,
288 const SocketCallback& callback); 190 const SocketCallback& callback) = 0;
289 191
290 // Sets the Out Of Band pairing data for this device to |data|. Exactly one 192 // Sets the Out Of Band pairing data for this device to |data|. Exactly one
291 // of |callback| or |error_callback| will be run. 193 // of |callback| or |error_callback| will be run.
292 virtual void SetOutOfBandPairingData( 194 virtual void SetOutOfBandPairingData(
293 const chromeos::BluetoothOutOfBandPairingData& data, 195 const BluetoothOutOfBandPairingData& data,
294 const base::Closure& callback, 196 const base::Closure& callback,
295 const ErrorCallback& error_callback); 197 const ErrorCallback& error_callback) = 0;
296 198
297 // Clears the Out Of Band pairing data for this device. Exactly one of 199 // Clears the Out Of Band pairing data for this device. Exactly one of
298 // |callback| or |error_callback| will be run. 200 // |callback| or |error_callback| will be run.
299 virtual void ClearOutOfBandPairingData( 201 virtual void ClearOutOfBandPairingData(
300 const base::Closure& callback, 202 const base::Closure& callback,
301 const ErrorCallback& error_callback); 203 const ErrorCallback& error_callback) = 0;
302
303 private:
304 friend class BluetoothAdapter;
305 friend class MockBluetoothDevice;
306
307 explicit BluetoothDevice(BluetoothAdapter* adapter);
308
309 // Sets the dbus object path for the device to |object_path|, indicating
310 // that the device has gone from being discovered to paired or bonded.
311 void SetObjectPath(const dbus::ObjectPath& object_path);
312
313 // Removes the dbus object path from the device, indicating that the
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
573 // The Bluetooth class of the device, a bitmask that may be decoded using
574 // https://www.bluetooth.org/Technical/AssignedNumbers/baseband.htm
575 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 }; 204 };
611 205
612 } // namespace chromeos 206 } // namespace chromeos
613 207
614 #endif // CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_DEVICE_H_ 208 #endif // CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_DEVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698