summaryrefslogtreecommitdiffstats
path: root/device/bluetooth
diff options
context:
space:
mode:
authorarmansito@chromium.org <armansito@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-30 01:21:38 +0000
committerarmansito@chromium.org <armansito@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-30 01:21:38 +0000
commit29b3d6276a95365d73bb16c376d0824145fb6549 (patch)
treea432a85e9554d1e2dccf13c6ad5cd0269a8b1447 /device/bluetooth
parentc8c1c1fc1371d366b338136d657ac8998070fc91 (diff)
downloadchromium_src-29b3d6276a95365d73bb16c376d0824145fb6549.zip
chromium_src-29b3d6276a95365d73bb16c376d0824145fb6549.tar.gz
chromium_src-29b3d6276a95365d73bb16c376d0824145fb6549.tar.bz2
device/bluetooth: Move GATT observer methods to BluetoothAdapter::Observer.
This CL merges BluetoothDevice::Observer and BluetoothGattService::Observer interfaces to BluetoothAdapter::Observer. This makes adding and removing observers much cleaner for users of the library. It also removes the problem of adding observers on platforms where instances are temporary and aren't kept alive for long. BUG=384664 TEST=device_unittests; browser_tests:BluetoothLowEnergyApiTest Review URL: https://codereview.chromium.org/418483003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@286371 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'device/bluetooth')
-rw-r--r--device/bluetooth/bluetooth_adapter.h78
-rw-r--r--device/bluetooth/bluetooth_adapter_chromeos.cc114
-rw-r--r--device/bluetooth/bluetooth_adapter_chromeos.h24
-rw-r--r--device/bluetooth/bluetooth_device.h26
-rw-r--r--device/bluetooth/bluetooth_device_chromeos.cc27
-rw-r--r--device/bluetooth/bluetooth_device_chromeos.h8
-rw-r--r--device/bluetooth/bluetooth_device_mac.h7
-rw-r--r--device/bluetooth/bluetooth_device_mac.mm12
-rw-r--r--device/bluetooth/bluetooth_device_win.cc13
-rw-r--r--device/bluetooth/bluetooth_device_win.h7
-rw-r--r--device/bluetooth/bluetooth_gatt_chromeos_unittest.cc356
-rw-r--r--device/bluetooth/bluetooth_gatt_service.h76
-rw-r--r--device/bluetooth/bluetooth_remote_gatt_characteristic_chromeos.cc3
-rw-r--r--device/bluetooth/bluetooth_remote_gatt_service_chromeos.cc56
-rw-r--r--device/bluetooth/bluetooth_remote_gatt_service_chromeos.h9
-rw-r--r--device/bluetooth/test/mock_bluetooth_device.h2
-rw-r--r--device/bluetooth/test/mock_bluetooth_gatt_service.h2
17 files changed, 405 insertions, 415 deletions
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());