Chromium Code Reviews| 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_DEVICE_CHROMEOS_H | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_CHROMEOS_H |
| 6 #define DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_CHROMEOS_H | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_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/bluetooth_agent_service_provider.h" | 12 #include "chromeos/dbus/bluetooth_agent_service_provider.h" |
|
armansito
2014/01/27 23:37:06
nit: You can probably remove this include now.
| |
| 13 #include "chromeos/dbus/bluetooth_device_client.h" | 13 #include "chromeos/dbus/bluetooth_device_client.h" |
| 14 #include "dbus/object_path.h" | 14 #include "dbus/object_path.h" |
| 15 #include "device/bluetooth/bluetooth_adapter_chromeos.h" | |
| 15 #include "device/bluetooth/bluetooth_device.h" | 16 #include "device/bluetooth/bluetooth_device.h" |
| 16 | 17 |
| 17 namespace chromeos { | 18 namespace chromeos { |
| 18 | 19 |
| 19 class BluetoothAdapterChromeOS; | |
| 20 | |
| 21 // The BluetoothDeviceChromeOS class implements BluetoothDevice for the | 20 // The BluetoothDeviceChromeOS class implements BluetoothDevice for the |
| 22 // Chrome OS platform. | 21 // Chrome OS platform. |
| 23 class BluetoothDeviceChromeOS | 22 class BluetoothDeviceChromeOS |
| 24 : public device::BluetoothDevice, | 23 : public device::BluetoothDevice { |
| 25 private chromeos::BluetoothAgentServiceProvider::Delegate { | |
| 26 public: | 24 public: |
| 27 // BluetoothDevice override | 25 // BluetoothDevice override |
| 28 virtual uint32 GetBluetoothClass() const OVERRIDE; | 26 virtual uint32 GetBluetoothClass() const OVERRIDE; |
| 29 virtual std::string GetAddress() const OVERRIDE; | 27 virtual std::string GetAddress() const OVERRIDE; |
| 30 virtual uint16 GetVendorID() const OVERRIDE; | 28 virtual uint16 GetVendorID() const OVERRIDE; |
| 31 virtual uint16 GetProductID() const OVERRIDE; | 29 virtual uint16 GetProductID() const OVERRIDE; |
| 32 virtual uint16 GetDeviceID() const OVERRIDE; | 30 virtual uint16 GetDeviceID() const OVERRIDE; |
| 33 virtual bool IsPaired() const OVERRIDE; | 31 virtual bool IsPaired() const OVERRIDE; |
| 34 virtual bool IsConnected() const OVERRIDE; | 32 virtual bool IsConnected() const OVERRIDE; |
| 35 virtual bool IsConnectable() const OVERRIDE; | 33 virtual bool IsConnectable() const OVERRIDE; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 // BluetoothDevice override | 74 // BluetoothDevice override |
| 77 virtual std::string GetDeviceName() const OVERRIDE; | 75 virtual std::string GetDeviceName() const OVERRIDE; |
| 78 | 76 |
| 79 private: | 77 private: |
| 80 friend class BluetoothAdapterChromeOS; | 78 friend class BluetoothAdapterChromeOS; |
| 81 | 79 |
| 82 BluetoothDeviceChromeOS(BluetoothAdapterChromeOS* adapter, | 80 BluetoothDeviceChromeOS(BluetoothAdapterChromeOS* adapter, |
| 83 const dbus::ObjectPath& object_path); | 81 const dbus::ObjectPath& object_path); |
| 84 virtual ~BluetoothDeviceChromeOS(); | 82 virtual ~BluetoothDeviceChromeOS(); |
| 85 | 83 |
| 86 // BluetoothAgentServiceProvider::Delegate override. | |
| 87 virtual void Release() OVERRIDE; | |
| 88 virtual void RequestPinCode(const dbus::ObjectPath& device_path, | |
| 89 const PinCodeCallback& callback) OVERRIDE; | |
| 90 virtual void DisplayPinCode(const dbus::ObjectPath& device_path, | |
| 91 const std::string& pincode) OVERRIDE; | |
| 92 virtual void RequestPasskey(const dbus::ObjectPath& device_path, | |
| 93 const PasskeyCallback& callback) OVERRIDE; | |
| 94 virtual void DisplayPasskey(const dbus::ObjectPath& device_path, | |
| 95 uint32 passkey, uint16 entered) OVERRIDE; | |
| 96 virtual void RequestConfirmation(const dbus::ObjectPath& device_path, | |
| 97 uint32 passkey, | |
| 98 const ConfirmationCallback& callback) | |
| 99 OVERRIDE; | |
| 100 virtual void RequestAuthorization(const dbus::ObjectPath& device_path, | |
| 101 const ConfirmationCallback& callback) | |
| 102 OVERRIDE; | |
| 103 virtual void AuthorizeService(const dbus::ObjectPath& device_path, | |
| 104 const std::string& uuid, | |
| 105 const ConfirmationCallback& callback) OVERRIDE; | |
| 106 virtual void Cancel() OVERRIDE; | |
| 107 | |
| 108 // Internal method to initiate a connection to this device, and methods called | 84 // Internal method to initiate a connection to this device, and methods called |
| 109 // by dbus:: on completion of the D-Bus method call. | 85 // by dbus:: on completion of the D-Bus method call. |
| 110 void ConnectInternal(bool after_pairing, | 86 void ConnectInternal(bool after_pairing, |
| 111 const base::Closure& callback, | 87 const base::Closure& callback, |
| 112 const ConnectErrorCallback& error_callback); | 88 const ConnectErrorCallback& error_callback); |
| 113 void OnConnect(bool after_pairing, | 89 void OnConnect(bool after_pairing, |
| 114 const base::Closure& callback); | 90 const base::Closure& callback); |
| 115 void OnConnectError(bool after_pairing, | 91 void OnConnectError(bool after_pairing, |
| 116 const ConnectErrorCallback& error_callback, | 92 const ConnectErrorCallback& error_callback, |
| 117 const std::string& error_name, | 93 const std::string& error_name, |
| 118 const std::string& error_message); | 94 const std::string& error_message); |
| 119 | 95 |
| 120 // Called by dbus:: on completion of the D-Bus method call to register the | |
| 121 // pairing agent. | |
| 122 void OnRegisterAgent(const base::Closure& callback, | |
| 123 const ConnectErrorCallback& error_callback); | |
| 124 void OnRegisterAgentError(const ConnectErrorCallback& error_callback, | |
| 125 const std::string& error_name, | |
| 126 const std::string& error_message); | |
| 127 | |
| 128 // Called by dbus:: on completion of the D-Bus method call to pair the device. | 96 // Called by dbus:: on completion of the D-Bus method call to pair the device. |
| 129 void OnPair(const base::Closure& callback, | 97 void OnPair(const base::Closure& callback, |
| 130 const ConnectErrorCallback& error_callback); | 98 const ConnectErrorCallback& error_callback); |
| 131 void OnPairError(const ConnectErrorCallback& error_callback, | 99 void OnPairError(const ConnectErrorCallback& error_callback, |
| 132 const std::string& error_name, | 100 const std::string& error_name, |
| 133 const std::string& error_message); | 101 const std::string& error_message); |
| 134 | 102 |
| 135 // Called by dbus:: on failure of the D-Bus method call to cancel pairing, | 103 // Called by dbus:: on failure of the D-Bus method call to cancel pairing, |
| 136 // there is no matching completion call since we don't do anything special | 104 // there is no matching completion call since we don't do anything special |
| 137 // in that case. | 105 // in that case. |
| 138 void OnCancelPairingError(const std::string& error_name, | 106 void OnCancelPairingError(const std::string& error_name, |
| 139 const std::string& error_message); | 107 const std::string& error_message); |
| 140 | 108 |
| 141 // Internal method to set the device as trusted. Trusted devices can connect | 109 // Internal method to set the device as trusted. Trusted devices can connect |
| 142 // to us automatically, and we can connect to them after rebooting; it also | 110 // to us automatically, and we can connect to them after rebooting; it also |
| 143 // causes the device to be remembered by the stack even if not paired. | 111 // causes the device to be remembered by the stack even if not paired. |
| 144 // |success| to the callback indicates whether or not the request succeeded. | 112 // |success| to the callback indicates whether or not the request succeeded. |
| 145 void SetTrusted(); | 113 void SetTrusted(); |
| 146 void OnSetTrusted(bool success); | 114 void OnSetTrusted(bool success); |
| 147 | 115 |
| 148 // Internal method to unregister the pairing agent and method called by dbus:: | |
| 149 // on failure of the D-Bus method call. No completion call as success is | |
| 150 // ignored. | |
| 151 void UnregisterAgent(); | |
| 152 void OnUnregisterAgentError(const std::string& error_name, | |
| 153 const std::string& error_message); | |
| 154 | |
| 155 // Called by dbus:: on completion of the D-Bus method call to disconnect the | 116 // Called by dbus:: on completion of the D-Bus method call to disconnect the |
| 156 // device. | 117 // device. |
| 157 void OnDisconnect(const base::Closure& callback); | 118 void OnDisconnect(const base::Closure& callback); |
| 158 void OnDisconnectError(const ErrorCallback& error_callback, | 119 void OnDisconnectError(const ErrorCallback& error_callback, |
| 159 const std::string& error_name, | 120 const std::string& error_name, |
| 160 const std::string& error_message); | 121 const std::string& error_message); |
| 161 | 122 |
| 162 // Called by dbus:: on failure of the D-Bus method call to unpair the device; | 123 // Called by dbus:: on failure of the D-Bus method call to unpair the device; |
| 163 // there is no matching completion call since this object is deleted in the | 124 // there is no matching completion call since this object is deleted in the |
| 164 // process of unpairing. | 125 // process of unpairing. |
| 165 void OnForgetError(const ErrorCallback& error_callback, | 126 void OnForgetError(const ErrorCallback& error_callback, |
| 166 const std::string& error_name, | 127 const std::string& error_name, |
| 167 const std::string& error_message); | 128 const std::string& error_message); |
| 168 | 129 |
| 169 // Run any outstanding pairing callbacks passing |status| as the result of | |
| 170 // pairing. Returns true if any callbacks were run, false if not. | |
| 171 bool RunPairingCallbacks(Status status); | |
| 172 | |
| 173 // Called by dbus:: on completion of the D-Bus method call to | 130 // Called by dbus:: on completion of the D-Bus method call to |
| 174 // connect a peofile. | 131 // connect a peofile. |
| 175 void OnConnectProfile(device::BluetoothProfile* profile, | 132 void OnConnectProfile(device::BluetoothProfile* profile, |
| 176 const base::Closure& callback); | 133 const base::Closure& callback); |
| 177 void OnConnectProfileError(device::BluetoothProfile* profile, | 134 void OnConnectProfileError(device::BluetoothProfile* profile, |
| 178 const ErrorCallback& error_callback, | 135 const ErrorCallback& error_callback, |
| 179 const std::string& error_name, | 136 const std::string& error_name, |
| 180 const std::string& error_message); | 137 const std::string& error_message); |
| 181 | 138 |
| 182 // Return the object path of the device; used by BluetoothAdapterChromeOS | 139 // Return the object path of the device; used by BluetoothAdapterChromeOS |
| 183 const dbus::ObjectPath& object_path() const { return object_path_; } | 140 const dbus::ObjectPath& object_path() const { return object_path_; } |
| 184 | 141 |
| 185 // The adapter that owns this device instance. | 142 // The adapter that owns this device instance. |
| 186 BluetoothAdapterChromeOS* adapter_; | 143 BluetoothAdapterChromeOS* adapter_; |
| 187 | 144 |
| 188 // The dbus object path of the device object. | 145 // The dbus object path of the device object. |
| 189 dbus::ObjectPath object_path_; | 146 dbus::ObjectPath object_path_; |
| 190 | 147 |
| 191 // Number of ongoing calls to Connect(). | 148 // Number of ongoing calls to Connect(). |
| 192 int num_connecting_calls_; | 149 int num_connecting_calls_; |
| 193 | 150 |
| 194 // During pairing this is set to an object that we don't own, but on which | 151 // During pairing this is set to an object that we don't own, but on which |
| 195 // we can make method calls to request, display or confirm PIN Codes and | 152 // we can make method calls to request, display or confirm PIN Codes and |
| 196 // Passkeys. Generally it is the object that owns this one. | 153 // Passkeys. Generally it is the object that owns this one. |
| 197 PairingDelegate* pairing_delegate_; | 154 PairingDelegate* pairing_delegate_; |
| 198 | 155 |
| 199 // Flag to indicate whether a pairing delegate method has been called during | 156 scoped_ptr<BluetoothAdapterChromeOS::PairingContext> pairing_context_; |
| 200 // pairing. | |
| 201 bool pairing_delegate_used_; | |
| 202 | |
| 203 // During pairing this is set to an instance of a D-Bus agent object | |
| 204 // intialized with our own class as its delegate. | |
| 205 scoped_ptr<BluetoothAgentServiceProvider> agent_; | |
| 206 | |
| 207 // During pairing these callbacks are set to those provided by method calls | |
| 208 // made on us by |agent_| and are called by our own method calls such as | |
| 209 // SetPinCode() and SetPasskey(). | |
| 210 PinCodeCallback pincode_callback_; | |
| 211 PasskeyCallback passkey_callback_; | |
| 212 ConfirmationCallback confirmation_callback_; | |
| 213 | 157 |
| 214 // Note: This should remain the last member so it'll be destroyed and | 158 // Note: This should remain the last member so it'll be destroyed and |
| 215 // invalidate its weak pointers before any other members are destroyed. | 159 // invalidate its weak pointers before any other members are destroyed. |
| 216 base::WeakPtrFactory<BluetoothDeviceChromeOS> weak_ptr_factory_; | 160 base::WeakPtrFactory<BluetoothDeviceChromeOS> weak_ptr_factory_; |
| 217 | 161 |
| 218 DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceChromeOS); | 162 DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceChromeOS); |
| 219 }; | 163 }; |
| 220 | 164 |
| 221 } // namespace chromeos | 165 } // namespace chromeos |
| 222 | 166 |
| 223 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_CHROMEOS_H | 167 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_CHROMEOS_H |
| OLD | NEW |