| 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" | |
| 13 #include "chromeos/dbus/bluetooth_device_client.h" | 12 #include "chromeos/dbus/bluetooth_device_client.h" |
| 14 #include "dbus/object_path.h" | 13 #include "dbus/object_path.h" |
| 14 #include "device/bluetooth/bluetooth_adapter_chromeos.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 BluetoothAdapterChromeOS; | |
| 20 | |
| 21 // The BluetoothDeviceChromeOS class implements BluetoothDevice for the | 19 // The BluetoothDeviceChromeOS class implements BluetoothDevice for the |
| 22 // Chrome OS platform. | 20 // Chrome OS platform. |
| 23 class BluetoothDeviceChromeOS | 21 class BluetoothDeviceChromeOS |
| 24 : public device::BluetoothDevice, | 22 : public device::BluetoothDevice { |
| 25 private chromeos::BluetoothAgentServiceProvider::Delegate { | |
| 26 public: | 23 public: |
| 27 // BluetoothDevice override | 24 // BluetoothDevice override |
| 28 virtual uint32 GetBluetoothClass() const OVERRIDE; | 25 virtual uint32 GetBluetoothClass() const OVERRIDE; |
| 29 virtual std::string GetAddress() const OVERRIDE; | 26 virtual std::string GetAddress() const OVERRIDE; |
| 30 virtual uint16 GetVendorID() const OVERRIDE; | 27 virtual uint16 GetVendorID() const OVERRIDE; |
| 31 virtual uint16 GetProductID() const OVERRIDE; | 28 virtual uint16 GetProductID() const OVERRIDE; |
| 32 virtual uint16 GetDeviceID() const OVERRIDE; | 29 virtual uint16 GetDeviceID() const OVERRIDE; |
| 33 virtual bool IsPaired() const OVERRIDE; | 30 virtual bool IsPaired() const OVERRIDE; |
| 34 virtual bool IsConnected() const OVERRIDE; | 31 virtual bool IsConnected() const OVERRIDE; |
| 35 virtual bool IsConnectable() const OVERRIDE; | 32 virtual bool IsConnectable() const OVERRIDE; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 // BluetoothDevice override | 73 // BluetoothDevice override |
| 77 virtual std::string GetDeviceName() const OVERRIDE; | 74 virtual std::string GetDeviceName() const OVERRIDE; |
| 78 | 75 |
| 79 private: | 76 private: |
| 80 friend class BluetoothAdapterChromeOS; | 77 friend class BluetoothAdapterChromeOS; |
| 81 | 78 |
| 82 BluetoothDeviceChromeOS(BluetoothAdapterChromeOS* adapter, | 79 BluetoothDeviceChromeOS(BluetoothAdapterChromeOS* adapter, |
| 83 const dbus::ObjectPath& object_path); | 80 const dbus::ObjectPath& object_path); |
| 84 virtual ~BluetoothDeviceChromeOS(); | 81 virtual ~BluetoothDeviceChromeOS(); |
| 85 | 82 |
| 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 | 83 // Internal method to initiate a connection to this device, and methods called |
| 109 // by dbus:: on completion of the D-Bus method call. | 84 // by dbus:: on completion of the D-Bus method call. |
| 110 void ConnectInternal(bool after_pairing, | 85 void ConnectInternal(bool after_pairing, |
| 111 const base::Closure& callback, | 86 const base::Closure& callback, |
| 112 const ConnectErrorCallback& error_callback); | 87 const ConnectErrorCallback& error_callback); |
| 113 void OnConnect(bool after_pairing, | 88 void OnConnect(bool after_pairing, |
| 114 const base::Closure& callback); | 89 const base::Closure& callback); |
| 115 void OnConnectError(bool after_pairing, | 90 void OnConnectError(bool after_pairing, |
| 116 const ConnectErrorCallback& error_callback, | 91 const ConnectErrorCallback& error_callback, |
| 117 const std::string& error_name, | 92 const std::string& error_name, |
| 118 const std::string& error_message); | 93 const std::string& error_message); |
| 119 | 94 |
| 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. | 95 // Called by dbus:: on completion of the D-Bus method call to pair the device. |
| 129 void OnPair(const base::Closure& callback, | 96 void OnPair(const base::Closure& callback, |
| 130 const ConnectErrorCallback& error_callback); | 97 const ConnectErrorCallback& error_callback); |
| 131 void OnPairError(const ConnectErrorCallback& error_callback, | 98 void OnPairError(const ConnectErrorCallback& error_callback, |
| 132 const std::string& error_name, | 99 const std::string& error_name, |
| 133 const std::string& error_message); | 100 const std::string& error_message); |
| 134 | 101 |
| 135 // Called by dbus:: on failure of the D-Bus method call to cancel pairing, | 102 // 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 | 103 // there is no matching completion call since we don't do anything special |
| 137 // in that case. | 104 // in that case. |
| 138 void OnCancelPairingError(const std::string& error_name, | 105 void OnCancelPairingError(const std::string& error_name, |
| 139 const std::string& error_message); | 106 const std::string& error_message); |
| 140 | 107 |
| 141 // Internal method to set the device as trusted. Trusted devices can connect | 108 // 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 | 109 // 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. | 110 // 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. | 111 // |success| to the callback indicates whether or not the request succeeded. |
| 145 void SetTrusted(); | 112 void SetTrusted(); |
| 146 void OnSetTrusted(bool success); | 113 void OnSetTrusted(bool success); |
| 147 | 114 |
| 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 | 115 // Called by dbus:: on completion of the D-Bus method call to disconnect the |
| 156 // device. | 116 // device. |
| 157 void OnDisconnect(const base::Closure& callback); | 117 void OnDisconnect(const base::Closure& callback); |
| 158 void OnDisconnectError(const ErrorCallback& error_callback, | 118 void OnDisconnectError(const ErrorCallback& error_callback, |
| 159 const std::string& error_name, | 119 const std::string& error_name, |
| 160 const std::string& error_message); | 120 const std::string& error_message); |
| 161 | 121 |
| 162 // Called by dbus:: on failure of the D-Bus method call to unpair the device; | 122 // 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 | 123 // there is no matching completion call since this object is deleted in the |
| 164 // process of unpairing. | 124 // process of unpairing. |
| 165 void OnForgetError(const ErrorCallback& error_callback, | 125 void OnForgetError(const ErrorCallback& error_callback, |
| 166 const std::string& error_name, | 126 const std::string& error_name, |
| 167 const std::string& error_message); | 127 const std::string& error_message); |
| 168 | 128 |
| 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 | 129 // Called by dbus:: on completion of the D-Bus method call to |
| 174 // connect a peofile. | 130 // connect a peofile. |
| 175 void OnConnectProfile(device::BluetoothProfile* profile, | 131 void OnConnectProfile(device::BluetoothProfile* profile, |
| 176 const base::Closure& callback); | 132 const base::Closure& callback); |
| 177 void OnConnectProfileError(device::BluetoothProfile* profile, | 133 void OnConnectProfileError(device::BluetoothProfile* profile, |
| 178 const ErrorCallback& error_callback, | 134 const ErrorCallback& error_callback, |
| 179 const std::string& error_name, | 135 const std::string& error_name, |
| 180 const std::string& error_message); | 136 const std::string& error_message); |
| 181 | 137 |
| 182 // Return the object path of the device; used by BluetoothAdapterChromeOS | 138 // Return the object path of the device; used by BluetoothAdapterChromeOS |
| 183 const dbus::ObjectPath& object_path() const { return object_path_; } | 139 const dbus::ObjectPath& object_path() const { return object_path_; } |
| 184 | 140 |
| 185 // The adapter that owns this device instance. | 141 // The adapter that owns this device instance. |
| 186 BluetoothAdapterChromeOS* adapter_; | 142 BluetoothAdapterChromeOS* adapter_; |
| 187 | 143 |
| 188 // The dbus object path of the device object. | 144 // The dbus object path of the device object. |
| 189 dbus::ObjectPath object_path_; | 145 dbus::ObjectPath object_path_; |
| 190 | 146 |
| 191 // Number of ongoing calls to Connect(). | 147 // Number of ongoing calls to Connect(). |
| 192 int num_connecting_calls_; | 148 int num_connecting_calls_; |
| 193 | 149 |
| 194 // During pairing this is set to an object that we don't own, but on which | 150 // 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 | 151 // we can make method calls to request, display or confirm PIN Codes and |
| 196 // Passkeys. Generally it is the object that owns this one. | 152 // Passkeys. Generally it is the object that owns this one. |
| 197 PairingDelegate* pairing_delegate_; | 153 PairingDelegate* pairing_delegate_; |
| 198 | 154 |
| 199 // Flag to indicate whether a pairing delegate method has been called during | 155 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 | 156 |
| 214 // Note: This should remain the last member so it'll be destroyed and | 157 // Note: This should remain the last member so it'll be destroyed and |
| 215 // invalidate its weak pointers before any other members are destroyed. | 158 // invalidate its weak pointers before any other members are destroyed. |
| 216 base::WeakPtrFactory<BluetoothDeviceChromeOS> weak_ptr_factory_; | 159 base::WeakPtrFactory<BluetoothDeviceChromeOS> weak_ptr_factory_; |
| 217 | 160 |
| 218 DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceChromeOS); | 161 DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceChromeOS); |
| 219 }; | 162 }; |
| 220 | 163 |
| 221 } // namespace chromeos | 164 } // namespace chromeos |
| 222 | 165 |
| 223 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_CHROMEOS_H | 166 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_CHROMEOS_H |
| OLD | NEW |