Commit 8649d108 authored by keybuk@chromium.org's avatar keybuk@chromium.org

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
parent d1dc8119
...@@ -244,11 +244,8 @@ void BluetoothAdapterExperimentalChromeOS::DevicePropertyChanged( ...@@ -244,11 +244,8 @@ void BluetoothAdapterExperimentalChromeOS::DevicePropertyChanged(
property_name == properties->alias.name() || property_name == properties->alias.name() ||
property_name == properties->paired.name() || property_name == properties->paired.name() ||
property_name == properties->connected.name() || property_name == properties->connected.name() ||
property_name == properties->uuids.name()) { property_name == properties->uuids.name())
FOR_EACH_OBSERVER( NotifyDeviceChanged(device_chromeos);
BluetoothAdapter::Observer, observers_,
DeviceChanged(this, device_chromeos));
}
} }
BluetoothDeviceExperimentalChromeOS* BluetoothDeviceExperimentalChromeOS*
...@@ -345,6 +342,14 @@ void BluetoothAdapterExperimentalChromeOS::PresentChanged(bool present) { ...@@ -345,6 +342,14 @@ void BluetoothAdapterExperimentalChromeOS::PresentChanged(bool present) {
AdapterPresentChanged(this, 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( void BluetoothAdapterExperimentalChromeOS::OnSetPowered(
const base::Closure& callback, const base::Closure& callback,
const ErrorCallback& error_callback, const ErrorCallback& error_callback,
......
...@@ -98,6 +98,10 @@ class BluetoothAdapterExperimentalChromeOS ...@@ -98,6 +98,10 @@ class BluetoothAdapterExperimentalChromeOS
void DiscoveringChanged(bool discovering); void DiscoveringChanged(bool discovering);
void PresentChanged(bool present); 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. // Called by dbus:: on completion of the powered property change.
void OnSetPowered(const base::Closure& callback, void OnSetPowered(const base::Closure& callback,
const ErrorCallback& error_callback, const ErrorCallback& error_callback,
......
...@@ -138,7 +138,9 @@ void BluetoothDeviceExperimentalChromeOS::Connect( ...@@ -138,7 +138,9 @@ void BluetoothDeviceExperimentalChromeOS::Connect(
BluetoothDevice::PairingDelegate* pairing_delegate, BluetoothDevice::PairingDelegate* pairing_delegate,
const base::Closure& callback, const base::Closure& callback,
const ConnectErrorCallback& error_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_ VLOG(1) << object_path_.value() << ": Connecting, " << num_connecting_calls_
<< " in progress"; << " in progress";
...@@ -399,7 +401,9 @@ void BluetoothDeviceExperimentalChromeOS::ConnectInternal( ...@@ -399,7 +401,9 @@ void BluetoothDeviceExperimentalChromeOS::ConnectInternal(
void BluetoothDeviceExperimentalChromeOS::OnConnect( void BluetoothDeviceExperimentalChromeOS::OnConnect(
const base::Closure& callback) { const base::Closure& callback) {
--num_connecting_calls_; if (--num_connecting_calls_ == 0)
adapter_->NotifyDeviceChanged(this);
DCHECK(num_connecting_calls_ >= 0); DCHECK(num_connecting_calls_ >= 0);
VLOG(1) << object_path_.value() << ": Connected, " << num_connecting_calls_ VLOG(1) << object_path_.value() << ": Connected, " << num_connecting_calls_
<< " still in progress"; << " still in progress";
...@@ -413,7 +417,9 @@ void BluetoothDeviceExperimentalChromeOS::OnConnectError( ...@@ -413,7 +417,9 @@ void BluetoothDeviceExperimentalChromeOS::OnConnectError(
const ConnectErrorCallback& error_callback, const ConnectErrorCallback& error_callback,
const std::string& error_name, const std::string& error_name,
const std::string& error_message) { const std::string& error_message) {
--num_connecting_calls_; if (--num_connecting_calls_ == 0)
adapter_->NotifyDeviceChanged(this);
DCHECK(num_connecting_calls_ >= 0); DCHECK(num_connecting_calls_ >= 0);
LOG(WARNING) << object_path_.value() << ": Failed to connect device: " LOG(WARNING) << object_path_.value() << ": Failed to connect device: "
<< error_name << ": " << error_message; << error_name << ": " << error_message;
...@@ -454,7 +460,9 @@ void BluetoothDeviceExperimentalChromeOS::OnRegisterAgentError( ...@@ -454,7 +460,9 @@ void BluetoothDeviceExperimentalChromeOS::OnRegisterAgentError(
const ConnectErrorCallback& error_callback, const ConnectErrorCallback& error_callback,
const std::string& error_name, const std::string& error_name,
const std::string& error_message) { const std::string& error_message) {
--num_connecting_calls_; if (--num_connecting_calls_ == 0)
adapter_->NotifyDeviceChanged(this);
DCHECK(num_connecting_calls_ >= 0); DCHECK(num_connecting_calls_ >= 0);
LOG(WARNING) << object_path_.value() << ": Failed to register agent: " LOG(WARNING) << object_path_.value() << ": Failed to register agent: "
<< error_name << ": " << error_message; << error_name << ": " << error_message;
...@@ -484,7 +492,9 @@ void BluetoothDeviceExperimentalChromeOS::OnPairError( ...@@ -484,7 +492,9 @@ void BluetoothDeviceExperimentalChromeOS::OnPairError(
const ConnectErrorCallback& error_callback, const ConnectErrorCallback& error_callback,
const std::string& error_name, const std::string& error_name,
const std::string& error_message) { const std::string& error_message) {
--num_connecting_calls_; if (--num_connecting_calls_ == 0)
adapter_->NotifyDeviceChanged(this);
DCHECK(num_connecting_calls_ >= 0); DCHECK(num_connecting_calls_ >= 0);
LOG(WARNING) << object_path_.value() << ": Failed to pair device: " LOG(WARNING) << object_path_.value() << ": Failed to pair device: "
<< error_name << ": " << error_message; << error_name << ": " << error_message;
......
...@@ -967,7 +967,7 @@ TEST_F(BluetoothExperimentalChromeOSTest, ConnectPairedDevice) { ...@@ -967,7 +967,7 @@ TEST_F(BluetoothExperimentalChromeOSTest, ConnectPairedDevice) {
EXPECT_EQ(1, callback_count_); EXPECT_EQ(1, callback_count_);
EXPECT_EQ(0, error_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_EQ(device, observer.last_device_);
EXPECT_TRUE(device->IsConnected()); EXPECT_TRUE(device->IsConnected());
...@@ -998,7 +998,7 @@ TEST_F(BluetoothExperimentalChromeOSTest, ConnectUnpairableDevice) { ...@@ -998,7 +998,7 @@ TEST_F(BluetoothExperimentalChromeOSTest, ConnectUnpairableDevice) {
EXPECT_EQ(1, callback_count_); EXPECT_EQ(1, callback_count_);
EXPECT_EQ(0, error_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_EQ(device, observer.last_device_);
EXPECT_TRUE(device->IsConnected()); EXPECT_TRUE(device->IsConnected());
...@@ -1047,7 +1047,8 @@ TEST_F(BluetoothExperimentalChromeOSTest, ConnectConnectedDevice) { ...@@ -1047,7 +1047,8 @@ TEST_F(BluetoothExperimentalChromeOSTest, ConnectConnectedDevice) {
EXPECT_EQ(1, callback_count_); EXPECT_EQ(1, callback_count_);
EXPECT_EQ(0, error_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_TRUE(device->IsConnected());
EXPECT_FALSE(device->IsConnecting()); EXPECT_FALSE(device->IsConnecting());
...@@ -1078,7 +1079,7 @@ TEST_F(BluetoothExperimentalChromeOSTest, ConnectDeviceFails) { ...@@ -1078,7 +1079,7 @@ TEST_F(BluetoothExperimentalChromeOSTest, ConnectDeviceFails) {
EXPECT_EQ(1, error_callback_count_); EXPECT_EQ(1, error_callback_count_);
EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_); 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->IsConnected());
EXPECT_FALSE(device->IsConnecting()); EXPECT_FALSE(device->IsConnecting());
...@@ -1187,8 +1188,8 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairAppleMouse) { ...@@ -1187,8 +1188,8 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairAppleMouse) {
EXPECT_EQ(1, callback_count_); EXPECT_EQ(1, callback_count_);
EXPECT_EQ(0, error_callback_count_); EXPECT_EQ(0, error_callback_count_);
// One change for connected, and one for paired. // Two changes for connecting, one change for connected, and one for paired.
EXPECT_EQ(2, observer.device_changed_count_); EXPECT_EQ(4, observer.device_changed_count_);
EXPECT_EQ(device, observer.last_device_); EXPECT_EQ(device, observer.last_device_);
EXPECT_TRUE(device->IsConnected()); EXPECT_TRUE(device->IsConnected());
...@@ -1242,8 +1243,8 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairAppleKeyboard) { ...@@ -1242,8 +1243,8 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairAppleKeyboard) {
EXPECT_EQ(1, callback_count_); EXPECT_EQ(1, callback_count_);
EXPECT_EQ(0, error_callback_count_); EXPECT_EQ(0, error_callback_count_);
// One change for connected, and one for paired. // Two changes for connecting, one change for connected, and one for paired.
EXPECT_EQ(2, observer.device_changed_count_); EXPECT_EQ(4, observer.device_changed_count_);
EXPECT_EQ(device, observer.last_device_); EXPECT_EQ(device, observer.last_device_);
EXPECT_TRUE(device->IsConnected()); EXPECT_TRUE(device->IsConnected());
...@@ -1315,8 +1316,8 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairMotorolaKeyboard) { ...@@ -1315,8 +1316,8 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairMotorolaKeyboard) {
EXPECT_EQ(1, callback_count_); EXPECT_EQ(1, callback_count_);
EXPECT_EQ(0, error_callback_count_); EXPECT_EQ(0, error_callback_count_);
// One change for connected, and one for paired. // Two changes for connecting, one change for connected, and one for paired.
EXPECT_EQ(2, observer.device_changed_count_); EXPECT_EQ(4, observer.device_changed_count_);
EXPECT_EQ(device, observer.last_device_); EXPECT_EQ(device, observer.last_device_);
EXPECT_TRUE(device->IsConnected()); EXPECT_TRUE(device->IsConnected());
...@@ -1369,8 +1370,8 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairSonyHeadphones) { ...@@ -1369,8 +1370,8 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairSonyHeadphones) {
EXPECT_EQ(1, callback_count_); EXPECT_EQ(1, callback_count_);
EXPECT_EQ(0, error_callback_count_); EXPECT_EQ(0, error_callback_count_);
// One change for connected, and one for paired. // Two changes for connecting, one change for connected, and one for paired.
EXPECT_EQ(2, observer.device_changed_count_); EXPECT_EQ(4, observer.device_changed_count_);
EXPECT_EQ(device, observer.last_device_); EXPECT_EQ(device, observer.last_device_);
EXPECT_TRUE(device->IsConnected()); EXPECT_TRUE(device->IsConnected());
...@@ -1425,8 +1426,8 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairPhone) { ...@@ -1425,8 +1426,8 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairPhone) {
EXPECT_EQ(1, callback_count_); EXPECT_EQ(1, callback_count_);
EXPECT_EQ(0, error_callback_count_); EXPECT_EQ(0, error_callback_count_);
// One change for connected, and one for paired. // Two changes for connecting, one change for connected, and one for paired.
EXPECT_EQ(2, observer.device_changed_count_); EXPECT_EQ(4, observer.device_changed_count_);
EXPECT_EQ(device, observer.last_device_); EXPECT_EQ(device, observer.last_device_);
EXPECT_TRUE(device->IsConnected()); EXPECT_TRUE(device->IsConnected());
...@@ -1482,8 +1483,8 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairWeirdDevice) { ...@@ -1482,8 +1483,8 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairWeirdDevice) {
EXPECT_EQ(1, callback_count_); EXPECT_EQ(1, callback_count_);
EXPECT_EQ(0, error_callback_count_); EXPECT_EQ(0, error_callback_count_);
// One change for connected, and one for paired. // Two changes for connecting, one change for connected, and one for paired.
EXPECT_EQ(2, observer.device_changed_count_); EXPECT_EQ(4, observer.device_changed_count_);
EXPECT_EQ(device, observer.last_device_); EXPECT_EQ(device, observer.last_device_);
EXPECT_TRUE(device->IsConnected()); EXPECT_TRUE(device->IsConnected());
...@@ -1580,8 +1581,9 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairingFailsAtConnection) { ...@@ -1580,8 +1581,9 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairingFailsAtConnection) {
EXPECT_EQ(1, error_callback_count_); EXPECT_EQ(1, error_callback_count_);
EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_); EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_);
// Just one change for paired, the device should not be connected. // Two changes for connecting, and one for paired; the device should not be
EXPECT_EQ(1, observer.device_changed_count_); // connected.
EXPECT_EQ(3, observer.device_changed_count_);
EXPECT_EQ(device, observer.last_device_); EXPECT_EQ(device, observer.last_device_);
EXPECT_FALSE(device->IsConnected()); EXPECT_FALSE(device->IsConnected());
...@@ -1637,8 +1639,8 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairingRejectedAtPinCode) { ...@@ -1637,8 +1639,8 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairingRejectedAtPinCode) {
EXPECT_EQ(1, error_callback_count_); EXPECT_EQ(1, error_callback_count_);
EXPECT_EQ(BluetoothDevice::ERROR_AUTH_REJECTED, last_connect_error_); EXPECT_EQ(BluetoothDevice::ERROR_AUTH_REJECTED, last_connect_error_);
// Should be no changes. // Should be no changes except connecting going true and false.
EXPECT_EQ(0, observer.device_changed_count_); EXPECT_EQ(2, observer.device_changed_count_);
EXPECT_FALSE(device->IsConnected()); EXPECT_FALSE(device->IsConnected());
EXPECT_FALSE(device->IsConnecting()); EXPECT_FALSE(device->IsConnecting());
EXPECT_FALSE(device->IsPaired()); EXPECT_FALSE(device->IsPaired());
...@@ -1684,8 +1686,8 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairingCancelledAtPinCode) { ...@@ -1684,8 +1686,8 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairingCancelledAtPinCode) {
EXPECT_EQ(1, error_callback_count_); EXPECT_EQ(1, error_callback_count_);
EXPECT_EQ(BluetoothDevice::ERROR_AUTH_CANCELED, last_connect_error_); EXPECT_EQ(BluetoothDevice::ERROR_AUTH_CANCELED, last_connect_error_);
// Should be no changes. // Should be no changes except connecting going true and false.
EXPECT_EQ(0, observer.device_changed_count_); EXPECT_EQ(2, observer.device_changed_count_);
EXPECT_FALSE(device->IsConnected()); EXPECT_FALSE(device->IsConnected());
EXPECT_FALSE(device->IsConnecting()); EXPECT_FALSE(device->IsConnecting());
EXPECT_FALSE(device->IsPaired()); EXPECT_FALSE(device->IsPaired());
...@@ -1731,8 +1733,8 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairingRejectedAtPasskey) { ...@@ -1731,8 +1733,8 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairingRejectedAtPasskey) {
EXPECT_EQ(1, error_callback_count_); EXPECT_EQ(1, error_callback_count_);
EXPECT_EQ(BluetoothDevice::ERROR_AUTH_REJECTED, last_connect_error_); EXPECT_EQ(BluetoothDevice::ERROR_AUTH_REJECTED, last_connect_error_);
// Should be no changes. // Should be no changes except connecting going true and false.
EXPECT_EQ(0, observer.device_changed_count_); EXPECT_EQ(2, observer.device_changed_count_);
EXPECT_FALSE(device->IsConnected()); EXPECT_FALSE(device->IsConnected());
EXPECT_FALSE(device->IsConnecting()); EXPECT_FALSE(device->IsConnecting());
EXPECT_FALSE(device->IsPaired()); EXPECT_FALSE(device->IsPaired());
...@@ -1778,8 +1780,8 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairingCancelledAtPasskey) { ...@@ -1778,8 +1780,8 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairingCancelledAtPasskey) {
EXPECT_EQ(1, error_callback_count_); EXPECT_EQ(1, error_callback_count_);
EXPECT_EQ(BluetoothDevice::ERROR_AUTH_CANCELED, last_connect_error_); EXPECT_EQ(BluetoothDevice::ERROR_AUTH_CANCELED, last_connect_error_);
// Should be no changes. // Should be no changes except connecting going true and false.
EXPECT_EQ(0, observer.device_changed_count_); EXPECT_EQ(2, observer.device_changed_count_);
EXPECT_FALSE(device->IsConnected()); EXPECT_FALSE(device->IsConnected());
EXPECT_FALSE(device->IsConnecting()); EXPECT_FALSE(device->IsConnecting());
EXPECT_FALSE(device->IsPaired()); EXPECT_FALSE(device->IsPaired());
...@@ -1825,8 +1827,8 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairingRejectedAtConfirmation) { ...@@ -1825,8 +1827,8 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairingRejectedAtConfirmation) {
EXPECT_EQ(1, error_callback_count_); EXPECT_EQ(1, error_callback_count_);
EXPECT_EQ(BluetoothDevice::ERROR_AUTH_REJECTED, last_connect_error_); EXPECT_EQ(BluetoothDevice::ERROR_AUTH_REJECTED, last_connect_error_);
// Should be no changes. // Should be no changes except connecting going true and false.
EXPECT_EQ(0, observer.device_changed_count_); EXPECT_EQ(2, observer.device_changed_count_);
EXPECT_FALSE(device->IsConnected()); EXPECT_FALSE(device->IsConnected());
EXPECT_FALSE(device->IsConnecting()); EXPECT_FALSE(device->IsConnecting());
EXPECT_FALSE(device->IsPaired()); EXPECT_FALSE(device->IsPaired());
...@@ -1872,8 +1874,8 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairingCancelledAtConfirmation) { ...@@ -1872,8 +1874,8 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairingCancelledAtConfirmation) {
EXPECT_EQ(1, error_callback_count_); EXPECT_EQ(1, error_callback_count_);
EXPECT_EQ(BluetoothDevice::ERROR_AUTH_CANCELED, last_connect_error_); EXPECT_EQ(BluetoothDevice::ERROR_AUTH_CANCELED, last_connect_error_);
// Should be no changes. // Should be no changes except connecting going true and false.
EXPECT_EQ(0, observer.device_changed_count_); EXPECT_EQ(2, observer.device_changed_count_);
EXPECT_FALSE(device->IsConnected()); EXPECT_FALSE(device->IsConnected());
EXPECT_FALSE(device->IsConnecting()); EXPECT_FALSE(device->IsConnecting());
EXPECT_FALSE(device->IsPaired()); EXPECT_FALSE(device->IsPaired());
...@@ -1918,8 +1920,8 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairingCancelledInFlight) { ...@@ -1918,8 +1920,8 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairingCancelledInFlight) {
EXPECT_EQ(1, error_callback_count_); EXPECT_EQ(1, error_callback_count_);
EXPECT_EQ(BluetoothDevice::ERROR_AUTH_CANCELED, last_connect_error_); EXPECT_EQ(BluetoothDevice::ERROR_AUTH_CANCELED, last_connect_error_);
// Should be no changes. // Should be no changes except connecting going true and false.
EXPECT_EQ(0, observer.device_changed_count_); EXPECT_EQ(2, observer.device_changed_count_);
EXPECT_FALSE(device->IsConnected()); EXPECT_FALSE(device->IsConnected());
EXPECT_FALSE(device->IsConnecting()); EXPECT_FALSE(device->IsConnecting());
EXPECT_FALSE(device->IsPaired()); EXPECT_FALSE(device->IsPaired());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment