Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / chromeos / dbus / fake_bluetooth_le_advertising_manager_client.cc
blob8145d1c211658a210b6c67af377cacf3c7d72481
1 // Copyright 2015 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 "base/logging.h"
6 #include "base/message_loop/message_loop.h"
7 #include "dbus/bus.h"
8 #include "dbus/message.h"
9 #include "dbus/object_proxy.h"
10 #include "fake_bluetooth_le_advertisement_service_provider.h"
11 #include "fake_bluetooth_le_advertising_manager_client.h"
12 #include "third_party/cros_system_api/dbus/service_constants.h"
14 namespace chromeos {
16 const char FakeBluetoothLEAdvertisingManagerClient::kAdvertisingManagerPath[] =
17 "/fake/hci0";
19 FakeBluetoothLEAdvertisingManagerClient::
20 FakeBluetoothLEAdvertisingManagerClient() {
23 FakeBluetoothLEAdvertisingManagerClient::
24 ~FakeBluetoothLEAdvertisingManagerClient() {
27 void FakeBluetoothLEAdvertisingManagerClient::Init(dbus::Bus* bus) {
30 void FakeBluetoothLEAdvertisingManagerClient::AddObserver(Observer* observer) {
33 void FakeBluetoothLEAdvertisingManagerClient::RemoveObserver(
34 Observer* observer) {
37 void FakeBluetoothLEAdvertisingManagerClient::RegisterAdvertisement(
38 const dbus::ObjectPath& manager_object_path,
39 const dbus::ObjectPath& advertisement_object_path,
40 const base::Closure& callback,
41 const ErrorCallback& error_callback) {
42 VLOG(1) << "RegisterAdvertisment: " << advertisement_object_path.value();
44 if (manager_object_path != dbus::ObjectPath(kAdvertisingManagerPath)) {
45 error_callback.Run(kNoResponseError, "Invalid Advertising Manager path.");
46 return;
49 ServiceProviderMap::iterator iter =
50 service_provider_map_.find(advertisement_object_path);
51 if (iter == service_provider_map_.end()) {
52 error_callback.Run(bluetooth_advertising_manager::kErrorInvalidArguments,
53 "Advertisement object not registered");
54 } else if (!currently_registered_.value().empty()) {
55 error_callback.Run(bluetooth_advertising_manager::kErrorFailed,
56 "Maximum advertisements reached");
57 } else if (advertisement_object_path != currently_registered_) {
58 error_callback.Run(bluetooth_advertising_manager::kErrorAlreadyExists,
59 "Already advertising.");
60 } else {
61 currently_registered_ = advertisement_object_path;
62 base::MessageLoop::current()->PostTask(FROM_HERE, callback);
66 void FakeBluetoothLEAdvertisingManagerClient::UnregisterAdvertisement(
67 const dbus::ObjectPath& manager_object_path,
68 const dbus::ObjectPath& advertisement_object_path,
69 const base::Closure& callback,
70 const ErrorCallback& error_callback) {
71 VLOG(1) << "UnregisterAdvertisment: " << advertisement_object_path.value();
73 if (manager_object_path != dbus::ObjectPath(kAdvertisingManagerPath)) {
74 error_callback.Run(kNoResponseError, "Invalid Advertising Manager path.");
75 return;
78 ServiceProviderMap::iterator iter =
79 service_provider_map_.find(advertisement_object_path);
80 if (iter == service_provider_map_.end()) {
81 error_callback.Run(bluetooth_advertising_manager::kErrorDoesNotExist,
82 "Advertisement not registered");
83 } else if (advertisement_object_path != currently_registered_) {
84 error_callback.Run(bluetooth_advertising_manager::kErrorDoesNotExist,
85 "Does not exist");
86 } else {
87 currently_registered_ = dbus::ObjectPath("");
88 base::MessageLoop::current()->PostTask(FROM_HERE, callback);
92 void FakeBluetoothLEAdvertisingManagerClient::
93 RegisterAdvertisementServiceProvider(
94 FakeBluetoothLEAdvertisementServiceProvider* service_provider) {
95 service_provider_map_[service_provider->object_path_] = service_provider;
98 void FakeBluetoothLEAdvertisingManagerClient::
99 UnregisterAdvertisementServiceProvider(
100 FakeBluetoothLEAdvertisementServiceProvider* service_provider) {
101 ServiceProviderMap::iterator iter =
102 service_provider_map_.find(service_provider->object_path_);
103 if (iter != service_provider_map_.end() && iter->second == service_provider)
104 service_provider_map_.erase(iter);
107 } // namespace chromeos