Index: chromeos/dbus/fake_bluetooth_gatt_service_client.cc |
diff --git a/chromeos/dbus/fake_bluetooth_gatt_service_client.cc b/chromeos/dbus/fake_bluetooth_gatt_service_client.cc |
index 506ee05a0ebe7393a763975e93796fae67214def..ae2b0b4a61230a82fce6f4f2ed4651bde427eab0 100644 |
--- a/chromeos/dbus/fake_bluetooth_gatt_service_client.cc |
+++ b/chromeos/dbus/fake_bluetooth_gatt_service_client.cc |
@@ -5,12 +5,20 @@ |
#include "chromeos/dbus/fake_bluetooth_gatt_service_client.h" |
#include "base/bind.h" |
+#include "base/message_loop/message_loop.h" |
+#include "base/time/time.h" |
#include "chromeos/dbus/dbus_thread_manager.h" |
#include "chromeos/dbus/fake_bluetooth_gatt_characteristic_client.h" |
#include "third_party/cros_system_api/dbus/service_constants.h" |
namespace chromeos { |
+namespace { |
+ |
+const int kExposeCharacteristicsDelayIntervalMs = 100; |
+ |
+} // namespace |
+ |
// static |
const char FakeBluetoothGattServiceClient::kHeartRateServicePathComponent[] = |
"service0000"; |
@@ -46,7 +54,8 @@ void FakeBluetoothGattServiceClient::Properties::Set( |
callback.Run(false); |
} |
-FakeBluetoothGattServiceClient::FakeBluetoothGattServiceClient() { |
+FakeBluetoothGattServiceClient::FakeBluetoothGattServiceClient() |
+ : weak_ptr_factory_(this) { |
} |
FakeBluetoothGattServiceClient::~FakeBluetoothGattServiceClient() { |
@@ -82,7 +91,7 @@ FakeBluetoothGattServiceClient::GetProperties( |
void FakeBluetoothGattServiceClient::ExposeHeartRateService( |
const dbus::ObjectPath& device_path) { |
- if (heart_rate_service_properties_.get()) { |
+ if (IsHeartRateVisible()) { |
DCHECK(!heart_rate_service_path_.empty()); |
VLOG(1) << "Fake Heart Rate Service already exposed."; |
return; |
@@ -100,15 +109,17 @@ void FakeBluetoothGattServiceClient::ExposeHeartRateService( |
NotifyServiceAdded(dbus::ObjectPath(heart_rate_service_path_)); |
- FakeBluetoothGattCharacteristicClient* char_client = |
- static_cast<FakeBluetoothGattCharacteristicClient*>( |
- DBusThreadManager::Get()->GetBluetoothGattCharacteristicClient()); |
- char_client->ExposeHeartRateCharacteristics( |
- dbus::ObjectPath(heart_rate_service_path_)); |
+ base::MessageLoop::current()->PostDelayedTask( |
+ FROM_HERE, |
+ base::Bind( |
+ &FakeBluetoothGattServiceClient::ExposeHeartRateCharacteristics, |
+ weak_ptr_factory_.GetWeakPtr()), |
+ base::TimeDelta::FromMilliseconds( |
+ kExposeCharacteristicsDelayIntervalMs)); |
} |
void FakeBluetoothGattServiceClient::HideHeartRateService() { |
- if (!heart_rate_service_properties_.get()) { |
+ if (!IsHeartRateVisible()) { |
DCHECK(heart_rate_service_path_.empty()); |
VLOG(1) << "Fake Heart Rate Service already hidden."; |
return; |
@@ -127,6 +138,15 @@ void FakeBluetoothGattServiceClient::HideHeartRateService() { |
heart_rate_service_path_.clear(); |
} |
+bool FakeBluetoothGattServiceClient::IsHeartRateVisible() const { |
+ return !!heart_rate_service_properties_.get(); |
+} |
+ |
+dbus::ObjectPath |
+FakeBluetoothGattServiceClient::GetHeartRateServicePath() const { |
+ return dbus::ObjectPath(heart_rate_service_path_); |
+} |
+ |
void FakeBluetoothGattServiceClient::OnPropertyChanged( |
const dbus::ObjectPath& object_path, |
const std::string& property_name) { |
@@ -152,4 +172,16 @@ void FakeBluetoothGattServiceClient::NotifyServiceRemoved( |
GattServiceRemoved(object_path)); |
} |
+void FakeBluetoothGattServiceClient::ExposeHeartRateCharacteristics() { |
+ if (!IsHeartRateVisible()) { |
+ VLOG(2) << "Heart Rate service not visible. Not exposing characteristics."; |
+ return; |
+ } |
+ FakeBluetoothGattCharacteristicClient* char_client = |
+ static_cast<FakeBluetoothGattCharacteristicClient*>( |
+ DBusThreadManager::Get()->GetBluetoothGattCharacteristicClient()); |
+ char_client->ExposeHeartRateCharacteristics( |
+ dbus::ObjectPath(heart_rate_service_path_)); |
+} |
+ |
} // namespace chromeos |