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

Unified Diff: chrome/browser/about_flags.cc

Issue 12452003: Move pref backing up flags from local state to device settings on ChromeOS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments. Created 7 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
« no previous file with comments | « chrome/app/policy/policy_templates.json ('k') | chrome/browser/chromeos/settings/cros_settings_names.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/about_flags.cc
diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc
index 9ef2d43cd91047a8c4bfc52bf2edce44eaf0b06d..be3512c995a2a92a8ce5121ec8f37baae1d3441f 100644
--- a/chrome/browser/about_flags.cc
+++ b/chrome/browser/about_flags.cc
@@ -43,6 +43,8 @@
#endif
#if defined(OS_CHROMEOS)
+#include "chrome/browser/chromeos/settings/cros_settings.h"
+#include "chrome/browser/chromeos/settings/cros_settings_names.h"
#include "chromeos/chromeos_switches.h"
#endif
@@ -1317,9 +1319,58 @@ class FlagsState {
DISALLOW_COPY_AND_ASSIGN(FlagsState);
};
+#if defined(OS_CHROMEOS)
+// Extracts the list of enabled lab experiments from device settings and stores
+// them in a set.
+void GetEnabledFlagsFromDeviceSettings(std::set<std::string>* result) {
+ const ListValue* enabled_experiments;
+ if (!chromeos::CrosSettings::Get()->GetList(chromeos::kStartUpFlags,
+ &enabled_experiments)) {
+ return;
+ }
+
+ for (ListValue::const_iterator it = enabled_experiments->begin();
+ it != enabled_experiments->end();
+ ++it) {
+ std::string experiment_name;
+ if (!(*it)->GetAsString(&experiment_name)) {
+ LOG(WARNING) << "Invalid entry in " << chromeos::kStartUpFlags;
+ continue;
+ }
+ result->insert(experiment_name);
+ }
+}
+
+// Takes a set of enabled lab experiments and saves it into the device settings
+// storage on ChromeOS.
+void SetEnabledFlagsToDeviceSettings(
+ const std::set<std::string>& enabled_experiments) {
+ scoped_ptr<base::ListValue> experiments_list(new base::ListValue());
+
+ for (std::set<std::string>::const_iterator it = enabled_experiments.begin();
+ it != enabled_experiments.end();
+ ++it) {
+ experiments_list->Append(new StringValue(*it));
+ }
+ chromeos::CrosSettings::Get()->Set(chromeos::kStartUpFlags,
+ *experiments_list);
+}
+#endif
+
// Extracts the list of enabled lab experiments from preferences and stores them
-// in a set.
+// in a set. On ChromeOS |prefs| can be NULL when reading machine level flags.
void GetEnabledFlags(const PrefService* prefs, std::set<std::string>* result) {
+#if defined(OS_CHROMEOS)
+ // On ChromeOS flags are stored in the device settings blob.
+ if (!prefs) {
+ GetEnabledFlagsFromDeviceSettings(result);
+ return;
+ }
+#else
+ // Never allow |prefs| to be NULL on other platforms.
+ CHECK(prefs);
+#endif
+
const ListValue* enabled_experiments = prefs->GetList(
prefs::kEnabledLabsExperiments);
if (!enabled_experiments)
@@ -1337,9 +1388,21 @@ void GetEnabledFlags(const PrefService* prefs, std::set<std::string>* result) {
}
}
-// Takes a set of enabled lab experiments
+// Takes a set of enabled lab experiments. On ChromeOS |prefs| can be NULL when
+// setting machine level flags.
void SetEnabledFlags(
PrefService* prefs, const std::set<std::string>& enabled_experiments) {
+#if defined(OS_CHROMEOS)
+ // On ChromeOS flags are stored in the device settings blob.
+ if (!prefs) {
+ SetEnabledFlagsToDeviceSettings(enabled_experiments);
+ return;
+ }
+#else
+ // Never allow |prefs| to be NULL on other platforms.
+ CHECK(prefs);
+#endif
+
ListPrefUpdate update(prefs, prefs::kEnabledLabsExperiments);
ListValue* experiments_list = update.Get();
« no previous file with comments | « chrome/app/policy/policy_templates.json ('k') | chrome/browser/chromeos/settings/cros_settings_names.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698