diff options
author | deymo@chromium.org <deymo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-18 06:55:41 +0000 |
---|---|---|
committer | deymo@chromium.org <deymo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-18 06:55:41 +0000 |
commit | eb72b66c329a1d94320678bcd28db8041f006e5f (patch) | |
tree | 5fb974b6c2643ee963e30c6a0a14797d2ded9cf3 /device/bluetooth | |
parent | b18583c0cec47182ea06949100d56acef713ff29 (diff) | |
download | chromium_src-eb72b66c329a1d94320678bcd28db8041f006e5f.zip chromium_src-eb72b66c329a1d94320678bcd28db8041f006e5f.tar.gz chromium_src-eb72b66c329a1d94320678bcd28db8041f006e5f.tar.bz2 |
bluetooth: ConnectErrorCode added in the BluetoothDevice::Connect error callback
Currently, only the interface is changed to accept an error callback with one
ConnectErrorCode argument, but all the functions will pass UNKNOW_ERROR.
BUG=chromium-os:27902
TEST=build it for chromeos daisy.
Review URL: https://chromiumcodereview.appspot.com/11485014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@173656 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'device/bluetooth')
-rw-r--r-- | device/bluetooth/bluetooth_device.h | 20 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_device_chromeos.cc | 53 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_device_chromeos.h | 20 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_device_win.cc | 2 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_device_win.h | 2 | ||||
-rw-r--r-- | device/bluetooth/test/mock_bluetooth_device.h | 3 |
6 files changed, 63 insertions, 37 deletions
diff --git a/device/bluetooth/bluetooth_device.h b/device/bluetooth/bluetooth_device.h index 90e420b..9b703f8 100644 --- a/device/bluetooth/bluetooth_device.h +++ b/device/bluetooth/bluetooth_device.h @@ -52,6 +52,19 @@ class BluetoothDevice { DEVICE_KEYBOARD_MOUSE_COMBO }; + // Possible errors passed back to an error callback function in case of a + // failed call to Connect(). + enum ConnectErrorCode { + ERROR_UNKNOWN, + ERROR_INPROGRESS, + ERROR_FAILED, + ERROR_CONNECT_FAILED, + ERROR_AUTH_FAILED, + ERROR_AUTH_CANCELED, + ERROR_AUTH_REJECTED, + ERROR_AUTH_TIMEOUT, + }; + // Interface for observing changes from bluetooth devices. class Observer { public: @@ -173,6 +186,11 @@ class BluetoothDevice { // is called, in the success case the callback is simply not called. typedef base::Callback<void()> ErrorCallback; + // The ConnectErrorCallback is used for methods that can fail with an error, + // passed back as an error code argument to this callback. + // In the success case this callback is not called. + typedef base::Callback<void(enum ConnectErrorCode)> ConnectErrorCallback; + // Returns the services (as BluetoothServiceRecord objects) that this device // provides. typedef ScopedVector<BluetoothServiceRecord> ServiceRecordList; @@ -224,7 +242,7 @@ class BluetoothDevice { // |callback| is called when the request is complete. virtual void Connect(PairingDelegate* pairing_delegate, const base::Closure& callback, - const ErrorCallback& error_callback) = 0; + const ConnectErrorCallback& error_callback) = 0; // Sends the PIN code |pincode| to the remote device during pairing. // diff --git a/device/bluetooth/bluetooth_device_chromeos.cc b/device/bluetooth/bluetooth_device_chromeos.cc index 2a09cac..45a35b4 100644 --- a/device/bluetooth/bluetooth_device_chromeos.cc +++ b/device/bluetooth/bluetooth_device_chromeos.cc @@ -110,9 +110,10 @@ bool BluetoothDeviceChromeOs::ExpectingConfirmation() const { return !confirmation_callback_.is_null(); } -void BluetoothDeviceChromeOs::Connect(PairingDelegate* pairing_delegate, - const base::Closure& callback, - const ErrorCallback& error_callback) { +void BluetoothDeviceChromeOs::Connect( + PairingDelegate* pairing_delegate, + const base::Closure& callback, + const ConnectErrorCallback& error_callback) { if (IsPaired() || IsBonded() || IsConnected()) { // Connection to already paired or connected device. ConnectApplications(callback, error_callback); @@ -122,11 +123,11 @@ void BluetoothDeviceChromeOs::Connect(PairingDelegate* pairing_delegate, DBusThreadManager::Get()->GetBluetoothAdapterClient()-> CreateDevice(adapter_->object_path_, address_, - base::Bind(&BluetoothDeviceChromeOs::ConnectCallback, + base::Bind(&BluetoothDeviceChromeOs::OnCreateDevice, weak_ptr_factory_.GetWeakPtr(), callback, error_callback), - base::Bind(&BluetoothDeviceChromeOs::ConnectErrorCallback, + base::Bind(&BluetoothDeviceChromeOs::OnCreateDeviceError, weak_ptr_factory_.GetWeakPtr(), error_callback)); } else { @@ -160,11 +161,11 @@ void BluetoothDeviceChromeOs::Connect(PairingDelegate* pairing_delegate, address_, agent_path, bluetooth_agent::kDisplayYesNoCapability, - base::Bind(&BluetoothDeviceChromeOs::ConnectCallback, + base::Bind(&BluetoothDeviceChromeOs::OnCreateDevice, weak_ptr_factory_.GetWeakPtr(), callback, error_callback), - base::Bind(&BluetoothDeviceChromeOs::ConnectErrorCallback, + base::Bind(&BluetoothDeviceChromeOs::OnCreateDeviceError, weak_ptr_factory_.GetWeakPtr(), error_callback)); } @@ -329,9 +330,9 @@ void BluetoothDeviceChromeOs::Update( } } -void BluetoothDeviceChromeOs::ConnectCallback( +void BluetoothDeviceChromeOs::OnCreateDevice( const base::Closure& callback, - const ErrorCallback& error_callback, + const ConnectErrorCallback& error_callback, const dbus::ObjectPath& device_path) { DVLOG(1) << "Connection successful: " << device_path.value(); if (object_path_.value().empty()) { @@ -354,19 +355,22 @@ void BluetoothDeviceChromeOs::ConnectCallback( base::Bind(&BluetoothDeviceChromeOs::OnSetTrusted, weak_ptr_factory_.GetWeakPtr(), callback, - error_callback)); + base::Bind(error_callback, + ERROR_UNKNOWN))); + // TODO(deymo): Replace ERROR_UNKNOWN with an appropriate new constant. // Connect application-layer protocols. ConnectApplications(callback, error_callback); } -void BluetoothDeviceChromeOs::ConnectErrorCallback( - const ErrorCallback& error_callback, +void BluetoothDeviceChromeOs::OnCreateDeviceError( + const ConnectErrorCallback& error_callback, const std::string& error_name, const std::string& error_message) { LOG(WARNING) << "Connection failed: " << address_ << ": " << error_name << ": " << error_message; - error_callback.Run(); + error_callback.Run(ERROR_UNKNOWN); + // TODO(deymo): Determine the right error code from error_name. } void BluetoothDeviceChromeOs::CollectServiceRecordsCallback( @@ -402,7 +406,7 @@ void BluetoothDeviceChromeOs::OnSetTrusted(const base::Closure& callback, void BluetoothDeviceChromeOs::ConnectApplications( const base::Closure& callback, - const ErrorCallback& error_callback) { + const ConnectErrorCallback& error_callback) { // Introspect the device object to determine supported applications. DBusThreadManager::Get()->GetIntrospectableClient()-> Introspect(bluetooth_device::kBluetoothDeviceServiceName, @@ -413,15 +417,17 @@ void BluetoothDeviceChromeOs::ConnectApplications( error_callback)); } -void BluetoothDeviceChromeOs::OnIntrospect(const base::Closure& callback, - const ErrorCallback& error_callback, - const std::string& service_name, - const dbus::ObjectPath& device_path, - const std::string& xml_data, - bool success) { +void BluetoothDeviceChromeOs::OnIntrospect( + const base::Closure& callback, + const ConnectErrorCallback& error_callback, + const std::string& service_name, + const dbus::ObjectPath& device_path, + const std::string& xml_data, + bool success) { if (!success) { LOG(WARNING) << "Failed to determine supported applications: " << address_; - error_callback.Run(); + error_callback.Run(ERROR_UNKNOWN); + // TODO(deymo): Replace ERROR_UNKNOWN with an appropriate new constant. return; } @@ -479,14 +485,15 @@ void BluetoothDeviceChromeOs::OnConnect(const base::Closure& callback, } void BluetoothDeviceChromeOs::OnConnectError( - const ErrorCallback& error_callback, + const ConnectErrorCallback& error_callback, const std::string& interface_name, const dbus::ObjectPath& device_path, const std::string& error_name, const std::string& error_message) { LOG(WARNING) << "Connection failed: " << address_ << ": " << interface_name << ": " << error_name << ": " << error_message; - error_callback.Run(); + error_callback.Run(ERROR_UNKNOWN); + // TODO(deymo): Determine the right error code from error_name. } void BluetoothDeviceChromeOs::DisconnectCallback( diff --git a/device/bluetooth/bluetooth_device_chromeos.h b/device/bluetooth/bluetooth_device_chromeos.h index 4b2d3b5..160a3ad 100644 --- a/device/bluetooth/bluetooth_device_chromeos.h +++ b/device/bluetooth/bluetooth_device_chromeos.h @@ -55,7 +55,7 @@ class BluetoothDeviceChromeOs virtual void Connect( device::BluetoothDevice::PairingDelegate* pairing_delegate, const base::Closure& callback, - const ErrorCallback& error_callback) OVERRIDE; + const ConnectErrorCallback& error_callback) OVERRIDE; virtual void SetPinCode(const std::string& pincode) OVERRIDE; virtual void SetPasskey(uint32 passkey) OVERRIDE; virtual void ConfirmPairing() OVERRIDE; @@ -103,17 +103,17 @@ class BluetoothDeviceChromeOs // CreatePairedDevice() succeeds, provides the new object path for the remote // device in |device_path|. |callback| and |error_callback| are the callbacks // provided to Connect(). - void ConnectCallback(const base::Closure& callback, - const ErrorCallback& error_callback, - const dbus::ObjectPath& device_path); + void OnCreateDevice(const base::Closure& callback, + const ConnectErrorCallback& error_callback, + const dbus::ObjectPath& device_path); // Called by BluetoothAdapterClient when a call to CreateDevice() or // CreatePairedDevice() fails with the error named |error_name| and // optional message |error_message|, |error_callback| is the callback // provided to Connect(). - void ConnectErrorCallback(const ErrorCallback& error_callback, - const std::string& error_name, - const std::string& error_message); + void OnCreateDeviceError(const ConnectErrorCallback& error_callback, + const std::string& error_name, + const std::string& error_message); // Called by BluetoothAdapterClient when a call to DiscoverServices() // completes. |callback| and |error_callback| are the callbacks provided to @@ -138,7 +138,7 @@ class BluetoothDeviceChromeOs // paired or previously connected. |error_callback| is called on failure. // Otherwise, |callback| is called when the request is complete. void ConnectApplications(const base::Closure& callback, - const ErrorCallback& error_callback); + const ConnectErrorCallback& error_callback); // Called by IntrospectableClient when a call to Introspect() completes. // |success| indicates whether or not the request succeeded, |callback| and @@ -146,7 +146,7 @@ class BluetoothDeviceChromeOs // |service_name| and |device_path| specify the remote object being // introspected and |xml_data| contains the XML-formatted protocol data. void OnIntrospect(const base::Closure& callback, - const ErrorCallback& error_callback, + const ConnectErrorCallback& error_callback, const std::string& service_name, const dbus::ObjectPath& device_path, const std::string& xml_data, bool success); @@ -164,7 +164,7 @@ class BluetoothDeviceChromeOs // |interface_name| specifies the interface being connected, // |device_path| the remote object path, // |error_name| the error name and |error_message| the optional message. - void OnConnectError(const ErrorCallback& error_callback, + void OnConnectError(const ConnectErrorCallback& error_callback, const std::string& interface_name, const dbus::ObjectPath& device_path, const std::string& error_name, diff --git a/device/bluetooth/bluetooth_device_win.cc b/device/bluetooth/bluetooth_device_win.cc index 5b6cd9c..14fe785 100644 --- a/device/bluetooth/bluetooth_device_win.cc +++ b/device/bluetooth/bluetooth_device_win.cc @@ -65,7 +65,7 @@ bool BluetoothDeviceWin::ExpectingConfirmation() const { void BluetoothDeviceWin::Connect( PairingDelegate* pairing_delegate, const base::Closure& callback, - const ErrorCallback& error_callback) { + const ConnectErrorCallback& error_callback) { NOTIMPLEMENTED(); } diff --git a/device/bluetooth/bluetooth_device_win.h b/device/bluetooth/bluetooth_device_win.h index ee2048b..3040fac 100644 --- a/device/bluetooth/bluetooth_device_win.h +++ b/device/bluetooth/bluetooth_device_win.h @@ -32,7 +32,7 @@ class BluetoothDeviceWin : public BluetoothDevice { virtual void Connect( PairingDelegate* pairing_delegate, const base::Closure& callback, - const ErrorCallback& error_callback) OVERRIDE; + const ConnectErrorCallback& error_callback) OVERRIDE; virtual void SetPinCode(const std::string& pincode) OVERRIDE; virtual void SetPasskey(uint32 passkey) OVERRIDE; virtual void ConfirmPairing() OVERRIDE; diff --git a/device/bluetooth/test/mock_bluetooth_device.h b/device/bluetooth/test/mock_bluetooth_device.h index e917a30..56ca4c2 100644 --- a/device/bluetooth/test/mock_bluetooth_device.h +++ b/device/bluetooth/test/mock_bluetooth_device.h @@ -46,7 +46,8 @@ class MockBluetoothDevice : public BluetoothDevice { MOCK_METHOD3(Connect, void(BluetoothDevice::PairingDelegate* pairnig_delegate, const base::Closure& callback, - const BluetoothDevice::ErrorCallback& error_callback)); + const BluetoothDevice::ConnectErrorCallback& + error_callback)); MOCK_METHOD1(SetPinCode, void(const std::string&)); MOCK_METHOD1(SetPasskey, void(uint32)); MOCK_METHOD0(ConfirmPairing, void()); |