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

Unified Diff: components/prefs/pref_service.cc

Issue 1910323002: Allow whitelisted prefs to be displayed in ChromeOS in chrome://local-state. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 side-by-side diff with in-line comments
Download patch
Index: components/prefs/pref_service.cc
diff --git a/components/prefs/pref_service.cc b/components/prefs/pref_service.cc
index 1ef2313b3fa45576e6784ed373609f23725984ef..d9b99ed9456c6e08d444466f6ec8282676528771 100644
--- a/components/prefs/pref_service.cc
+++ b/components/prefs/pref_service.cc
@@ -52,6 +52,15 @@ uint32_t GetWriteFlags(const PrefService::Preference* pref) {
return write_flags;
}
+bool HasValidPrefix(const std::string& pref_name,
+ const std::vector<std::string> valid_prefixes) {
+ for (const std::string& prefix : valid_prefixes) {
+ if (pref_name.compare(0, prefix.size(), prefix) == 0)
+ return true;
+ }
+ return false;
+}
+
} // namespace
PrefService::PrefService(
@@ -201,15 +210,32 @@ scoped_ptr<base::DictionaryValue> PrefService::GetPreferenceValues() const {
return out;
}
+void PrefService::SetPreferenceOmitdefault(const std::string& pref_name,
+ base::DictionaryValue* out) const {
+ const Preference* pref = FindPreference(pref_name);
+ if (pref->IsDefaultValue())
+ return;
+ out->Set(pref_name, pref->GetValue()->CreateDeepCopy());
+}
+
scoped_ptr<base::DictionaryValue> PrefService::GetPreferenceValuesOmitDefaults()
const {
DCHECK(CalledOnValidThread());
scoped_ptr<base::DictionaryValue> out(new base::DictionaryValue);
for (const auto& it : *pref_registry_) {
- const Preference* pref = FindPreference(it.first);
- if (pref->IsDefaultValue())
- continue;
- out->Set(it.first, pref->GetValue()->CreateDeepCopy());
+ SetPreferenceOmitdefault(it.first, out.get());
+ }
+ return out;
+}
+
+scoped_ptr<base::DictionaryValue>
+PrefService::GetWhitelistedPreferenceValuesOmitDefaults(
+ const std::vector<std::string>& whitelisted_prefixes) const {
+ DCHECK(CalledOnValidThread());
+ scoped_ptr<base::DictionaryValue> out(new base::DictionaryValue);
+ for (const auto& it : *pref_registry_) {
+ if (HasValidPrefix(it.first, whitelisted_prefixes))
+ SetPreferenceOmitdefault(it.first, out.get());
}
return out;
}
« chrome/browser/ui/webui/local_state/local_state_ui.cc ('K') | « components/prefs/pref_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698