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

Unified Diff: chrome/browser/ui/webui/local_state/local_state_ui.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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/webui/local_state/local_state_ui.cc
diff --git a/chrome/browser/ui/webui/local_state/local_state_ui.cc b/chrome/browser/ui/webui/local_state/local_state_ui.cc
index 22740b170aed2da1de510627ecdb5e800432cc78..8bfa53c0bd623b3f792442c1d94324146a1a5009 100644
--- a/chrome/browser/ui/webui/local_state/local_state_ui.cc
+++ b/chrome/browser/ui/webui/local_state/local_state_ui.cc
@@ -50,11 +50,40 @@ void LocalStateUIHandler::RegisterMessages() {
base::Unretained(this)));
}
+#if defined(OS_CHROMEOS)
+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;
+}
+
+void FilterPrefs(const std::vector<std::string>& valid_prefixes,
+ base::DictionaryValue* prefs) {
+ std::vector<std::string> prefs_to_remove;
+ for (base::DictionaryValue::Iterator it(*prefs); !it.IsAtEnd();
+ it.Advance()) {
+ if (!HasValidPrefix(it.key(), valid_prefixes))
+ prefs_to_remove.push_back(it.key());
+ }
+ for (const std::string& pref_to_remove : prefs_to_remove) {
+ std::unique_ptr<base::Value> removed_value;
+ bool successfully_removed = prefs->Remove(pref_to_remove, &removed_value);
+ DCHECK(successfully_removed);
+ }
+}
+#endif // defined(OS_CHROMEOS)
+
void LocalStateUIHandler::HandleRequestJson(const base::ListValue* args) {
-#if !defined(OS_CHROMEOS)
std::unique_ptr<base::DictionaryValue> local_state_values(
g_browser_process->local_state()->GetPreferenceValuesOmitDefaults());
-
+#if defined(OS_CHROMEOS)
+ std::vector<std::string> whitelisted_prefixes = {
+ "variations", "user_experience_metrics", "uninstall_metrics"};
+ FilterPrefs(whitelisted_prefixes, local_state_values.get());
+#endif // !defined(OS_CHROMEOS)
Bernhard Bauer 2016/04/25 16:17:58 Remove the exclamation mark here as well.
hamelphi 2016/04/25 21:05:14 Done.
std::string json;
JSONStringValueSerializer serializer(&json);
serializer.set_pretty_print(true);
@@ -64,7 +93,6 @@ void LocalStateUIHandler::HandleRequestJson(const base::ListValue* args) {
web_ui()->CallJavascriptFunction("localState.setLocalState",
base::StringValue(json));
-#endif // !defined(OS_CHROMEOS)
}
} // namespace
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698