Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chromeos / dbus / fake_bluetooth_profile_manager_client.cc
blobbba54a87d83f072c821e050188a62c0ecc01c350
1 // Copyright (c) 2013 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_profile_manager_client.h"
7 #include "base/location.h"
8 #include "base/logging.h"
9 #include "base/single_thread_task_runner.h"
10 #include "base/thread_task_runner_handle.h"
11 #include "chromeos/dbus/fake_bluetooth_profile_service_provider.h"
12 #include "dbus/bus.h"
13 #include "dbus/message.h"
14 #include "dbus/object_proxy.h"
15 #include "third_party/cros_system_api/dbus/service_constants.h"
17 namespace chromeos {
19 const char FakeBluetoothProfileManagerClient::kL2capUuid[] =
20 "4d995052-33cc-4fdf-b446-75f32942a076";
21 const char FakeBluetoothProfileManagerClient::kRfcommUuid[] =
22 "3f6d6dbf-a6ad-45fc-9653-47dc912ef70e";
23 const char FakeBluetoothProfileManagerClient::kUnregisterableUuid[] =
24 "00000000-0000-0000-0000-000000000000";
26 FakeBluetoothProfileManagerClient::FakeBluetoothProfileManagerClient() {
29 FakeBluetoothProfileManagerClient::~FakeBluetoothProfileManagerClient() {
32 void FakeBluetoothProfileManagerClient::Init(dbus::Bus* bus) {
35 void FakeBluetoothProfileManagerClient::RegisterProfile(
36 const dbus::ObjectPath& profile_path,
37 const std::string& uuid,
38 const Options& options,
39 const base::Closure& callback,
40 const ErrorCallback& error_callback) {
41 VLOG(1) << "RegisterProfile: " << profile_path.value() << ": " << uuid;
43 if (uuid == kUnregisterableUuid) {
44 base::ThreadTaskRunnerHandle::Get()->PostTask(
45 FROM_HERE, base::Bind(error_callback,
46 bluetooth_profile_manager::kErrorInvalidArguments,
47 "Can't register this UUID"));
48 return;
51 // TODO(jamuraa): check options for channel & psm
53 ServiceProviderMap::iterator iter = service_provider_map_.find(profile_path);
54 if (iter == service_provider_map_.end()) {
55 error_callback.Run(bluetooth_profile_manager::kErrorInvalidArguments,
56 "No profile created");
57 } else {
58 ProfileMap::iterator piter = profile_map_.find(uuid);
59 if (piter != profile_map_.end()) {
60 error_callback.Run(bluetooth_profile_manager::kErrorAlreadyExists,
61 "Profile already registered");
62 } else {
63 profile_map_[uuid] = profile_path;
64 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback);
69 void FakeBluetoothProfileManagerClient::UnregisterProfile(
70 const dbus::ObjectPath& profile_path,
71 const base::Closure& callback,
72 const ErrorCallback& error_callback) {
73 VLOG(1) << "UnregisterProfile: " << profile_path.value();
75 ServiceProviderMap::iterator iter = service_provider_map_.find(profile_path);
76 if (iter == service_provider_map_.end()) {
77 error_callback.Run(bluetooth_profile_manager::kErrorInvalidArguments,
78 "Profile not registered");
79 } else {
80 for (ProfileMap::iterator piter = profile_map_.begin();
81 piter != profile_map_.end(); ++piter) {
82 if (piter->second == profile_path) {
83 profile_map_.erase(piter);
84 break;
88 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback);
92 void FakeBluetoothProfileManagerClient::RegisterProfileServiceProvider(
93 FakeBluetoothProfileServiceProvider* service_provider) {
94 service_provider_map_[service_provider->object_path_] = service_provider;
97 void FakeBluetoothProfileManagerClient::UnregisterProfileServiceProvider(
98 FakeBluetoothProfileServiceProvider* service_provider) {
99 ServiceProviderMap::iterator iter =
100 service_provider_map_.find(service_provider->object_path_);
101 if (iter != service_provider_map_.end() && iter->second == service_provider)
102 service_provider_map_.erase(iter);
105 FakeBluetoothProfileServiceProvider*
106 FakeBluetoothProfileManagerClient::GetProfileServiceProvider(
107 const std::string& uuid) {
108 ProfileMap::iterator iter = profile_map_.find(uuid);
109 if (iter == profile_map_.end())
110 return nullptr;
111 return service_provider_map_[iter->second];
114 } // namespace chromeos