diff options
author | jamuraa <jamuraa@chromium.org> | 2015-02-09 13:13:47 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-02-09 21:14:52 +0000 |
commit | 089a7dade5bfd6858fd88851d2171be816854845 (patch) | |
tree | 104ea90ae8a1f0452cccf5c47c2208e6801a4b08 /device | |
parent | d7798e13906ebb1b531043738446eb378da369b1 (diff) | |
download | chromium_src-089a7dade5bfd6858fd88851d2171be816854845.zip chromium_src-089a7dade5bfd6858fd88851d2171be816854845.tar.gz chromium_src-089a7dade5bfd6858fd88851d2171be816854845.tar.bz2 |
Fix crash on second failed connect to a paired device
When failing to connect to a previously-paired device, the profile would
not be cleared. This sets adapter_ in RegisterProfile() so that it will
be set correctly for profile release later.
Also includes unit tests, adding a paired but non-connectable device.
BUG=455868
Review URL: https://codereview.chromium.org/910433002
Cr-Commit-Position: refs/heads/master@{#315394}
Diffstat (limited to 'device')
-rw-r--r-- | device/bluetooth/bluetooth_adapter_chromeos.cc | 3 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_chromeos_unittest.cc | 30 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_socket_chromeos.cc | 9 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_socket_chromeos_unittest.cc | 30 |
4 files changed, 52 insertions, 20 deletions
diff --git a/device/bluetooth/bluetooth_adapter_chromeos.cc b/device/bluetooth/bluetooth_adapter_chromeos.cc index c7f94e9..e6c6283 100644 --- a/device/bluetooth/bluetooth_adapter_chromeos.cc +++ b/device/bluetooth/bluetooth_adapter_chromeos.cc @@ -1012,8 +1012,7 @@ void BluetoothAdapterChromeOS::OnRegisterProfileError( << ": Failed to register profile: " << error_name << ": " << error_message; error_callback.Run(error_message); - delete profiles_[uuid]; - profiles_.erase(uuid); + ReleaseProfile(uuid); } void BluetoothAdapterChromeOS::OnSetDiscoverable( diff --git a/device/bluetooth/bluetooth_chromeos_unittest.cc b/device/bluetooth/bluetooth_chromeos_unittest.cc index 370b3b7..6ce931b 100644 --- a/device/bluetooth/bluetooth_chromeos_unittest.cc +++ b/device/bluetooth/bluetooth_chromeos_unittest.cc @@ -414,9 +414,11 @@ TEST_F(BluetoothChromeOSTest, AlreadyPresent) { // There should be a device BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); - EXPECT_EQ(1U, devices.size()); + EXPECT_EQ(2U, devices.size()); EXPECT_EQ(FakeBluetoothDeviceClient::kPairedDeviceAddress, devices[0]->GetAddress()); + EXPECT_EQ(FakeBluetoothDeviceClient::kPairedUnconnectableDeviceAddress, + devices[1]->GetAddress()); } TEST_F(BluetoothChromeOSTest, BecomePresent) { @@ -436,8 +438,8 @@ TEST_F(BluetoothChromeOSTest, BecomePresent) { EXPECT_TRUE(adapter_->IsPresent()); // We should have had a device announced. - EXPECT_EQ(1, observer.device_added_count_); - EXPECT_EQ(FakeBluetoothDeviceClient::kPairedDeviceAddress, + EXPECT_EQ(2, observer.device_added_count_); + EXPECT_EQ(FakeBluetoothDeviceClient::kPairedUnconnectableDeviceAddress, observer.last_device_address_); // Other callbacks shouldn't be called if the values are false. @@ -463,8 +465,8 @@ TEST_F(BluetoothChromeOSTest, BecomeNotPresent) { EXPECT_FALSE(adapter_->IsPresent()); // We should have had a device removed. - EXPECT_EQ(1, observer.device_removed_count_); - EXPECT_EQ(FakeBluetoothDeviceClient::kPairedDeviceAddress, + EXPECT_EQ(2, observer.device_removed_count_); + EXPECT_EQ(FakeBluetoothDeviceClient::kPairedUnconnectableDeviceAddress, observer.last_device_address_); // Other callbacks shouldn't be called since the values are false. @@ -500,8 +502,8 @@ TEST_F(BluetoothChromeOSTest, SecondAdapter) { EXPECT_FALSE(adapter_->IsPresent()); // We should have had a device removed. - EXPECT_EQ(1, observer.device_removed_count_); - EXPECT_EQ(FakeBluetoothDeviceClient::kPairedDeviceAddress, + EXPECT_EQ(2, observer.device_removed_count_); + EXPECT_EQ(FakeBluetoothDeviceClient::kPairedUnconnectableDeviceAddress, observer.last_device_address_); // Other callbacks shouldn't be called since the values are false. @@ -1534,7 +1536,7 @@ TEST_F(BluetoothChromeOSTest, DeviceProperties) { GetAdapter(); BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); - ASSERT_EQ(1U, devices.size()); + ASSERT_EQ(2U, devices.size()); ASSERT_EQ(FakeBluetoothDeviceClient::kPairedDeviceAddress, devices[0]->GetAddress()); @@ -1566,7 +1568,7 @@ TEST_F(BluetoothChromeOSTest, DeviceClassChanged) { GetAdapter(); BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); - ASSERT_EQ(1U, devices.size()); + ASSERT_EQ(2U, devices.size()); ASSERT_EQ(FakeBluetoothDeviceClient::kPairedDeviceAddress, devices[0]->GetAddress()); ASSERT_EQ(BluetoothDevice::DEVICE_COMPUTER, devices[0]->GetDeviceType()); @@ -1592,7 +1594,7 @@ TEST_F(BluetoothChromeOSTest, DeviceNameChanged) { GetAdapter(); BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); - ASSERT_EQ(1U, devices.size()); + ASSERT_EQ(2U, devices.size()); ASSERT_EQ(FakeBluetoothDeviceClient::kPairedDeviceAddress, devices[0]->GetAddress()); ASSERT_EQ(base::UTF8ToUTF16(FakeBluetoothDeviceClient::kPairedDeviceName), @@ -1620,7 +1622,7 @@ TEST_F(BluetoothChromeOSTest, DeviceUuidsChanged) { GetAdapter(); BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); - ASSERT_EQ(1U, devices.size()); + ASSERT_EQ(2U, devices.size()); ASSERT_EQ(FakeBluetoothDeviceClient::kPairedDeviceAddress, devices[0]->GetAddress()); @@ -1663,7 +1665,7 @@ TEST_F(BluetoothChromeOSTest, ForgetDevice) { GetAdapter(); BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); - ASSERT_EQ(1U, devices.size()); + ASSERT_EQ(2U, devices.size()); ASSERT_EQ(FakeBluetoothDeviceClient::kPairedDeviceAddress, devices[0]->GetAddress()); @@ -1683,7 +1685,7 @@ TEST_F(BluetoothChromeOSTest, ForgetDevice) { // GetDevices shouldn't return the device either. devices = adapter_->GetDevices(); - ASSERT_EQ(0U, devices.size()); + ASSERT_EQ(1U, devices.size()); } TEST_F(BluetoothChromeOSTest, ForgetUnpairedDevice) { @@ -3342,7 +3344,7 @@ TEST_F(BluetoothChromeOSTest, Shutdown) { EXPECT_TRUE(adapter_->IsPowered()); EXPECT_TRUE(adapter_->IsDiscoverable()); EXPECT_TRUE(adapter_->IsDiscovering()); - EXPECT_EQ(1U, adapter_->GetDevices().size()); + EXPECT_EQ(2U, adapter_->GetDevices().size()); EXPECT_NE(nullptr, adapter_->GetDevice( FakeBluetoothDeviceClient::kPairedDeviceAddress)); EXPECT_NE(dbus::ObjectPath(""), static_cast<BluetoothAdapterChromeOS*>( diff --git a/device/bluetooth/bluetooth_socket_chromeos.cc b/device/bluetooth/bluetooth_socket_chromeos.cc index b2958f2..3026113 100644 --- a/device/bluetooth/bluetooth_socket_chromeos.cc +++ b/device/bluetooth/bluetooth_socket_chromeos.cc @@ -128,8 +128,7 @@ void BluetoothSocketChromeOS::Listen( return; } - adapter_ = adapter; - adapter_->AddObserver(this); + adapter->AddObserver(this); uuid_ = uuid; options_.reset(new BluetoothProfileManagerClient::Options()); @@ -149,7 +148,7 @@ void BluetoothSocketChromeOS::Listen( NOTREACHED(); } - RegisterProfile(static_cast<BluetoothAdapterChromeOS*>(adapter_.get()), + RegisterProfile(static_cast<BluetoothAdapterChromeOS*>(adapter.get()), success_callback, error_callback); } @@ -222,10 +221,12 @@ void BluetoothSocketChromeOS::RegisterProfile( DCHECK(!profile_); DCHECK(adapter); + adapter_ = adapter; + // If the adapter is not present, this is a listening socket and the // adapter isn't running yet. Report success and carry on; // the profile will be registered when the daemon becomes available. - if (!adapter->IsPresent()) { + if (!adapter_->IsPresent()) { VLOG(1) << uuid_.canonical_value() << " on " << device_path_.value() << ": Delaying profile registration."; base::MessageLoop::current()->PostTask(FROM_HERE, success_callback); diff --git a/device/bluetooth/bluetooth_socket_chromeos_unittest.cc b/device/bluetooth/bluetooth_socket_chromeos_unittest.cc index 79d43ae..8381cdd 100644 --- a/device/bluetooth/bluetooth_socket_chromeos_unittest.cc +++ b/device/bluetooth/bluetooth_socket_chromeos_unittest.cc @@ -528,4 +528,34 @@ TEST_F(BluetoothSocketChromeOSTest, ListenAcrossAdapterRestart) { EXPECT_EQ(1U, success_callback_count_); } +TEST_F(BluetoothSocketChromeOSTest, PairedConnectFails) { + BluetoothDevice* device = adapter_->GetDevice( + FakeBluetoothDeviceClient::kPairedUnconnectableDeviceAddress); + ASSERT_TRUE(device != NULL); + + device->ConnectToService( + BluetoothUUID(FakeBluetoothProfileManagerClient::kRfcommUuid), + base::Bind(&BluetoothSocketChromeOSTest::ConnectToServiceSuccessCallback, + base::Unretained(this)), + base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, + base::Unretained(this))); + message_loop_.Run(); + + EXPECT_EQ(0U, success_callback_count_); + EXPECT_EQ(1U, error_callback_count_); + EXPECT_TRUE(last_socket_.get() == NULL); + + device->ConnectToService( + BluetoothUUID(FakeBluetoothProfileManagerClient::kRfcommUuid), + base::Bind(&BluetoothSocketChromeOSTest::ConnectToServiceSuccessCallback, + base::Unretained(this)), + base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, + base::Unretained(this))); + message_loop_.Run(); + + EXPECT_EQ(0U, success_callback_count_); + EXPECT_EQ(2U, error_callback_count_); + EXPECT_TRUE(last_socket_.get() == NULL); +} + } // namespace chromeos |