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

Unified Diff: chromeos/dbus/fake_shill_profile_client.cc

Issue 2754903002: Prevent networkingPrivate.forgetNetwork from removing shared configs (Closed)
Patch Set: . Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: chromeos/dbus/fake_shill_profile_client.cc
diff --git a/chromeos/dbus/fake_shill_profile_client.cc b/chromeos/dbus/fake_shill_profile_client.cc
index 9a5fe1a3c0522195735e597ff2458e1fabf3e7de..3a9d955276a5776cc1419e9865fde1aa5ff69655 100644
--- a/chromeos/dbus/fake_shill_profile_client.cc
+++ b/chromeos/dbus/fake_shill_profile_client.cc
@@ -23,6 +23,7 @@
namespace chromeos {
struct FakeShillProfileClient::ProfileProperties {
+ std::string path; // Profile path
base::DictionaryValue entries; // Dictionary of Service Dictionaries
base::DictionaryValue properties; // Dictionary of Profile properties
};
@@ -127,11 +128,22 @@ void FakeShillProfileClient::AddProfile(const std::string& profile_path,
if (GetProfile(dbus::ObjectPath(profile_path), ErrorCallback()))
return;
- std::unique_ptr<ProfileProperties> profile =
- base::MakeUnique<ProfileProperties>();
+ // If adding a shared profile, make sure there are no user profiles currently
+ // on the stack - note that it's enough to check the top of the stack only.
+ if (profile_path == GetSharedProfilePath()) {
+ if (!(profiles_.empty() ||
+ profiles_.back()->path == GetSharedProfilePath())) {
+ NOTREACHED() << "Adding shared profile when a user profile exists.";
+ return;
+ }
+ }
stevenjb 2017/03/30 17:33:13 nit: We shouldn't need to support multiple shared
tbarzic 2017/03/30 18:00:05 Done.
+
+ auto profile = base::MakeUnique<ProfileProperties>();
profile->properties.SetStringWithoutPathExpansion(shill::kUserHashProperty,
userhash);
- profiles_[profile_path] = std::move(profile);
+ profile->path = profile_path;
+ profiles_.emplace_back(std::move(profile));
+
DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()->
AddProfile(profile_path);
}
@@ -211,26 +223,32 @@ bool FakeShillProfileClient::AddOrUpdateServiceImpl(
void FakeShillProfileClient::GetProfilePaths(
std::vector<std::string>* profiles) {
- for (auto iter = profiles_.begin(); iter != profiles_.end(); ++iter)
- profiles->push_back(iter->first);
+ for (const auto& profile : profiles_)
+ profiles->push_back(profile->path);
+}
+
+void FakeShillProfileClient::GetProfilePathsContainingService(
+ const std::string& service_path,
+ std::vector<std::string>* profiles) {
+ for (const auto& profile : profiles_) {
+ if (GetServiceDataFromProfile(profile.get(), service_path, nullptr))
+ profiles->push_back(profile->path);
+ }
}
bool FakeShillProfileClient::GetService(const std::string& service_path,
std::string* profile_path,
base::DictionaryValue* properties) {
properties->Clear();
- for (auto iter = profiles_.begin(); iter != profiles_.end(); ++iter) {
- const ProfileProperties* profile = iter->second.get();
- const base::DictionaryValue* entry;
- if (!profile->entries.GetDictionaryWithoutPathExpansion(
- service_path, &entry)) {
- continue;
+
+ bool found_profile = false;
+ for (const auto& profile : profiles_) {
+ if (GetServiceDataFromProfile(profile.get(), service_path, properties)) {
+ found_profile = true;
+ *profile_path = profile->path;
}
- *profile_path = iter->first;
- properties->MergeDictionary(entry);
- return true;
}
- return false;
+ return found_profile;
}
void FakeShillProfileClient::ClearProfiles() {
@@ -240,14 +258,29 @@ void FakeShillProfileClient::ClearProfiles() {
FakeShillProfileClient::ProfileProperties* FakeShillProfileClient::GetProfile(
const dbus::ObjectPath& profile_path,
const ErrorCallback& error_callback) {
- auto found = profiles_.find(profile_path.value());
- if (found == profiles_.end()) {
- if (!error_callback.is_null())
- error_callback.Run("Error.InvalidProfile", "Invalid profile");
- return nullptr;
+ for (auto& profile : profiles_) {
+ if (profile->path == profile_path.value())
+ return profile.get();
}
+ if (!error_callback.is_null())
+ error_callback.Run("Error.InvalidProfile", "Invalid profile");
+ return nullptr;
+}
- return found->second.get();
+bool FakeShillProfileClient::GetServiceDataFromProfile(
+ const FakeShillProfileClient::ProfileProperties* profile,
+ const std::string& service_path,
+ base::DictionaryValue* properties) {
+ const base::DictionaryValue* entry;
+ if (!profile->entries.GetDictionaryWithoutPathExpansion(service_path,
+ &entry)) {
+ return false;
+ }
+
+ if (properties)
+ properties->MergeDictionary(entry);
+
+ return true;
}
} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698