Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: chromeos/dbus/fake_shill_profile_client.cc

Issue 2754903002: Prevent networkingPrivate.forgetNetwork from removing shared configs (Closed)
Patch Set: . Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chromeos/dbus/fake_shill_profile_client.h ('k') | chromeos/dbus/fake_shill_service_client.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/memory/ptr_util.h"
11 #include "base/single_thread_task_runner.h" 11 #include "base/single_thread_task_runner.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 std::string path; // Profile path
26 base::DictionaryValue entries; // Dictionary of Service Dictionaries 27 base::DictionaryValue entries; // Dictionary of Service Dictionaries
27 base::DictionaryValue properties; // Dictionary of Profile properties 28 base::DictionaryValue properties; // Dictionary of Profile properties
28 }; 29 };
29 30
30 namespace { 31 namespace {
31 32
32 void PassDictionary( 33 void PassDictionary(
33 const ShillProfileClient::DictionaryValueCallbackWithoutStatus& callback, 34 const ShillProfileClient::DictionaryValueCallbackWithoutStatus& callback,
34 const base::DictionaryValue* dictionary) { 35 const base::DictionaryValue* dictionary) {
35 callback.Run(*dictionary); 36 callback.Run(*dictionary);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 121
121 ShillProfileClient::TestInterface* FakeShillProfileClient::GetTestInterface() { 122 ShillProfileClient::TestInterface* FakeShillProfileClient::GetTestInterface() {
122 return this; 123 return this;
123 } 124 }
124 125
125 void FakeShillProfileClient::AddProfile(const std::string& profile_path, 126 void FakeShillProfileClient::AddProfile(const std::string& profile_path,
126 const std::string& userhash) { 127 const std::string& userhash) {
127 if (GetProfile(dbus::ObjectPath(profile_path), ErrorCallback())) 128 if (GetProfile(dbus::ObjectPath(profile_path), ErrorCallback()))
128 return; 129 return;
129 130
130 std::unique_ptr<ProfileProperties> profile = 131 // If adding a shared profile, make sure there are no user profiles currently
131 base::MakeUnique<ProfileProperties>(); 132 // on the stack - this assumes there is at most one shared profile.
133 CHECK(profile_path != GetSharedProfilePath() || profiles_.empty())
134 << "Shared profile must be added before any user profile.";
135
136 auto profile = base::MakeUnique<ProfileProperties>();
132 profile->properties.SetStringWithoutPathExpansion(shill::kUserHashProperty, 137 profile->properties.SetStringWithoutPathExpansion(shill::kUserHashProperty,
133 userhash); 138 userhash);
134 profiles_[profile_path] = std::move(profile); 139 profile->path = profile_path;
140 profiles_.emplace_back(std::move(profile));
141
135 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> 142 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()->
136 AddProfile(profile_path); 143 AddProfile(profile_path);
137 } 144 }
138 145
139 void FakeShillProfileClient::AddEntry(const std::string& profile_path, 146 void FakeShillProfileClient::AddEntry(const std::string& profile_path,
140 const std::string& entry_path, 147 const std::string& entry_path,
141 const base::DictionaryValue& properties) { 148 const base::DictionaryValue& properties) {
142 ProfileProperties* profile = GetProfile(dbus::ObjectPath(profile_path), 149 ProfileProperties* profile = GetProfile(dbus::ObjectPath(profile_path),
143 ErrorCallback()); 150 ErrorCallback());
144 DCHECK(profile); 151 DCHECK(profile);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 return false; 211 return false;
205 } 212 }
206 213
207 profile->entries.SetWithoutPathExpansion(service_path, 214 profile->entries.SetWithoutPathExpansion(service_path,
208 service_properties->DeepCopy()); 215 service_properties->DeepCopy());
209 return true; 216 return true;
210 } 217 }
211 218
212 void FakeShillProfileClient::GetProfilePaths( 219 void FakeShillProfileClient::GetProfilePaths(
213 std::vector<std::string>* profiles) { 220 std::vector<std::string>* profiles) {
214 for (auto iter = profiles_.begin(); iter != profiles_.end(); ++iter) 221 for (const auto& profile : profiles_)
215 profiles->push_back(iter->first); 222 profiles->push_back(profile->path);
223 }
224
225 void FakeShillProfileClient::GetProfilePathsContainingService(
226 const std::string& service_path,
227 std::vector<std::string>* profiles) {
228 for (const auto& profile : profiles_) {
229 if (GetServiceDataFromProfile(profile.get(), service_path, nullptr))
230 profiles->push_back(profile->path);
231 }
216 } 232 }
217 233
218 bool FakeShillProfileClient::GetService(const std::string& service_path, 234 bool FakeShillProfileClient::GetService(const std::string& service_path,
219 std::string* profile_path, 235 std::string* profile_path,
220 base::DictionaryValue* properties) { 236 base::DictionaryValue* properties) {
221 properties->Clear(); 237 properties->Clear();
222 for (auto iter = profiles_.begin(); iter != profiles_.end(); ++iter) { 238
223 const ProfileProperties* profile = iter->second.get(); 239 bool found_profile = false;
224 const base::DictionaryValue* entry; 240 for (const auto& profile : profiles_) {
225 if (!profile->entries.GetDictionaryWithoutPathExpansion( 241 if (GetServiceDataFromProfile(profile.get(), service_path, properties)) {
226 service_path, &entry)) { 242 found_profile = true;
227 continue; 243 *profile_path = profile->path;
228 } 244 }
229 *profile_path = iter->first;
230 properties->MergeDictionary(entry);
231 return true;
232 } 245 }
233 return false; 246 return found_profile;
234 } 247 }
235 248
236 void FakeShillProfileClient::ClearProfiles() { 249 void FakeShillProfileClient::ClearProfiles() {
237 profiles_.clear(); 250 profiles_.clear();
238 } 251 }
239 252
240 FakeShillProfileClient::ProfileProperties* FakeShillProfileClient::GetProfile( 253 FakeShillProfileClient::ProfileProperties* FakeShillProfileClient::GetProfile(
241 const dbus::ObjectPath& profile_path, 254 const dbus::ObjectPath& profile_path,
242 const ErrorCallback& error_callback) { 255 const ErrorCallback& error_callback) {
243 auto found = profiles_.find(profile_path.value()); 256 for (auto& profile : profiles_) {
244 if (found == profiles_.end()) { 257 if (profile->path == profile_path.value())
245 if (!error_callback.is_null()) 258 return profile.get();
246 error_callback.Run("Error.InvalidProfile", "Invalid profile"); 259 }
247 return nullptr; 260 if (!error_callback.is_null())
261 error_callback.Run("Error.InvalidProfile", "Invalid profile");
262 return nullptr;
263 }
264
265 bool FakeShillProfileClient::GetServiceDataFromProfile(
266 const FakeShillProfileClient::ProfileProperties* profile,
267 const std::string& service_path,
268 base::DictionaryValue* properties) {
269 const base::DictionaryValue* entry;
270 if (!profile->entries.GetDictionaryWithoutPathExpansion(service_path,
271 &entry)) {
272 return false;
248 } 273 }
249 274
250 return found->second.get(); 275 if (properties)
276 properties->MergeDictionary(entry);
277
278 return true;
251 } 279 }
252 280
253 } // namespace chromeos 281 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/fake_shill_profile_client.h ('k') | chromeos/dbus/fake_shill_service_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698