Chromium Code Reviews| Index: device/bluetooth/dbus/fake_bluetooth_gatt_service_client.cc |
| diff --git a/device/bluetooth/dbus/fake_bluetooth_gatt_service_client.cc b/device/bluetooth/dbus/fake_bluetooth_gatt_service_client.cc |
| index cc080118321735fcd09fadb04749773db3877f47..4d82cd3c1c42249a600e4185d165c5d6d76fb551 100644 |
| --- a/device/bluetooth/dbus/fake_bluetooth_gatt_service_client.cc |
| +++ b/device/bluetooth/dbus/fake_bluetooth_gatt_service_client.cc |
| @@ -10,6 +10,7 @@ |
| #include "base/threading/thread_task_runner_handle.h" |
| #include "base/time/time.h" |
| #include "device/bluetooth/dbus/bluez_dbus_manager.h" |
| +#include "device/bluetooth/dbus/fake_bluetooth_device_client.h" |
| #include "device/bluetooth/dbus/fake_bluetooth_gatt_characteristic_client.h" |
| #include "third_party/cros_system_api/dbus/service_constants.h" |
| @@ -18,6 +19,7 @@ namespace bluez { |
| namespace { |
| const int kExposeCharacteristicsDelayIntervalMs = 100; |
| +const int kToggleServicesResolvedPropertyDelayIntervalMs = 100; |
| } // namespace |
| @@ -111,6 +113,14 @@ void FakeBluetoothGattServiceClient::ExposeHeartRateService( |
| &FakeBluetoothGattServiceClient::ExposeHeartRateCharacteristics, |
| weak_ptr_factory_.GetWeakPtr()), |
| base::TimeDelta::FromMilliseconds(kExposeCharacteristicsDelayIntervalMs)); |
| + |
| + base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
|
rkc
2016/05/17 18:38:50
Why does this need to be delayed at all? Can PostT
Miao
2016/05/18 03:26:58
I think PostTask is sufficient. The reason is the
|
| + FROM_HERE, |
| + base::Bind( |
| + &FakeBluetoothGattServiceClient::ToggleServicesResolvedProperty, |
| + weak_ptr_factory_.GetWeakPtr(), device_path, true), |
| + base::TimeDelta::FromMilliseconds( |
| + kToggleServicesResolvedPropertyDelayIntervalMs)); |
| } |
| void FakeBluetoothGattServiceClient::HideHeartRateService() { |
| @@ -134,6 +144,33 @@ void FakeBluetoothGattServiceClient::HideHeartRateService() { |
| heart_rate_service_path_.clear(); |
| } |
| +void FakeBluetoothGattServiceClient::ExposeHeartRateServiceWithoutDelay( |
| + const dbus::ObjectPath& device_path) { |
| + if (IsHeartRateVisible()) { |
| + DCHECK(!heart_rate_service_path_.empty()); |
| + VLOG(1) << "Fake Heart Rate Service already exposed."; |
| + return; |
| + } |
| + VLOG(2) << "Exposing fake Heart Rate Service."; |
| + heart_rate_service_path_ = |
| + device_path.value() + "/" + kHeartRateServicePathComponent; |
| + heart_rate_service_properties_.reset(new Properties(base::Bind( |
| + &FakeBluetoothGattServiceClient::OnPropertyChanged, |
| + base::Unretained(this), dbus::ObjectPath(heart_rate_service_path_)))); |
| + heart_rate_service_properties_->uuid.ReplaceValue(kHeartRateServiceUUID); |
| + heart_rate_service_properties_->device.ReplaceValue(device_path); |
| + heart_rate_service_properties_->primary.ReplaceValue(true); |
| + |
| + NotifyServiceAdded(dbus::ObjectPath(heart_rate_service_path_)); |
| + |
| + static_cast<FakeBluetoothGattCharacteristicClient*>( |
| + bluez::BluezDBusManager::Get()->GetBluetoothGattCharacteristicClient()) |
| + ->ExposeHeartRateCharacteristics( |
| + dbus::ObjectPath(heart_rate_service_path_)); |
| + |
| + ToggleServicesResolvedProperty(device_path, true); |
| +} |
| + |
| bool FakeBluetoothGattServiceClient::IsHeartRateVisible() const { |
| return !!heart_rate_service_properties_.get(); |
| } |
| @@ -179,4 +216,17 @@ void FakeBluetoothGattServiceClient::ExposeHeartRateCharacteristics() { |
| dbus::ObjectPath(heart_rate_service_path_)); |
| } |
| +void FakeBluetoothGattServiceClient::ToggleServicesResolvedProperty( |
| + const dbus::ObjectPath& object_path, |
| + bool resolved) { |
| + DCHECK(object_path.IsValid()); |
| + |
| + VLOG(2) << "Toggle the ServicesResolved property to " << resolved |
| + << " of device " << object_path.value(); |
| + FakeBluetoothDeviceClient* device = static_cast<FakeBluetoothDeviceClient*>( |
| + bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()); |
| + // Notify on service discovery complete. |
| + device->GetProperties(object_path)->services_resolved.ReplaceValue(true); |
| +} |
| + |
| } // namespace bluez |