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_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> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | |
12 #include "base/callback.h" | 11 #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" | 12 #include "base/string16.h" |
17 #include "chromeos/dbus/bluetooth_agent_service_provider.h" | 13 #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 | 14 |
22 namespace chromeos { | 15 namespace chromeos { |
23 | 16 |
24 class BluetoothAdapter; | |
25 class BluetoothServiceRecord; | 17 class BluetoothServiceRecord; |
26 class BluetoothSocket; | 18 class BluetoothSocket; |
27 | 19 |
28 // The BluetoothDevice class represents a remote Bluetooth device, both | 20 struct BluetoothOutOfBandPairingData; |
29 // its properties and capabilities as discovered by a local adapter and | 21 |
30 // actions that may be performed on the remove device such as pairing, | 22 // BluetoothDevice represents a remote Bluetooth device, both its properties and |
31 // connection and disconnection. | 23 // capabilities as discovered by a local adapter and actions that may be |
24 // performed on the remove device such as pairing, 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 | 35 // Possible values that may be returned by GetDeviceType(), representing |
44 // different types of bluetooth device that we support or are aware of | 36 // different types of bluetooth device that we support or are aware of |
45 // decoded from the bluetooth class information. | 37 // decoded from the bluetooth class information. |
46 enum DeviceType { | 38 enum DeviceType { |
47 DEVICE_UNKNOWN, | 39 DEVICE_UNKNOWN, |
48 DEVICE_COMPUTER, | 40 DEVICE_COMPUTER, |
49 DEVICE_PHONE, | 41 DEVICE_PHONE, |
50 DEVICE_MODEM, | 42 DEVICE_MODEM, |
51 DEVICE_PERIPHERAL, | 43 DEVICE_PERIPHERAL, |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 // be a synthesied string containing the address and localized type name | 138 // be a synthesied string containing the address and localized type name |
147 // if the device has no obtained name. | 139 // if the device has no obtained name. |
148 virtual string16 GetName() const; | 140 virtual string16 GetName() const; |
149 | 141 |
150 // Returns the type of the device, limited to those we support or are | 142 // Returns the type of the device, limited to those we support or are |
151 // aware of, by decoding the bluetooth class information. The returned | 143 // aware of, by decoding the bluetooth class information. The returned |
152 // values are unique, and do not overlap, so DEVICE_KEYBOARD is not also | 144 // values are unique, and do not overlap, so DEVICE_KEYBOARD is not also |
153 // DEVICE_PERIPHERAL. | 145 // DEVICE_PERIPHERAL. |
154 DeviceType GetDeviceType() const; | 146 DeviceType GetDeviceType() const; |
155 | 147 |
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; | |
162 | |
163 // Indicates whether the device is paired to the adapter, whether or not | 148 // Indicates whether the device is paired to the adapter, whether or not |
164 // that pairing is permanent or temporary. | 149 // that pairing is permanent or temporary. |
165 virtual bool IsPaired() const; | 150 virtual bool IsPaired() const = 0; |
166 | 151 |
167 // Indicates whether the device is visible to the adapter, this is not | 152 // Indicates whether the device is visible to the adapter, this is not |
168 // mutually exclusive to being paired. | 153 // mutually exclusive to being paired. |
169 bool IsVisible() const { return visible_; } | 154 bool IsVisible() const { return visible_; } |
bryeung
2012/09/19 13:27:16
why not virtual?
youngki
2012/09/19 19:35:23
Changed it to virtual. The original code didn't ha
bryeung
2012/09/19 20:13:35
Might as well move the body into the cc file to ma
youngki
2012/09/19 20:22:09
Done.
| |
170 | 155 |
171 // Indicates whether the device is bonded to the adapter, bonding is | 156 // Indicates whether the device is bonded to the adapter, bonding is |
172 // formed by pairing and exchanging high-security link keys so that | 157 // formed by pairing and exchanging high-security link keys so that |
173 // connections may be encrypted. | 158 // connections may be encrypted. |
174 virtual bool IsBonded() const; | 159 virtual bool IsBonded() const; |
175 | 160 |
176 // Indicates whether the device is currently connected to the adapter | 161 // Indicates whether the device is currently connected to the adapter |
177 // and at least one service available for use. | 162 // and at least one service available for use. |
178 virtual bool IsConnected() const; | 163 virtual bool IsConnected() const; |
179 | 164 |
180 // Returns the services (as UUID strings) that this device provides. | 165 // Returns the services (as UUID strings) that this device provides. |
181 typedef std::vector<std::string> ServiceList; | 166 typedef std::vector<std::string> ServiceList; |
182 const ServiceList& GetServices() const { return service_uuids_; } | 167 virtual const ServiceList& GetServices() const = 0; |
183 | 168 |
184 // The ErrorCallback is used for methods that can fail in which case it | 169 // 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. | 170 // is called, in the success case the callback is simply not called. |
186 typedef base::Callback<void()> ErrorCallback; | 171 typedef base::Callback<void()> ErrorCallback; |
187 | 172 |
188 // Returns the services (as BluetoothServiceRecord objects) that this device | 173 // Returns the services (as BluetoothServiceRecord objects) that this device |
189 // provides. | 174 // provides. |
190 typedef ScopedVector<BluetoothServiceRecord> ServiceRecordList; | 175 typedef ScopedVector<BluetoothServiceRecord> ServiceRecordList; |
191 typedef base::Callback<void(const ServiceRecordList&)> ServiceRecordsCallback; | 176 typedef base::Callback<void(const ServiceRecordList&)> ServiceRecordsCallback; |
192 void GetServiceRecords(const ServiceRecordsCallback& callback, | 177 virtual void GetServiceRecords(const ServiceRecordsCallback& callback, |
193 const ErrorCallback& error_callback); | 178 const ErrorCallback& error_callback) = 0; |
194 | 179 |
195 // Indicates whether this device provides the given service. |uuid| should | 180 // Indicates whether this device provides the given service. |uuid| should |
196 // be in canonical form (see bluetooth_utils::CanonicalUuid). | 181 // be in canonical form (see bluetooth_utils::CanonicalUuid). |
197 virtual bool ProvidesServiceWithUUID(const std::string& uuid) const; | 182 virtual bool ProvidesServiceWithUUID(const std::string& uuid) const = 0; |
198 | 183 |
199 // The ProvidesServiceCallback is used by ProvidesServiceWithName to indicate | 184 // The ProvidesServiceCallback is used by ProvidesServiceWithName to indicate |
200 // whether or not a matching service was found. | 185 // whether or not a matching service was found. |
201 typedef base::Callback<void(bool)> ProvidesServiceCallback; | 186 typedef base::Callback<void(bool)> ProvidesServiceCallback; |
202 | 187 |
203 // Indicates whether this device provides the given service. | 188 // Indicates whether this device provides the given service. |
204 virtual void ProvidesServiceWithName(const std::string& name, | 189 virtual void ProvidesServiceWithName( |
205 const ProvidesServiceCallback& callback); | 190 const std::string& name, |
191 const ProvidesServiceCallback& callback) = 0; | |
206 | 192 |
207 // Indicates whether the device is currently pairing and expecting a | 193 // Indicates whether the device is currently pairing and expecting a |
208 // PIN Code to be returned. | 194 // PIN Code to be returned. |
209 bool ExpectingPinCode() const { return !pincode_callback_.is_null(); } | 195 virtual bool ExpectingPinCode() const = 0; |
210 | 196 |
211 // Indicates whether the device is currently pairing and expecting a | 197 // Indicates whether the device is currently pairing and expecting a |
212 // Passkey to be returned. | 198 // Passkey to be returned. |
213 bool ExpectingPasskey() const { return !passkey_callback_.is_null(); } | 199 virtual bool ExpectingPasskey() const = 0; |
214 | 200 |
215 // Indicates whether the device is currently pairing and expecting | 201 // Indicates whether the device is currently pairing and expecting |
216 // confirmation of a displayed passkey. | 202 // confirmation of a displayed passkey. |
217 bool ExpectingConfirmation() const { | 203 virtual bool ExpectingConfirmation() const = 0; |
218 return !confirmation_callback_.is_null(); | 204 |
219 } | 205 // SocketCallback is used by ConnectToService to return a BluetoothSocket to |
206 // the caller, or NULL if there was an error. The socket will remain open | |
207 // until the last reference to the returned BluetoothSocket is released. | |
208 typedef base::Callback<void(scoped_refptr<BluetoothSocket>)> | |
209 SocketCallback; | |
220 | 210 |
221 // Initiates a connection to the device, pairing first if necessary. | 211 // Initiates a connection to the device, pairing first if necessary. |
222 // | 212 // |
223 // Method calls will be made on the supplied object |pairing_delegate| | 213 // Method calls will be made on the supplied object |pairing_delegate| |
224 // to indicate what display, and in response should make method calls | 214 // to indicate what display, and in response should make method calls |
225 // back to the device object. Not all devices require user responses | 215 // back to the device object. Not all devices require user responses |
226 // during pairing, so it is normal for |pairing_delegate| to receive no | 216 // during pairing, so it is normal for |pairing_delegate| to receive no |
227 // calls. To explicitly force a low-security connection without bonding, | 217 // calls. To explicitly force a low-security connection without bonding, |
228 // pass NULL, though this is ignored if the device is already paired. | 218 // pass NULL, though this is ignored if the device is already paired. |
229 // | 219 // |
230 // If the request fails, |error_callback| will be called; otherwise, | 220 // If the request fails, |error_callback| will be called; otherwise, |
231 // |callback| is called when the request is complete. | 221 // |callback| is called when the request is complete. |
232 void Connect(PairingDelegate* pairing_delegate, | 222 virtual void Connect(PairingDelegate* pairing_delegate, |
233 const base::Closure& callback, | 223 const base::Closure& callback, |
234 const ErrorCallback& error_callback); | 224 const ErrorCallback& error_callback) = 0; |
235 | 225 |
236 // Sends the PIN code |pincode| to the remote device during pairing. | 226 // Sends the PIN code |pincode| to the remote device during pairing. |
237 // | 227 // |
238 // PIN Codes are generally required for Bluetooth 2.0 and earlier devices | 228 // PIN Codes are generally required for Bluetooth 2.0 and earlier devices |
239 // for which there is no automatic pairing or special handling. | 229 // for which there is no automatic pairing or special handling. |
240 void SetPinCode(const std::string& pincode); | 230 virtual void SetPinCode(const std::string& pincode) = 0; |
241 | 231 |
242 // Sends the Passkey |passkey| to the remote device during pairing. | 232 // Sends the Passkey |passkey| to the remote device during pairing. |
243 // | 233 // |
244 // Passkeys are generally required for Bluetooth 2.1 and later devices | 234 // 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 | 235 // 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. | 236 // passkey-less pairing, and are a numeric in the range 0-999999. |
247 void SetPasskey(uint32 passkey); | 237 virtual void SetPasskey(uint32 passkey) = 0; |
248 | 238 |
249 // Confirms to the remote device during pairing that a passkey provided by | 239 // Confirms to the remote device during pairing that a passkey provided by |
250 // the ConfirmPasskey() delegate call is displayed on both devices. | 240 // the ConfirmPasskey() delegate call is displayed on both devices. |
251 void ConfirmPairing(); | 241 virtual void ConfirmPairing() = 0; |
252 | 242 |
253 // Rejects a pairing or connection request from a remote device. | 243 // Rejects a pairing or connection request from a remote device. |
254 void RejectPairing(); | 244 virtual void RejectPairing() = 0; |
255 | 245 |
256 // Cancels a pairing or connection attempt to a remote device. | 246 // Cancels a pairing or connection attempt to a remote device. |
257 void CancelPairing(); | 247 virtual void CancelPairing() = 0; |
258 | 248 |
259 // Disconnects the device, terminating the low-level ACL connection | 249 // Disconnects the device, terminating the low-level ACL connection |
260 // and any application connections using it. Link keys and other pairing | 250 // and any application connections using it. Link keys and other pairing |
261 // information are not discarded, and the device object is not deleted. | 251 // information are not discarded, and the device object is not deleted. |
262 // If the request fails, |error_callback| will be called; otherwise, | 252 // If the request fails, |error_callback| will be called; otherwise, |
263 // |callback| is called when the request is complete. | 253 // |callback| is called when the request is complete. |
264 void Disconnect(const base::Closure& callback, | 254 virtual void Disconnect(const base::Closure& callback, |
265 const ErrorCallback& error_callback); | 255 const ErrorCallback& error_callback) = 0; |
266 | 256 |
267 // Disconnects the device, terminating the low-level ACL connection | 257 // Disconnects the device, terminating the low-level ACL connection |
268 // and any application connections using it, and then discards link keys | 258 // and any application connections using it, and then discards link keys |
269 // and other pairing information. The device object remainds valid until | 259 // and other pairing information. The device object remainds valid until |
270 // returing from the calling function, after which it should be assumed to | 260 // 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. | 261 // 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 | 262 // There is no callback for success beause this object is often deleted |
273 // before that callback would be called. | 263 // before that callback would be called. |
274 void Forget(const ErrorCallback& error_callback); | 264 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 | 265 |
281 // Attempts to open a socket to a service matching |uuid| on this device. If | 266 // 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. | 267 // the connection is successful, |callback| is called with a BluetoothSocket. |
283 // Otherwise |callback| is called with NULL. The socket is closed as soon as | 268 // Otherwise |callback| is called with NULL. The socket is closed as soon as |
284 // all references to the BluetoothSocket are released. Note that the | 269 // all references to the BluetoothSocket are released. Note that the |
285 // BluetoothSocket object can outlive both this BluetoothDevice and the | 270 // BluetoothSocket object can outlive both this BluetoothDevice and the |
286 // BluetoothAdapter for this device. | 271 // BluetoothAdapter for this device. |
287 void ConnectToService(const std::string& service_uuid, | 272 virtual void ConnectToService(const std::string& service_uuid, |
288 const SocketCallback& callback); | 273 const SocketCallback& callback) = 0; |
289 | 274 |
290 // Sets the Out Of Band pairing data for this device to |data|. Exactly one | 275 // Sets the Out Of Band pairing data for this device to |data|. Exactly one |
291 // of |callback| or |error_callback| will be run. | 276 // of |callback| or |error_callback| will be run. |
292 virtual void SetOutOfBandPairingData( | 277 virtual void SetOutOfBandPairingData( |
293 const chromeos::BluetoothOutOfBandPairingData& data, | 278 const BluetoothOutOfBandPairingData& data, |
294 const base::Closure& callback, | 279 const base::Closure& callback, |
295 const ErrorCallback& error_callback); | 280 const ErrorCallback& error_callback) = 0; |
296 | 281 |
297 // Clears the Out Of Band pairing data for this device. Exactly one of | 282 // Clears the Out Of Band pairing data for this device. Exactly one of |
298 // |callback| or |error_callback| will be run. | 283 // |callback| or |error_callback| will be run. |
299 virtual void ClearOutOfBandPairingData( | 284 virtual void ClearOutOfBandPairingData( |
300 const base::Closure& callback, | 285 const base::Closure& callback, |
301 const ErrorCallback& error_callback); | 286 const ErrorCallback& error_callback) = 0; |
302 | 287 |
303 private: | 288 protected: |
304 friend class BluetoothAdapter; | 289 BluetoothDevice(); |
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 | 290 |
573 // The Bluetooth class of the device, a bitmask that may be decoded using | 291 // The Bluetooth class of the device, a bitmask that may be decoded using |
574 // https://www.bluetooth.org/Technical/AssignedNumbers/baseband.htm | 292 // https://www.bluetooth.org/Technical/AssignedNumbers/baseband.htm |
575 uint32 bluetooth_class_; | 293 uint32 bluetooth_class_; |
576 | 294 |
295 // The name of the device, as supplied by the remote device. | |
296 std::string name_; | |
297 | |
298 // The Bluetooth address of the device. | |
299 std::string address_; | |
300 | |
577 // Tracked device state, updated by the adapter managing the lifecyle of | 301 // Tracked device state, updated by the adapter managing the lifecyle of |
578 // the device. | 302 // the device. |
579 bool visible_; | 303 bool visible_; |
580 bool bonded_; | 304 bool bonded_; |
581 bool connected_; | 305 bool connected_; |
582 | 306 |
583 // The services (identified by UUIDs) that this device provides. | 307 private: |
584 std::vector<std::string> service_uuids_; | 308 // Returns a localized string containing the device's bluetooth address and |
585 | 309 // a device type for display when |name_| is empty. |
586 // During pairing this is set to an object that we don't own, but on which | 310 string16 GetAddressWithLocalizedDeviceTypeName() const; |
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 }; | 311 }; |
611 | 312 |
612 } // namespace chromeos | 313 } // namespace chromeos |
613 | 314 |
614 #endif // CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_DEVICE_H_ | 315 #endif // CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_DEVICE_H_ |
OLD | NEW |