diff options
author | jennyz@chromium.org <jennyz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-23 01:53:18 +0000 |
---|---|---|
committer | jennyz@chromium.org <jennyz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-23 01:53:18 +0000 |
commit | 4379bcd1f804f21e349614fbb385bdbd406eecc4 (patch) | |
tree | 57b98b64ecc98ae34a6c240a46830e7c17bf9aaa /device | |
parent | bef20d54ddb1f93e665ec7402f8d5731794c3f56 (diff) | |
download | chromium_src-4379bcd1f804f21e349614fbb385bdbd406eecc4.zip chromium_src-4379bcd1f804f21e349614fbb385bdbd406eecc4.tar.gz chromium_src-4379bcd1f804f21e349614fbb385bdbd406eecc4.tar.bz2 |
Fix bluetooth crashing issue, which happens due the pairing_delegate goes away, and BluetoothDeviceCallback not aware of this and keep calling it in the BT event callbacks. Cancel BT pairing event if user close the pairing dialog, so that BT device will cancel pairing, instead of waiting for timeout.
BUG=170540
Review URL: https://codereview.chromium.org/11926021
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@178200 0039d316-1c4b-4281-b951-d872f2087c98
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); |