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 bool IsInitialized() const OVERRIDE; | 46 virtual bool IsInitialized() const OVERRIDE; |
44 virtual bool IsPresent() const OVERRIDE; | 47 virtual bool IsPresent() const OVERRIDE; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 // BluetoothDeviceClient::Observer override. | 82 // BluetoothDeviceClient::Observer override. |
80 virtual void DeviceAdded(const dbus::ObjectPath& object_path) OVERRIDE; | 83 virtual void DeviceAdded(const dbus::ObjectPath& object_path) OVERRIDE; |
81 virtual void DeviceRemoved(const dbus::ObjectPath& object_path) OVERRIDE; | 84 virtual void DeviceRemoved(const dbus::ObjectPath& object_path) OVERRIDE; |
82 virtual void DevicePropertyChanged(const dbus::ObjectPath& object_path, | 85 virtual void DevicePropertyChanged(const dbus::ObjectPath& object_path, |
83 const std::string& property_name) OVERRIDE; | 86 const std::string& property_name) OVERRIDE; |
84 | 87 |
85 // BluetoothInputClient::Observer override. | 88 // BluetoothInputClient::Observer override. |
86 virtual void InputPropertyChanged(const dbus::ObjectPath& object_path, | 89 virtual void InputPropertyChanged(const dbus::ObjectPath& object_path, |
87 const std::string& property_name) OVERRIDE; | 90 const std::string& property_name) OVERRIDE; |
88 | 91 |
| 92 // BluetoothAgentServiceProvider::Delegate override. |
| 93 virtual void Release() OVERRIDE; |
| 94 virtual void RequestPinCode(const dbus::ObjectPath& device_path, |
| 95 const PinCodeCallback& callback) OVERRIDE; |
| 96 virtual void DisplayPinCode(const dbus::ObjectPath& device_path, |
| 97 const std::string& pincode) OVERRIDE; |
| 98 virtual void RequestPasskey(const dbus::ObjectPath& device_path, |
| 99 const PasskeyCallback& callback) OVERRIDE; |
| 100 virtual void DisplayPasskey(const dbus::ObjectPath& device_path, |
| 101 uint32 passkey, uint16 entered) OVERRIDE; |
| 102 virtual void RequestConfirmation(const dbus::ObjectPath& device_path, |
| 103 uint32 passkey, |
| 104 const ConfirmationCallback& callback) |
| 105 OVERRIDE; |
| 106 virtual void RequestAuthorization(const dbus::ObjectPath& device_path, |
| 107 const ConfirmationCallback& callback) |
| 108 OVERRIDE; |
| 109 virtual void AuthorizeService(const dbus::ObjectPath& device_path, |
| 110 const std::string& uuid, |
| 111 const ConfirmationCallback& callback) OVERRIDE; |
| 112 virtual void Cancel() OVERRIDE; |
| 113 |
| 114 // PairingContext is an API between BluetoothAdapterChromeOS and |
| 115 // BluetoothDeviceChromeOS for a single pairing attempt, wrapping the |
| 116 // callbacks of the underlying BluetoothAgentServiceProvider object. |
| 117 class PairingContext { |
| 118 public: |
| 119 ~PairingContext(); |
| 120 |
| 121 // Indicates whether the device is currently pairing and expecting a |
| 122 // PIN Code to be returned. |
| 123 bool ExpectingPinCode() const; |
| 124 |
| 125 // Indicates whether the device is currently pairing and expecting a |
| 126 // Passkey to be returned. |
| 127 bool ExpectingPasskey() const; |
| 128 |
| 129 // Indicates whether the device is currently pairing and expecting |
| 130 // confirmation of a displayed passkey. |
| 131 bool ExpectingConfirmation() const; |
| 132 |
| 133 // Sends the PIN code |pincode| to the remote device during pairing. |
| 134 // |
| 135 // PIN Codes are generally required for Bluetooth 2.0 and earlier devices |
| 136 // for which there is no automatic pairing or special handling. |
| 137 void SetPinCode(const std::string& pincode); |
| 138 |
| 139 // Sends the Passkey |passkey| to the remote device during pairing. |
| 140 // |
| 141 // Passkeys are generally required for Bluetooth 2.1 and later devices |
| 142 // which cannot provide input or display on their own, and don't accept |
| 143 // passkey-less pairing, and are a numeric in the range 0-999999. |
| 144 void SetPasskey(uint32 passkey); |
| 145 |
| 146 // Confirms to the remote device during pairing that a passkey provided by |
| 147 // the ConfirmPasskey() delegate call is displayed on both devices. |
| 148 void ConfirmPairing(); |
| 149 |
| 150 // Rejects a pairing or connection request from a remote device, returns |
| 151 // false if there was no way to reject the pairing. |
| 152 bool RejectPairing(); |
| 153 |
| 154 // Cancels a pairing or connection attempt to a remote device, returns |
| 155 // false if there was no way to cancel the pairing. |
| 156 bool CancelPairing(); |
| 157 |
| 158 private: |
| 159 friend class BluetoothAdapterChromeOS; |
| 160 friend class BluetoothDeviceChromeOS; |
| 161 |
| 162 explicit PairingContext( |
| 163 device::BluetoothDevice::PairingDelegate* pairing_delegate_); |
| 164 |
| 165 // Internal method to response to the relevant callback for a RejectPairing |
| 166 // or CancelPairing call. |
| 167 bool RunPairingCallbacks( |
| 168 BluetoothAgentServiceProvider::Delegate::Status status); |
| 169 |
| 170 // UI Pairing Delegate to make method calls on, this must live as long as |
| 171 // the object capturing the PairingContext. |
| 172 device::BluetoothDevice::PairingDelegate* pairing_delegate_; |
| 173 |
| 174 // Flag to indicate whether any pairing delegate method has been called |
| 175 // during pairing. Used to determine whether we need to inform the delegate |
| 176 // to dismiss any dialog, and used to send the "no pairing interaction" |
| 177 // metric. |
| 178 bool pairing_delegate_used_; |
| 179 |
| 180 // During pairing these callbacks are set to those provided by method calls |
| 181 // made on the BluetoothAdapterChromeOS instance by its respective |
| 182 // BluetoothAgentServiceProvider instance, and are called by our own |
| 183 // method calls such as SetPinCode() and SetPasskey(). |
| 184 PinCodeCallback pincode_callback_; |
| 185 PasskeyCallback passkey_callback_; |
| 186 ConfirmationCallback confirmation_callback_; |
| 187 }; |
| 188 |
| 189 // Internal method to obtain the ChromeOS BluetoothDevice object, returned in |
| 190 // |device_chromeos| and associated PairingContext, returned in |
| 191 // |pairing_context| for the device with path |object_path|. A pairing context |
| 192 // is created using the default delegate if one does not already exist. |
| 193 // Returns true on success. |
| 194 bool GetDeviceAndPairingContext(const dbus::ObjectPath& object_path, |
| 195 BluetoothDeviceChromeOS** device_chromeos, |
| 196 PairingContext** pairing_context); |
| 197 |
| 198 // Called by dbus:: on completion of the D-Bus method call to register the |
| 199 // pairing agent. |
| 200 void OnRegisterAgent(); |
| 201 void OnRegisterAgentError(const std::string& error_name, |
| 202 const std::string& error_message); |
| 203 |
89 // Internal method used to locate the device object by object path | 204 // Internal method used to locate the device object by object path |
90 // (the devices map and BluetoothDevice methods are by address) | 205 // (the devices map and BluetoothDevice methods are by address) |
91 BluetoothDeviceChromeOS* GetDeviceWithPath( | 206 BluetoothDeviceChromeOS* GetDeviceWithPath( |
92 const dbus::ObjectPath& object_path); | 207 const dbus::ObjectPath& object_path); |
93 | 208 |
94 // Set the tracked adapter to the one in |object_path|, this object will | 209 // Set the tracked adapter to the one in |object_path|, this object will |
95 // subsequently operate on that adapter until it is removed. | 210 // subsequently operate on that adapter until it is removed. |
96 void SetAdapter(const dbus::ObjectPath& object_path); | 211 void SetAdapter(const dbus::ObjectPath& object_path); |
97 | 212 |
98 // Set the adapter name to one chosen from the system information, and method | 213 // Set the adapter name to one chosen from the system information, and method |
(...skipping 30 matching lines...) Expand all Loading... |
129 void OnStopDiscoveryError(const ErrorCallback& error_callback, | 244 void OnStopDiscoveryError(const ErrorCallback& error_callback, |
130 const std::string& error_name, | 245 const std::string& error_name, |
131 const std::string& error_message); | 246 const std::string& error_message); |
132 | 247 |
133 // Object path of the adapter we track. | 248 // Object path of the adapter we track. |
134 dbus::ObjectPath object_path_; | 249 dbus::ObjectPath object_path_; |
135 | 250 |
136 // List of observers interested in event notifications from us. | 251 // List of observers interested in event notifications from us. |
137 ObserverList<device::BluetoothAdapter::Observer> observers_; | 252 ObserverList<device::BluetoothAdapter::Observer> observers_; |
138 | 253 |
| 254 // Instance of the D-Bus agent object used for pairing, initialized with |
| 255 // our own class as its delegate. |
| 256 scoped_ptr<BluetoothAgentServiceProvider> agent_; |
| 257 |
139 // Note: This should remain the last member so it'll be destroyed and | 258 // Note: This should remain the last member so it'll be destroyed and |
140 // invalidate its weak pointers before any other members are destroyed. | 259 // invalidate its weak pointers before any other members are destroyed. |
141 base::WeakPtrFactory<BluetoothAdapterChromeOS> weak_ptr_factory_; | 260 base::WeakPtrFactory<BluetoothAdapterChromeOS> weak_ptr_factory_; |
142 | 261 |
143 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterChromeOS); | 262 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterChromeOS); |
144 }; | 263 }; |
145 | 264 |
146 } // namespace chromeos | 265 } // namespace chromeos |
147 | 266 |
148 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_ | 267 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_ |
OLD | NEW |