Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2095)

Unified Diff: device/bluetooth/dbus/fake_bluetooth_gatt_service_client.cc

Issue 1979633004: Invoke GattDiscoveryCompleteForService by observing ServicesResolved property (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove_attr
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « device/bluetooth/dbus/fake_bluetooth_gatt_service_client.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..12daa95a5e688d296592bb9c064ec85e55391215 100644
--- a/device/bluetooth/dbus/fake_bluetooth_gatt_service_client.cc
+++ b/device/bluetooth/dbus/fake_bluetooth_gatt_service_client.cc
@@ -10,17 +10,12 @@
#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"
namespace bluez {
-namespace {
-
-const int kExposeCharacteristicsDelayIntervalMs = 100;
-
-} // namespace
-
// static
const char FakeBluetoothGattServiceClient::kHeartRateServicePathComponent[] =
"service0000";
@@ -105,12 +100,17 @@ void FakeBluetoothGattServiceClient::ExposeHeartRateService(
NotifyServiceAdded(dbus::ObjectPath(heart_rate_service_path_));
- base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::Bind(
&FakeBluetoothGattServiceClient::ExposeHeartRateCharacteristics,
- weak_ptr_factory_.GetWeakPtr()),
- base::TimeDelta::FromMilliseconds(kExposeCharacteristicsDelayIntervalMs));
+ weak_ptr_factory_.GetWeakPtr()));
+
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE,
+ base::Bind(
+ &FakeBluetoothGattServiceClient::ToggleServicesResolvedProperty,
+ weak_ptr_factory_.GetWeakPtr(), device_path, true));
}
void FakeBluetoothGattServiceClient::HideHeartRateService() {
@@ -134,6 +134,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 +206,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
« no previous file with comments | « device/bluetooth/dbus/fake_bluetooth_gatt_service_client.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698