OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chromeos/dbus/fake_bluetooth_profile_manager_client.h" | 5 #include "chromeos/dbus/fake_bluetooth_profile_manager_client.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/message_loop/message_loop.h" | |
13 #include "chromeos/dbus/fake_bluetooth_profile_service_provider.h" | 12 #include "chromeos/dbus/fake_bluetooth_profile_service_provider.h" |
14 #include "dbus/bus.h" | 13 #include "dbus/bus.h" |
15 #include "dbus/message.h" | 14 #include "dbus/message.h" |
16 #include "dbus/object_path.h" | 15 #include "dbus/object_path.h" |
17 #include "dbus/object_proxy.h" | 16 #include "dbus/object_proxy.h" |
18 #include "third_party/cros_system_api/dbus/service_constants.h" | 17 #include "third_party/cros_system_api/dbus/service_constants.h" |
19 | 18 |
20 namespace chromeos { | 19 namespace chromeos { |
21 | 20 |
22 const char FakeBluetoothProfileManagerClient::kL2capUuid[] = | 21 const char FakeBluetoothProfileManagerClient::kL2capUuid[] = |
(...skipping 24 matching lines...) Expand all Loading... |
47 if (iter == service_provider_map_.end()) { | 46 if (iter == service_provider_map_.end()) { |
48 error_callback.Run(bluetooth_profile_manager::kErrorInvalidArguments, | 47 error_callback.Run(bluetooth_profile_manager::kErrorInvalidArguments, |
49 "No profile created"); | 48 "No profile created"); |
50 } else { | 49 } else { |
51 ProfileMap::iterator piter = profile_map_.find(uuid); | 50 ProfileMap::iterator piter = profile_map_.find(uuid); |
52 if (piter != profile_map_.end()) { | 51 if (piter != profile_map_.end()) { |
53 error_callback.Run(bluetooth_profile_manager::kErrorAlreadyExists, | 52 error_callback.Run(bluetooth_profile_manager::kErrorAlreadyExists, |
54 "Profile already registered"); | 53 "Profile already registered"); |
55 } else { | 54 } else { |
56 profile_map_[uuid] = profile_path; | 55 profile_map_[uuid] = profile_path; |
57 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 56 callback.Run(); |
58 } | 57 } |
59 } | 58 } |
60 } | 59 } |
61 | 60 |
62 void FakeBluetoothProfileManagerClient::UnregisterProfile( | 61 void FakeBluetoothProfileManagerClient::UnregisterProfile( |
63 const dbus::ObjectPath& profile_path, | 62 const dbus::ObjectPath& profile_path, |
64 const base::Closure& callback, | 63 const base::Closure& callback, |
65 const ErrorCallback& error_callback) { | 64 const ErrorCallback& error_callback) { |
66 VLOG(1) << "UnregisterProfile: " << profile_path.value(); | 65 VLOG(1) << "UnregisterProfile: " << profile_path.value(); |
67 | 66 |
68 ServiceProviderMap::iterator iter = service_provider_map_.find(profile_path); | 67 ServiceProviderMap::iterator iter = service_provider_map_.find(profile_path); |
69 if (iter == service_provider_map_.end()) { | 68 if (iter == service_provider_map_.end()) { |
70 error_callback.Run(bluetooth_profile_manager::kErrorInvalidArguments, | 69 error_callback.Run(bluetooth_profile_manager::kErrorInvalidArguments, |
71 "Profile not registered"); | 70 "Profile not registered"); |
72 } else { | 71 } else { |
73 for (ProfileMap::iterator piter = profile_map_.begin(); | 72 for (ProfileMap::iterator piter = profile_map_.begin(); |
74 piter != profile_map_.end(); ++piter) { | 73 piter != profile_map_.end(); ++piter) { |
75 if (piter->second == profile_path) { | 74 if (piter->second == profile_path) { |
76 profile_map_.erase(piter); | 75 profile_map_.erase(piter); |
77 break; | 76 break; |
78 } | 77 } |
79 } | 78 } |
80 | 79 |
81 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 80 callback.Run(); |
82 } | 81 } |
83 } | 82 } |
84 | 83 |
85 void FakeBluetoothProfileManagerClient::RegisterProfileServiceProvider( | 84 void FakeBluetoothProfileManagerClient::RegisterProfileServiceProvider( |
86 FakeBluetoothProfileServiceProvider* service_provider) { | 85 FakeBluetoothProfileServiceProvider* service_provider) { |
87 service_provider_map_[service_provider->object_path_] = service_provider; | 86 service_provider_map_[service_provider->object_path_] = service_provider; |
88 } | 87 } |
89 | 88 |
90 void FakeBluetoothProfileManagerClient::UnregisterProfileServiceProvider( | 89 void FakeBluetoothProfileManagerClient::UnregisterProfileServiceProvider( |
91 FakeBluetoothProfileServiceProvider* service_provider) { | 90 FakeBluetoothProfileServiceProvider* service_provider) { |
92 ServiceProviderMap::iterator iter = | 91 ServiceProviderMap::iterator iter = |
93 service_provider_map_.find(service_provider->object_path_); | 92 service_provider_map_.find(service_provider->object_path_); |
94 if (iter != service_provider_map_.end() && iter->second == service_provider) | 93 if (iter != service_provider_map_.end() && iter->second == service_provider) |
95 service_provider_map_.erase(iter); | 94 service_provider_map_.erase(iter); |
96 } | 95 } |
97 | 96 |
98 FakeBluetoothProfileServiceProvider* | 97 FakeBluetoothProfileServiceProvider* |
99 FakeBluetoothProfileManagerClient::GetProfileServiceProvider( | 98 FakeBluetoothProfileManagerClient::GetProfileServiceProvider( |
100 const std::string& uuid) { | 99 const std::string& uuid) { |
101 ProfileMap::iterator iter = profile_map_.find(uuid); | 100 ProfileMap::iterator iter = profile_map_.find(uuid); |
102 if (iter == profile_map_.end()) | 101 if (iter == profile_map_.end()) |
103 return NULL; | 102 return NULL; |
104 return service_provider_map_[iter->second]; | 103 return service_provider_map_[iter->second]; |
105 } | 104 } |
106 | 105 |
107 } // namespace chromeos | 106 } // namespace chromeos |
OLD | NEW |