Add some instrumentation for jank in URLRequest::Start.
[chromium-blink-merge.git] / chromeos / dbus / fake_bluetooth_gatt_characteristic_service_provider.cc
blob6301210621b9d48d30baeba8059224fcf582636c
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chromeos/dbus/fake_bluetooth_gatt_characteristic_service_provider.h"
7 #include "base/logging.h"
8 #include "base/strings/string_util.h"
9 #include "chromeos/dbus/dbus_thread_manager.h"
10 #include "chromeos/dbus/fake_bluetooth_gatt_manager_client.h"
12 namespace chromeos {
14 FakeBluetoothGattCharacteristicServiceProvider::
15 FakeBluetoothGattCharacteristicServiceProvider(
16 const dbus::ObjectPath& object_path,
17 Delegate* delegate,
18 const std::string& uuid,
19 const std::vector<std::string>& flags,
20 const std::vector<std::string>& permissions,
21 const dbus::ObjectPath& service_path)
22 : object_path_(object_path),
23 uuid_(uuid),
24 service_path_(service_path),
25 delegate_(delegate) {
26 VLOG(1) << "Creating Bluetooth GATT characteristic: " << object_path_.value();
28 DCHECK(object_path_.IsValid());
29 DCHECK(service_path_.IsValid());
30 DCHECK(!uuid.empty());
31 DCHECK(delegate_);
32 DCHECK(StartsWithASCII(
33 object_path_.value(), service_path_.value() + "/", true));
35 // TODO(armansito): Do something with |flags| and |permissions|.
37 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client =
38 static_cast<FakeBluetoothGattManagerClient*>(
39 DBusThreadManager::Get()->GetBluetoothGattManagerClient());
40 fake_bluetooth_gatt_manager_client->
41 RegisterCharacteristicServiceProvider(this);
44 FakeBluetoothGattCharacteristicServiceProvider::
45 ~FakeBluetoothGattCharacteristicServiceProvider() {
46 VLOG(1) << "Cleaning up Bluetooth GATT characteristic: "
47 << object_path_.value();
49 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client =
50 static_cast<FakeBluetoothGattManagerClient*>(
51 DBusThreadManager::Get()->GetBluetoothGattManagerClient());
52 fake_bluetooth_gatt_manager_client->
53 UnregisterCharacteristicServiceProvider(this);
56 void FakeBluetoothGattCharacteristicServiceProvider::SendValueChanged(
57 const std::vector<uint8>& value) {
58 VLOG(1) << "Sent characteristic value changed: " << object_path_.value()
59 << " UUID: " << uuid_;
62 void FakeBluetoothGattCharacteristicServiceProvider::GetValue(
63 const Delegate::ValueCallback& callback,
64 const Delegate::ErrorCallback& error_callback) {
65 VLOG(1) << "GATT characteristic value Get request: " << object_path_.value()
66 << " UUID: " << uuid_;
68 // Check if this characteristic is registered.
69 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client =
70 static_cast<FakeBluetoothGattManagerClient*>(
71 DBusThreadManager::Get()->GetBluetoothGattManagerClient());
72 if (!fake_bluetooth_gatt_manager_client->IsServiceRegistered(service_path_)) {
73 VLOG(1) << "GATT characteristic not registered.";
74 error_callback.Run();
75 return;
78 // Pass on to the delegate.
79 DCHECK(delegate_);
80 delegate_->GetCharacteristicValue(callback, error_callback);
83 void FakeBluetoothGattCharacteristicServiceProvider::SetValue(
84 const std::vector<uint8>& value,
85 const base::Closure& callback,
86 const Delegate::ErrorCallback& error_callback) {
87 VLOG(1) << "GATT characteristic value Set request: " << object_path_.value()
88 << " UUID: " << uuid_;
90 // Check if this characteristic is registered.
91 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client =
92 static_cast<FakeBluetoothGattManagerClient*>(
93 DBusThreadManager::Get()->GetBluetoothGattManagerClient());
94 if (!fake_bluetooth_gatt_manager_client->IsServiceRegistered(service_path_)) {
95 VLOG(1) << "GATT characteristic not registered.";
96 error_callback.Run();
97 return;
100 // Pass on to the delegate.
101 DCHECK(delegate_);
102 delegate_->SetCharacteristicValue(value, callback, error_callback);
105 } // namespace chromeos