Supervised user import: Listen for profile creation/deletion
[chromium-blink-merge.git] / chromeos / dbus / fake_bluetooth_le_advertising_manager_client.cc
blob570283239b77e3ce3d22d3d4ec28b0ed5e3cee8d
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 {
58 currently_registered_ = advertisement_object_path;
59 base::MessageLoop::current()->PostTask(FROM_HERE, callback);
63 void FakeBluetoothLEAdvertisingManagerClient::UnregisterAdvertisement(
64 const dbus::ObjectPath& manager_object_path,
65 const dbus::ObjectPath& advertisement_object_path,
66 const base::Closure& callback,
67 const ErrorCallback& error_callback) {
68 VLOG(1) << "UnregisterAdvertisment: " << advertisement_object_path.value();
70 if (manager_object_path != dbus::ObjectPath(kAdvertisingManagerPath)) {
71 error_callback.Run(kNoResponseError, "Invalid Advertising Manager path.");
72 return;
75 ServiceProviderMap::iterator iter =
76 service_provider_map_.find(advertisement_object_path);
77 if (iter == service_provider_map_.end()) {
78 error_callback.Run(bluetooth_advertising_manager::kErrorDoesNotExist,
79 "Advertisement not registered");
80 } else if (advertisement_object_path != currently_registered_) {
81 error_callback.Run(bluetooth_advertising_manager::kErrorDoesNotExist,
82 "Does not exist");
83 } else {
84 currently_registered_ = dbus::ObjectPath("");
85 base::MessageLoop::current()->PostTask(FROM_HERE, callback);
89 void FakeBluetoothLEAdvertisingManagerClient::
90 RegisterAdvertisementServiceProvider(
91 FakeBluetoothLEAdvertisementServiceProvider* service_provider) {
92 service_provider_map_[service_provider->object_path_] = service_provider;
95 void FakeBluetoothLEAdvertisingManagerClient::
96 UnregisterAdvertisementServiceProvider(
97 FakeBluetoothLEAdvertisementServiceProvider* service_provider) {
98 ServiceProviderMap::iterator iter =
99 service_provider_map_.find(service_provider->object_path_);
100 if (iter != service_provider_map_.end() && iter->second == service_provider)
101 service_provider_map_.erase(iter);
104 } // namespace chromeos