diff options
author | keybuk@chromium.org <keybuk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-24 17:56:08 +0000 |
---|---|---|
committer | keybuk@chromium.org <keybuk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-24 17:56:08 +0000 |
commit | fbfcdffc9de4c4aeb4efdf7a48a59023978005e0 (patch) | |
tree | 20f195b8ad81eda2dbb6e12de3042b18807ee4d5 /device/bluetooth | |
parent | bfcd88899348e8d71fa8b62811359d7cf8c759d9 (diff) | |
download | chromium_src-fbfcdffc9de4c4aeb4efdf7a48a59023978005e0.zip chromium_src-fbfcdffc9de4c4aeb4efdf7a48a59023978005e0.tar.gz chromium_src-fbfcdffc9de4c4aeb4efdf7a48a59023978005e0.tar.bz2 |
Bluetooth: send DeviceChanged for more properties
The address and trusted properties of the underlying D-Bus device
interface correspond to BluetoothDevice properties, so DeviceChanged()
must be sent for a change in value of those too.
In addition the reconnect_mode property of the D-Bus input interface
changing (including the interface being added and removed for this
object) corresponds to BluetoothDevice::IsConnectable() so
DeviceChanged() must also be sent.
BUG=233370
TEST=device_unittests
R=youngki@chromium.org
Review URL: https://codereview.chromium.org/14065018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@196177 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'device/bluetooth')
3 files changed, 69 insertions, 21 deletions
diff --git a/device/bluetooth/bluetooth_adapter_experimental_chromeos.cc b/device/bluetooth/bluetooth_adapter_experimental_chromeos.cc index 5143dd1..5051690 100644 --- a/device/bluetooth/bluetooth_adapter_experimental_chromeos.cc +++ b/device/bluetooth/bluetooth_adapter_experimental_chromeos.cc @@ -11,6 +11,7 @@ #include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/experimental_bluetooth_adapter_client.h" #include "chromeos/dbus/experimental_bluetooth_device_client.h" +#include "chromeos/dbus/experimental_bluetooth_input_client.h" #include "device/bluetooth/bluetooth_device.h" #include "device/bluetooth/bluetooth_device_experimental_chromeos.h" @@ -25,6 +26,8 @@ BluetoothAdapterExperimentalChromeOS::BluetoothAdapterExperimentalChromeOS() AddObserver(this); DBusThreadManager::Get()->GetExperimentalBluetoothDeviceClient()-> AddObserver(this); + DBusThreadManager::Get()->GetExperimentalBluetoothInputClient()-> + AddObserver(this); std::vector<dbus::ObjectPath> object_paths = DBusThreadManager::Get()->GetExperimentalBluetoothAdapterClient()-> @@ -41,6 +44,8 @@ BluetoothAdapterExperimentalChromeOS::~BluetoothAdapterExperimentalChromeOS() { RemoveObserver(this); DBusThreadManager::Get()->GetExperimentalBluetoothDeviceClient()-> RemoveObserver(this); + DBusThreadManager::Get()->GetExperimentalBluetoothInputClient()-> + RemoveObserver(this); } void BluetoothAdapterExperimentalChromeOS::AddObserver( @@ -241,13 +246,35 @@ void BluetoothAdapterExperimentalChromeOS::DevicePropertyChanged( GetProperties(object_path); if (property_name == properties->bluetooth_class.name() || + property_name == properties->address.name() || property_name == properties->alias.name() || property_name == properties->paired.name() || + property_name == properties->trusted.name() || property_name == properties->connected.name() || property_name == properties->uuids.name()) NotifyDeviceChanged(device_chromeos); } +void BluetoothAdapterExperimentalChromeOS::InputPropertyChanged( + const dbus::ObjectPath& object_path, + const std::string& property_name) { + BluetoothDeviceExperimentalChromeOS* device_chromeos = + GetDeviceWithPath(object_path); + if (!device_chromeos) + return; + + ExperimentalBluetoothInputClient::Properties* properties = + DBusThreadManager::Get()->GetExperimentalBluetoothInputClient()-> + GetProperties(object_path); + + // Properties structure can be removed, which triggers a change in the + // BluetoothDevice::IsConnectable() property, as does a change in the + // actual reconnect_mode property. + if (!properties || + property_name == properties->reconnect_mode.name()) + NotifyDeviceChanged(device_chromeos); +} + BluetoothDeviceExperimentalChromeOS* BluetoothAdapterExperimentalChromeOS::GetDeviceWithPath( const dbus::ObjectPath& object_path) { diff --git a/device/bluetooth/bluetooth_adapter_experimental_chromeos.h b/device/bluetooth/bluetooth_adapter_experimental_chromeos.h index b11007d..e761a86 100644 --- a/device/bluetooth/bluetooth_adapter_experimental_chromeos.h +++ b/device/bluetooth/bluetooth_adapter_experimental_chromeos.h @@ -10,6 +10,7 @@ #include "base/memory/weak_ptr.h" #include "chromeos/dbus/experimental_bluetooth_adapter_client.h" #include "chromeos/dbus/experimental_bluetooth_device_client.h" +#include "chromeos/dbus/experimental_bluetooth_input_client.h" #include "dbus/object_path.h" #include "device/bluetooth/bluetooth_adapter.h" @@ -31,7 +32,8 @@ class BluetoothExperimentalChromeOSTest; class BluetoothAdapterExperimentalChromeOS : public device::BluetoothAdapter, private chromeos::ExperimentalBluetoothAdapterClient::Observer, - private chromeos::ExperimentalBluetoothDeviceClient::Observer { + private chromeos::ExperimentalBluetoothDeviceClient::Observer, + private chromeos::ExperimentalBluetoothInputClient::Observer { public: // BluetoothAdapter override virtual void AddObserver( @@ -80,6 +82,10 @@ class BluetoothAdapterExperimentalChromeOS virtual void DevicePropertyChanged(const dbus::ObjectPath& object_path, const std::string& property_name) OVERRIDE; + // ExperimentalBluetoothInputClient::Observer override. + virtual void InputPropertyChanged(const dbus::ObjectPath& object_path, + const std::string& property_name) OVERRIDE; + // Internal method used to locate the device object by object path // (the devices map and BluetoothDevice methods are by address) BluetoothDeviceExperimentalChromeOS* GetDeviceWithPath( diff --git a/device/bluetooth/bluetooth_experimental_chromeos_unittest.cc b/device/bluetooth/bluetooth_experimental_chromeos_unittest.cc index 3dfc4b6..9d668f4 100644 --- a/device/bluetooth/bluetooth_experimental_chromeos_unittest.cc +++ b/device/bluetooth/bluetooth_experimental_chromeos_unittest.cc @@ -966,7 +966,9 @@ TEST_F(BluetoothExperimentalChromeOSTest, ConnectPairedDevice) { EXPECT_EQ(1, callback_count_); EXPECT_EQ(0, error_callback_count_); - EXPECT_EQ(3, observer.device_changed_count_); + // Two changes for connecting, one for connected and one for for trusted + // after connecting. + EXPECT_EQ(4, observer.device_changed_count_); EXPECT_EQ(device, observer.last_device_); EXPECT_TRUE(device->IsConnected()); @@ -997,7 +999,9 @@ TEST_F(BluetoothExperimentalChromeOSTest, ConnectUnpairableDevice) { EXPECT_EQ(1, callback_count_); EXPECT_EQ(0, error_callback_count_); - EXPECT_EQ(3, observer.device_changed_count_); + // Two changes for connecting, one for connected, one for for trusted after + // connection, and one for the reconnect mode (IsConnectable). + EXPECT_EQ(5, observer.device_changed_count_); EXPECT_EQ(device, observer.last_device_); EXPECT_TRUE(device->IsConnected()); @@ -1038,7 +1042,7 @@ TEST_F(BluetoothExperimentalChromeOSTest, ConnectConnectedDevice) { ASSERT_TRUE(device->IsConnected()); // Connect again; since the device is already Connected, this shouldn't do - // anything, not even the observer method should be called. + // anything to initiate the connection. TestObserver observer(adapter_); adapter_->AddObserver(&observer); @@ -1052,8 +1056,9 @@ TEST_F(BluetoothExperimentalChromeOSTest, ConnectConnectedDevice) { EXPECT_EQ(1, callback_count_); EXPECT_EQ(0, error_callback_count_); - // Connecting will trigger true and false. - EXPECT_EQ(2, observer.device_changed_count_); + // The observer will be called because Connecting will toggle true and false, + // and the trusted property will be updated to true. + EXPECT_EQ(3, observer.device_changed_count_); EXPECT_TRUE(device->IsConnected()); EXPECT_FALSE(device->IsConnecting()); @@ -1193,8 +1198,10 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairAppleMouse) { EXPECT_EQ(1, callback_count_); EXPECT_EQ(0, error_callback_count_); - // Two changes for connecting, one change for connected, and one for paired. - EXPECT_EQ(4, observer.device_changed_count_); + // Two changes for connecting, one change for connected, one for paired, + // two for trusted (after pairing and connection), and one for the reconnect + // mode (IsConnectable). + EXPECT_EQ(7, observer.device_changed_count_); EXPECT_EQ(device, observer.last_device_); EXPECT_TRUE(device->IsConnected()); @@ -1254,8 +1261,10 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairAppleKeyboard) { EXPECT_EQ(1, callback_count_); EXPECT_EQ(0, error_callback_count_); - // Two changes for connecting, one change for connected, and one for paired. - EXPECT_EQ(4, observer.device_changed_count_); + // Two changes for connecting, one change for connected, one for paired, + // two for trusted (after pairing and connection), and one for the reconnect + // mode (IsConnectable). + EXPECT_EQ(7, observer.device_changed_count_); EXPECT_EQ(device, observer.last_device_); EXPECT_TRUE(device->IsConnected()); @@ -1333,8 +1342,10 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairMotorolaKeyboard) { EXPECT_EQ(1, callback_count_); EXPECT_EQ(0, error_callback_count_); - // Two changes for connecting, one change for connected, and one for paired. - EXPECT_EQ(4, observer.device_changed_count_); + // Two changes for connecting, one change for connected, one for paired, + // two for trusted (after pairing and connection), and one for the reconnect + // mode (IsConnectable). + EXPECT_EQ(7, observer.device_changed_count_); EXPECT_EQ(device, observer.last_device_); EXPECT_TRUE(device->IsConnected()); @@ -1395,8 +1406,9 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairSonyHeadphones) { EXPECT_EQ(1, callback_count_); EXPECT_EQ(0, error_callback_count_); - // Two changes for connecting, one change for connected, and one for paired. - EXPECT_EQ(4, observer.device_changed_count_); + // Two changes for connecting, one change for connected, one for paired and + // two for trusted (after pairing and connection). + EXPECT_EQ(6, observer.device_changed_count_); EXPECT_EQ(device, observer.last_device_); EXPECT_TRUE(device->IsConnected()); @@ -1458,8 +1470,9 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairPhone) { EXPECT_EQ(1, callback_count_); EXPECT_EQ(0, error_callback_count_); - // Two changes for connecting, one change for connected, and one for paired. - EXPECT_EQ(4, observer.device_changed_count_); + // Two changes for connecting, one change for connected, one for paired and + // two for trusted (after pairing and connection). + EXPECT_EQ(6, observer.device_changed_count_); EXPECT_EQ(device, observer.last_device_); EXPECT_TRUE(device->IsConnected()); @@ -1518,8 +1531,9 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairWeirdDevice) { EXPECT_EQ(1, callback_count_); EXPECT_EQ(0, error_callback_count_); - // Two changes for connecting, one change for connected, and one for paired. - EXPECT_EQ(4, observer.device_changed_count_); + // Two changes for connecting, one change for connected, one for paired and + // two for trusted (after pairing and connection). + EXPECT_EQ(6, observer.device_changed_count_); EXPECT_EQ(device, observer.last_device_); EXPECT_TRUE(device->IsConnected()); @@ -1619,9 +1633,10 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairingFailsAtConnection) { EXPECT_EQ(1, error_callback_count_); EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_); - // Two changes for connecting, and one for paired; the device should not be - // connected. - EXPECT_EQ(3, observer.device_changed_count_); + // Two changes for connecting, one for paired, one for for trusted + // after pairing and one for the reconnect mode (IsConnectable). + // The device should not be connected, + EXPECT_EQ(5, observer.device_changed_count_); EXPECT_EQ(device, observer.last_device_); EXPECT_FALSE(device->IsConnected()); |