OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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_shill_profile_client.h" | 5 #include "chromeos/dbus/fake_shill_profile_client.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/memory/ptr_util.h" |
10 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
11 #include "base/stl_util.h" | |
12 #include "base/threading/thread_task_runner_handle.h" | 12 #include "base/threading/thread_task_runner_handle.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "chromeos/dbus/dbus_thread_manager.h" | 14 #include "chromeos/dbus/dbus_thread_manager.h" |
15 #include "chromeos/dbus/shill_property_changed_observer.h" | 15 #include "chromeos/dbus/shill_property_changed_observer.h" |
16 #include "chromeos/dbus/shill_service_client.h" | 16 #include "chromeos/dbus/shill_service_client.h" |
17 #include "dbus/bus.h" | 17 #include "dbus/bus.h" |
18 #include "dbus/message.h" | 18 #include "dbus/message.h" |
19 #include "dbus/object_path.h" | 19 #include "dbus/object_path.h" |
20 #include "dbus/values_util.h" | 20 #include "dbus/values_util.h" |
21 #include "third_party/cros_system_api/dbus/service_constants.h" | 21 #include "third_party/cros_system_api/dbus/service_constants.h" |
22 | 22 |
23 namespace chromeos { | 23 namespace chromeos { |
24 | 24 |
25 struct FakeShillProfileClient::ProfileProperties { | 25 struct FakeShillProfileClient::ProfileProperties { |
26 base::DictionaryValue entries; // Dictionary of Service Dictionaries | 26 base::DictionaryValue entries; // Dictionary of Service Dictionaries |
27 base::DictionaryValue properties; // Dictionary of Profile properties | 27 base::DictionaryValue properties; // Dictionary of Profile properties |
28 }; | 28 }; |
29 | 29 |
30 namespace { | 30 namespace { |
31 | 31 |
32 void PassDictionary( | 32 void PassDictionary( |
33 const ShillProfileClient::DictionaryValueCallbackWithoutStatus& callback, | 33 const ShillProfileClient::DictionaryValueCallbackWithoutStatus& callback, |
34 const base::DictionaryValue* dictionary) { | 34 const base::DictionaryValue* dictionary) { |
35 callback.Run(*dictionary); | 35 callback.Run(*dictionary); |
36 } | 36 } |
37 | 37 |
38 } // namespace | 38 } // namespace |
39 | 39 |
40 FakeShillProfileClient::FakeShillProfileClient() { | 40 FakeShillProfileClient::FakeShillProfileClient() {} |
41 } | |
42 | 41 |
43 FakeShillProfileClient::~FakeShillProfileClient() { | 42 FakeShillProfileClient::~FakeShillProfileClient() {} |
44 base::STLDeleteValues(&profiles_); | |
45 } | |
46 | 43 |
47 void FakeShillProfileClient::Init(dbus::Bus* bus) { | 44 void FakeShillProfileClient::Init(dbus::Bus* bus) {} |
48 } | |
49 | 45 |
50 void FakeShillProfileClient::AddPropertyChangedObserver( | 46 void FakeShillProfileClient::AddPropertyChangedObserver( |
51 const dbus::ObjectPath& profile_path, | 47 const dbus::ObjectPath& profile_path, |
52 ShillPropertyChangedObserver* observer) { | 48 ShillPropertyChangedObserver* observer) { |
53 } | 49 } |
54 | 50 |
55 void FakeShillProfileClient::RemovePropertyChangedObserver( | 51 void FakeShillProfileClient::RemovePropertyChangedObserver( |
56 const dbus::ObjectPath& profile_path, | 52 const dbus::ObjectPath& profile_path, |
57 ShillPropertyChangedObserver* observer) { | 53 ShillPropertyChangedObserver* observer) { |
58 } | 54 } |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 | 120 |
125 ShillProfileClient::TestInterface* FakeShillProfileClient::GetTestInterface() { | 121 ShillProfileClient::TestInterface* FakeShillProfileClient::GetTestInterface() { |
126 return this; | 122 return this; |
127 } | 123 } |
128 | 124 |
129 void FakeShillProfileClient::AddProfile(const std::string& profile_path, | 125 void FakeShillProfileClient::AddProfile(const std::string& profile_path, |
130 const std::string& userhash) { | 126 const std::string& userhash) { |
131 if (GetProfile(dbus::ObjectPath(profile_path), ErrorCallback())) | 127 if (GetProfile(dbus::ObjectPath(profile_path), ErrorCallback())) |
132 return; | 128 return; |
133 | 129 |
134 ProfileProperties* profile = new ProfileProperties; | 130 std::unique_ptr<ProfileProperties> profile = |
| 131 base::MakeUnique<ProfileProperties>(); |
135 profile->properties.SetStringWithoutPathExpansion(shill::kUserHashProperty, | 132 profile->properties.SetStringWithoutPathExpansion(shill::kUserHashProperty, |
136 userhash); | 133 userhash); |
137 profiles_[profile_path] = profile; | 134 profiles_[profile_path] = std::move(profile); |
138 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> | 135 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> |
139 AddProfile(profile_path); | 136 AddProfile(profile_path); |
140 } | 137 } |
141 | 138 |
142 void FakeShillProfileClient::AddEntry(const std::string& profile_path, | 139 void FakeShillProfileClient::AddEntry(const std::string& profile_path, |
143 const std::string& entry_path, | 140 const std::string& entry_path, |
144 const base::DictionaryValue& properties) { | 141 const base::DictionaryValue& properties) { |
145 ProfileProperties* profile = GetProfile(dbus::ObjectPath(profile_path), | 142 ProfileProperties* profile = GetProfile(dbus::ObjectPath(profile_path), |
146 ErrorCallback()); | 143 ErrorCallback()); |
147 DCHECK(profile); | 144 DCHECK(profile); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 return false; | 204 return false; |
208 } | 205 } |
209 | 206 |
210 profile->entries.SetWithoutPathExpansion(service_path, | 207 profile->entries.SetWithoutPathExpansion(service_path, |
211 service_properties->DeepCopy()); | 208 service_properties->DeepCopy()); |
212 return true; | 209 return true; |
213 } | 210 } |
214 | 211 |
215 void FakeShillProfileClient::GetProfilePaths( | 212 void FakeShillProfileClient::GetProfilePaths( |
216 std::vector<std::string>* profiles) { | 213 std::vector<std::string>* profiles) { |
217 for (ProfileMap::iterator iter = profiles_.begin(); | 214 for (auto iter = profiles_.begin(); iter != profiles_.end(); ++iter) |
218 iter != profiles_.end(); ++iter) { | |
219 profiles->push_back(iter->first); | 215 profiles->push_back(iter->first); |
220 } | |
221 } | 216 } |
222 | 217 |
223 bool FakeShillProfileClient::GetService(const std::string& service_path, | 218 bool FakeShillProfileClient::GetService(const std::string& service_path, |
224 std::string* profile_path, | 219 std::string* profile_path, |
225 base::DictionaryValue* properties) { | 220 base::DictionaryValue* properties) { |
226 properties->Clear(); | 221 properties->Clear(); |
227 for (ProfileMap::const_iterator iter = profiles_.begin(); | 222 for (auto iter = profiles_.begin(); iter != profiles_.end(); ++iter) { |
228 iter != profiles_.end(); ++iter) { | 223 const ProfileProperties* profile = iter->second.get(); |
229 const ProfileProperties* profile = iter->second; | |
230 const base::DictionaryValue* entry; | 224 const base::DictionaryValue* entry; |
231 if (!profile->entries.GetDictionaryWithoutPathExpansion( | 225 if (!profile->entries.GetDictionaryWithoutPathExpansion( |
232 service_path, &entry)) { | 226 service_path, &entry)) { |
233 continue; | 227 continue; |
234 } | 228 } |
235 *profile_path = iter->first; | 229 *profile_path = iter->first; |
236 properties->MergeDictionary(entry); | 230 properties->MergeDictionary(entry); |
237 return true; | 231 return true; |
238 } | 232 } |
239 return false; | 233 return false; |
240 } | 234 } |
241 | 235 |
242 void FakeShillProfileClient::ClearProfiles() { | 236 void FakeShillProfileClient::ClearProfiles() { |
243 base::STLDeleteValues(&profiles_); | 237 profiles_.clear(); |
244 } | 238 } |
245 | 239 |
246 FakeShillProfileClient::ProfileProperties* FakeShillProfileClient::GetProfile( | 240 FakeShillProfileClient::ProfileProperties* FakeShillProfileClient::GetProfile( |
247 const dbus::ObjectPath& profile_path, | 241 const dbus::ObjectPath& profile_path, |
248 const ErrorCallback& error_callback) { | 242 const ErrorCallback& error_callback) { |
249 ProfileMap::const_iterator found = profiles_.find(profile_path.value()); | 243 auto found = profiles_.find(profile_path.value()); |
250 if (found == profiles_.end()) { | 244 if (found == profiles_.end()) { |
251 if (!error_callback.is_null()) | 245 if (!error_callback.is_null()) |
252 error_callback.Run("Error.InvalidProfile", "Invalid profile"); | 246 error_callback.Run("Error.InvalidProfile", "Invalid profile"); |
253 return NULL; | 247 return nullptr; |
254 } | 248 } |
255 | 249 |
256 return found->second; | 250 return found->second.get(); |
257 } | 251 } |
258 | 252 |
259 } // namespace chromeos | 253 } // namespace chromeos |
OLD | NEW |