diff options
author | keybuk@chromium.org <keybuk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-20 00:10:32 +0000 |
---|---|---|
committer | keybuk@chromium.org <keybuk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-20 00:10:32 +0000 |
commit | 8649d108a270cdf6d2353bc0979fe501184348b6 (patch) | |
tree | 62f08f8bab7eb25d41c2405057866733155dfb13 /device | |
parent | d1dc811965f205ed5988a4470c80f41c0637a89b (diff) | |
download | chromium_src-8649d108a270cdf6d2353bc0979fe501184348b6.zip chromium_src-8649d108a270cdf6d2353bc0979fe501184348b6.tar.gz chromium_src-8649d108a270cdf6d2353bc0979fe501184348b6.tar.bz2 |
Bluetooth: call DeviceChanged observer method on IsConnecting() change
BUG=231985
TEST=device_unittests
Review URL: https://codereview.chromium.org/14199010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@195345 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'device')
4 files changed, 63 insertions, 42 deletions
diff --git a/device/bluetooth/bluetooth_adapter_experimental_chromeos.cc b/device/bluetooth/bluetooth_adapter_experimental_chromeos.cc index 2af9376..5143dd1 100644 --- a/device/bluetooth/bluetooth_adapter_experimental_chromeos.cc +++ b/device/bluetooth/bluetooth_adapter_experimental_chromeos.cc @@ -244,11 +244,8 @@ void BluetoothAdapterExperimentalChromeOS::DevicePropertyChanged( property_name == properties->alias.name() || property_name == properties->paired.name() || property_name == properties->connected.name() || - property_name == properties->uuids.name()) { - FOR_EACH_OBSERVER( - BluetoothAdapter::Observer, observers_, - DeviceChanged(this, device_chromeos)); - } + property_name == properties->uuids.name()) + NotifyDeviceChanged(device_chromeos); } BluetoothDeviceExperimentalChromeOS* @@ -345,6 +342,14 @@ void BluetoothAdapterExperimentalChromeOS::PresentChanged(bool present) { AdapterPresentChanged(this, present)); } +void BluetoothAdapterExperimentalChromeOS::NotifyDeviceChanged( + BluetoothDeviceExperimentalChromeOS* device) { + DCHECK(device->adapter_ == this); + + FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, + DeviceChanged(this, device)); +} + void BluetoothAdapterExperimentalChromeOS::OnSetPowered( const base::Closure& callback, const ErrorCallback& error_callback, diff --git a/device/bluetooth/bluetooth_adapter_experimental_chromeos.h b/device/bluetooth/bluetooth_adapter_experimental_chromeos.h index 8471b0f..b11007d 100644 --- a/device/bluetooth/bluetooth_adapter_experimental_chromeos.h +++ b/device/bluetooth/bluetooth_adapter_experimental_chromeos.h @@ -98,6 +98,10 @@ class BluetoothAdapterExperimentalChromeOS void DiscoveringChanged(bool discovering); void PresentChanged(bool present); + // Announce to observers a change in device state that is not reflected by + // its D-Bus properties. + void NotifyDeviceChanged(BluetoothDeviceExperimentalChromeOS* device); + // Called by dbus:: on completion of the powered property change. void OnSetPowered(const base::Closure& callback, const ErrorCallback& error_callback, diff --git a/device/bluetooth/bluetooth_device_experimental_chromeos.cc b/device/bluetooth/bluetooth_device_experimental_chromeos.cc index 85e84d3..0797983 100644 --- a/device/bluetooth/bluetooth_device_experimental_chromeos.cc +++ b/device/bluetooth/bluetooth_device_experimental_chromeos.cc @@ -138,7 +138,9 @@ void BluetoothDeviceExperimentalChromeOS::Connect( BluetoothDevice::PairingDelegate* pairing_delegate, const base::Closure& callback, const ConnectErrorCallback& error_callback) { - ++num_connecting_calls_; + if (num_connecting_calls_++ == 0) + adapter_->NotifyDeviceChanged(this); + VLOG(1) << object_path_.value() << ": Connecting, " << num_connecting_calls_ << " in progress"; @@ -399,7 +401,9 @@ void BluetoothDeviceExperimentalChromeOS::ConnectInternal( void BluetoothDeviceExperimentalChromeOS::OnConnect( const base::Closure& callback) { - --num_connecting_calls_; + if (--num_connecting_calls_ == 0) + adapter_->NotifyDeviceChanged(this); + DCHECK(num_connecting_calls_ >= 0); VLOG(1) << object_path_.value() << ": Connected, " << num_connecting_calls_ << " still in progress"; @@ -413,7 +417,9 @@ void BluetoothDeviceExperimentalChromeOS::OnConnectError( const ConnectErrorCallback& error_callback, const std::string& error_name, const std::string& error_message) { - --num_connecting_calls_; + if (--num_connecting_calls_ == 0) + adapter_->NotifyDeviceChanged(this); + DCHECK(num_connecting_calls_ >= 0); LOG(WARNING) << object_path_.value() << ": Failed to connect device: " << error_name << ": " << error_message; @@ -454,7 +460,9 @@ void BluetoothDeviceExperimentalChromeOS::OnRegisterAgentError( const ConnectErrorCallback& error_callback, const std::string& error_name, const std::string& error_message) { - --num_connecting_calls_; + if (--num_connecting_calls_ == 0) + adapter_->NotifyDeviceChanged(this); + DCHECK(num_connecting_calls_ >= 0); LOG(WARNING) << object_path_.value() << ": Failed to register agent: " << error_name << ": " << error_message; @@ -484,7 +492,9 @@ void BluetoothDeviceExperimentalChromeOS::OnPairError( const ConnectErrorCallback& error_callback, const std::string& error_name, const std::string& error_message) { - --num_connecting_calls_; + if (--num_connecting_calls_ == 0) + adapter_->NotifyDeviceChanged(this); + DCHECK(num_connecting_calls_ >= 0); LOG(WARNING) << object_path_.value() << ": Failed to pair device: " << error_name << ": " << error_message; diff --git a/device/bluetooth/bluetooth_experimental_chromeos_unittest.cc b/device/bluetooth/bluetooth_experimental_chromeos_unittest.cc index ed929df..4fc8e67 100644 --- a/device/bluetooth/bluetooth_experimental_chromeos_unittest.cc +++ b/device/bluetooth/bluetooth_experimental_chromeos_unittest.cc @@ -967,7 +967,7 @@ TEST_F(BluetoothExperimentalChromeOSTest, ConnectPairedDevice) { EXPECT_EQ(1, callback_count_); EXPECT_EQ(0, error_callback_count_); - EXPECT_EQ(1, observer.device_changed_count_); + EXPECT_EQ(3, observer.device_changed_count_); EXPECT_EQ(device, observer.last_device_); EXPECT_TRUE(device->IsConnected()); @@ -998,7 +998,7 @@ TEST_F(BluetoothExperimentalChromeOSTest, ConnectUnpairableDevice) { EXPECT_EQ(1, callback_count_); EXPECT_EQ(0, error_callback_count_); - EXPECT_EQ(1, observer.device_changed_count_); + EXPECT_EQ(3, observer.device_changed_count_); EXPECT_EQ(device, observer.last_device_); EXPECT_TRUE(device->IsConnected()); @@ -1047,7 +1047,8 @@ TEST_F(BluetoothExperimentalChromeOSTest, ConnectConnectedDevice) { EXPECT_EQ(1, callback_count_); EXPECT_EQ(0, error_callback_count_); - EXPECT_EQ(0, observer.device_changed_count_); + // Connecting will trigger true and false. + EXPECT_EQ(2, observer.device_changed_count_); EXPECT_TRUE(device->IsConnected()); EXPECT_FALSE(device->IsConnecting()); @@ -1078,7 +1079,7 @@ TEST_F(BluetoothExperimentalChromeOSTest, ConnectDeviceFails) { EXPECT_EQ(1, error_callback_count_); EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_); - EXPECT_EQ(0, observer.device_changed_count_); + EXPECT_EQ(2, observer.device_changed_count_); EXPECT_FALSE(device->IsConnected()); EXPECT_FALSE(device->IsConnecting()); @@ -1187,8 +1188,8 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairAppleMouse) { EXPECT_EQ(1, callback_count_); EXPECT_EQ(0, error_callback_count_); - // One change for connected, and one for paired. - EXPECT_EQ(2, observer.device_changed_count_); + // Two changes for connecting, one change for connected, and one for paired. + EXPECT_EQ(4, observer.device_changed_count_); EXPECT_EQ(device, observer.last_device_); EXPECT_TRUE(device->IsConnected()); @@ -1242,8 +1243,8 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairAppleKeyboard) { EXPECT_EQ(1, callback_count_); EXPECT_EQ(0, error_callback_count_); - // One change for connected, and one for paired. - EXPECT_EQ(2, observer.device_changed_count_); + // Two changes for connecting, one change for connected, and one for paired. + EXPECT_EQ(4, observer.device_changed_count_); EXPECT_EQ(device, observer.last_device_); EXPECT_TRUE(device->IsConnected()); @@ -1315,8 +1316,8 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairMotorolaKeyboard) { EXPECT_EQ(1, callback_count_); EXPECT_EQ(0, error_callback_count_); - // One change for connected, and one for paired. - EXPECT_EQ(2, observer.device_changed_count_); + // Two changes for connecting, one change for connected, and one for paired. + EXPECT_EQ(4, observer.device_changed_count_); EXPECT_EQ(device, observer.last_device_); EXPECT_TRUE(device->IsConnected()); @@ -1369,8 +1370,8 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairSonyHeadphones) { EXPECT_EQ(1, callback_count_); EXPECT_EQ(0, error_callback_count_); - // One change for connected, and one for paired. - EXPECT_EQ(2, observer.device_changed_count_); + // Two changes for connecting, one change for connected, and one for paired. + EXPECT_EQ(4, observer.device_changed_count_); EXPECT_EQ(device, observer.last_device_); EXPECT_TRUE(device->IsConnected()); @@ -1425,8 +1426,8 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairPhone) { EXPECT_EQ(1, callback_count_); EXPECT_EQ(0, error_callback_count_); - // One change for connected, and one for paired. - EXPECT_EQ(2, observer.device_changed_count_); + // Two changes for connecting, one change for connected, and one for paired. + EXPECT_EQ(4, observer.device_changed_count_); EXPECT_EQ(device, observer.last_device_); EXPECT_TRUE(device->IsConnected()); @@ -1482,8 +1483,8 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairWeirdDevice) { EXPECT_EQ(1, callback_count_); EXPECT_EQ(0, error_callback_count_); - // One change for connected, and one for paired. - EXPECT_EQ(2, observer.device_changed_count_); + // Two changes for connecting, one change for connected, and one for paired. + EXPECT_EQ(4, observer.device_changed_count_); EXPECT_EQ(device, observer.last_device_); EXPECT_TRUE(device->IsConnected()); @@ -1580,8 +1581,9 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairingFailsAtConnection) { EXPECT_EQ(1, error_callback_count_); EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_); - // Just one change for paired, the device should not be connected. - EXPECT_EQ(1, observer.device_changed_count_); + // Two changes for connecting, and one for paired; the device should not be + // connected. + EXPECT_EQ(3, observer.device_changed_count_); EXPECT_EQ(device, observer.last_device_); EXPECT_FALSE(device->IsConnected()); @@ -1637,8 +1639,8 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairingRejectedAtPinCode) { EXPECT_EQ(1, error_callback_count_); EXPECT_EQ(BluetoothDevice::ERROR_AUTH_REJECTED, last_connect_error_); - // Should be no changes. - EXPECT_EQ(0, observer.device_changed_count_); + // Should be no changes except connecting going true and false. + EXPECT_EQ(2, observer.device_changed_count_); EXPECT_FALSE(device->IsConnected()); EXPECT_FALSE(device->IsConnecting()); EXPECT_FALSE(device->IsPaired()); @@ -1684,8 +1686,8 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairingCancelledAtPinCode) { EXPECT_EQ(1, error_callback_count_); EXPECT_EQ(BluetoothDevice::ERROR_AUTH_CANCELED, last_connect_error_); - // Should be no changes. - EXPECT_EQ(0, observer.device_changed_count_); + // Should be no changes except connecting going true and false. + EXPECT_EQ(2, observer.device_changed_count_); EXPECT_FALSE(device->IsConnected()); EXPECT_FALSE(device->IsConnecting()); EXPECT_FALSE(device->IsPaired()); @@ -1731,8 +1733,8 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairingRejectedAtPasskey) { EXPECT_EQ(1, error_callback_count_); EXPECT_EQ(BluetoothDevice::ERROR_AUTH_REJECTED, last_connect_error_); - // Should be no changes. - EXPECT_EQ(0, observer.device_changed_count_); + // Should be no changes except connecting going true and false. + EXPECT_EQ(2, observer.device_changed_count_); EXPECT_FALSE(device->IsConnected()); EXPECT_FALSE(device->IsConnecting()); EXPECT_FALSE(device->IsPaired()); @@ -1778,8 +1780,8 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairingCancelledAtPasskey) { EXPECT_EQ(1, error_callback_count_); EXPECT_EQ(BluetoothDevice::ERROR_AUTH_CANCELED, last_connect_error_); - // Should be no changes. - EXPECT_EQ(0, observer.device_changed_count_); + // Should be no changes except connecting going true and false. + EXPECT_EQ(2, observer.device_changed_count_); EXPECT_FALSE(device->IsConnected()); EXPECT_FALSE(device->IsConnecting()); EXPECT_FALSE(device->IsPaired()); @@ -1825,8 +1827,8 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairingRejectedAtConfirmation) { EXPECT_EQ(1, error_callback_count_); EXPECT_EQ(BluetoothDevice::ERROR_AUTH_REJECTED, last_connect_error_); - // Should be no changes. - EXPECT_EQ(0, observer.device_changed_count_); + // Should be no changes except connecting going true and false. + EXPECT_EQ(2, observer.device_changed_count_); EXPECT_FALSE(device->IsConnected()); EXPECT_FALSE(device->IsConnecting()); EXPECT_FALSE(device->IsPaired()); @@ -1872,8 +1874,8 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairingCancelledAtConfirmation) { EXPECT_EQ(1, error_callback_count_); EXPECT_EQ(BluetoothDevice::ERROR_AUTH_CANCELED, last_connect_error_); - // Should be no changes. - EXPECT_EQ(0, observer.device_changed_count_); + // Should be no changes except connecting going true and false. + EXPECT_EQ(2, observer.device_changed_count_); EXPECT_FALSE(device->IsConnected()); EXPECT_FALSE(device->IsConnecting()); EXPECT_FALSE(device->IsPaired()); @@ -1918,8 +1920,8 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairingCancelledInFlight) { EXPECT_EQ(1, error_callback_count_); EXPECT_EQ(BluetoothDevice::ERROR_AUTH_CANCELED, last_connect_error_); - // Should be no changes. - EXPECT_EQ(0, observer.device_changed_count_); + // Should be no changes except connecting going true and false. + EXPECT_EQ(2, observer.device_changed_count_); EXPECT_FALSE(device->IsConnected()); EXPECT_FALSE(device->IsConnecting()); EXPECT_FALSE(device->IsPaired()); |