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

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
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..ef4ff502d6d4c62c016b95f214536582b60e930d 100644
--- a/chrome/browser/ui/webui/local_state/local_state_ui.cc
+++ b/chrome/browser/ui/webui/local_state/local_state_ui.cc
@@ -4,10 +4,9 @@
#include "chrome/browser/ui/webui/local_state/local_state_ui.h"
-#include <string>
-
#include "base/json/json_string_value_serializer.h"
#include "base/macros.h"
+#include "base/values.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/profile.h"
@@ -21,6 +20,12 @@
namespace {
+#if defined(OS_CHROMEOS)
Alexei Svitkine (slow) 2016/04/26 15:33:35 Nit: Add a comment above this block. e.g.: // On
hamelphi1 2016/04/26 17:42:40 Done.
+#define ENABLE_FILTERING true
+#else
+#define ENABLE_FILTERING false
+#endif // defined(OS_CHROMEOS)
+
// UI Handler for chrome://local-state. Displays the Local State file as JSON.
class LocalStateUIHandler : public content::WebUIMessageHandler {
public:
@@ -51,10 +56,13 @@ void LocalStateUIHandler::RegisterMessages() {
}
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 (ENABLE_FILTERING) {
+ std::vector<std::string> whitelisted_prefixes = {
+ "variations", "user_experience_metrics", "uninstall_metrics"};
+ internal::FilterPrefs(whitelisted_prefixes, local_state_values.get());
+ }
std::string json;
JSONStringValueSerializer serializer(&json);
serializer.set_pretty_print(true);
@@ -64,11 +72,39 @@ void LocalStateUIHandler::HandleRequestJson(const base::ListValue* args) {
web_ui()->CallJavascriptFunction("localState.setLocalState",
base::StringValue(json));
-#endif // !defined(OS_CHROMEOS)
+}
+
+// Returns true if |pref_name| starts with one of the |valid_prefixes|.
+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
+namespace internal {
+
+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);
+ }
+}
+
+} // namespace internal
+
LocalStateUI::LocalStateUI(content::WebUI* web_ui) : WebUIController(web_ui) {
// Set up the chrome://local-state source.
content::WebUIDataSource* html_source =

Powered by Google App Engine
This is Rietveld 408576698