diff options
20 files changed, 621 insertions, 671 deletions
diff --git a/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_apitest.cc b/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_apitest.cc index 829009e..a04f151 100644 --- a/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_apitest.cc +++ b/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_apitest.cc @@ -291,8 +291,8 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetService) { ResultCatcher catcher; catcher.RestrictToProfile(browser()->profile()); - event_router()->DeviceAdded(mock_adapter_, device0_.get()); - event_router()->GattServiceAdded(device0_.get(), service0_.get()); + event_router()->GattServiceAdded( + mock_adapter_, device0_.get(), service0_.get()); EXPECT_CALL(*mock_adapter_, GetDevice(_)) .Times(3) @@ -314,8 +314,8 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetService) { EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); - event_router()->GattServiceRemoved(device0_.get(), service0_.get()); - event_router()->DeviceRemoved(mock_adapter_, device0_.get()); + event_router()->GattServiceRemoved( + mock_adapter_, device0_.get(), service0_.get()); } IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, ServiceEvents) { @@ -327,29 +327,31 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, ServiceEvents) { ASSERT_TRUE(LoadExtension( test_data_dir_.AppendASCII("bluetooth_low_energy/service_events"))); - // Cause events to be sent to the extension. - event_router()->DeviceAdded(mock_adapter_, device0_.get()); - // These will create the identifier mappings. - event_router()->GattServiceAdded(device0_.get(), service0_.get()); - event_router()->GattServiceAdded(device0_.get(), service1_.get()); + event_router()->GattServiceAdded( + mock_adapter_, device0_.get(), service0_.get()); + event_router()->GattServiceAdded( + mock_adapter_, device0_.get(), service1_.get()); // These will send the onServiceAdded event to apps. - event_router()->GattDiscoveryCompleteForService(service0_.get()); - event_router()->GattDiscoveryCompleteForService(service1_.get()); + event_router()->GattDiscoveryCompleteForService(mock_adapter_, + service0_.get()); + event_router()->GattDiscoveryCompleteForService(mock_adapter_, + service1_.get()); // This will send the onServiceChanged event to apps. - event_router()->GattServiceChanged(service1_.get()); + event_router()->GattServiceChanged(mock_adapter_, service1_.get()); // This will send the onServiceRemoved event to apps. - event_router()->GattServiceRemoved(device0_.get(), service0_.get()); + event_router()->GattServiceRemoved( + mock_adapter_, device0_.get(), service0_.get()); EXPECT_TRUE(listener.WaitUntilSatisfied()); listener.Reply("go"); EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); - event_router()->GattServiceRemoved(device0_.get(), service1_.get()); - event_router()->DeviceRemoved(mock_adapter_, device0_.get()); + event_router()->GattServiceRemoved( + mock_adapter_, device0_.get(), service1_.get()); } IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetRemovedService) { @@ -368,9 +370,10 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetRemovedService) { .Times(1) .WillOnce(Return(service0_.get())); - event_router()->DeviceAdded(mock_adapter_, device0_.get()); - event_router()->GattServiceAdded(device0_.get(), service0_.get()); - event_router()->GattDiscoveryCompleteForService(service0_.get()); + event_router()->GattServiceAdded( + mock_adapter_, device0_.get(), service0_.get()); + event_router()->GattDiscoveryCompleteForService(mock_adapter_, + service0_.get()); ExtensionTestMessageListener get_service_success_listener("getServiceSuccess", true); @@ -382,7 +385,8 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetRemovedService) { EXPECT_CALL(*mock_adapter_, GetDevice(_)).Times(0); EXPECT_CALL(*device0_, GetGattService(kTestServiceId0)).Times(0); - event_router()->GattServiceRemoved(device0_.get(), service0_.get()); + event_router()->GattServiceRemoved( + mock_adapter_, device0_.get(), service0_.get()); ExtensionTestMessageListener get_service_fail_listener("getServiceFail", true); @@ -393,7 +397,6 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetRemovedService) { get_service_fail_listener.Reply("go"); EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); - event_router()->DeviceRemoved(mock_adapter_, device0_.get()); } IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetIncludedServices) { @@ -410,8 +413,8 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetIncludedServices) { // Set up for the rest of the calls before replying. Included services can be // returned even if there is no instance ID mapping for them yet, so no need // to call GattServiceAdded for |service1_| here. - event_router()->DeviceAdded(mock_adapter_, device0_.get()); - event_router()->GattServiceAdded(device0_.get(), service0_.get()); + event_router()->GattServiceAdded( + mock_adapter_, device0_.get(), service0_.get()); std::vector<BluetoothGattService*> includes; includes.push_back(service1_.get()); @@ -434,8 +437,8 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetIncludedServices) { listener.Reply("go"); EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); - event_router()->GattServiceRemoved(device0_.get(), service0_.get()); - event_router()->DeviceRemoved(mock_adapter_, device0_.get()); + event_router()->GattServiceRemoved( + mock_adapter_, device0_.get(), service0_.get()); } IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetCharacteristics) { @@ -446,8 +449,8 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetCharacteristics) { characteristics.push_back(chrc0_.get()); characteristics.push_back(chrc1_.get()); - event_router()->DeviceAdded(mock_adapter_, device0_.get()); - event_router()->GattServiceAdded(device0_.get(), service0_.get()); + event_router()->GattServiceAdded( + mock_adapter_, device0_.get(), service0_.get()); EXPECT_CALL(*mock_adapter_, GetDevice(_)).Times(3).WillRepeatedly( Return(device0_.get())); @@ -468,17 +471,17 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetCharacteristics) { listener.Reply("go"); EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); - event_router()->GattServiceRemoved(device0_.get(), service0_.get()); - event_router()->DeviceRemoved(mock_adapter_, device0_.get()); + event_router()->GattServiceRemoved( + mock_adapter_, device0_.get(), service0_.get()); } IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetCharacteristic) { ResultCatcher catcher; catcher.RestrictToProfile(browser()->profile()); - event_router()->DeviceAdded(mock_adapter_, device0_.get()); - event_router()->GattServiceAdded(device0_.get(), service0_.get()); - event_router()->GattCharacteristicAdded(service0_.get(), chrc0_.get()); + event_router()->GattServiceAdded( + mock_adapter_, device0_.get(), service0_.get()); + event_router()->GattCharacteristicAdded(mock_adapter_, chrc0_.get()); EXPECT_CALL(*mock_adapter_, GetDevice(_)) .Times(4) @@ -505,18 +508,18 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetCharacteristic) { EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); - event_router()->GattCharacteristicRemoved(service0_.get(), chrc0_.get()); - event_router()->GattServiceRemoved(device0_.get(), service0_.get()); - event_router()->DeviceRemoved(mock_adapter_, device0_.get()); + event_router()->GattCharacteristicRemoved(mock_adapter_, chrc0_.get()); + event_router()->GattServiceRemoved( + mock_adapter_, device0_.get(), service0_.get()); } IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, CharacteristicProperties) { ResultCatcher catcher; catcher.RestrictToProfile(browser()->profile()); - event_router()->DeviceAdded(mock_adapter_, device0_.get()); - event_router()->GattServiceAdded(device0_.get(), service0_.get()); - event_router()->GattCharacteristicAdded(service0_.get(), chrc0_.get()); + event_router()->GattServiceAdded( + mock_adapter_, device0_.get(), service0_.get()); + event_router()->GattCharacteristicAdded(mock_adapter_, chrc0_.get()); EXPECT_CALL(*mock_adapter_, GetDevice(_)) .Times(12) @@ -565,9 +568,9 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, CharacteristicProperties) { EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); - event_router()->GattCharacteristicRemoved(service0_.get(), chrc0_.get()); - event_router()->GattServiceRemoved(device0_.get(), service0_.get()); - event_router()->DeviceRemoved(mock_adapter_, device0_.get()); + event_router()->GattCharacteristicRemoved(mock_adapter_, chrc0_.get()); + event_router()->GattServiceRemoved( + mock_adapter_, device0_.get(), service0_.get()); } IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetRemovedCharacteristic) { @@ -584,9 +587,9 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetRemovedCharacteristic) { .Times(1) .WillOnce(Return(chrc0_.get())); - event_router()->DeviceAdded(mock_adapter_, device0_.get()); - event_router()->GattServiceAdded(device0_.get(), service0_.get()); - event_router()->GattCharacteristicAdded(service0_.get(), chrc0_.get()); + event_router()->GattServiceAdded( + mock_adapter_, device0_.get(), service0_.get()); + event_router()->GattCharacteristicAdded(mock_adapter_, chrc0_.get()); ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( "bluetooth_low_energy/get_removed_characteristic"))); @@ -601,7 +604,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetRemovedCharacteristic) { EXPECT_CALL(*device0_, GetGattService(_)).Times(0); EXPECT_CALL(*service0_, GetCharacteristic(_)).Times(0); - event_router()->GattCharacteristicRemoved(service0_.get(), chrc0_.get()); + event_router()->GattCharacteristicRemoved(mock_adapter_, chrc0_.get()); listener.Reply("go"); listener.Reset(); @@ -610,8 +613,8 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetRemovedCharacteristic) { listener.Reply("go"); EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); - event_router()->GattServiceRemoved(device0_.get(), service0_.get()); - event_router()->DeviceRemoved(mock_adapter_, device0_.get()); + event_router()->GattServiceRemoved( + mock_adapter_, device0_.get(), service0_.get()); } IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, CharacteristicValueChanged) { @@ -619,11 +622,12 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, CharacteristicValueChanged) { catcher.RestrictToProfile(browser()->profile()); // Cause events to be sent to the extension. - event_router()->DeviceAdded(mock_adapter_, device0_.get()); - event_router()->GattServiceAdded(device0_.get(), service0_.get()); - event_router()->GattServiceAdded(device0_.get(), service1_.get()); - event_router()->GattCharacteristicAdded(service0_.get(), chrc0_.get()); - event_router()->GattCharacteristicAdded(service1_.get(), chrc2_.get()); + event_router()->GattServiceAdded( + mock_adapter_, device0_.get(), service0_.get()); + event_router()->GattServiceAdded( + mock_adapter_, device0_.get(), service1_.get()); + event_router()->GattCharacteristicAdded(mock_adapter_, chrc0_.get()); + event_router()->GattCharacteristicAdded(mock_adapter_, chrc2_.get()); EXPECT_CALL(*mock_adapter_, GetDevice(_)) .Times(2) @@ -667,27 +671,28 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, CharacteristicValueChanged) { std::vector<uint8> value; event_router()->GattCharacteristicValueChanged( - service0_.get(), chrc0_.get(), value); + mock_adapter_, chrc0_.get(), value); event_router()->GattCharacteristicValueChanged( - service1_.get(), chrc2_.get(), value); + mock_adapter_, chrc2_.get(), value); listener.Reply("go"); EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); - event_router()->GattCharacteristicRemoved(service1_.get(), chrc2_.get()); - event_router()->GattCharacteristicRemoved(service0_.get(), chrc0_.get()); - event_router()->GattServiceRemoved(device0_.get(), service1_.get()); - event_router()->GattServiceRemoved(device0_.get(), service0_.get()); - event_router()->DeviceRemoved(mock_adapter_, device0_.get()); + event_router()->GattCharacteristicRemoved(mock_adapter_, chrc2_.get()); + event_router()->GattCharacteristicRemoved(mock_adapter_, chrc0_.get()); + event_router()->GattServiceRemoved( + mock_adapter_, device0_.get(), service1_.get()); + event_router()->GattServiceRemoved( + mock_adapter_, device0_.get(), service0_.get()); } IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, ReadCharacteristicValue) { ResultCatcher catcher; catcher.RestrictToProfile(browser()->profile()); - event_router()->DeviceAdded(mock_adapter_, device0_.get()); - event_router()->GattServiceAdded(device0_.get(), service0_.get()); - event_router()->GattCharacteristicAdded(service0_.get(), chrc0_.get()); + event_router()->GattServiceAdded( + mock_adapter_, device0_.get(), service0_.get()); + event_router()->GattCharacteristicAdded(mock_adapter_, chrc0_.get()); EXPECT_CALL(*mock_adapter_, GetDevice(_)) .Times(3) @@ -716,18 +721,18 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, ReadCharacteristicValue) { EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); - event_router()->GattCharacteristicRemoved(service0_.get(), chrc0_.get()); - event_router()->GattServiceRemoved(device0_.get(), service0_.get()); - event_router()->DeviceRemoved(mock_adapter_, device0_.get()); + event_router()->GattCharacteristicRemoved(mock_adapter_, chrc0_.get()); + event_router()->GattServiceRemoved( + mock_adapter_, device0_.get(), service0_.get()); } IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, WriteCharacteristicValue) { ResultCatcher catcher; catcher.RestrictToProfile(browser()->profile()); - event_router()->DeviceAdded(mock_adapter_, device0_.get()); - event_router()->GattServiceAdded(device0_.get(), service0_.get()); - event_router()->GattCharacteristicAdded(service0_.get(), chrc0_.get()); + event_router()->GattServiceAdded( + mock_adapter_, device0_.get(), service0_.get()); + event_router()->GattCharacteristicAdded(mock_adapter_, chrc0_.get()); EXPECT_CALL(*mock_adapter_, GetDevice(_)) .Times(3) @@ -758,9 +763,9 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, WriteCharacteristicValue) { EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); - event_router()->GattCharacteristicRemoved(service0_.get(), chrc0_.get()); - event_router()->GattServiceRemoved(device0_.get(), service0_.get()); - event_router()->DeviceRemoved(mock_adapter_, device0_.get()); + event_router()->GattCharacteristicRemoved(mock_adapter_, chrc0_.get()); + event_router()->GattServiceRemoved( + mock_adapter_, device0_.get(), service0_.get()); } IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetDescriptors) { @@ -771,9 +776,9 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetDescriptors) { descriptors.push_back(desc0_.get()); descriptors.push_back(desc1_.get()); - event_router()->DeviceAdded(mock_adapter_, device0_.get()); - event_router()->GattServiceAdded(device0_.get(), service0_.get()); - event_router()->GattCharacteristicAdded(service0_.get(), chrc0_.get()); + event_router()->GattServiceAdded( + mock_adapter_, device0_.get(), service0_.get()); + event_router()->GattCharacteristicAdded(mock_adapter_, chrc0_.get()); EXPECT_CALL(*mock_adapter_, GetDevice(_)) .Times(3) @@ -799,19 +804,19 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetDescriptors) { EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); - event_router()->GattCharacteristicRemoved(service0_.get(), chrc0_.get()); - event_router()->GattServiceRemoved(device0_.get(), service0_.get()); - event_router()->DeviceRemoved(mock_adapter_, device0_.get()); + event_router()->GattCharacteristicRemoved(mock_adapter_, chrc0_.get()); + event_router()->GattServiceRemoved( + mock_adapter_, device0_.get(), service0_.get()); } IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetDescriptor) { ResultCatcher catcher; catcher.RestrictToProfile(browser()->profile()); - event_router()->DeviceAdded(mock_adapter_, device0_.get()); - event_router()->GattServiceAdded(device0_.get(), service0_.get()); - event_router()->GattCharacteristicAdded(service0_.get(), chrc0_.get()); - event_router()->GattDescriptorAdded(chrc0_.get(), desc0_.get()); + event_router()->GattServiceAdded( + mock_adapter_, device0_.get(), service0_.get()); + event_router()->GattCharacteristicAdded(mock_adapter_, chrc0_.get()); + event_router()->GattDescriptorAdded(mock_adapter_, desc0_.get()); EXPECT_CALL(*mock_adapter_, GetDevice(_)) .Times(5) @@ -843,10 +848,10 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetDescriptor) { EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); - event_router()->GattDescriptorRemoved(chrc0_.get(), desc0_.get()); - event_router()->GattCharacteristicRemoved(service0_.get(), chrc0_.get()); - event_router()->GattServiceRemoved(device0_.get(), service0_.get()); - event_router()->DeviceRemoved(mock_adapter_, device0_.get()); + event_router()->GattDescriptorRemoved(mock_adapter_, desc0_.get()); + event_router()->GattCharacteristicRemoved(mock_adapter_, chrc0_.get()); + event_router()->GattServiceRemoved( + mock_adapter_, device0_.get(), service0_.get()); } IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetRemovedDescriptor) { @@ -866,10 +871,10 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetRemovedDescriptor) { .Times(1) .WillOnce(Return(desc0_.get())); - event_router()->DeviceAdded(mock_adapter_, device0_.get()); - event_router()->GattServiceAdded(device0_.get(), service0_.get()); - event_router()->GattCharacteristicAdded(service0_.get(), chrc0_.get()); - event_router()->GattDescriptorAdded(chrc0_.get(), desc0_.get()); + event_router()->GattServiceAdded( + mock_adapter_, device0_.get(), service0_.get()); + event_router()->GattCharacteristicAdded(mock_adapter_, chrc0_.get()); + event_router()->GattDescriptorAdded(mock_adapter_, desc0_.get()); ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( "bluetooth_low_energy/get_removed_descriptor"))); @@ -886,7 +891,7 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetRemovedDescriptor) { EXPECT_CALL(*service0_, GetCharacteristic(_)).Times(0); EXPECT_CALL(*chrc0_, GetDescriptor(_)).Times(0); - event_router()->GattDescriptorRemoved(chrc0_.get(), desc0_.get()); + event_router()->GattDescriptorRemoved(mock_adapter_, desc0_.get()); listener.Reply("go"); listener.Reset(); @@ -895,20 +900,20 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetRemovedDescriptor) { listener.Reply("go"); EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); - event_router()->GattCharacteristicRemoved(service0_.get(), chrc0_.get()); - event_router()->GattServiceRemoved(device0_.get(), service0_.get()); - event_router()->DeviceRemoved(mock_adapter_, device0_.get()); + event_router()->GattCharacteristicRemoved(mock_adapter_, chrc0_.get()); + event_router()->GattServiceRemoved( + mock_adapter_, device0_.get(), service0_.get()); } IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, DescriptorValueChanged) { ResultCatcher catcher; catcher.RestrictToProfile(browser()->profile()); - event_router()->DeviceAdded(mock_adapter_, device0_.get()); - event_router()->GattServiceAdded(device0_.get(), service0_.get()); - event_router()->GattCharacteristicAdded(service0_.get(), chrc0_.get()); - event_router()->GattDescriptorAdded(chrc0_.get(), desc0_.get()); - event_router()->GattDescriptorAdded(chrc0_.get(), desc1_.get()); + event_router()->GattServiceAdded( + mock_adapter_, device0_.get(), service0_.get()); + event_router()->GattCharacteristicAdded(mock_adapter_, chrc0_.get()); + event_router()->GattDescriptorAdded(mock_adapter_, desc0_.get()); + event_router()->GattDescriptorAdded(mock_adapter_, desc1_.get()); // Load the extension and let it set up. ExtensionTestMessageListener listener("ready", true); @@ -917,28 +922,30 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, DescriptorValueChanged) { // Cause events to be sent to the extension. std::vector<uint8> value; - event_router()->GattDescriptorValueChanged(chrc0_.get(), desc0_.get(), value); - event_router()->GattDescriptorValueChanged(chrc0_.get(), desc1_.get(), value); + event_router()->GattDescriptorValueChanged( + mock_adapter_, desc0_.get(), value); + event_router()->GattDescriptorValueChanged( + mock_adapter_, desc1_.get(), value); EXPECT_TRUE(listener.WaitUntilSatisfied()); listener.Reply("go"); EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); - event_router()->GattDescriptorRemoved(chrc0_.get(), desc1_.get()); - event_router()->GattDescriptorRemoved(chrc0_.get(), desc0_.get()); - event_router()->GattCharacteristicRemoved(service0_.get(), chrc0_.get()); - event_router()->GattServiceRemoved(device0_.get(), service0_.get()); - event_router()->DeviceRemoved(mock_adapter_, device0_.get()); + event_router()->GattDescriptorRemoved(mock_adapter_, desc1_.get()); + event_router()->GattDescriptorRemoved(mock_adapter_, desc0_.get()); + event_router()->GattCharacteristicRemoved(mock_adapter_, chrc0_.get()); + event_router()->GattServiceRemoved( + mock_adapter_, device0_.get(), service0_.get()); } IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, ReadDescriptorValue) { ResultCatcher catcher; catcher.RestrictToProfile(browser()->profile()); - event_router()->DeviceAdded(mock_adapter_, device0_.get()); - event_router()->GattServiceAdded(device0_.get(), service0_.get()); - event_router()->GattCharacteristicAdded(service0_.get(), chrc0_.get()); - event_router()->GattDescriptorAdded(chrc0_.get(), desc0_.get()); + event_router()->GattServiceAdded( + mock_adapter_, device0_.get(), service0_.get()); + event_router()->GattCharacteristicAdded(mock_adapter_, chrc0_.get()); + event_router()->GattDescriptorAdded(mock_adapter_, desc0_.get()); EXPECT_CALL(*mock_adapter_, GetDevice(_)) .Times(3) @@ -971,20 +978,20 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, ReadDescriptorValue) { EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); - event_router()->GattDescriptorRemoved(chrc0_.get(), desc0_.get()); - event_router()->GattCharacteristicRemoved(service0_.get(), chrc0_.get()); - event_router()->GattServiceRemoved(device0_.get(), service0_.get()); - event_router()->DeviceRemoved(mock_adapter_, device0_.get()); + event_router()->GattDescriptorRemoved(mock_adapter_, desc0_.get()); + event_router()->GattCharacteristicRemoved(mock_adapter_, chrc0_.get()); + event_router()->GattServiceRemoved( + mock_adapter_, device0_.get(), service0_.get()); } IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, WriteDescriptorValue) { ResultCatcher catcher; catcher.RestrictToProfile(browser()->profile()); - event_router()->DeviceAdded(mock_adapter_, device0_.get()); - event_router()->GattServiceAdded(device0_.get(), service0_.get()); - event_router()->GattCharacteristicAdded(service0_.get(), chrc0_.get()); - event_router()->GattDescriptorAdded(chrc0_.get(), desc0_.get()); + event_router()->GattServiceAdded( + mock_adapter_, device0_.get(), service0_.get()); + event_router()->GattCharacteristicAdded(mock_adapter_, chrc0_.get()); + event_router()->GattDescriptorAdded(mock_adapter_, desc0_.get()); EXPECT_CALL(*mock_adapter_, GetDevice(_)) .Times(3) @@ -1019,10 +1026,10 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, WriteDescriptorValue) { EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); - event_router()->GattDescriptorRemoved(chrc0_.get(), desc0_.get()); - event_router()->GattCharacteristicRemoved(service0_.get(), chrc0_.get()); - event_router()->GattServiceRemoved(device0_.get(), service0_.get()); - event_router()->DeviceRemoved(mock_adapter_, device0_.get()); + event_router()->GattDescriptorRemoved(mock_adapter_, desc0_.get()); + event_router()->GattCharacteristicRemoved(mock_adapter_, chrc0_.get()); + event_router()->GattServiceRemoved( + mock_adapter_, device0_.get(), service0_.get()); } IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, PermissionDenied) { @@ -1038,10 +1045,10 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, UuidPermissionMethods) { ResultCatcher catcher; catcher.RestrictToProfile(browser()->profile()); - event_router()->DeviceAdded(mock_adapter_, device0_.get()); - event_router()->GattServiceAdded(device0_.get(), service0_.get()); - event_router()->GattCharacteristicAdded(service0_.get(), chrc0_.get()); - event_router()->GattDescriptorAdded(chrc0_.get(), desc0_.get()); + event_router()->GattServiceAdded( + mock_adapter_, device0_.get(), service0_.get()); + event_router()->GattCharacteristicAdded(mock_adapter_, chrc0_.get()); + event_router()->GattDescriptorAdded(mock_adapter_, desc0_.get()); std::vector<BluetoothGattService*> services; services.push_back(service0_.get()); @@ -1060,10 +1067,10 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, UuidPermissionMethods) { "bluetooth_low_energy/uuid_permission_methods"))); EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); - event_router()->GattDescriptorRemoved(chrc0_.get(), desc0_.get()); - event_router()->GattCharacteristicRemoved(service0_.get(), chrc0_.get()); - event_router()->GattServiceRemoved(device0_.get(), service0_.get()); - event_router()->DeviceRemoved(mock_adapter_, device0_.get()); + event_router()->GattDescriptorRemoved(mock_adapter_, desc0_.get()); + event_router()->GattCharacteristicRemoved(mock_adapter_, chrc0_.get()); + event_router()->GattServiceRemoved( + mock_adapter_, device0_.get(), service0_.get()); } IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, UuidPermissionEvents) { @@ -1075,33 +1082,32 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, UuidPermissionEvents) { "bluetooth_low_energy/uuid_permission_events"))); // Cause events to be sent to the extension. - event_router()->DeviceAdded(mock_adapter_, device0_.get()); - event_router()->GattServiceAdded(device0_.get(), service0_.get()); - event_router()->GattCharacteristicAdded(service0_.get(), chrc0_.get()); - event_router()->GattDescriptorAdded(chrc0_.get(), desc0_.get()); + event_router()->GattServiceAdded( + mock_adapter_, device0_.get(), service0_.get()); + event_router()->GattCharacteristicAdded(mock_adapter_, chrc0_.get()); + event_router()->GattDescriptorAdded(mock_adapter_, desc0_.get()); std::vector<uint8> value; event_router()->GattCharacteristicValueChanged( - service0_.get(), chrc0_.get(), value); - event_router()->GattDescriptorValueChanged(chrc0_.get(), desc0_.get(), value); - event_router()->GattServiceChanged(service0_.get()); + mock_adapter_, chrc0_.get(), value); + event_router()->GattDescriptorValueChanged( + mock_adapter_, desc0_.get(), value); + event_router()->GattServiceChanged(mock_adapter_, service0_.get()); EXPECT_TRUE(listener.WaitUntilSatisfied()); listener.Reply("go"); EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); - event_router()->GattDescriptorRemoved(chrc0_.get(), desc0_.get()); - event_router()->GattCharacteristicRemoved(service0_.get(), chrc0_.get()); - event_router()->GattServiceRemoved(device0_.get(), service0_.get()); - event_router()->DeviceRemoved(mock_adapter_, device0_.get()); + event_router()->GattDescriptorRemoved(mock_adapter_, desc0_.get()); + event_router()->GattCharacteristicRemoved(mock_adapter_, chrc0_.get()); + event_router()->GattServiceRemoved( + mock_adapter_, device0_.get(), service0_.get()); } IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GattConnection) { ResultCatcher catcher; catcher.RestrictToProfile(browser()->profile()); - event_router()->DeviceAdded(mock_adapter_, device0_.get()); - event_router()->DeviceAdded(mock_adapter_, device1_.get()); EXPECT_CALL(*mock_adapter_, GetDevice(_)) .WillRepeatedly(Return(static_cast<BluetoothDevice*>(NULL))); @@ -1127,16 +1133,12 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GattConnection) { ASSERT_TRUE(LoadExtension( test_data_dir_.AppendASCII("bluetooth_low_energy/gatt_connection"))); EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); - - event_router()->DeviceRemoved(mock_adapter_, device1_.get()); - event_router()->DeviceRemoved(mock_adapter_, device0_.get()); } IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, ReconnectAfterDisconnected) { ResultCatcher catcher; catcher.RestrictToProfile(browser()->profile()); - event_router()->DeviceAdded(mock_adapter_, device0_.get()); EXPECT_CALL(*mock_adapter_, GetDevice(kTestLeDeviceAddress0)) .WillRepeatedly(Return(device0_.get())); @@ -1161,14 +1163,12 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, ReconnectAfterDisconnected) { "bluetooth_low_energy/reconnect_after_disconnected"))); EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); - event_router()->DeviceRemoved(mock_adapter_, device0_.get()); } IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, ConnectInProgress) { ResultCatcher catcher; catcher.RestrictToProfile(browser()->profile()); - event_router()->DeviceAdded(mock_adapter_, device0_.get()); EXPECT_CALL(*mock_adapter_, GetDevice(kTestLeDeviceAddress0)) .WillRepeatedly(Return(device0_.get())); @@ -1201,19 +1201,19 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, ConnectInProgress) { EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); - event_router()->DeviceRemoved(mock_adapter_, device0_.get()); } IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, StartStopNotifications) { ResultCatcher catcher; catcher.RestrictToProfile(browser()->profile()); - event_router()->DeviceAdded(mock_adapter_, device0_.get()); - event_router()->GattServiceAdded(device0_.get(), service0_.get()); - event_router()->GattServiceAdded(device0_.get(), service1_.get()); - event_router()->GattCharacteristicAdded(service0_.get(), chrc0_.get()); - event_router()->GattCharacteristicAdded(service0_.get(), chrc1_.get()); - event_router()->GattCharacteristicAdded(service1_.get(), chrc2_.get()); + event_router()->GattServiceAdded( + mock_adapter_, device0_.get(), service0_.get()); + event_router()->GattServiceAdded( + mock_adapter_, device0_.get(), service1_.get()); + event_router()->GattCharacteristicAdded(mock_adapter_, chrc0_.get()); + event_router()->GattCharacteristicAdded(mock_adapter_, chrc1_.get()); + event_router()->GattCharacteristicAdded(mock_adapter_, chrc2_.get()); EXPECT_CALL(*mock_adapter_, GetDevice(_)) .WillRepeatedly(Return(device0_.get())); @@ -1262,21 +1262,22 @@ IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, StartStopNotifications) { std::vector<uint8> value; event_router()->GattCharacteristicValueChanged( - service0_.get(), chrc0_.get(), value); + mock_adapter_, chrc0_.get(), value); event_router()->GattCharacteristicValueChanged( - service0_.get(), chrc1_.get(), value); + mock_adapter_, chrc1_.get(), value); event_router()->GattCharacteristicValueChanged( - service1_.get(), chrc2_.get(), value); + mock_adapter_, chrc2_.get(), value); listener.Reply("go"); EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); - event_router()->GattCharacteristicRemoved(service1_.get(), chrc2_.get()); - event_router()->GattCharacteristicRemoved(service0_.get(), chrc1_.get()); - event_router()->GattCharacteristicRemoved(service0_.get(), chrc0_.get()); - event_router()->GattServiceRemoved(device0_.get(), service1_.get()); - event_router()->GattServiceRemoved(device0_.get(), service0_.get()); - event_router()->DeviceRemoved(mock_adapter_, device0_.get()); + event_router()->GattCharacteristicRemoved(mock_adapter_, chrc2_.get()); + event_router()->GattCharacteristicRemoved(mock_adapter_, chrc1_.get()); + event_router()->GattCharacteristicRemoved(mock_adapter_, chrc0_.get()); + event_router()->GattServiceRemoved( + mock_adapter_, device0_.get(), service1_.get()); + event_router()->GattServiceRemoved( + mock_adapter_, device0_.get(), service0_.get()); } } // namespace diff --git a/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_event_router.cc b/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_event_router.cc index 4baeb27..7c66a04 100644 --- a/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_event_router.cc +++ b/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_event_router.cc @@ -174,26 +174,6 @@ BluetoothLowEnergyEventRouter::~BluetoothLowEnergyEventRouter() { return; adapter_->RemoveObserver(this); - - for (std::set<std::string>::const_iterator iter = observed_devices_.begin(); - iter != observed_devices_.end(); - ++iter) { - BluetoothDevice* device = adapter_->GetDevice(*iter); - if (!device) - continue; - device->RemoveObserver(this); - } - - for (std::set<std::string>::const_iterator iter = - observed_gatt_services_.begin(); - iter != observed_gatt_services_.end(); - ++iter) { - BluetoothGattService* service = FindServiceById(*iter); - if (!service) - continue; - service->RemoveObserver(this); - } - adapter_ = NULL; } @@ -821,56 +801,32 @@ void BluetoothLowEnergyEventRouter::SetAdapterForTesting( InitializeIdentifierMappings(); } -void BluetoothLowEnergyEventRouter::DeviceAdded(BluetoothAdapter* adapter, - BluetoothDevice* device) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - DCHECK(observed_devices_.find(device->GetAddress()) == - observed_devices_.end()); - device->AddObserver(this); - observed_devices_.insert(device->GetAddress()); -} - -void BluetoothLowEnergyEventRouter::DeviceRemoved(BluetoothAdapter* adapter, - BluetoothDevice* device) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - DCHECK(observed_devices_.find(device->GetAddress()) != - observed_devices_.end()); - device->RemoveObserver(this); - observed_devices_.erase(device->GetAddress()); -} - void BluetoothLowEnergyEventRouter::GattServiceAdded( + BluetoothAdapter* adapter, BluetoothDevice* device, BluetoothGattService* service) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + DCHECK_EQ(adapter, adapter_); VLOG(2) << "GATT service added: " << service->GetIdentifier(); - DCHECK(observed_gatt_services_.find(service->GetIdentifier()) == - observed_gatt_services_.end()); DCHECK(service_id_to_device_address_.find(service->GetIdentifier()) == service_id_to_device_address_.end()); - service->AddObserver(this); - - const std::string& service_id = service->GetIdentifier(); - observed_gatt_services_.insert(service_id); - service_id_to_device_address_[service_id] = device->GetAddress(); + service_id_to_device_address_[service->GetIdentifier()] = + device->GetAddress(); } void BluetoothLowEnergyEventRouter::GattServiceRemoved( + BluetoothAdapter* adapter, BluetoothDevice* device, BluetoothGattService* service) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + DCHECK_EQ(adapter, adapter_); VLOG(2) << "GATT service removed: " << service->GetIdentifier(); - DCHECK(observed_gatt_services_.find(service->GetIdentifier()) != - observed_gatt_services_.end()); DCHECK(service_id_to_device_address_.find(service->GetIdentifier()) != service_id_to_device_address_.end()); - service->RemoveObserver(this); - observed_gatt_services_.erase(service->GetIdentifier()); - DCHECK(device->GetAddress() == service_id_to_device_address_[service->GetIdentifier()]); service_id_to_device_address_.erase(service->GetIdentifier()); @@ -887,12 +843,12 @@ void BluetoothLowEnergyEventRouter::GattServiceRemoved( } void BluetoothLowEnergyEventRouter::GattDiscoveryCompleteForService( + BluetoothAdapter* adapter, BluetoothGattService* service) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + DCHECK_EQ(adapter, adapter_); VLOG(2) << "GATT service discovery complete: " << service->GetIdentifier(); - DCHECK(observed_gatt_services_.find(service->GetIdentifier()) != - observed_gatt_services_.end()); DCHECK(service_id_to_device_address_.find(service->GetIdentifier()) != service_id_to_device_address_.end()); @@ -908,12 +864,11 @@ void BluetoothLowEnergyEventRouter::GattDiscoveryCompleteForService( } void BluetoothLowEnergyEventRouter::GattServiceChanged( + BluetoothAdapter* adapter, BluetoothGattService* service) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + DCHECK_EQ(adapter, adapter_); VLOG(2) << "GATT service changed: " << service->GetIdentifier(); - - DCHECK(observed_gatt_services_.find(service->GetIdentifier()) != - observed_gatt_services_.end()); DCHECK(service_id_to_device_address_.find(service->GetIdentifier()) != service_id_to_device_address_.end()); @@ -929,11 +884,15 @@ void BluetoothLowEnergyEventRouter::GattServiceChanged( } void BluetoothLowEnergyEventRouter::GattCharacteristicAdded( - BluetoothGattService* service, + BluetoothAdapter* adapter, BluetoothGattCharacteristic* characteristic) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + DCHECK_EQ(adapter, adapter_); VLOG(2) << "GATT characteristic added: " << characteristic->GetIdentifier(); + BluetoothGattService* service = characteristic->GetService(); + DCHECK(service); + DCHECK(chrc_id_to_service_id_.find(characteristic->GetIdentifier()) == chrc_id_to_service_id_.end()); DCHECK(service_id_to_device_address_.find(service->GetIdentifier()) != @@ -944,11 +903,15 @@ void BluetoothLowEnergyEventRouter::GattCharacteristicAdded( } void BluetoothLowEnergyEventRouter::GattCharacteristicRemoved( - BluetoothGattService* service, + BluetoothAdapter* adapter, BluetoothGattCharacteristic* characteristic) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + DCHECK_EQ(adapter, adapter_); VLOG(2) << "GATT characteristic removed: " << characteristic->GetIdentifier(); + BluetoothGattService* service = characteristic->GetService(); + DCHECK(service); + DCHECK(chrc_id_to_service_id_.find(characteristic->GetIdentifier()) != chrc_id_to_service_id_.end()); DCHECK(service->GetIdentifier() == @@ -958,11 +921,15 @@ void BluetoothLowEnergyEventRouter::GattCharacteristicRemoved( } void BluetoothLowEnergyEventRouter::GattDescriptorAdded( - BluetoothGattCharacteristic* characteristic, + BluetoothAdapter* adapter, BluetoothGattDescriptor* descriptor) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + DCHECK_EQ(adapter, adapter_); VLOG(2) << "GATT descriptor added: " << descriptor->GetIdentifier(); + BluetoothGattCharacteristic* characteristic = descriptor->GetCharacteristic(); + DCHECK(characteristic); + DCHECK(desc_id_to_chrc_id_.find(descriptor->GetIdentifier()) == desc_id_to_chrc_id_.end()); DCHECK(chrc_id_to_service_id_.find(characteristic->GetIdentifier()) != @@ -973,11 +940,15 @@ void BluetoothLowEnergyEventRouter::GattDescriptorAdded( } void BluetoothLowEnergyEventRouter::GattDescriptorRemoved( - BluetoothGattCharacteristic* characteristic, + BluetoothAdapter* adapter, BluetoothGattDescriptor* descriptor) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + DCHECK_EQ(adapter, adapter_); VLOG(2) << "GATT descriptor removed: " << descriptor->GetIdentifier(); + BluetoothGattCharacteristic* characteristic = descriptor->GetCharacteristic(); + DCHECK(characteristic); + DCHECK(desc_id_to_chrc_id_.find(descriptor->GetIdentifier()) != desc_id_to_chrc_id_.end()); DCHECK(characteristic->GetIdentifier() == @@ -987,15 +958,17 @@ void BluetoothLowEnergyEventRouter::GattDescriptorRemoved( } void BluetoothLowEnergyEventRouter::GattCharacteristicValueChanged( - BluetoothGattService* service, + BluetoothAdapter* adapter, BluetoothGattCharacteristic* characteristic, const std::vector<uint8>& value) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + DCHECK_EQ(adapter, adapter_); VLOG(2) << "GATT characteristic value changed: " << characteristic->GetIdentifier(); - DCHECK(observed_gatt_services_.find(service->GetIdentifier()) != - observed_gatt_services_.end()); + BluetoothGattService* service = characteristic->GetService(); + DCHECK(service); + DCHECK(service_id_to_device_address_.find(service->GetIdentifier()) != service_id_to_device_address_.end()); DCHECK(chrc_id_to_service_id_.find(characteristic->GetIdentifier()) != @@ -1019,12 +992,16 @@ void BluetoothLowEnergyEventRouter::GattCharacteristicValueChanged( } void BluetoothLowEnergyEventRouter::GattDescriptorValueChanged( - BluetoothGattCharacteristic* characteristic, + BluetoothAdapter* adapter, BluetoothGattDescriptor* descriptor, const std::vector<uint8>& value) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + DCHECK_EQ(adapter, adapter_); VLOG(2) << "GATT descriptor value changed: " << descriptor->GetIdentifier(); + BluetoothGattCharacteristic* characteristic = descriptor->GetCharacteristic(); + DCHECK(characteristic); + DCHECK(desc_id_to_chrc_id_.find(descriptor->GetIdentifier()) != desc_id_to_chrc_id_.end()); DCHECK(characteristic->GetIdentifier() == @@ -1062,8 +1039,6 @@ void BluetoothLowEnergyEventRouter::InitializeIdentifierMappings() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(service_id_to_device_address_.empty()); DCHECK(chrc_id_to_service_id_.empty()); - DCHECK(observed_devices_.empty()); - DCHECK(observed_gatt_services_.empty()); // Devices BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); @@ -1071,8 +1046,6 @@ void BluetoothLowEnergyEventRouter::InitializeIdentifierMappings() { iter != devices.end(); ++iter) { BluetoothDevice* device = *iter; - device->AddObserver(this); - observed_devices_.insert(device->GetAddress()); // Services std::vector<BluetoothGattService*> services = device->GetGattServices(); @@ -1080,10 +1053,8 @@ void BluetoothLowEnergyEventRouter::InitializeIdentifierMappings() { siter != services.end(); ++siter) { BluetoothGattService* service = *siter; - service->AddObserver(this); const std::string& service_id = service->GetIdentifier(); - observed_gatt_services_.insert(service_id); service_id_to_device_address_[service_id] = device->GetAddress(); // Characteristics diff --git a/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_event_router.h b/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_event_router.h index c7a169a..8445ad3 100644 --- a/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_event_router.h +++ b/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_event_router.h @@ -46,9 +46,7 @@ class Extension; // The BluetoothLowEnergyEventRouter is used by the bluetoothLowEnergy API to // interface with the internal Bluetooth API in device/bluetooth. class BluetoothLowEnergyEventRouter - : public device::BluetoothAdapter::Observer, - public device::BluetoothDevice::Observer, - public device::BluetoothGattService::Observer { + : public device::BluetoothAdapter::Observer { public: explicit BluetoothLowEnergyEventRouter(content::BrowserContext* context); virtual ~BluetoothLowEnergyEventRouter(); @@ -228,41 +226,37 @@ class BluetoothLowEnergyEventRouter void SetAdapterForTesting(device::BluetoothAdapter* adapter); // device::BluetoothAdapter::Observer overrides. - virtual void DeviceAdded(device::BluetoothAdapter* adapter, - device::BluetoothDevice* device) OVERRIDE; - virtual void DeviceRemoved(device::BluetoothAdapter* adapter, - device::BluetoothDevice* device) OVERRIDE; - - // device::BluetoothDevice::Observer overrides. - virtual void GattServiceAdded(device::BluetoothDevice* device, + virtual void GattServiceAdded(device::BluetoothAdapter* adapter, + device::BluetoothDevice* device, device::BluetoothGattService* service) OVERRIDE; virtual void GattServiceRemoved( + device::BluetoothAdapter* adapter, device::BluetoothDevice* device, device::BluetoothGattService* service) OVERRIDE; - - // device::BluetoothGattService::Observer overrides. virtual void GattDiscoveryCompleteForService( + device::BluetoothAdapter* adapter, device::BluetoothGattService* service) OVERRIDE; virtual void GattServiceChanged( + device::BluetoothAdapter* adapter, device::BluetoothGattService* service) OVERRIDE; virtual void GattCharacteristicAdded( - device::BluetoothGattService* service, + device::BluetoothAdapter* adapter, device::BluetoothGattCharacteristic* characteristic) OVERRIDE; virtual void GattCharacteristicRemoved( - device::BluetoothGattService* service, + device::BluetoothAdapter* adapter, device::BluetoothGattCharacteristic* characteristic) OVERRIDE; virtual void GattDescriptorAdded( - device::BluetoothGattCharacteristic* characteristic, + device::BluetoothAdapter* adapter, device::BluetoothGattDescriptor* descriptor) OVERRIDE; virtual void GattDescriptorRemoved( - device::BluetoothGattCharacteristic* characteristic, + device::BluetoothAdapter* adapter, device::BluetoothGattDescriptor* descriptor) OVERRIDE; virtual void GattCharacteristicValueChanged( - device::BluetoothGattService* service, + device::BluetoothAdapter* adapter, device::BluetoothGattCharacteristic* characteristic, const std::vector<uint8>& value) OVERRIDE; virtual void GattDescriptorValueChanged( - device::BluetoothGattCharacteristic* characteristic, + device::BluetoothAdapter* adapter, device::BluetoothGattDescriptor* descriptor, const std::vector<uint8>& value) OVERRIDE; @@ -394,12 +388,6 @@ class BluetoothLowEnergyEventRouter InstanceIdMap chrc_id_to_service_id_; InstanceIdMap desc_id_to_chrc_id_; - // Sets of BluetoothDevice and BluetoothGattService objects that are being - // observed, used to remove the BluetoothLowEnergyEventRouter as an observer - // during clean up. - std::set<std::string> observed_devices_; - std::set<std::string> observed_gatt_services_; - // Pointer to the current BluetoothAdapter instance. This represents a local // Bluetooth adapter of the system. scoped_refptr<device::BluetoothAdapter> adapter_; diff --git a/device/bluetooth/bluetooth_adapter.h b/device/bluetooth/bluetooth_adapter.h index 75d1bcc..140ba14 100644 --- a/device/bluetooth/bluetooth_adapter.h +++ b/device/bluetooth/bluetooth_adapter.h @@ -19,6 +19,9 @@ namespace device { class BluetoothDiscoverySession; +class BluetoothGattCharacteristic; +class BluetoothGattDescriptor; +class BluetoothGattService; class BluetoothSocket; class BluetoothUUID; @@ -77,6 +80,81 @@ class BluetoothAdapter : public base::RefCounted<BluetoothAdapter> { // cached. Instead, copy its Bluetooth address. virtual void DeviceRemoved(BluetoothAdapter* adapter, BluetoothDevice* device) {} + + // Called when a new GATT service |service| is added to the device |device|, + // as the service is received from the device. Don't cache |service|. Store + // its identifier instead (i.e. BluetoothGattService::GetIdentifier). + virtual void GattServiceAdded(BluetoothAdapter* adapter, + BluetoothDevice* device, + BluetoothGattService* service) {} + + // Called when the GATT service |service| is removed from the device + // |device|. This can happen if the attribute database of the remote device + // changes or when |device| gets removed. + virtual void GattServiceRemoved(BluetoothAdapter* adapter, + BluetoothDevice* device, + BluetoothGattService* service) {} + + // Called when all characteristic and descriptor discovery procedures are + // known to be completed for the GATT service |service|. This method will be + // called after the initial discovery of a GATT service and will usually be + // preceded by calls to GattCharacteristicAdded and GattDescriptorAdded. + virtual void GattDiscoveryCompleteForService( + BluetoothAdapter* adapter, + BluetoothGattService* service) {} + + // Called when properties of the remote GATT service |service| have changed. + // This will get called for properties such as UUID, as well as for changes + // to the list of known characteristics and included services. Observers + // should read all GATT characteristic and descriptors objects and do any + // necessary set up required for a changed service. + virtual void GattServiceChanged(BluetoothAdapter* adapter, + BluetoothGattService* service) {} + + // Called when the remote GATT characteristic |characteristic| has been + // discovered. Use this to issue any initial read/write requests to the + // characteristic but don't cache the pointer as it may become invalid. + // Instead, use the specially assigned identifier to obtain a characteristic + // and cache that identifier as necessary, as it can be used to retrieve the + // characteristic from its GATT service. The number of characteristics with + // the same UUID belonging to a service depends on the particular profile + // the remote device implements, hence the client of a GATT based profile + // will usually operate on the whole set of characteristics and not just + // one. + virtual void GattCharacteristicAdded( + BluetoothAdapter* adapter, + BluetoothGattCharacteristic* characteristic) {} + + // Called when a GATT characteristic |characteristic| has been removed from + // the system. + virtual void GattCharacteristicRemoved( + BluetoothAdapter* adapter, + BluetoothGattCharacteristic* characteristic) {} + + // Called when the remote GATT characteristic descriptor |descriptor| has + // been discovered. Don't cache the arguments as the pointers may become + // invalid. Instead, use the specially assigned identifier to obtain a + // descriptor and cache that identifier as necessary. + virtual void GattDescriptorAdded(BluetoothAdapter* adapter, + BluetoothGattDescriptor* descriptor) {} + + // Called when a GATT characteristic descriptor |descriptor| has been + // removed from the system. + virtual void GattDescriptorRemoved(BluetoothAdapter* adapter, + BluetoothGattDescriptor* descriptor) {} + + // Called when the value of a characteristic has changed. This might be a + // result of a read/write request to, or a notification/indication from, a + // remote GATT characteristic. + virtual void GattCharacteristicValueChanged( + BluetoothAdapter* adapter, + BluetoothGattCharacteristic* characteristic, + const std::vector<uint8>& value) {} + + // Called when the value of a characteristic descriptor has been updated. + virtual void GattDescriptorValueChanged(BluetoothAdapter* adapter, + BluetoothGattDescriptor* descriptor, + const std::vector<uint8>& value) {} }; // Used to configure a listening servie. diff --git a/device/bluetooth/bluetooth_adapter_chromeos.cc b/device/bluetooth/bluetooth_adapter_chromeos.cc index bdfa4ce..a5f1a98 100644 --- a/device/bluetooth/bluetooth_adapter_chromeos.cc +++ b/device/bluetooth/bluetooth_adapter_chromeos.cc @@ -22,6 +22,9 @@ #include "device/bluetooth/bluetooth_device.h" #include "device/bluetooth/bluetooth_device_chromeos.h" #include "device/bluetooth/bluetooth_pairing_chromeos.h" +#include "device/bluetooth/bluetooth_remote_gatt_characteristic_chromeos.h" +#include "device/bluetooth/bluetooth_remote_gatt_descriptor_chromeos.h" +#include "device/bluetooth/bluetooth_remote_gatt_service_chromeos.h" #include "device/bluetooth/bluetooth_socket_chromeos.h" #include "device/bluetooth/bluetooth_socket_thread.h" #include "device/bluetooth/bluetooth_uuid.h" @@ -752,6 +755,117 @@ void BluetoothAdapterChromeOS::NotifyDeviceChanged( DeviceChanged(this, device)); } +void BluetoothAdapterChromeOS::NotifyGattServiceAdded( + BluetoothRemoteGattServiceChromeOS* service) { + DCHECK_EQ(service->GetAdapter(), this); + DCHECK_EQ( + static_cast<BluetoothDeviceChromeOS*>(service->GetDevice())->adapter_, + this); + + FOR_EACH_OBSERVER(BluetoothAdapter::Observer, + observers_, + GattServiceAdded(this, service->GetDevice(), service)); +} + +void BluetoothAdapterChromeOS::NotifyGattServiceRemoved( + BluetoothRemoteGattServiceChromeOS* service) { + DCHECK_EQ(service->GetAdapter(), this); + DCHECK_EQ( + static_cast<BluetoothDeviceChromeOS*>(service->GetDevice())->adapter_, + this); + + FOR_EACH_OBSERVER(BluetoothAdapter::Observer, + observers_, + GattServiceRemoved(this, service->GetDevice(), service)); +} + +void BluetoothAdapterChromeOS::NotifyGattServiceChanged( + BluetoothRemoteGattServiceChromeOS* service) { + DCHECK_EQ(service->GetAdapter(), this); + + FOR_EACH_OBSERVER(BluetoothAdapter::Observer, + observers_, + GattServiceChanged(this, service)); +} + +void BluetoothAdapterChromeOS::NotifyGattDiscoveryComplete( + BluetoothRemoteGattServiceChromeOS* service) { + DCHECK_EQ(service->GetAdapter(), this); + + FOR_EACH_OBSERVER(BluetoothAdapter::Observer, + observers_, + GattDiscoveryCompleteForService(this, service)); +} + +void BluetoothAdapterChromeOS::NotifyGattCharacteristicAdded( + BluetoothRemoteGattCharacteristicChromeOS* characteristic) { + DCHECK_EQ(static_cast<BluetoothRemoteGattServiceChromeOS*>( + characteristic->GetService())->GetAdapter(), + this); + + FOR_EACH_OBSERVER(BluetoothAdapter::Observer, + observers_, + GattCharacteristicAdded(this, characteristic)); +} + +void BluetoothAdapterChromeOS::NotifyGattCharacteristicRemoved( + BluetoothRemoteGattCharacteristicChromeOS* characteristic) { + DCHECK_EQ(static_cast<BluetoothRemoteGattServiceChromeOS*>( + characteristic->GetService())->GetAdapter(), + this); + + FOR_EACH_OBSERVER(BluetoothAdapter::Observer, + observers_, + GattCharacteristicRemoved(this, characteristic)); +} + +void BluetoothAdapterChromeOS::NotifyGattDescriptorAdded( + BluetoothRemoteGattDescriptorChromeOS* descriptor) { + DCHECK_EQ(static_cast<BluetoothRemoteGattServiceChromeOS*>( + descriptor->GetCharacteristic()->GetService())->GetAdapter(), + this); + + FOR_EACH_OBSERVER(BluetoothAdapter::Observer, + observers_, + GattDescriptorAdded(this, descriptor)); +} + +void BluetoothAdapterChromeOS::NotifyGattDescriptorRemoved( + BluetoothRemoteGattDescriptorChromeOS* descriptor) { + DCHECK_EQ(static_cast<BluetoothRemoteGattServiceChromeOS*>( + descriptor->GetCharacteristic()->GetService())->GetAdapter(), + this); + + FOR_EACH_OBSERVER(BluetoothAdapter::Observer, + observers_, + GattDescriptorRemoved(this, descriptor)); +} + +void BluetoothAdapterChromeOS::NotifyGattCharacteristicValueChanged( + BluetoothRemoteGattCharacteristicChromeOS* characteristic, + const std::vector<uint8>& value) { + DCHECK_EQ(static_cast<BluetoothRemoteGattServiceChromeOS*>( + characteristic->GetService())->GetAdapter(), + this); + + FOR_EACH_OBSERVER( + BluetoothAdapter::Observer, + observers_, + GattCharacteristicValueChanged(this, characteristic, value)); +} + +void BluetoothAdapterChromeOS::NotifyGattDescriptorValueChanged( + BluetoothRemoteGattDescriptorChromeOS* descriptor, + const std::vector<uint8>& value) { + DCHECK_EQ(static_cast<BluetoothRemoteGattServiceChromeOS*>( + descriptor->GetCharacteristic()->GetService())->GetAdapter(), + this); + + FOR_EACH_OBSERVER(BluetoothAdapter::Observer, + observers_, + GattDescriptorValueChanged(this, descriptor, value)); +} + void BluetoothAdapterChromeOS::OnSetDiscoverable( const base::Closure& callback, const ErrorCallback& error_callback, diff --git a/device/bluetooth/bluetooth_adapter_chromeos.h b/device/bluetooth/bluetooth_adapter_chromeos.h index 87518bd..7e1e50e 100644 --- a/device/bluetooth/bluetooth_adapter_chromeos.h +++ b/device/bluetooth/bluetooth_adapter_chromeos.h @@ -27,6 +27,9 @@ namespace chromeos { class BluetoothChromeOSTest; class BluetoothDeviceChromeOS; class BluetoothPairingChromeOS; +class BluetoothRemoteGattCharacteristicChromeOS; +class BluetoothRemoteGattDescriptorChromeOS; +class BluetoothRemoteGattServiceChromeOS; // The BluetoothAdapterChromeOS class implements BluetoothAdapter for the // Chrome OS platform. @@ -82,6 +85,27 @@ class BluetoothAdapterChromeOS // its D-Bus properties. void NotifyDeviceChanged(BluetoothDeviceChromeOS* device); + // The following methods are used to send various GATT observer events to + // observers. + void NotifyGattServiceAdded(BluetoothRemoteGattServiceChromeOS* service); + void NotifyGattServiceRemoved(BluetoothRemoteGattServiceChromeOS* service); + void NotifyGattServiceChanged(BluetoothRemoteGattServiceChromeOS* service); + void NotifyGattDiscoveryComplete(BluetoothRemoteGattServiceChromeOS* service); + void NotifyGattCharacteristicAdded( + BluetoothRemoteGattCharacteristicChromeOS* characteristic); + void NotifyGattCharacteristicRemoved( + BluetoothRemoteGattCharacteristicChromeOS* characteristic); + void NotifyGattDescriptorAdded( + BluetoothRemoteGattDescriptorChromeOS* descriptor); + void NotifyGattDescriptorRemoved( + BluetoothRemoteGattDescriptorChromeOS* descriptor); + void NotifyGattCharacteristicValueChanged( + BluetoothRemoteGattCharacteristicChromeOS* characteristic, + const std::vector<uint8>& value); + void NotifyGattDescriptorValueChanged( + BluetoothRemoteGattDescriptorChromeOS* descriptor, + const std::vector<uint8>& value); + // Returns the object path of the adapter. const dbus::ObjectPath& object_path() const { return object_path_; } diff --git a/device/bluetooth/bluetooth_device.h b/device/bluetooth/bluetooth_device.h index 582caf3..4557f3b 100644 --- a/device/bluetooth/bluetooth_device.h +++ b/device/bluetooth/bluetooth_device.h @@ -81,26 +81,6 @@ class BluetoothDevice { ERROR_UNSUPPORTED_DEVICE }; - // Interface for observing changes from bluetooth devices. - class Observer { - public: - virtual ~Observer() {} - - // Called when a new GATT service |service| is added to the device |device|, - // as the service is received from the device. Don't cache |service|. Store - // its identifier instead (i.e. BluetoothGattService::GetIdentifier). - virtual void GattServiceAdded(BluetoothDevice* device, - BluetoothGattService* service) {} - - // Called when the GATT service |service| is removed from the device - // |device|. This can happen if the attribute database of the remote device - // changes or when |device| gets removed. - virtual void GattServiceRemoved(BluetoothDevice* device, - BluetoothGattService* service) {} - - // TODO(keybuk): add observers for pairing and connection. - }; - // Interface for negotiating pairing of bluetooth devices. class PairingDelegate { public: @@ -190,12 +170,6 @@ class BluetoothDevice { virtual ~BluetoothDevice(); - // Adds and removes observers for events on this Bluetooth device. If - // monitoring multiple devices, check the |device| parameter of the observer - // methods to determine which device is issuing the event. - virtual void AddObserver(Observer* observer) = 0; - virtual void RemoveObserver(Observer* observer) = 0; - // Returns the Bluetooth class of the device, used by GetDeviceType() // and metrics logging, virtual uint32 GetBluetoothClass() const = 0; diff --git a/device/bluetooth/bluetooth_device_chromeos.cc b/device/bluetooth/bluetooth_device_chromeos.cc index f607247..0f1f273 100644 --- a/device/bluetooth/bluetooth_device_chromeos.cc +++ b/device/bluetooth/bluetooth_device_chromeos.cc @@ -153,24 +153,13 @@ BluetoothDeviceChromeOS::~BluetoothDeviceChromeOS() { gatt_services_.clear(); for (GattServiceMap::iterator iter = gatt_services.begin(); iter != gatt_services.end(); ++iter) { - FOR_EACH_OBSERVER(BluetoothDevice::Observer, observers_, - GattServiceRemoved(this, iter->second)); + DCHECK(adapter_); + adapter_->NotifyGattServiceRemoved( + static_cast<BluetoothRemoteGattServiceChromeOS*>(iter->second)); delete iter->second; } } -void BluetoothDeviceChromeOS::AddObserver( - device::BluetoothDevice::Observer* observer) { - DCHECK(observer); - observers_.AddObserver(observer); -} - -void BluetoothDeviceChromeOS::RemoveObserver( - device::BluetoothDevice::Observer* observer) { - DCHECK(observer); - observers_.RemoveObserver(observer); -} - uint32 BluetoothDeviceChromeOS::GetBluetoothClass() const { BluetoothDeviceClient::Properties* properties = DBusThreadManager::Get()->GetBluetoothDeviceClient()-> @@ -510,8 +499,8 @@ void BluetoothDeviceChromeOS::GattServiceAdded( DCHECK(service->object_path() == object_path); DCHECK(service->GetUUID().IsValid()); - FOR_EACH_OBSERVER(device::BluetoothDevice::Observer, observers_, - GattServiceAdded(this, service)); + DCHECK(adapter_); + adapter_->NotifyGattServiceAdded(service); } void BluetoothDeviceChromeOS::GattServiceRemoved( @@ -528,8 +517,10 @@ void BluetoothDeviceChromeOS::GattServiceRemoved( static_cast<BluetoothRemoteGattServiceChromeOS*>(iter->second); DCHECK(service->object_path() == object_path); gatt_services_.erase(iter); - FOR_EACH_OBSERVER(device::BluetoothDevice::Observer, observers_, - GattServiceRemoved(this, service)); + + DCHECK(adapter_); + adapter_->NotifyGattServiceRemoved(service); + delete service; } diff --git a/device/bluetooth/bluetooth_device_chromeos.h b/device/bluetooth/bluetooth_device_chromeos.h index b7247f5..6f33560 100644 --- a/device/bluetooth/bluetooth_device_chromeos.h +++ b/device/bluetooth/bluetooth_device_chromeos.h @@ -10,7 +10,6 @@ #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" -#include "base/observer_list.h" #include "base/sequenced_task_runner.h" #include "chromeos/dbus/bluetooth_device_client.h" #include "chromeos/dbus/bluetooth_gatt_service_client.h" @@ -33,10 +32,6 @@ class BluetoothDeviceChromeOS public BluetoothGattServiceClient::Observer { public: // BluetoothDevice override - virtual void AddObserver( - device::BluetoothDevice::Observer* observer) OVERRIDE; - virtual void RemoveObserver( - device::BluetoothDevice::Observer* observer) OVERRIDE; virtual uint32 GetBluetoothClass() const OVERRIDE; virtual std::string GetAddress() const OVERRIDE; virtual VendorIDSource GetVendorIDSource() const OVERRIDE; @@ -172,9 +167,6 @@ class BluetoothDeviceChromeOS // The dbus object path of the device object. dbus::ObjectPath object_path_; - // List of observers interested in event notifications from us. - ObserverList<device::BluetoothDevice::Observer> observers_; - // Number of ongoing calls to Connect(). int num_connecting_calls_; diff --git a/device/bluetooth/bluetooth_device_mac.h b/device/bluetooth/bluetooth_device_mac.h index 68380c2..b107573 100644 --- a/device/bluetooth/bluetooth_device_mac.h +++ b/device/bluetooth/bluetooth_device_mac.h @@ -24,10 +24,6 @@ class BluetoothDeviceMac : public BluetoothDevice { virtual ~BluetoothDeviceMac(); // BluetoothDevice override - virtual void AddObserver( - device::BluetoothDevice::Observer* observer) OVERRIDE; - virtual void RemoveObserver( - device::BluetoothDevice::Observer* observer) OVERRIDE; virtual uint32 GetBluetoothClass() const OVERRIDE; virtual std::string GetAddress() const OVERRIDE; virtual VendorIDSource GetVendorIDSource() const OVERRIDE; @@ -89,9 +85,6 @@ class BluetoothDeviceMac : public BluetoothDevice { int GetHostTransmitPower( BluetoothHCITransmitPowerLevelType power_level_type) const; - // List of observers interested in event notifications from us. - ObserverList<Observer> observers_; - base::scoped_nsobject<IOBluetoothDevice> device_; DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceMac); diff --git a/device/bluetooth/bluetooth_device_mac.mm b/device/bluetooth/bluetooth_device_mac.mm index a913300..888ae69 100644 --- a/device/bluetooth/bluetooth_device_mac.mm +++ b/device/bluetooth/bluetooth_device_mac.mm @@ -63,18 +63,6 @@ BluetoothDeviceMac::BluetoothDeviceMac(IOBluetoothDevice* device) BluetoothDeviceMac::~BluetoothDeviceMac() { } -void BluetoothDeviceMac::AddObserver( - device::BluetoothDevice::Observer* observer) { - DCHECK(observer); - observers_.AddObserver(observer); -} - -void BluetoothDeviceMac::RemoveObserver( - device::BluetoothDevice::Observer* observer) { - DCHECK(observer); - observers_.RemoveObserver(observer); -} - uint32 BluetoothDeviceMac::GetBluetoothClass() const { return [device_ classOfDevice]; } diff --git a/device/bluetooth/bluetooth_device_win.cc b/device/bluetooth/bluetooth_device_win.cc index b4c78162..db79c6a 100644 --- a/device/bluetooth/bluetooth_device_win.cc +++ b/device/bluetooth/bluetooth_device_win.cc @@ -61,19 +61,6 @@ void BluetoothDeviceWin::SetVisible(bool visible) { visible_ = visible; } -void BluetoothDeviceWin::AddObserver( - device::BluetoothDevice::Observer* observer) { - DCHECK(observer); - observers_.AddObserver(observer); -} - -void BluetoothDeviceWin::RemoveObserver( - device::BluetoothDevice::Observer* observer) { - DCHECK(observer); - observers_.RemoveObserver(observer); -} - - uint32 BluetoothDeviceWin::GetBluetoothClass() const { return bluetooth_class_; } diff --git a/device/bluetooth/bluetooth_device_win.h b/device/bluetooth/bluetooth_device_win.h index b403cf6..aa262bd 100644 --- a/device/bluetooth/bluetooth_device_win.h +++ b/device/bluetooth/bluetooth_device_win.h @@ -30,10 +30,6 @@ class BluetoothDeviceWin : public BluetoothDevice { virtual ~BluetoothDeviceWin(); // BluetoothDevice override - virtual void AddObserver( - device::BluetoothDevice::Observer* observer) OVERRIDE; - virtual void RemoveObserver( - device::BluetoothDevice::Observer* observer) OVERRIDE; virtual uint32 GetBluetoothClass() const OVERRIDE; virtual std::string GetAddress() const OVERRIDE; virtual VendorIDSource GetVendorIDSource() const OVERRIDE; @@ -96,9 +92,6 @@ class BluetoothDeviceWin : public BluetoothDevice { net::NetLog* net_log_; net::NetLog::Source net_log_source_; - // List of observers interested in event notifications from us. - ObserverList<Observer> observers_; - // The Bluetooth class of the device, a bitmask that may be decoded using // https://www.bluetooth.org/Technical/AssignedNumbers/baseband.htm uint32 bluetooth_class_; diff --git a/device/bluetooth/bluetooth_gatt_chromeos_unittest.cc b/device/bluetooth/bluetooth_gatt_chromeos_unittest.cc index a585f81..d3f78cb 100644 --- a/device/bluetooth/bluetooth_gatt_chromeos_unittest.cc +++ b/device/bluetooth/bluetooth_gatt_chromeos_unittest.cc @@ -57,28 +57,33 @@ bool ValuesEqual(const std::vector<uint8>& value0, return true; } -class TestDeviceObserver : public BluetoothDevice::Observer { +class TestObserver : public BluetoothAdapter::Observer { public: - TestDeviceObserver(scoped_refptr<BluetoothAdapter> adapter, - BluetoothDevice* device) + TestObserver(scoped_refptr<BluetoothAdapter> adapter) : gatt_service_added_count_(0), gatt_service_removed_count_(0), - device_address_(device->GetAddress()), + gatt_service_changed_count_(0), + gatt_discovery_complete_count_(0), + gatt_characteristic_added_count_(0), + gatt_characteristic_removed_count_(0), + gatt_characteristic_value_changed_count_(0), + gatt_descriptor_added_count_(0), + gatt_descriptor_removed_count_(0), + gatt_descriptor_value_changed_count_(0), adapter_(adapter) { - device->AddObserver(this); + adapter_->AddObserver(this); } - virtual ~TestDeviceObserver() { - BluetoothDevice* device = adapter_->GetDevice(device_address_); - if (device) - device->RemoveObserver(this); + virtual ~TestObserver() { + adapter_->RemoveObserver(this); } - // BluetoothDevice::Observer overrides. - virtual void GattServiceAdded( - BluetoothDevice* device, - BluetoothGattService* service) OVERRIDE { - ASSERT_EQ(device_address_, device->GetAddress()); + // BluetoothAdapter::Observer overrides. + virtual void GattServiceAdded(BluetoothAdapter* adapter, + BluetoothDevice* device, + BluetoothGattService* service) OVERRIDE { + ASSERT_EQ(adapter_.get(), adapter); + ASSERT_EQ(service->GetDevice(), device); ++gatt_service_added_count_; last_gatt_service_id_ = service->GetIdentifier(); @@ -92,10 +97,11 @@ class TestDeviceObserver : public BluetoothDevice::Observer { QuitMessageLoop(); } - virtual void GattServiceRemoved( - BluetoothDevice* device, - BluetoothGattService* service) OVERRIDE { - ASSERT_EQ(device_address_, device->GetAddress()); + virtual void GattServiceRemoved(BluetoothAdapter* adapter, + BluetoothDevice* device, + BluetoothGattService* service) OVERRIDE { + ASSERT_EQ(adapter_.get(), adapter); + ASSERT_EQ(service->GetDevice(), device); ++gatt_service_removed_count_; last_gatt_service_id_ = service->GetIdentifier(); @@ -110,172 +116,131 @@ class TestDeviceObserver : public BluetoothDevice::Observer { QuitMessageLoop(); } - int gatt_service_added_count_; - int gatt_service_removed_count_; - std::string last_gatt_service_id_; - BluetoothUUID last_gatt_service_uuid_; - - private: - // Some tests use a message loop since background processing is simulated; - // break out of those loops. - void QuitMessageLoop() { - if (base::MessageLoop::current() && - base::MessageLoop::current()->is_running()) - base::MessageLoop::current()->Quit(); - } - - std::string device_address_; - scoped_refptr<BluetoothAdapter> adapter_; -}; - -class TestGattServiceObserver : public BluetoothGattService::Observer { - public: - TestGattServiceObserver(scoped_refptr<BluetoothAdapter> adapter, - BluetoothDevice* device, - BluetoothGattService* service) - : gatt_service_changed_count_(0), - gatt_discovery_complete_count_(0), - gatt_characteristic_added_count_(0), - gatt_characteristic_removed_count_(0), - gatt_characteristic_value_changed_count_(0), - gatt_descriptor_added_count_(0), - gatt_descriptor_removed_count_(0), - gatt_descriptor_value_changed_count_(0), - device_address_(device->GetAddress()), - gatt_service_id_(service->GetIdentifier()), - adapter_(adapter) { - service->AddObserver(this); - } - - virtual ~TestGattServiceObserver() { - // See if either the device or the service even exist. - BluetoothDevice* device = adapter_->GetDevice(device_address_); - if (!device) - return; - - BluetoothGattService* service = device->GetGattService(gatt_service_id_); - if (!service) - return; - - service->RemoveObserver(this); - } - - // BluetoothGattService::Observer overrides. virtual void GattDiscoveryCompleteForService( + BluetoothAdapter* adapter, BluetoothGattService* service) OVERRIDE { - ASSERT_EQ(gatt_service_id_, service->GetIdentifier()); + ASSERT_EQ(adapter_.get(), adapter); ++gatt_discovery_complete_count_; QuitMessageLoop(); } - virtual void GattServiceChanged(BluetoothGattService* service) OVERRIDE { - ASSERT_EQ(gatt_service_id_, service->GetIdentifier()); + virtual void GattServiceChanged(BluetoothAdapter* adapter, + BluetoothGattService* service) OVERRIDE { + ASSERT_EQ(adapter_.get(), adapter); ++gatt_service_changed_count_; QuitMessageLoop(); } virtual void GattCharacteristicAdded( - BluetoothGattService* service, + BluetoothAdapter* adapter, BluetoothGattCharacteristic* characteristic) OVERRIDE { - ASSERT_EQ(gatt_service_id_, service->GetIdentifier()); + ASSERT_EQ(adapter_.get(), adapter); ++gatt_characteristic_added_count_; last_gatt_characteristic_id_ = characteristic->GetIdentifier(); last_gatt_characteristic_uuid_ = characteristic->GetUUID(); - EXPECT_EQ(service->GetCharacteristic(last_gatt_characteristic_id_), + ASSERT_TRUE(characteristic->GetService()); + EXPECT_EQ(characteristic->GetService()->GetCharacteristic( + last_gatt_characteristic_id_), characteristic); - EXPECT_EQ(service, characteristic->GetService()); QuitMessageLoop(); } virtual void GattCharacteristicRemoved( - BluetoothGattService* service, + BluetoothAdapter* adapter, BluetoothGattCharacteristic* characteristic) OVERRIDE { - ASSERT_EQ(gatt_service_id_, service->GetIdentifier()); + ASSERT_EQ(adapter_.get(), adapter); ++gatt_characteristic_removed_count_; last_gatt_characteristic_id_ = characteristic->GetIdentifier(); last_gatt_characteristic_uuid_ = characteristic->GetUUID(); // The service should return NULL for this characteristic. - EXPECT_FALSE(service->GetCharacteristic(last_gatt_characteristic_id_)); - EXPECT_EQ(service, characteristic->GetService()); + ASSERT_TRUE(characteristic->GetService()); + EXPECT_FALSE(characteristic->GetService()->GetCharacteristic( + last_gatt_characteristic_id_)); QuitMessageLoop(); } virtual void GattCharacteristicValueChanged( - BluetoothGattService* service, + BluetoothAdapter* adapter, BluetoothGattCharacteristic* characteristic, const std::vector<uint8>& value) OVERRIDE { - ASSERT_EQ(gatt_service_id_, service->GetIdentifier()); + ASSERT_EQ(adapter_.get(), adapter); ++gatt_characteristic_value_changed_count_; last_gatt_characteristic_id_ = characteristic->GetIdentifier(); last_gatt_characteristic_uuid_ = characteristic->GetUUID(); last_changed_characteristic_value_ = value; - EXPECT_EQ(service->GetCharacteristic(last_gatt_characteristic_id_), + ASSERT_TRUE(characteristic->GetService()); + EXPECT_EQ(characteristic->GetService()->GetCharacteristic( + last_gatt_characteristic_id_), characteristic); - EXPECT_EQ(service, characteristic->GetService()); QuitMessageLoop(); } virtual void GattDescriptorAdded( - BluetoothGattCharacteristic* characteristic, + BluetoothAdapter* adapter, BluetoothGattDescriptor* descriptor) OVERRIDE { - ASSERT_EQ(gatt_service_id_, characteristic->GetService()->GetIdentifier()); + ASSERT_EQ(adapter_.get(), adapter); ++gatt_descriptor_added_count_; last_gatt_descriptor_id_ = descriptor->GetIdentifier(); last_gatt_descriptor_uuid_ = descriptor->GetUUID(); - EXPECT_EQ(characteristic->GetDescriptor(last_gatt_descriptor_id_), + ASSERT_TRUE(descriptor->GetCharacteristic()); + EXPECT_EQ(descriptor->GetCharacteristic()->GetDescriptor( + last_gatt_descriptor_id_), descriptor); - EXPECT_EQ(characteristic, descriptor->GetCharacteristic()); QuitMessageLoop(); } virtual void GattDescriptorRemoved( - BluetoothGattCharacteristic* characteristic, + BluetoothAdapter* adapter, BluetoothGattDescriptor* descriptor) OVERRIDE { - ASSERT_EQ(gatt_service_id_, characteristic->GetService()->GetIdentifier()); + ASSERT_EQ(adapter_.get(), adapter); ++gatt_descriptor_removed_count_; last_gatt_descriptor_id_ = descriptor->GetIdentifier(); last_gatt_descriptor_uuid_ = descriptor->GetUUID(); // The characteristic should return NULL for this descriptor.. - EXPECT_FALSE(characteristic->GetDescriptor(last_gatt_descriptor_id_)); - EXPECT_EQ(characteristic, descriptor->GetCharacteristic()); + ASSERT_TRUE(descriptor->GetCharacteristic()); + EXPECT_FALSE(descriptor->GetCharacteristic()->GetDescriptor( + last_gatt_descriptor_id_)); QuitMessageLoop(); } virtual void GattDescriptorValueChanged( - BluetoothGattCharacteristic* characteristic, + BluetoothAdapter* adapter, BluetoothGattDescriptor* descriptor, const std::vector<uint8>& value) OVERRIDE { - ASSERT_EQ(gatt_service_id_, characteristic->GetService()->GetIdentifier()); + ASSERT_EQ(adapter_.get(), adapter); ++gatt_descriptor_value_changed_count_; last_gatt_descriptor_id_ = descriptor->GetIdentifier(); last_gatt_descriptor_uuid_ = descriptor->GetUUID(); last_changed_descriptor_value_ = value; - EXPECT_EQ(characteristic->GetDescriptor(last_gatt_descriptor_id_), + ASSERT_TRUE(descriptor->GetCharacteristic()); + EXPECT_EQ(descriptor->GetCharacteristic()->GetDescriptor( + last_gatt_descriptor_id_), descriptor); - EXPECT_EQ(characteristic, descriptor->GetCharacteristic()); QuitMessageLoop(); } + int gatt_service_added_count_; + int gatt_service_removed_count_; int gatt_service_changed_count_; int gatt_discovery_complete_count_; int gatt_characteristic_added_count_; @@ -284,6 +249,8 @@ class TestGattServiceObserver : public BluetoothGattService::Observer { int gatt_descriptor_added_count_; int gatt_descriptor_removed_count_; int gatt_descriptor_value_changed_count_; + std::string last_gatt_service_id_; + BluetoothUUID last_gatt_service_uuid_; std::string last_gatt_characteristic_id_; BluetoothUUID last_gatt_characteristic_uuid_; std::vector<uint8> last_changed_characteristic_value_; @@ -300,8 +267,6 @@ class TestGattServiceObserver : public BluetoothGattService::Observer { base::MessageLoop::current()->Quit(); } - std::string device_address_; - std::string gatt_service_id_; scoped_refptr<BluetoothAdapter> adapter_; }; @@ -515,7 +480,8 @@ TEST_F(BluetoothGattChromeOSTest, GattServiceAddedAndRemoved) { FakeBluetoothDeviceClient::kLowEnergyAddress); ASSERT_TRUE(device); - TestDeviceObserver observer(adapter_, device); + TestObserver observer(adapter_); + EXPECT_EQ(0, observer.gatt_service_added_count_); EXPECT_EQ(0, observer.gatt_service_removed_count_); EXPECT_TRUE(observer.last_gatt_service_id_.empty()); @@ -605,7 +571,7 @@ TEST_F(BluetoothGattChromeOSTest, GattCharacteristicAddedAndRemoved) { FakeBluetoothDeviceClient::kLowEnergyAddress); ASSERT_TRUE(device); - TestDeviceObserver observer(adapter_, device); + TestObserver observer(adapter_); // Expose the fake Heart Rate service. This will asynchronously expose // characteristics. @@ -616,12 +582,11 @@ TEST_F(BluetoothGattChromeOSTest, GattCharacteristicAddedAndRemoved) { BluetoothGattService* service = device->GetGattService(observer.last_gatt_service_id_); - TestGattServiceObserver service_observer(adapter_, device, service); - EXPECT_EQ(0, service_observer.gatt_service_changed_count_); - EXPECT_EQ(0, service_observer.gatt_discovery_complete_count_); - EXPECT_EQ(0, service_observer.gatt_characteristic_added_count_); - EXPECT_EQ(0, service_observer.gatt_characteristic_removed_count_); - EXPECT_EQ(0, service_observer.gatt_characteristic_value_changed_count_); + EXPECT_EQ(0, observer.gatt_service_changed_count_); + EXPECT_EQ(0, observer.gatt_discovery_complete_count_); + EXPECT_EQ(0, observer.gatt_characteristic_added_count_); + EXPECT_EQ(0, observer.gatt_characteristic_removed_count_); + EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count_); EXPECT_TRUE(service->GetCharacteristics().empty()); // Run the message loop so that the characteristics appear. @@ -630,19 +595,19 @@ TEST_F(BluetoothGattChromeOSTest, GattCharacteristicAddedAndRemoved) { // 3 characteristics should appear. Only 1 of the characteristics sends // value changed signals. Service changed should be fired once for // descriptor added. - EXPECT_EQ(0, service_observer.gatt_service_changed_count_); - EXPECT_EQ(1, service_observer.gatt_discovery_complete_count_); - EXPECT_EQ(3, service_observer.gatt_characteristic_added_count_); - EXPECT_EQ(0, service_observer.gatt_characteristic_removed_count_); - EXPECT_EQ(0, service_observer.gatt_characteristic_value_changed_count_); + EXPECT_EQ(0, observer.gatt_service_changed_count_); + EXPECT_EQ(1, observer.gatt_discovery_complete_count_); + EXPECT_EQ(3, observer.gatt_characteristic_added_count_); + EXPECT_EQ(0, observer.gatt_characteristic_removed_count_); + EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count_); EXPECT_EQ(3U, service->GetCharacteristics().size()); // Hide the characteristics. 3 removed signals should be received. fake_bluetooth_gatt_characteristic_client_->HideHeartRateCharacteristics(); - EXPECT_EQ(0, service_observer.gatt_service_changed_count_); - EXPECT_EQ(3, service_observer.gatt_characteristic_added_count_); - EXPECT_EQ(3, service_observer.gatt_characteristic_removed_count_); - EXPECT_EQ(0, service_observer.gatt_characteristic_value_changed_count_); + EXPECT_EQ(0, observer.gatt_service_changed_count_); + EXPECT_EQ(3, observer.gatt_characteristic_added_count_); + EXPECT_EQ(3, observer.gatt_characteristic_removed_count_); + EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count_); EXPECT_TRUE(service->GetCharacteristics().empty()); // Re-expose the heart rate characteristics. We shouldn't get another @@ -651,19 +616,19 @@ TEST_F(BluetoothGattChromeOSTest, GattCharacteristicAddedAndRemoved) { // only if the service will also be subsequently removed. fake_bluetooth_gatt_characteristic_client_->ExposeHeartRateCharacteristics( fake_bluetooth_gatt_service_client_->GetHeartRateServicePath()); - EXPECT_EQ(0, service_observer.gatt_service_changed_count_); - EXPECT_EQ(1, service_observer.gatt_discovery_complete_count_); - EXPECT_EQ(6, service_observer.gatt_characteristic_added_count_); - EXPECT_EQ(3, service_observer.gatt_characteristic_removed_count_); - EXPECT_EQ(0, service_observer.gatt_characteristic_value_changed_count_); + EXPECT_EQ(0, observer.gatt_service_changed_count_); + EXPECT_EQ(1, observer.gatt_discovery_complete_count_); + EXPECT_EQ(6, observer.gatt_characteristic_added_count_); + EXPECT_EQ(3, observer.gatt_characteristic_removed_count_); + EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count_); EXPECT_EQ(3U, service->GetCharacteristics().size()); // Hide the service. All characteristics should disappear. fake_bluetooth_gatt_service_client_->HideHeartRateService(); - EXPECT_EQ(0, service_observer.gatt_service_changed_count_); - EXPECT_EQ(6, service_observer.gatt_characteristic_added_count_); - EXPECT_EQ(6, service_observer.gatt_characteristic_removed_count_); - EXPECT_EQ(0, service_observer.gatt_characteristic_value_changed_count_); + EXPECT_EQ(0, observer.gatt_service_changed_count_); + EXPECT_EQ(6, observer.gatt_characteristic_added_count_); + EXPECT_EQ(6, observer.gatt_characteristic_removed_count_); + EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count_); } TEST_F(BluetoothGattChromeOSTest, GattDescriptorAddedAndRemoved) { @@ -674,7 +639,7 @@ TEST_F(BluetoothGattChromeOSTest, GattDescriptorAddedAndRemoved) { FakeBluetoothDeviceClient::kLowEnergyAddress); ASSERT_TRUE(device); - TestDeviceObserver observer(adapter_, device); + TestObserver observer(adapter_); // Expose the fake Heart Rate service. This will asynchronously expose // characteristics. @@ -685,22 +650,21 @@ TEST_F(BluetoothGattChromeOSTest, GattDescriptorAddedAndRemoved) { BluetoothGattService* service = device->GetGattService(observer.last_gatt_service_id_); - TestGattServiceObserver service_observer(adapter_, device, service); - EXPECT_EQ(0, service_observer.gatt_service_changed_count_); - EXPECT_EQ(0, service_observer.gatt_descriptor_added_count_); - EXPECT_EQ(0, service_observer.gatt_descriptor_removed_count_); - EXPECT_EQ(0, service_observer.gatt_descriptor_value_changed_count_); + EXPECT_EQ(0, observer.gatt_service_changed_count_); + EXPECT_EQ(0, observer.gatt_descriptor_added_count_); + EXPECT_EQ(0, observer.gatt_descriptor_removed_count_); + EXPECT_EQ(0, observer.gatt_descriptor_value_changed_count_); EXPECT_TRUE(service->GetCharacteristics().empty()); // Run the message loop so that the characteristics appear. base::MessageLoop::current()->Run(); - EXPECT_EQ(0, service_observer.gatt_service_changed_count_); + EXPECT_EQ(0, observer.gatt_service_changed_count_); // Only the Heart Rate Measurement characteristic has a descriptor. - EXPECT_EQ(1, service_observer.gatt_descriptor_added_count_); - EXPECT_EQ(0, service_observer.gatt_descriptor_removed_count_); - EXPECT_EQ(0, service_observer.gatt_descriptor_value_changed_count_); + EXPECT_EQ(1, observer.gatt_descriptor_added_count_); + EXPECT_EQ(0, observer.gatt_descriptor_removed_count_); + EXPECT_EQ(0, observer.gatt_descriptor_value_changed_count_); BluetoothGattCharacteristic* characteristic = service->GetCharacteristic( fake_bluetooth_gatt_characteristic_client_-> @@ -724,40 +688,37 @@ TEST_F(BluetoothGattChromeOSTest, GattDescriptorAddedAndRemoved) { EXPECT_FALSE(descriptor->IsLocal()); EXPECT_EQ(BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid(), descriptor->GetUUID()); - EXPECT_EQ(descriptor->GetUUID(), - service_observer.last_gatt_descriptor_uuid_); - EXPECT_EQ(descriptor->GetIdentifier(), - service_observer.last_gatt_descriptor_id_); + EXPECT_EQ(descriptor->GetUUID(), observer.last_gatt_descriptor_uuid_); + EXPECT_EQ(descriptor->GetIdentifier(), observer.last_gatt_descriptor_id_); // Hide the descriptor. fake_bluetooth_gatt_descriptor_client_->HideDescriptor( dbus::ObjectPath(descriptor->GetIdentifier())); EXPECT_TRUE(characteristic->GetDescriptors().empty()); - EXPECT_EQ(0, service_observer.gatt_service_changed_count_); - EXPECT_EQ(1, service_observer.gatt_descriptor_added_count_); - EXPECT_EQ(1, service_observer.gatt_descriptor_removed_count_); - EXPECT_EQ(0, service_observer.gatt_descriptor_value_changed_count_); + EXPECT_EQ(0, observer.gatt_service_changed_count_); + EXPECT_EQ(1, observer.gatt_descriptor_added_count_); + EXPECT_EQ(1, observer.gatt_descriptor_removed_count_); + EXPECT_EQ(0, observer.gatt_descriptor_value_changed_count_); // Expose the descriptor again. - service_observer.last_gatt_descriptor_id_.clear(); - service_observer.last_gatt_descriptor_uuid_ = BluetoothUUID(); + observer.last_gatt_descriptor_id_.clear(); + observer.last_gatt_descriptor_uuid_ = BluetoothUUID(); fake_bluetooth_gatt_descriptor_client_->ExposeDescriptor( dbus::ObjectPath(characteristic->GetIdentifier()), FakeBluetoothGattDescriptorClient:: kClientCharacteristicConfigurationUUID); - EXPECT_EQ(0, service_observer.gatt_service_changed_count_); + EXPECT_EQ(0, observer.gatt_service_changed_count_); EXPECT_EQ(1U, characteristic->GetDescriptors().size()); - EXPECT_EQ(2, service_observer.gatt_descriptor_added_count_); - EXPECT_EQ(1, service_observer.gatt_descriptor_removed_count_); - EXPECT_EQ(0, service_observer.gatt_descriptor_value_changed_count_); + EXPECT_EQ(2, observer.gatt_descriptor_added_count_); + EXPECT_EQ(1, observer.gatt_descriptor_removed_count_); + EXPECT_EQ(0, observer.gatt_descriptor_value_changed_count_); descriptor = characteristic->GetDescriptors()[0]; EXPECT_FALSE(descriptor->IsLocal()); EXPECT_EQ(BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid(), descriptor->GetUUID()); - EXPECT_EQ(descriptor->GetUUID(), service_observer.last_gatt_descriptor_uuid_); - EXPECT_EQ(descriptor->GetIdentifier(), - service_observer.last_gatt_descriptor_id_); + EXPECT_EQ(descriptor->GetUUID(), observer.last_gatt_descriptor_uuid_); + EXPECT_EQ(descriptor->GetIdentifier(), observer.last_gatt_descriptor_id_); } TEST_F(BluetoothGattChromeOSTest, AdapterAddedAfterGattService) { @@ -844,7 +805,7 @@ TEST_F(BluetoothGattChromeOSTest, GattCharacteristicValue) { FakeBluetoothDeviceClient::kLowEnergyAddress); ASSERT_TRUE(device); - TestDeviceObserver observer(adapter_, device); + TestObserver observer(adapter_); // Expose the fake Heart Rate service. This will asynchronously expose // characteristics. @@ -855,15 +816,14 @@ TEST_F(BluetoothGattChromeOSTest, GattCharacteristicValue) { BluetoothGattService* service = device->GetGattService(observer.last_gatt_service_id_); - TestGattServiceObserver service_observer(adapter_, device, service); - EXPECT_EQ(0, service_observer.gatt_characteristic_value_changed_count_); + EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count_); // Run the message loop so that the characteristics appear. base::MessageLoop::current()->Run(); // Issue write request to non-writeable characteristics. - service_observer.last_gatt_characteristic_id_.clear(); - service_observer.last_gatt_characteristic_uuid_ = BluetoothUUID(); + observer.last_gatt_characteristic_id_.clear(); + observer.last_gatt_characteristic_uuid_ = BluetoothUUID(); std::vector<uint8> write_value; write_value.push_back(0x01); @@ -882,11 +842,11 @@ TEST_F(BluetoothGattChromeOSTest, GattCharacteristicValue) { base::Unretained(this)), base::Bind(&BluetoothGattChromeOSTest::ErrorCallback, base::Unretained(this))); - EXPECT_TRUE(service_observer.last_gatt_characteristic_id_.empty()); - EXPECT_FALSE(service_observer.last_gatt_characteristic_uuid_.IsValid()); + EXPECT_TRUE(observer.last_gatt_characteristic_id_.empty()); + EXPECT_FALSE(observer.last_gatt_characteristic_uuid_.IsValid()); EXPECT_EQ(0, success_callback_count_); EXPECT_EQ(1, error_callback_count_); - EXPECT_EQ(0, service_observer.gatt_characteristic_value_changed_count_); + EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count_); characteristic = service->GetCharacteristic( fake_bluetooth_gatt_characteristic_client_-> @@ -902,11 +862,11 @@ TEST_F(BluetoothGattChromeOSTest, GattCharacteristicValue) { base::Unretained(this)), base::Bind(&BluetoothGattChromeOSTest::ErrorCallback, base::Unretained(this))); - EXPECT_TRUE(service_observer.last_gatt_characteristic_id_.empty()); - EXPECT_FALSE(service_observer.last_gatt_characteristic_uuid_.IsValid()); + EXPECT_TRUE(observer.last_gatt_characteristic_id_.empty()); + EXPECT_FALSE(observer.last_gatt_characteristic_uuid_.IsValid()); EXPECT_EQ(0, success_callback_count_); EXPECT_EQ(2, error_callback_count_); - EXPECT_EQ(0, service_observer.gatt_characteristic_value_changed_count_); + EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count_); // Issue write request to writeable characteristic. The "Body Sensor Location" // characteristic does not send notifications and WriteValue does not result @@ -926,11 +886,11 @@ TEST_F(BluetoothGattChromeOSTest, GattCharacteristicValue) { base::Unretained(this)), base::Bind(&BluetoothGattChromeOSTest::ErrorCallback, base::Unretained(this))); - EXPECT_TRUE(service_observer.last_gatt_characteristic_id_.empty()); - EXPECT_FALSE(service_observer.last_gatt_characteristic_uuid_.IsValid()); + EXPECT_TRUE(observer.last_gatt_characteristic_id_.empty()); + EXPECT_FALSE(observer.last_gatt_characteristic_uuid_.IsValid()); EXPECT_EQ(1, success_callback_count_); EXPECT_EQ(2, error_callback_count_); - EXPECT_EQ(0, service_observer.gatt_characteristic_value_changed_count_); + EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count_); // Issue a read request. A successful read results in a // CharacteristicValueChanged notification. @@ -949,7 +909,7 @@ TEST_F(BluetoothGattChromeOSTest, GattCharacteristicValue) { base::Unretained(this))); EXPECT_EQ(2, success_callback_count_); EXPECT_EQ(2, error_callback_count_); - EXPECT_EQ(1, service_observer.gatt_characteristic_value_changed_count_); + EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count_); EXPECT_TRUE(ValuesEqual(characteristic->GetValue(), last_read_value_)); } @@ -961,7 +921,7 @@ TEST_F(BluetoothGattChromeOSTest, GattCharacteristicProperties) { FakeBluetoothDeviceClient::kLowEnergyAddress); ASSERT_TRUE(device); - TestDeviceObserver observer(adapter_, device); + TestObserver observer(adapter_); // Expose the fake Heart Rate service. This will asynchronously expose // characteristics. @@ -971,7 +931,6 @@ TEST_F(BluetoothGattChromeOSTest, GattCharacteristicProperties) { BluetoothGattService* service = device->GetGattService(observer.last_gatt_service_id_); - TestGattServiceObserver service_observer(adapter_, device, service); EXPECT_TRUE(service->GetCharacteristics().empty()); // Run the message loop so that the characteristics appear. @@ -1004,7 +963,7 @@ TEST_F(BluetoothGattChromeOSTest, GattDescriptorValue) { FakeBluetoothDeviceClient::kLowEnergyAddress); ASSERT_TRUE(device); - TestDeviceObserver observer(adapter_, device); + TestObserver observer(adapter_); // Expose the fake Heart Rate service. This will asynchronously expose // characteristics. @@ -1015,16 +974,15 @@ TEST_F(BluetoothGattChromeOSTest, GattDescriptorValue) { BluetoothGattService* service = device->GetGattService(observer.last_gatt_service_id_); - TestGattServiceObserver service_observer(adapter_, device, service); - EXPECT_EQ(0, service_observer.gatt_service_changed_count_); - EXPECT_EQ(0, service_observer.gatt_discovery_complete_count_); - EXPECT_EQ(0, service_observer.gatt_descriptor_value_changed_count_); + EXPECT_EQ(0, observer.gatt_service_changed_count_); + EXPECT_EQ(0, observer.gatt_discovery_complete_count_); + EXPECT_EQ(0, observer.gatt_descriptor_value_changed_count_); EXPECT_TRUE(service->GetCharacteristics().empty()); // Run the message loop so that the characteristics appear. base::MessageLoop::current()->Run(); - EXPECT_EQ(0, service_observer.gatt_service_changed_count_); - EXPECT_EQ(1, service_observer.gatt_discovery_complete_count_); + EXPECT_EQ(0, observer.gatt_service_changed_count_); + EXPECT_EQ(1, observer.gatt_discovery_complete_count_); // Only the Heart Rate Measurement characteristic has a descriptor. BluetoothGattCharacteristic* characteristic = service->GetCharacteristic( @@ -1061,8 +1019,8 @@ TEST_F(BluetoothGattChromeOSTest, GattDescriptorValue) { EXPECT_EQ(0, error_callback_count_); EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue())); EXPECT_TRUE(ValuesEqual(desc_value, descriptor->GetValue())); - EXPECT_EQ(0, service_observer.gatt_service_changed_count_); - EXPECT_EQ(1, service_observer.gatt_descriptor_value_changed_count_); + EXPECT_EQ(0, observer.gatt_service_changed_count_); + EXPECT_EQ(1, observer.gatt_descriptor_value_changed_count_); // Write value. Writes to this descriptor will fail. desc_value[0] = 0x03; @@ -1076,8 +1034,8 @@ TEST_F(BluetoothGattChromeOSTest, GattDescriptorValue) { EXPECT_EQ(1, error_callback_count_); EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue())); EXPECT_FALSE(ValuesEqual(desc_value, descriptor->GetValue())); - EXPECT_EQ(0, service_observer.gatt_service_changed_count_); - EXPECT_EQ(1, service_observer.gatt_descriptor_value_changed_count_); + EXPECT_EQ(0, observer.gatt_service_changed_count_); + EXPECT_EQ(1, observer.gatt_descriptor_value_changed_count_); // Read new value. descriptor->ReadRemoteDescriptor( @@ -1089,8 +1047,8 @@ TEST_F(BluetoothGattChromeOSTest, GattDescriptorValue) { EXPECT_EQ(1, error_callback_count_); EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue())); EXPECT_FALSE(ValuesEqual(desc_value, descriptor->GetValue())); - EXPECT_EQ(0, service_observer.gatt_service_changed_count_); - EXPECT_EQ(2, service_observer.gatt_descriptor_value_changed_count_); + EXPECT_EQ(0, observer.gatt_service_changed_count_); + EXPECT_EQ(2, observer.gatt_descriptor_value_changed_count_); } TEST_F(BluetoothGattChromeOSTest, NotifySessions) { @@ -1101,7 +1059,7 @@ TEST_F(BluetoothGattChromeOSTest, NotifySessions) { adapter_->GetDevice(FakeBluetoothDeviceClient::kLowEnergyAddress); ASSERT_TRUE(device); - TestDeviceObserver observer(adapter_, device); + TestObserver observer(adapter_); // Expose the fake Heart Rate service. This will asynchronously expose // characteristics. @@ -1112,8 +1070,7 @@ TEST_F(BluetoothGattChromeOSTest, NotifySessions) { BluetoothGattService* service = device->GetGattService(observer.last_gatt_service_id_); - TestGattServiceObserver service_observer(adapter_, device, service); - EXPECT_EQ(0, service_observer.gatt_characteristic_value_changed_count_); + EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count_); // Run the message loop so that the characteristics appear. base::MessageLoop::current()->Run(); @@ -1136,7 +1093,7 @@ TEST_F(BluetoothGattChromeOSTest, NotifySessions) { // notification. EXPECT_EQ(0, success_callback_count_); EXPECT_EQ(0, error_callback_count_); - EXPECT_EQ(1, service_observer.gatt_characteristic_value_changed_count_); + EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count_); EXPECT_TRUE(update_sessions_.empty()); // Send a two more requests, which should get queued. @@ -1152,7 +1109,7 @@ TEST_F(BluetoothGattChromeOSTest, NotifySessions) { base::Unretained(this))); EXPECT_EQ(0, success_callback_count_); EXPECT_EQ(0, error_callback_count_); - EXPECT_EQ(1, service_observer.gatt_characteristic_value_changed_count_); + EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count_); EXPECT_TRUE(update_sessions_.empty()); EXPECT_TRUE(characteristic->IsNotifying()); @@ -1162,12 +1119,12 @@ TEST_F(BluetoothGattChromeOSTest, NotifySessions) { EXPECT_EQ(3, success_callback_count_); EXPECT_EQ(0, error_callback_count_); - EXPECT_EQ(1, service_observer.gatt_characteristic_value_changed_count_); + EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count_); EXPECT_EQ(3U, update_sessions_.size()); // Notifications should be getting sent regularly now. base::MessageLoop::current()->Run(); - EXPECT_GT(service_observer.gatt_characteristic_value_changed_count_, 1); + EXPECT_GT(observer.gatt_characteristic_value_changed_count_, 1); // Stop one of the sessions. The session should become inactive but the // characteristic should still be notifying. @@ -1195,7 +1152,7 @@ TEST_F(BluetoothGattChromeOSTest, NotifySessions) { EXPECT_FALSE(characteristic->IsNotifying()); success_callback_count_ = 0; - service_observer.gatt_characteristic_value_changed_count_ = 0; + observer.gatt_characteristic_value_changed_count_ = 0; // Enable notifications again. characteristic->StartNotifySession( @@ -1205,7 +1162,7 @@ TEST_F(BluetoothGattChromeOSTest, NotifySessions) { base::Unretained(this))); EXPECT_EQ(0, success_callback_count_); EXPECT_EQ(0, error_callback_count_); - EXPECT_EQ(1, service_observer.gatt_characteristic_value_changed_count_); + EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count_); EXPECT_TRUE(update_sessions_.empty()); EXPECT_TRUE(characteristic->IsNotifying()); @@ -1214,14 +1171,14 @@ TEST_F(BluetoothGattChromeOSTest, NotifySessions) { EXPECT_EQ(1, success_callback_count_); EXPECT_EQ(0, error_callback_count_); - EXPECT_EQ(1, service_observer.gatt_characteristic_value_changed_count_); + EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count_); EXPECT_EQ(1U, update_sessions_.size()); EXPECT_TRUE(update_sessions_[0]->IsActive()); EXPECT_TRUE(characteristic->IsNotifying()); // Check that notifications are happening. base::MessageLoop::current()->Run(); - EXPECT_GT(service_observer.gatt_characteristic_value_changed_count_, 1); + EXPECT_GT(observer.gatt_characteristic_value_changed_count_, 1); // Request another session. This should return immediately. characteristic->StartNotifySession( @@ -1251,7 +1208,7 @@ TEST_F(BluetoothGattChromeOSTest, NotifySessionsMadeInactive) { adapter_->GetDevice(FakeBluetoothDeviceClient::kLowEnergyAddress); ASSERT_TRUE(device); - TestDeviceObserver observer(adapter_, device); + TestObserver observer(adapter_); // Expose the fake Heart Rate service. This will asynchronously expose // characteristics. @@ -1262,8 +1219,7 @@ TEST_F(BluetoothGattChromeOSTest, NotifySessionsMadeInactive) { BluetoothGattService* service = device->GetGattService(observer.last_gatt_service_id_); - TestGattServiceObserver service_observer(adapter_, device, service); - EXPECT_EQ(0, service_observer.gatt_characteristic_value_changed_count_); + EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count_); // Run the message loop so that the characteristics appear. base::MessageLoop::current()->Run(); @@ -1301,7 +1257,7 @@ TEST_F(BluetoothGattChromeOSTest, NotifySessionsMadeInactive) { // notification. EXPECT_EQ(0, success_callback_count_); EXPECT_EQ(0, error_callback_count_); - EXPECT_EQ(1, service_observer.gatt_characteristic_value_changed_count_); + EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count_); EXPECT_TRUE(characteristic->IsNotifying()); EXPECT_TRUE(update_sessions_.empty()); @@ -1311,7 +1267,7 @@ TEST_F(BluetoothGattChromeOSTest, NotifySessionsMadeInactive) { EXPECT_EQ(4, success_callback_count_); EXPECT_EQ(0, error_callback_count_); - EXPECT_EQ(1, service_observer.gatt_characteristic_value_changed_count_); + EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count_); EXPECT_TRUE(characteristic->IsNotifying()); EXPECT_EQ(4U, update_sessions_.size()); @@ -1338,7 +1294,7 @@ TEST_F(BluetoothGattChromeOSTest, NotifySessionsMadeInactive) { // the session count and make a request through the client. update_sessions_.clear(); success_callback_count_ = 0; - service_observer.gatt_characteristic_value_changed_count_ = 0; + observer.gatt_characteristic_value_changed_count_ = 0; characteristic->StartNotifySession( base::Bind(&BluetoothGattChromeOSTest::NotifySessionCallback, base::Unretained(this)), @@ -1347,7 +1303,7 @@ TEST_F(BluetoothGattChromeOSTest, NotifySessionsMadeInactive) { EXPECT_EQ(0, success_callback_count_); EXPECT_EQ(0, error_callback_count_); - EXPECT_EQ(1, service_observer.gatt_characteristic_value_changed_count_); + EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count_); EXPECT_TRUE(characteristic->IsNotifying()); EXPECT_TRUE(update_sessions_.empty()); @@ -1355,7 +1311,7 @@ TEST_F(BluetoothGattChromeOSTest, NotifySessionsMadeInactive) { EXPECT_EQ(1, success_callback_count_); EXPECT_EQ(0, error_callback_count_); - EXPECT_EQ(1, service_observer.gatt_characteristic_value_changed_count_); + EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count_); EXPECT_TRUE(characteristic->IsNotifying()); EXPECT_EQ(1U, update_sessions_.size()); EXPECT_TRUE(update_sessions_[0]->IsActive()); diff --git a/device/bluetooth/bluetooth_gatt_service.h b/device/bluetooth/bluetooth_gatt_service.h index 583c136..a62278f 100644 --- a/device/bluetooth/bluetooth_gatt_service.h +++ b/device/bluetooth/bluetooth_gatt_service.h @@ -125,87 +125,11 @@ class BluetoothGattService { const ErrorCallback& error_callback) = 0; }; - // Interface for observing changes from a BluetoothGattService. Properties - // of remote services are received asynchronously. The Observer interface can - // be used to be notified when the initial values of a service are received - // as well as when successive changes occur during its life cycle. - class Observer { - public: - // Called when all characteristic and descriptor discovery procedures are - // known to be completed for the GATT service |service|. This method will be - // called after the initial discovery of a GATT service and will usually be - // preceded by calls to GattCharacteristicAdded and GattDescriptorAdded. - virtual void GattDiscoveryCompleteForService( - BluetoothGattService* service) {} - - // Called when properties of the remote GATT service |service| have changed. - // This will get called for properties such as UUID, as well as for changes - // to the list of known characteristics and included services. Observers - // should read all GATT characteristic and descriptors objects and do any - // necessary set up required for a changed service. - virtual void GattServiceChanged(BluetoothGattService* service) {} - - // Called when the remote GATT characteristic |characteristic| belonging to - // GATT service |service| has been discovered. Use this to issue any initial - // read/write requests to the characteristic but don't cache the pointer as - // it may become invalid. Instead, use the specially assigned identifier - // to obtain a characteristic and cache that identifier as necessary, as it - // can be used to retrieve the characteristic from its GATT service. The - // number of characteristics with the same UUID belonging to a service - // depends on the particular profile the remote device implements, hence the - // client of a GATT based profile will usually operate on the whole set of - // characteristics and not just one. - virtual void GattCharacteristicAdded( - BluetoothGattService* service, - BluetoothGattCharacteristic* characteristic) {} - - // Called when a GATT characteristic |characteristic| belonging to GATT - // service |service| has been removed. - virtual void GattCharacteristicRemoved( - BluetoothGattService* service, - BluetoothGattCharacteristic* characteristic) {} - - // Called when the remote GATT characteristic descriptor |descriptor| - // belonging to characteristic |characteristic| has been discovered. Don't - // cache the arguments as the pointers may become invalid. Instead, use the - // specially assigned identifier to obtain a descriptor and cache that - // identifier as necessary. - virtual void GattDescriptorAdded( - BluetoothGattCharacteristic* characteristic, - BluetoothGattDescriptor* descriptor) {} - - // Called when a GATT characteristic descriptor |descriptor| belonging to - // characteristic |characteristic| has been removed. - virtual void GattDescriptorRemoved( - BluetoothGattCharacteristic* characteristic, - BluetoothGattDescriptor* descriptor) {} - - // Called when the value of a characteristic has changed. This might be a - // result of a read/write request to, or a notification/indication from, a - // remote GATT characteristic. - virtual void GattCharacteristicValueChanged( - BluetoothGattService* service, - BluetoothGattCharacteristic* characteristic, - const std::vector<uint8>& value) {} - - // Called when the value of a characteristic descriptor has been updated. - virtual void GattDescriptorValueChanged( - BluetoothGattCharacteristic* characteristic, - BluetoothGattDescriptor* descriptor, - const std::vector<uint8>& value) {} - }; - // The ErrorCallback is used by methods to asynchronously report errors. typedef base::Closure ErrorCallback; virtual ~BluetoothGattService(); - // Adds and removes observers for events on this GATT service. If monitoring - // multiple services, check the |service| parameter of observer methods to - // determine which service is issuing the event. - virtual void AddObserver(Observer* observer) = 0; - virtual void RemoveObserver(Observer* observer) = 0; - // Constructs a BluetoothGattService that can be locally hosted when the local // adapter is in the peripheral role. The resulting object can then be made // available by calling the "Register" method. This method constructs a diff --git a/device/bluetooth/bluetooth_remote_gatt_characteristic_chromeos.cc b/device/bluetooth/bluetooth_remote_gatt_characteristic_chromeos.cc index ad15a06..1c54a17 100644 --- a/device/bluetooth/bluetooth_remote_gatt_characteristic_chromeos.cc +++ b/device/bluetooth/bluetooth_remote_gatt_characteristic_chromeos.cc @@ -9,7 +9,7 @@ #include "base/logging.h" #include "base/strings/stringprintf.h" #include "chromeos/dbus/dbus_thread_manager.h" -#include "device/bluetooth/bluetooth_adapter.h" +#include "device/bluetooth/bluetooth_adapter_chromeos.h" #include "device/bluetooth/bluetooth_device.h" #include "device/bluetooth/bluetooth_gatt_notify_session_chromeos.h" #include "device/bluetooth/bluetooth_remote_gatt_descriptor_chromeos.h" @@ -244,6 +244,7 @@ void BluetoothRemoteGattCharacteristicChromeOS::StartNotifySession( ++num_notify_sessions_; DCHECK(service_); + DCHECK(service_->GetAdapter()); DCHECK(service_->GetDevice()); scoped_ptr<device::BluetoothGattNotifySession> session( new BluetoothGattNotifySessionChromeOS( diff --git a/device/bluetooth/bluetooth_remote_gatt_service_chromeos.cc b/device/bluetooth/bluetooth_remote_gatt_service_chromeos.cc index f7e99b6..b921242 100644 --- a/device/bluetooth/bluetooth_remote_gatt_service_chromeos.cc +++ b/device/bluetooth/bluetooth_remote_gatt_service_chromeos.cc @@ -54,24 +54,13 @@ BluetoothRemoteGattServiceChromeOS::~BluetoothRemoteGattServiceChromeOS() { characteristics_.clear(); for (CharacteristicMap::iterator iter = characteristics.begin(); iter != characteristics.end(); ++iter) { - FOR_EACH_OBSERVER(device::BluetoothGattService::Observer, observers_, - GattCharacteristicRemoved(this, iter->second)); + DCHECK(adapter_); + adapter_->NotifyGattCharacteristicRemoved(iter->second); + delete iter->second; } } -void BluetoothRemoteGattServiceChromeOS::AddObserver( - device::BluetoothGattService::Observer* observer) { - DCHECK(observer); - observers_.AddObserver(observer); -} - -void BluetoothRemoteGattServiceChromeOS::RemoveObserver( - device::BluetoothGattService::Observer* observer) { - DCHECK(observer); - observers_.RemoveObserver(observer); -} - std::string BluetoothRemoteGattServiceChromeOS::GetIdentifier() const { return object_path_.value(); } @@ -152,7 +141,7 @@ void BluetoothRemoteGattServiceChromeOS::Unregister( error_callback.Run(); } -scoped_refptr<device::BluetoothAdapter> +BluetoothAdapterChromeOS* BluetoothRemoteGattServiceChromeOS::GetAdapter() const { return adapter_; } @@ -164,18 +153,16 @@ void BluetoothRemoteGattServiceChromeOS::NotifyServiceChanged() { if (!discovery_complete_) return; - FOR_EACH_OBSERVER(device::BluetoothGattService::Observer, observers_, - GattServiceChanged(this)); + DCHECK(adapter_); + adapter_->NotifyGattServiceChanged(this); } void BluetoothRemoteGattServiceChromeOS::NotifyCharacteristicValueChanged( BluetoothRemoteGattCharacteristicChromeOS* characteristic, const std::vector<uint8>& value) { DCHECK(characteristic->GetService() == this); - FOR_EACH_OBSERVER( - device::BluetoothGattService::Observer, - observers_, - GattCharacteristicValueChanged(this, characteristic, value)); + DCHECK(adapter_); + adapter_->NotifyGattCharacteristicValueChanged(characteristic, value); } void BluetoothRemoteGattServiceChromeOS::NotifyDescriptorAddedOrRemoved( @@ -184,13 +171,14 @@ void BluetoothRemoteGattServiceChromeOS::NotifyDescriptorAddedOrRemoved( bool added) { DCHECK(characteristic->GetService() == this); DCHECK(descriptor->GetCharacteristic() == characteristic); + DCHECK(adapter_); + if (added) { - FOR_EACH_OBSERVER(device::BluetoothGattService::Observer, observers_, - GattDescriptorAdded(characteristic, descriptor)); + adapter_->NotifyGattDescriptorAdded(descriptor); return; } - FOR_EACH_OBSERVER(device::BluetoothGattService::Observer, observers_, - GattDescriptorRemoved(characteristic, descriptor)); + + adapter_->NotifyGattDescriptorRemoved(descriptor); } void BluetoothRemoteGattServiceChromeOS::NotifyDescriptorValueChanged( @@ -199,9 +187,8 @@ void BluetoothRemoteGattServiceChromeOS::NotifyDescriptorValueChanged( const std::vector<uint8>& value) { DCHECK(characteristic->GetService() == this); DCHECK(descriptor->GetCharacteristic() == characteristic); - FOR_EACH_OBSERVER( - device::BluetoothGattService::Observer, observers_, - GattDescriptorValueChanged(characteristic, descriptor, value)); + DCHECK(adapter_); + adapter_->NotifyGattDescriptorValueChanged(descriptor, value); } void BluetoothRemoteGattServiceChromeOS::GattServicePropertyChanged( @@ -228,9 +215,8 @@ void BluetoothRemoteGattServiceChromeOS::GattServicePropertyChanged( VLOG(1) << "All characteristics were discovered for service: " << object_path.value(); discovery_complete_ = true; - FOR_EACH_OBSERVER(device::BluetoothGattService::Observer, - observers_, - GattDiscoveryCompleteForService(this)); + DCHECK(adapter_); + adapter_->NotifyGattDiscoveryComplete(this); } void BluetoothRemoteGattServiceChromeOS::GattCharacteristicAdded( @@ -259,8 +245,8 @@ void BluetoothRemoteGattServiceChromeOS::GattCharacteristicAdded( DCHECK(characteristic->GetIdentifier() == object_path.value()); DCHECK(characteristic->GetUUID().IsValid()); - FOR_EACH_OBSERVER(device::BluetoothGattService::Observer, observers_, - GattCharacteristicAdded(this, characteristic)); + DCHECK(adapter_); + adapter_->NotifyGattCharacteristicAdded(characteristic); } void BluetoothRemoteGattServiceChromeOS::GattCharacteristicRemoved( @@ -278,8 +264,8 @@ void BluetoothRemoteGattServiceChromeOS::GattCharacteristicRemoved( DCHECK(characteristic->object_path() == object_path); characteristics_.erase(iter); - FOR_EACH_OBSERVER(device::BluetoothGattService::Observer, observers_, - GattCharacteristicRemoved(this, characteristic)); + DCHECK(adapter_); + adapter_->NotifyGattCharacteristicRemoved(characteristic); delete characteristic; } diff --git a/device/bluetooth/bluetooth_remote_gatt_service_chromeos.h b/device/bluetooth/bluetooth_remote_gatt_service_chromeos.h index 600233d..54bde89 100644 --- a/device/bluetooth/bluetooth_remote_gatt_service_chromeos.h +++ b/device/bluetooth/bluetooth_remote_gatt_service_chromeos.h @@ -40,10 +40,6 @@ class BluetoothRemoteGattServiceChromeOS public BluetoothGattCharacteristicClient::Observer { public: // device::BluetoothGattService overrides. - virtual void AddObserver( - device::BluetoothGattService::Observer* observer) OVERRIDE; - virtual void RemoveObserver( - device::BluetoothGattService::Observer* observer) OVERRIDE; virtual std::string GetIdentifier() const OVERRIDE; virtual device::BluetoothUUID GetUUID() const OVERRIDE; virtual bool IsLocal() const OVERRIDE; @@ -68,7 +64,7 @@ class BluetoothRemoteGattServiceChromeOS const dbus::ObjectPath& object_path() const { return object_path_; } // Returns the adapter associated with this service. - scoped_refptr<device::BluetoothAdapter> GetAdapter() const; + BluetoothAdapterChromeOS* GetAdapter() const; // Notifies its observers that the GATT service has changed. This is mainly // used by BluetoothRemoteGattCharacteristicChromeOS instances to notify @@ -127,9 +123,6 @@ class BluetoothRemoteGattServiceChromeOS // Object path of the GATT service. dbus::ObjectPath object_path_; - // List of observers interested in event notifications from us. - ObserverList<device::BluetoothGattService::Observer> observers_; - // The adapter associated with this service. It's ok to store a raw pointer // here since |adapter_| indirectly owns this instance. BluetoothAdapterChromeOS* adapter_; diff --git a/device/bluetooth/test/mock_bluetooth_device.h b/device/bluetooth/test/mock_bluetooth_device.h index 29ce177..7bb24f6 100644 --- a/device/bluetooth/test/mock_bluetooth_device.h +++ b/device/bluetooth/test/mock_bluetooth_device.h @@ -26,8 +26,6 @@ class MockBluetoothDevice : public BluetoothDevice { bool connected); virtual ~MockBluetoothDevice(); - MOCK_METHOD1(AddObserver, void(BluetoothDevice::Observer*)); - MOCK_METHOD1(RemoveObserver, void(BluetoothDevice::Observer*)); MOCK_CONST_METHOD0(GetBluetoothClass, uint32()); MOCK_CONST_METHOD0(GetDeviceName, std::string()); MOCK_CONST_METHOD0(GetAddress, std::string()); diff --git a/device/bluetooth/test/mock_bluetooth_gatt_service.h b/device/bluetooth/test/mock_bluetooth_gatt_service.h index 08e5934..b03adfa 100644 --- a/device/bluetooth/test/mock_bluetooth_gatt_service.h +++ b/device/bluetooth/test/mock_bluetooth_gatt_service.h @@ -26,8 +26,6 @@ class MockBluetoothGattService : public BluetoothGattService { bool is_local); virtual ~MockBluetoothGattService(); - MOCK_METHOD1(AddObserver, void(BluetoothGattService::Observer*)); - MOCK_METHOD1(RemoveObserver, void(BluetoothGattService::Observer*)); MOCK_CONST_METHOD0(GetIdentifier, std::string()); MOCK_CONST_METHOD0(GetUUID, BluetoothUUID()); MOCK_CONST_METHOD0(IsLocal, bool()); |