OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_ |
6 #define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
11 #include "chromeos/dbus/bluetooth_adapter_client.h" | 11 #include "chromeos/dbus/bluetooth_adapter_client.h" |
| 12 #include "chromeos/dbus/bluetooth_agent_service_provider.h" |
12 #include "chromeos/dbus/bluetooth_device_client.h" | 13 #include "chromeos/dbus/bluetooth_device_client.h" |
13 #include "chromeos/dbus/bluetooth_input_client.h" | 14 #include "chromeos/dbus/bluetooth_input_client.h" |
14 #include "dbus/object_path.h" | 15 #include "dbus/object_path.h" |
15 #include "device/bluetooth/bluetooth_adapter.h" | 16 #include "device/bluetooth/bluetooth_adapter.h" |
| 17 #include "device/bluetooth/bluetooth_device.h" |
16 | 18 |
17 namespace device { | 19 namespace device { |
18 | 20 |
19 class BluetoothAdapterFactory; | 21 class BluetoothAdapterFactory; |
20 | 22 |
21 } // namespace device | 23 } // namespace device |
22 | 24 |
23 namespace chromeos { | 25 namespace chromeos { |
24 | 26 |
25 class BluetoothChromeOSTest; | 27 class BluetoothChromeOSTest; |
26 class BluetoothDeviceChromeOS; | 28 class BluetoothDeviceChromeOS; |
27 | 29 |
28 // The BluetoothAdapterChromeOS class implements BluetoothAdapter for the | 30 // The BluetoothAdapterChromeOS class implements BluetoothAdapter for the |
29 // Chrome OS platform. | 31 // Chrome OS platform. |
30 class BluetoothAdapterChromeOS | 32 class BluetoothAdapterChromeOS |
31 : public device::BluetoothAdapter, | 33 : public device::BluetoothAdapter, |
32 private chromeos::BluetoothAdapterClient::Observer, | 34 private chromeos::BluetoothAdapterClient::Observer, |
33 private chromeos::BluetoothDeviceClient::Observer, | 35 private chromeos::BluetoothDeviceClient::Observer, |
34 private chromeos::BluetoothInputClient::Observer { | 36 private chromeos::BluetoothInputClient::Observer, |
| 37 private chromeos::BluetoothAgentServiceProvider::Delegate { |
35 public: | 38 public: |
36 // BluetoothAdapter override | 39 // BluetoothAdapter override |
37 virtual void AddObserver( | 40 virtual void AddObserver( |
38 device::BluetoothAdapter::Observer* observer) OVERRIDE; | 41 device::BluetoothAdapter::Observer* observer) OVERRIDE; |
39 virtual void RemoveObserver( | 42 virtual void RemoveObserver( |
40 device::BluetoothAdapter::Observer* observer) OVERRIDE; | 43 device::BluetoothAdapter::Observer* observer) OVERRIDE; |
41 virtual std::string GetAddress() const OVERRIDE; | 44 virtual std::string GetAddress() const OVERRIDE; |
42 virtual std::string GetName() const OVERRIDE; | 45 virtual std::string GetName() const OVERRIDE; |
43 virtual void SetName(const std::string& name, | 46 virtual void SetName(const std::string& name, |
44 const base::Closure& callback, | 47 const base::Closure& callback, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 // BluetoothDeviceClient::Observer override. | 90 // BluetoothDeviceClient::Observer override. |
88 virtual void DeviceAdded(const dbus::ObjectPath& object_path) OVERRIDE; | 91 virtual void DeviceAdded(const dbus::ObjectPath& object_path) OVERRIDE; |
89 virtual void DeviceRemoved(const dbus::ObjectPath& object_path) OVERRIDE; | 92 virtual void DeviceRemoved(const dbus::ObjectPath& object_path) OVERRIDE; |
90 virtual void DevicePropertyChanged(const dbus::ObjectPath& object_path, | 93 virtual void DevicePropertyChanged(const dbus::ObjectPath& object_path, |
91 const std::string& property_name) OVERRIDE; | 94 const std::string& property_name) OVERRIDE; |
92 | 95 |
93 // BluetoothInputClient::Observer override. | 96 // BluetoothInputClient::Observer override. |
94 virtual void InputPropertyChanged(const dbus::ObjectPath& object_path, | 97 virtual void InputPropertyChanged(const dbus::ObjectPath& object_path, |
95 const std::string& property_name) OVERRIDE; | 98 const std::string& property_name) OVERRIDE; |
96 | 99 |
| 100 // BluetoothAgentServiceProvider::Delegate override. |
| 101 virtual void Release() OVERRIDE; |
| 102 virtual void RequestPinCode(const dbus::ObjectPath& device_path, |
| 103 const PinCodeCallback& callback) OVERRIDE; |
| 104 virtual void DisplayPinCode(const dbus::ObjectPath& device_path, |
| 105 const std::string& pincode) OVERRIDE; |
| 106 virtual void RequestPasskey(const dbus::ObjectPath& device_path, |
| 107 const PasskeyCallback& callback) OVERRIDE; |
| 108 virtual void DisplayPasskey(const dbus::ObjectPath& device_path, |
| 109 uint32 passkey, uint16 entered) OVERRIDE; |
| 110 virtual void RequestConfirmation(const dbus::ObjectPath& device_path, |
| 111 uint32 passkey, |
| 112 const ConfirmationCallback& callback) |
| 113 OVERRIDE; |
| 114 virtual void RequestAuthorization(const dbus::ObjectPath& device_path, |
| 115 const ConfirmationCallback& callback) |
| 116 OVERRIDE; |
| 117 virtual void AuthorizeService(const dbus::ObjectPath& device_path, |
| 118 const std::string& uuid, |
| 119 const ConfirmationCallback& callback) OVERRIDE; |
| 120 virtual void Cancel() OVERRIDE; |
| 121 |
| 122 // PairingContext is an API between BluetoothAdapterChromeOS and |
| 123 // BluetoothDeviceChromeOS for a single pairing attempt, wrapping the |
| 124 // callbacks of the underlying BluetoothAgentServiceProvider object. |
| 125 class PairingContext { |
| 126 public: |
| 127 ~PairingContext(); |
| 128 |
| 129 // Indicates whether the device is currently pairing and expecting a |
| 130 // PIN Code to be returned. |
| 131 bool ExpectingPinCode() const; |
| 132 |
| 133 // Indicates whether the device is currently pairing and expecting a |
| 134 // Passkey to be returned. |
| 135 bool ExpectingPasskey() const; |
| 136 |
| 137 // Indicates whether the device is currently pairing and expecting |
| 138 // confirmation of a displayed passkey. |
| 139 bool ExpectingConfirmation() const; |
| 140 |
| 141 // Sends the PIN code |pincode| to the remote device during pairing. |
| 142 // |
| 143 // PIN Codes are generally required for Bluetooth 2.0 and earlier devices |
| 144 // for which there is no automatic pairing or special handling. |
| 145 void SetPinCode(const std::string& pincode); |
| 146 |
| 147 // Sends the Passkey |passkey| to the remote device during pairing. |
| 148 // |
| 149 // Passkeys are generally required for Bluetooth 2.1 and later devices |
| 150 // which cannot provide input or display on their own, and don't accept |
| 151 // passkey-less pairing, and are a numeric in the range 0-999999. |
| 152 void SetPasskey(uint32 passkey); |
| 153 |
| 154 // Confirms to the remote device during pairing that a passkey provided by |
| 155 // the ConfirmPasskey() delegate call is displayed on both devices. |
| 156 void ConfirmPairing(); |
| 157 |
| 158 // Rejects a pairing or connection request from a remote device, returns |
| 159 // false if there was no way to reject the pairing. |
| 160 bool RejectPairing(); |
| 161 |
| 162 // Cancels a pairing or connection attempt to a remote device, returns |
| 163 // false if there was no way to cancel the pairing. |
| 164 bool CancelPairing(); |
| 165 |
| 166 private: |
| 167 friend class BluetoothAdapterChromeOS; |
| 168 friend class BluetoothDeviceChromeOS; |
| 169 |
| 170 explicit PairingContext( |
| 171 device::BluetoothDevice::PairingDelegate* pairing_delegate_); |
| 172 |
| 173 // Internal method to response to the relevant callback for a RejectPairing |
| 174 // or CancelPairing call. |
| 175 bool RunPairingCallbacks( |
| 176 BluetoothAgentServiceProvider::Delegate::Status status); |
| 177 |
| 178 // UI Pairing Delegate to make method calls on, this must live as long as |
| 179 // the object capturing the PairingContext. |
| 180 device::BluetoothDevice::PairingDelegate* pairing_delegate_; |
| 181 |
| 182 // Flag to indicate whether any pairing delegate method has been called |
| 183 // during pairing. Used to determine whether we need to log the |
| 184 // "no pairing interaction" metric. |
| 185 bool pairing_delegate_used_; |
| 186 |
| 187 // During pairing these callbacks are set to those provided by method calls |
| 188 // made on the BluetoothAdapterChromeOS instance by its respective |
| 189 // BluetoothAgentServiceProvider instance, and are called by our own |
| 190 // method calls such as SetPinCode() and SetPasskey(). |
| 191 PinCodeCallback pincode_callback_; |
| 192 PasskeyCallback passkey_callback_; |
| 193 ConfirmationCallback confirmation_callback_; |
| 194 }; |
| 195 |
| 196 // Called by dbus:: on completion of the D-Bus method call to register the |
| 197 // pairing agent. |
| 198 void OnRegisterAgent(); |
| 199 void OnRegisterAgentError(const std::string& error_name, |
| 200 const std::string& error_message); |
| 201 |
97 // Internal method used to locate the device object by object path | 202 // Internal method used to locate the device object by object path |
98 // (the devices map and BluetoothDevice methods are by address) | 203 // (the devices map and BluetoothDevice methods are by address) |
99 BluetoothDeviceChromeOS* GetDeviceWithPath( | 204 BluetoothDeviceChromeOS* GetDeviceWithPath( |
100 const dbus::ObjectPath& object_path); | 205 const dbus::ObjectPath& object_path); |
101 | 206 |
| 207 // Internal method to obtain the ChromeOS BluetoothDevice object, returned in |
| 208 // |device_chromeos| and associated PairingContext, returned in |
| 209 // |pairing_context| for the device with path |object_path|. |
| 210 // Returns true on success, false if device doesn't exist or there is no |
| 211 // pairing context for it. |
| 212 bool GetDeviceAndPairingContext(const dbus::ObjectPath& object_path, |
| 213 BluetoothDeviceChromeOS** device_chromeos, |
| 214 PairingContext** pairing_context); |
| 215 |
102 // Set the tracked adapter to the one in |object_path|, this object will | 216 // Set the tracked adapter to the one in |object_path|, this object will |
103 // subsequently operate on that adapter until it is removed. | 217 // subsequently operate on that adapter until it is removed. |
104 void SetAdapter(const dbus::ObjectPath& object_path); | 218 void SetAdapter(const dbus::ObjectPath& object_path); |
105 | 219 |
106 // Set the adapter name to one chosen from the system information. | 220 // Set the adapter name to one chosen from the system information. |
107 void SetDefaultAdapterName(); | 221 void SetDefaultAdapterName(); |
108 | 222 |
109 // Remove the currently tracked adapter. IsPresent() will return false after | 223 // Remove the currently tracked adapter. IsPresent() will return false after |
110 // this is called. | 224 // this is called. |
111 void RemoveAdapter(); | 225 void RemoveAdapter(); |
(...skipping 29 matching lines...) Expand all Loading... |
141 void OnStopDiscoveryError(const ErrorCallback& error_callback, | 255 void OnStopDiscoveryError(const ErrorCallback& error_callback, |
142 const std::string& error_name, | 256 const std::string& error_name, |
143 const std::string& error_message); | 257 const std::string& error_message); |
144 | 258 |
145 // Object path of the adapter we track. | 259 // Object path of the adapter we track. |
146 dbus::ObjectPath object_path_; | 260 dbus::ObjectPath object_path_; |
147 | 261 |
148 // List of observers interested in event notifications from us. | 262 // List of observers interested in event notifications from us. |
149 ObserverList<device::BluetoothAdapter::Observer> observers_; | 263 ObserverList<device::BluetoothAdapter::Observer> observers_; |
150 | 264 |
| 265 // Instance of the D-Bus agent object used for pairing, initialized with |
| 266 // our own class as its delegate. |
| 267 scoped_ptr<BluetoothAgentServiceProvider> agent_; |
| 268 |
151 // Note: This should remain the last member so it'll be destroyed and | 269 // Note: This should remain the last member so it'll be destroyed and |
152 // invalidate its weak pointers before any other members are destroyed. | 270 // invalidate its weak pointers before any other members are destroyed. |
153 base::WeakPtrFactory<BluetoothAdapterChromeOS> weak_ptr_factory_; | 271 base::WeakPtrFactory<BluetoothAdapterChromeOS> weak_ptr_factory_; |
154 | 272 |
155 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterChromeOS); | 273 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterChromeOS); |
156 }; | 274 }; |
157 | 275 |
158 } // namespace chromeos | 276 } // namespace chromeos |
159 | 277 |
160 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_ | 278 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_ |
OLD | NEW |