diff options
Diffstat (limited to 'device')
-rw-r--r-- | device/bluetooth/bluetooth_device.h | 6 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_device_chromeos.cc | 48 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_device_chromeos.h | 5 |
3 files changed, 45 insertions, 14 deletions
diff --git a/device/bluetooth/bluetooth_device.h b/device/bluetooth/bluetooth_device.h index 893b925..319b549 100644 --- a/device/bluetooth/bluetooth_device.h +++ b/device/bluetooth/bluetooth_device.h @@ -240,6 +240,9 @@ class BluetoothDevice { // // If the request fails, |error_callback| will be called; otherwise, // |callback| is called when the request is complete. + // After calling Connect, CancelPairing should be called to cancel the pairing + // process and release |pairing_delegate_| if user cancels the pairing and + // closes the pairing UI. virtual void Connect(PairingDelegate* pairing_delegate, const base::Closure& callback, const ConnectErrorCallback& error_callback) = 0; @@ -264,7 +267,8 @@ class BluetoothDevice { // Rejects a pairing or connection request from a remote device. virtual void RejectPairing() = 0; - // Cancels a pairing or connection attempt to a remote device. + // Cancels a pairing or connection attempt to a remote device or release + // |pairing_deleage_| and |agent_|. virtual void CancelPairing() = 0; // Disconnects the device, terminating the low-level ACL connection diff --git a/device/bluetooth/bluetooth_device_chromeos.cc b/device/bluetooth/bluetooth_device_chromeos.cc index b452ff0..3b044b5 100644 --- a/device/bluetooth/bluetooth_device_chromeos.cc +++ b/device/bluetooth/bluetooth_device_chromeos.cc @@ -215,20 +215,35 @@ void BluetoothDeviceChromeOs::RejectPairing() { } void BluetoothDeviceChromeOs::CancelPairing() { - if (!agent_.get()) - return; - - if (!pincode_callback_.is_null()) { - pincode_callback_.Run(CANCELLED, ""); - pincode_callback_.Reset(); - } - if (!passkey_callback_.is_null()) { - passkey_callback_.Run(CANCELLED, 0); - passkey_callback_.Reset(); + bool have_callback = false; + if (agent_.get()) { + if (!pincode_callback_.is_null()) { + pincode_callback_.Run(CANCELLED, ""); + pincode_callback_.Reset(); + have_callback = true; + } + if (!passkey_callback_.is_null()) { + passkey_callback_.Run(CANCELLED, 0); + passkey_callback_.Reset(); + have_callback = true; + } + if (!confirmation_callback_.is_null()) { + confirmation_callback_.Run(CANCELLED); + confirmation_callback_.Reset(); + have_callback = true; + } } - if (!confirmation_callback_.is_null()) { - confirmation_callback_.Run(CANCELLED); - confirmation_callback_.Reset(); + + if (!have_callback) { + // User cancels the pairing process. + DBusThreadManager::Get()->GetBluetoothAdapterClient()->CancelDeviceCreation( + adapter_->object_path_, + address_, + base::Bind(&BluetoothDeviceChromeOs::OnCancelDeviceCreation, + weak_ptr_factory_.GetWeakPtr())); + + pairing_delegate_ = NULL; + agent_.reset(); } } @@ -558,6 +573,13 @@ void BluetoothDeviceChromeOs::ForgetCallback( } } +void BluetoothDeviceChromeOs::OnCancelDeviceCreation( + const dbus::ObjectPath& adapter_path, + bool success) { + if (!success) + LOG(WARNING) << "CancelDeviceCreation failed: " << address_; +} + void BluetoothDeviceChromeOs::SearchServicesForNameErrorCallback( const ProvidesServiceCallback& callback) { callback.Run(false); diff --git a/device/bluetooth/bluetooth_device_chromeos.h b/device/bluetooth/bluetooth_device_chromeos.h index 160a3ad..e0dfda0 100644 --- a/device/bluetooth/bluetooth_device_chromeos.h +++ b/device/bluetooth/bluetooth_device_chromeos.h @@ -185,6 +185,11 @@ class BluetoothDeviceChromeOs void ForgetCallback(const ErrorCallback& error_callback, const dbus::ObjectPath& adapter_path, bool success); + // Called by BluetoothAdapterClient when a call to CancelDeviceCreation() + // completes, |success| indicates whether or not the request succeeded. + void OnCancelDeviceCreation(const dbus::ObjectPath& adapter_path, + bool success); + // Called if the call to GetServiceRecords from ProvidesServiceWithName fails. void SearchServicesForNameErrorCallback( const ProvidesServiceCallback& callback); |