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..3c57261980ee6ec3ffab44ebacf70b1a7beb58d5 100644 |
--- a/chrome/browser/ui/webui/local_state/local_state_ui.cc |
+++ b/chrome/browser/ui/webui/local_state/local_state_ui.cc |
@@ -4,8 +4,6 @@ |
#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 "build/build_config.h" |
@@ -19,8 +17,43 @@ |
#include "content/public/browser/web_ui_message_handler.h" |
#include "grit/browser_resources.h" |
+namespace internal { |
Alexei Svitkine (slow)
2016/04/25 21:30:13
Move the internal namespace below the anon namespa
hamelphi
2016/04/26 15:25:28
Done.
|
+ |
+namespace { |
Alexei Svitkine (slow)
2016/04/25 21:30:13
Nit: Add an empty line below this above above the
hamelphi
2016/04/26 15:25:28
Done.
|
+bool HasValidPrefix(const std::string& pref_name, |
Alexei Svitkine (slow)
2016/04/25 21:30:13
Nit: Add a short comment above this function.
hamelphi
2016/04/26 15:25:28
Done.
|
+ 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 |
+ |
+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 |
+ |
namespace { |
+#if defined(OS_CHROMEOS) |
+#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 +84,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,7 +100,6 @@ void LocalStateUIHandler::HandleRequestJson(const base::ListValue* args) { |
web_ui()->CallJavascriptFunction("localState.setLocalState", |
base::StringValue(json)); |
-#endif // !defined(OS_CHROMEOS) |
} |
} // namespace |