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

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"
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 service_properties->DeepCopy()); 208 service_properties->DeepCopy());
209 return true; 209 return true;
210 } 210 }
211 211
212 void FakeShillProfileClient::GetProfilePaths( 212 void FakeShillProfileClient::GetProfilePaths(
213 std::vector<std::string>* profiles) { 213 std::vector<std::string>* profiles) {
214 for (auto iter = profiles_.begin(); iter != profiles_.end(); ++iter) 214 for (auto iter = profiles_.begin(); iter != profiles_.end(); ++iter)
215 profiles->push_back(iter->first); 215 profiles->push_back(iter->first);
216 } 216 }
217 217
218 void FakeShillProfileClient::GetProfilePathsContainingService(
219 const std::string& service_path,
220 std::vector<std::string>* profiles) {
221 for (auto iter = profiles_.begin(); iter != profiles_.end(); ++iter) {
222 std::string profile_path;
223 if (GetServiceDataFromProfile(iter, service_path, &profile_path, nullptr))
224 profiles->push_back(profile_path);
225 }
226 }
stevenjb 2017/03/29 00:06:45 blank line
tbarzic 2017/03/29 01:48:50 Done.
218 bool FakeShillProfileClient::GetService(const std::string& service_path, 227 bool FakeShillProfileClient::GetService(const std::string& service_path,
219 std::string* profile_path, 228 std::string* profile_path,
220 base::DictionaryValue* properties) { 229 base::DictionaryValue* properties) {
221 properties->Clear(); 230 properties->Clear();
231
232 auto shared = profiles_.find(GetSharedProfilePath());
233 bool found_shared = false;
234 if (shared != profiles_.end()) {
235 found_shared = GetServiceDataFromProfile(shared, service_path, profile_path,
236 properties);
237 }
stevenjb 2017/03/29 00:06:45 So, I kind of hate to ask this, but this is ugly a
tbarzic 2017/03/29 01:48:50 Sounds reasonable. Done.
238
222 for (auto iter = profiles_.begin(); iter != profiles_.end(); ++iter) { 239 for (auto iter = profiles_.begin(); iter != profiles_.end(); ++iter) {
223 const ProfileProperties* profile = iter->second.get(); 240 // Shared profile properties have already been applied before the for loop.
224 const base::DictionaryValue* entry; 241 if (iter->first == GetSharedProfilePath())
225 if (!profile->entries.GetDictionaryWithoutPathExpansion(
226 service_path, &entry)) {
227 continue; 242 continue;
243 if (GetServiceDataFromProfile(iter, service_path, profile_path,
244 properties)) {
245 return true;
228 } 246 }
229 *profile_path = iter->first;
230 properties->MergeDictionary(entry);
231 return true;
232 } 247 }
233 return false; 248 return found_shared;
234 } 249 }
235 250
236 void FakeShillProfileClient::ClearProfiles() { 251 void FakeShillProfileClient::ClearProfiles() {
237 profiles_.clear(); 252 profiles_.clear();
238 } 253 }
239 254
240 FakeShillProfileClient::ProfileProperties* FakeShillProfileClient::GetProfile( 255 FakeShillProfileClient::ProfileProperties* FakeShillProfileClient::GetProfile(
241 const dbus::ObjectPath& profile_path, 256 const dbus::ObjectPath& profile_path,
242 const ErrorCallback& error_callback) { 257 const ErrorCallback& error_callback) {
243 auto found = profiles_.find(profile_path.value()); 258 auto found = profiles_.find(profile_path.value());
244 if (found == profiles_.end()) { 259 if (found == profiles_.end()) {
245 if (!error_callback.is_null()) 260 if (!error_callback.is_null())
246 error_callback.Run("Error.InvalidProfile", "Invalid profile"); 261 error_callback.Run("Error.InvalidProfile", "Invalid profile");
247 return nullptr; 262 return nullptr;
248 } 263 }
249 264
250 return found->second.get(); 265 return found->second.get();
251 } 266 }
252 267
268 bool FakeShillProfileClient::GetServiceDataFromProfile(
269 const ProfileMap::iterator& iter,
stevenjb 2017/03/29 00:06:45 I would rather pass the profile path and const Pro
tbarzic 2017/03/29 01:48:50 Done in sense that now only ProfileProperties are
270 const std::string& service_path,
271 std::string* profile_path,
272 base::DictionaryValue* properties) {
273 const ProfileProperties* profile = iter->second.get();
274 const base::DictionaryValue* entry;
275 if (!profile->entries.GetDictionaryWithoutPathExpansion(service_path,
276 &entry)) {
277 return false;
278 }
279 *profile_path = iter->first;
280 if (properties)
281 properties->MergeDictionary(entry);
282 return true;
283 }
284
253 } // namespace chromeos 285 } // 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