OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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_DEVICE_EXPERIMENTAL_CHROMEOS_H | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_EXPERIMENTAL_CHROMEOS_H |
6 #define DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_EXPERIMENTAL_CHROMEOS_H | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_EXPERIMENTAL_CHROMEOS_H |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "chromeos/dbus/experimental_bluetooth_agent_service_provider.h" | 12 #include "chromeos/dbus/experimental_bluetooth_agent_service_provider.h" |
13 #include "chromeos/dbus/experimental_bluetooth_device_client.h" | 13 #include "chromeos/dbus/experimental_bluetooth_device_client.h" |
14 #include "dbus/object_path.h" | 14 #include "dbus/object_path.h" |
15 #include "device/bluetooth/bluetooth_device.h" | 15 #include "device/bluetooth/bluetooth_device.h" |
16 | 16 |
17 namespace chromeos { | 17 namespace chromeos { |
18 | 18 |
19 class BluetoothAdapterExperimentalChromeOS; | 19 class BluetoothAdapterExperimentalChromeOS; |
20 | 20 |
21 // The BluetoothDeviceExperimentalChromeOS class is an alternate implementation | 21 // The BluetoothDeviceExperimentalChromeOS class is an alternate implementation |
22 // of BluetoothDevice for the Chrome OS platform using the Bluetooth Smart | 22 // of BluetoothDevice for the Chrome OS platform using the Bluetooth Smart |
23 // capable backend. It will become the sole implementation for Chrome OS, and | 23 // capable backend. It will become the sole implementation for Chrome OS, and |
24 // be renamed to BluetoothDeviceChromeOS, once the backend is switched. | 24 // be renamed to BluetoothDeviceChromeOS, once the backend is switched. |
25 class BluetoothDeviceExperimentalChromeOS | 25 class BluetoothDeviceExperimentalChromeOS |
26 : public device::BluetoothDevice, | 26 : public device::BluetoothDevice, |
27 private chromeos::ExperimentalBluetoothAgentServiceProvider::Delegate { | 27 private chromeos::ExperimentalBluetoothAgentServiceProvider::Delegate { |
28 public: | 28 public: |
29 // BluetoothDevice override | 29 // BluetoothDevice override |
| 30 virtual uint32 GetBluetoothClass() const OVERRIDE; |
30 virtual std::string GetAddress() const OVERRIDE; | 31 virtual std::string GetAddress() const OVERRIDE; |
| 32 virtual uint16 GetVendorID() const OVERRIDE; |
| 33 virtual uint16 GetProductID() const OVERRIDE; |
| 34 virtual uint16 GetDeviceID() const OVERRIDE; |
31 virtual bool IsPaired() const OVERRIDE; | 35 virtual bool IsPaired() const OVERRIDE; |
32 virtual bool IsConnected() const OVERRIDE; | 36 virtual bool IsConnected() const OVERRIDE; |
33 virtual bool IsConnectable() const OVERRIDE; | 37 virtual bool IsConnectable() const OVERRIDE; |
34 virtual bool IsConnecting() const OVERRIDE; | 38 virtual bool IsConnecting() const OVERRIDE; |
35 virtual ServiceList GetServices() const OVERRIDE; | 39 virtual ServiceList GetServices() const OVERRIDE; |
36 virtual void GetServiceRecords( | 40 virtual void GetServiceRecords( |
37 const ServiceRecordsCallback& callback, | 41 const ServiceRecordsCallback& callback, |
38 const ErrorCallback& error_callback) OVERRIDE; | 42 const ErrorCallback& error_callback) OVERRIDE; |
39 virtual void ProvidesServiceWithName( | 43 virtual void ProvidesServiceWithName( |
40 const std::string& name, | 44 const std::string& name, |
(...skipping 23 matching lines...) Expand all Loading... |
64 virtual void SetOutOfBandPairingData( | 68 virtual void SetOutOfBandPairingData( |
65 const device::BluetoothOutOfBandPairingData& data, | 69 const device::BluetoothOutOfBandPairingData& data, |
66 const base::Closure& callback, | 70 const base::Closure& callback, |
67 const ErrorCallback& error_callback) OVERRIDE; | 71 const ErrorCallback& error_callback) OVERRIDE; |
68 virtual void ClearOutOfBandPairingData( | 72 virtual void ClearOutOfBandPairingData( |
69 const base::Closure& callback, | 73 const base::Closure& callback, |
70 const ErrorCallback& error_callback) OVERRIDE; | 74 const ErrorCallback& error_callback) OVERRIDE; |
71 | 75 |
72 protected: | 76 protected: |
73 // BluetoothDevice override | 77 // BluetoothDevice override |
74 virtual uint32 GetBluetoothClass() const OVERRIDE; | |
75 virtual std::string GetDeviceName() const OVERRIDE; | 78 virtual std::string GetDeviceName() const OVERRIDE; |
76 | 79 |
77 private: | 80 private: |
78 friend class BluetoothAdapterExperimentalChromeOS; | 81 friend class BluetoothAdapterExperimentalChromeOS; |
79 | 82 |
80 BluetoothDeviceExperimentalChromeOS( | 83 BluetoothDeviceExperimentalChromeOS( |
81 BluetoothAdapterExperimentalChromeOS* adapter, | 84 BluetoothAdapterExperimentalChromeOS* adapter, |
82 const dbus::ObjectPath& object_path); | 85 const dbus::ObjectPath& object_path); |
83 virtual ~BluetoothDeviceExperimentalChromeOS(); | 86 virtual ~BluetoothDeviceExperimentalChromeOS(); |
84 | 87 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 // there is no matching completion call since this object is deleted in the | 162 // there is no matching completion call since this object is deleted in the |
160 // process of unpairing. | 163 // process of unpairing. |
161 void OnForgetError(const ErrorCallback& error_callback, | 164 void OnForgetError(const ErrorCallback& error_callback, |
162 const std::string& error_name, | 165 const std::string& error_name, |
163 const std::string& error_message); | 166 const std::string& error_message); |
164 | 167 |
165 // Run any outstanding pairing callbacks passing |status| as the result of | 168 // Run any outstanding pairing callbacks passing |status| as the result of |
166 // pairing. Returns true if any callbacks were run, false if not. | 169 // pairing. Returns true if any callbacks were run, false if not. |
167 bool RunPairingCallbacks(Status status); | 170 bool RunPairingCallbacks(Status status); |
168 | 171 |
| 172 // Record the result of pairing as a UMA histogram metric; |success| should |
| 173 // be true if pairing succeeded, and |false| if not - in which case |
| 174 // |error_code| specifies the reason for failure. |
| 175 void RecordPairingResult(bool success, ConnectErrorCode error_code); |
| 176 |
169 // Return the object path of the device; used by | 177 // Return the object path of the device; used by |
170 // BluetoothAdapterExperimentalChromeOS | 178 // BluetoothAdapterExperimentalChromeOS |
171 const dbus::ObjectPath& object_path() const { return object_path_; } | 179 const dbus::ObjectPath& object_path() const { return object_path_; } |
172 | 180 |
173 // The adapter that owns this device instance. | 181 // The adapter that owns this device instance. |
174 BluetoothAdapterExperimentalChromeOS* adapter_; | 182 BluetoothAdapterExperimentalChromeOS* adapter_; |
175 | 183 |
176 // The dbus object path of the device object. | 184 // The dbus object path of the device object. |
177 dbus::ObjectPath object_path_; | 185 dbus::ObjectPath object_path_; |
178 | 186 |
179 // Number of ongoing calls to Connect(). | 187 // Number of ongoing calls to Connect(). |
180 int num_connecting_calls_; | 188 int num_connecting_calls_; |
181 | 189 |
182 // During pairing this is set to an object that we don't own, but on which | 190 // During pairing this is set to an object that we don't own, but on which |
183 // we can make method calls to request, display or confirm PIN Codes and | 191 // we can make method calls to request, display or confirm PIN Codes and |
184 // Passkeys. Generally it is the object that owns this one. | 192 // Passkeys. Generally it is the object that owns this one. |
185 PairingDelegate* pairing_delegate_; | 193 PairingDelegate* pairing_delegate_; |
186 | 194 |
| 195 // Flag to indicate whether a pairing delegate method has been called during |
| 196 // pairing. |
| 197 bool pairing_delegate_used_; |
| 198 |
187 // During pairing this is set to an instance of a D-Bus agent object | 199 // During pairing this is set to an instance of a D-Bus agent object |
188 // intialized with our own class as its delegate. | 200 // intialized with our own class as its delegate. |
189 scoped_ptr<ExperimentalBluetoothAgentServiceProvider> agent_; | 201 scoped_ptr<ExperimentalBluetoothAgentServiceProvider> agent_; |
190 | 202 |
191 // During pairing these callbacks are set to those provided by method calls | 203 // During pairing these callbacks are set to those provided by method calls |
192 // made on us by |agent_| and are called by our own method calls such as | 204 // made on us by |agent_| and are called by our own method calls such as |
193 // SetPinCode() and SetPasskey(). | 205 // SetPinCode() and SetPasskey(). |
194 PinCodeCallback pincode_callback_; | 206 PinCodeCallback pincode_callback_; |
195 PasskeyCallback passkey_callback_; | 207 PasskeyCallback passkey_callback_; |
196 ConfirmationCallback confirmation_callback_; | 208 ConfirmationCallback confirmation_callback_; |
197 | 209 |
198 // Note: This should remain the last member so it'll be destroyed and | 210 // Note: This should remain the last member so it'll be destroyed and |
199 // invalidate its weak pointers before any other members are destroyed. | 211 // invalidate its weak pointers before any other members are destroyed. |
200 base::WeakPtrFactory<BluetoothDeviceExperimentalChromeOS> weak_ptr_factory_; | 212 base::WeakPtrFactory<BluetoothDeviceExperimentalChromeOS> weak_ptr_factory_; |
201 | 213 |
202 DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceExperimentalChromeOS); | 214 DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceExperimentalChromeOS); |
203 }; | 215 }; |
204 | 216 |
205 } // namespace chromeos | 217 } // namespace chromeos |
206 | 218 |
207 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_EXPERIMENTAL_CHROMEOS_H | 219 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_EXPERIMENTAL_CHROMEOS_H |
OLD | NEW |