summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpastarmovj@chromium.org <pastarmovj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-12 17:37:40 +0000
committerpastarmovj@chromium.org <pastarmovj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-12 17:37:40 +0000
commite6d1c4f8756e0c8f75314f31ef3d538a0d7ffeca (patch)
treea9a76ba37d0418c93df99040d1a9bc6761440038
parentf7574895c6c11f2335059a29385bda29ffb75545 (diff)
downloadchromium_src-e6d1c4f8756e0c8f75314f31ef3d538a0d7ffeca.zip
chromium_src-e6d1c4f8756e0c8f75314f31ef3d538a0d7ffeca.tar.gz
chromium_src-e6d1c4f8756e0c8f75314f31ef3d538a0d7ffeca.tar.bz2
Refactor the storage layer out of about_flags.
This step is a preparation for moving owner flags storage from local state to signed settings. BUG=221353 TEST=existing about_flags tests still pass. Review URL: https://chromiumcodereview.appspot.com/16542004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@205854 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/about_flags.cc115
-rw-r--r--chrome/browser/about_flags.h16
-rw-r--r--chrome/browser/about_flags_unittest.cc70
-rw-r--r--chrome/browser/chrome_browser_main.cc5
-rw-r--r--chrome/browser/flags_storage.h28
-rw-r--r--chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.cc5
-rw-r--r--chrome/browser/pref_service_flags_storage.cc49
-rw-r--r--chrome/browser/pref_service_flags_storage.h31
-rw-r--r--chrome/browser/sync/profile_sync_service.cc10
-rw-r--r--chrome/browser/ui/webui/flags_ui.cc11
-rw-r--r--chrome/chrome_browser.gypi3
11 files changed, 221 insertions, 122 deletions
diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc
index 10c2540..834073d 100644
--- a/chrome/browser/about_flags.cc
+++ b/chrome/browser/about_flags.cc
@@ -12,15 +12,13 @@
#include "base/command_line.h"
#include "base/memory/singleton.h"
-#include "base/prefs/pref_service.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "cc/base/switches.h"
-#include "chrome/browser/prefs/scoped_user_pref_update.h"
+#include "chrome/browser/flags_storage.h"
#include "chrome/common/chrome_content_client.h"
#include "chrome/common/chrome_switches.h"
-#include "chrome/common/pref_names.h"
#include "content/public/browser/user_metrics.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
@@ -1556,13 +1554,16 @@ size_t num_experiments = arraysize(kExperiments);
class FlagsState {
public:
FlagsState() : needs_restart_(false) {}
- void ConvertFlagsToSwitches(PrefService* prefs, CommandLine* command_line);
+ void ConvertFlagsToSwitches(FlagsStorage* flags_storage,
+ CommandLine* command_line);
bool IsRestartNeededToCommitChanges();
void SetExperimentEnabled(
- PrefService* prefs, const std::string& internal_name, bool enable);
+ FlagsStorage* flags_storage,
+ const std::string& internal_name,
+ bool enable);
void RemoveFlagsSwitches(
std::map<std::string, CommandLine::StringType>* switch_list);
- void ResetAllFlags(PrefService* prefs);
+ void ResetAllFlags(FlagsStorage* flags_storage);
void reset();
// Returns the singleton instance of this class
@@ -1577,40 +1578,6 @@ class FlagsState {
DISALLOW_COPY_AND_ASSIGN(FlagsState);
};
-// Extracts the list of enabled lab experiments from preferences and stores them
-// in a set.
-void GetEnabledFlags(const PrefService* prefs, std::set<std::string>* result) {
- const ListValue* enabled_experiments = prefs->GetList(
- prefs::kEnabledLabsExperiments);
- if (!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 " << prefs::kEnabledLabsExperiments;
- continue;
- }
- result->insert(experiment_name);
- }
-}
-
-// Takes a set of enabled lab experiments
-void SetEnabledFlags(
- PrefService* prefs, const std::set<std::string>& enabled_experiments) {
- ListPrefUpdate update(prefs, prefs::kEnabledLabsExperiments);
- ListValue* experiments_list = update.Get();
-
- experiments_list->Clear();
- for (std::set<std::string>::const_iterator it = enabled_experiments.begin();
- it != enabled_experiments.end();
- ++it) {
- experiments_list->Append(new StringValue(*it));
- }
-}
-
// Adds the internal names for the specified experiment to |names|.
void AddInternalName(const Experiment& e, std::set<std::string>* names) {
if (e.type == Experiment::SINGLE_VALUE) {
@@ -1654,15 +1621,14 @@ bool ValidateExperiment(const Experiment& e) {
// Removes all experiments from prefs::kEnabledLabsExperiments that are
// unknown, to prevent this list to become very long as experiments are added
// and removed.
-void SanitizeList(PrefService* prefs) {
+void SanitizeList(FlagsStorage* flags_storage) {
std::set<std::string> known_experiments;
for (size_t i = 0; i < num_experiments; ++i) {
DCHECK(ValidateExperiment(experiments[i]));
AddInternalName(experiments[i], &known_experiments);
}
- std::set<std::string> enabled_experiments;
- GetEnabledFlags(prefs, &enabled_experiments);
+ std::set<std::string> enabled_experiments = flags_storage->GetFlags();
std::set<std::string> new_enabled_experiments;
std::set_intersection(
@@ -1671,20 +1637,20 @@ void SanitizeList(PrefService* prefs) {
std::inserter(new_enabled_experiments, new_enabled_experiments.begin()));
if (new_enabled_experiments != enabled_experiments)
- SetEnabledFlags(prefs, new_enabled_experiments);
+ flags_storage->SetFlags(new_enabled_experiments);
}
void GetSanitizedEnabledFlags(
- PrefService* prefs, std::set<std::string>* result) {
- SanitizeList(prefs);
- GetEnabledFlags(prefs, result);
+ FlagsStorage* flags_storage, std::set<std::string>* result) {
+ SanitizeList(flags_storage);
+ *result = flags_storage->GetFlags();
}
// Variant of GetSanitizedEnabledFlags that also removes any flags that aren't
// enabled on the current platform.
void GetSanitizedEnabledFlagsForCurrentPlatform(
- PrefService* prefs, std::set<std::string>* result) {
- GetSanitizedEnabledFlags(prefs, result);
+ FlagsStorage* flags_storage, std::set<std::string>* result) {
+ GetSanitizedEnabledFlags(flags_storage, result);
// Filter out any experiments that aren't enabled on the current platform. We
// don't remove these from prefs else syncing to a platform with a different
@@ -1754,16 +1720,18 @@ string16 Experiment::DescriptionForChoice(int index) const {
return l10n_util::GetStringUTF16(description_id);
}
-void ConvertFlagsToSwitches(PrefService* prefs, CommandLine* command_line) {
- FlagsState::GetInstance()->ConvertFlagsToSwitches(prefs, command_line);
+void ConvertFlagsToSwitches(FlagsStorage* flags_storage,
+ CommandLine* command_line) {
+ FlagsState::GetInstance()->ConvertFlagsToSwitches(flags_storage,
+ command_line);
}
-void GetFlagsExperimentsData(PrefService* prefs,
+void GetFlagsExperimentsData(FlagsStorage* flags_storage,
FlagAccess access,
base::ListValue* supported_experiments,
base::ListValue* unsupported_experiments) {
std::set<std::string> enabled_experiments;
- GetSanitizedEnabledFlags(prefs, &enabled_experiments);
+ GetSanitizedEnabledFlags(flags_storage, &enabled_experiments);
int current_platform = GetCurrentPlatform();
@@ -1814,9 +1782,11 @@ bool IsRestartNeededToCommitChanges() {
return FlagsState::GetInstance()->IsRestartNeededToCommitChanges();
}
-void SetExperimentEnabled(
- PrefService* prefs, const std::string& internal_name, bool enable) {
- FlagsState::GetInstance()->SetExperimentEnabled(prefs, internal_name, enable);
+void SetExperimentEnabled(FlagsStorage* flags_storage,
+ const std::string& internal_name,
+ bool enable) {
+ FlagsState::GetInstance()->SetExperimentEnabled(flags_storage,
+ internal_name, enable);
}
void RemoveFlagsSwitches(
@@ -1824,8 +1794,8 @@ void RemoveFlagsSwitches(
FlagsState::GetInstance()->RemoveFlagsSwitches(switch_list);
}
-void ResetAllFlags(PrefService* prefs) {
- FlagsState::GetInstance()->ResetAllFlags(prefs);
+void ResetAllFlags(FlagsStorage* flags_storage) {
+ FlagsState::GetInstance()->ResetAllFlags(flags_storage);
}
int GetCurrentPlatform() {
@@ -1844,9 +1814,8 @@ int GetCurrentPlatform() {
#endif
}
-void RecordUMAStatistics(const PrefService* prefs) {
- std::set<std::string> flags;
- GetEnabledFlags(prefs, &flags);
+void RecordUMAStatistics(FlagsStorage* flags_storage) {
+ std::set<std::string> flags = flags_storage->GetFlags();
for (std::set<std::string>::iterator it = flags.begin(); it != flags.end();
++it) {
std::string action("AboutFlags_");
@@ -1877,13 +1846,14 @@ void SetFlagToSwitchMapping(const std::string& key,
}
void FlagsState::ConvertFlagsToSwitches(
- PrefService* prefs, CommandLine* command_line) {
+ FlagsStorage* flags_storage, CommandLine* command_line) {
if (command_line->HasSwitch(switches::kNoExperiments))
return;
std::set<std::string> enabled_experiments;
- GetSanitizedEnabledFlagsForCurrentPlatform(prefs, &enabled_experiments);
+ GetSanitizedEnabledFlagsForCurrentPlatform(flags_storage,
+ &enabled_experiments);
NameToSwitchAndValueMap name_to_switch_map;
for (size_t i = 0; i < num_experiments; ++i) {
@@ -1941,8 +1911,9 @@ bool FlagsState::IsRestartNeededToCommitChanges() {
return needs_restart_;
}
-void FlagsState::SetExperimentEnabled(
- PrefService* prefs, const std::string& internal_name, bool enable) {
+void FlagsState::SetExperimentEnabled(FlagsStorage* flags_storage,
+ const std::string& internal_name,
+ bool enable) {
size_t at_index = internal_name.find(testing::kMultiSeparator);
if (at_index != std::string::npos) {
DCHECK(enable);
@@ -1950,20 +1921,20 @@ void FlagsState::SetExperimentEnabled(
// currently selected choice.
DCHECK_NE(at_index, 0u);
const std::string experiment_name = internal_name.substr(0, at_index);
- SetExperimentEnabled(prefs, experiment_name, false);
+ SetExperimentEnabled(flags_storage, experiment_name, false);
// And enable the new choice, if it is not the default first choice.
if (internal_name != experiment_name + "@0") {
std::set<std::string> enabled_experiments;
- GetSanitizedEnabledFlags(prefs, &enabled_experiments);
+ GetSanitizedEnabledFlags(flags_storage, &enabled_experiments);
needs_restart_ |= enabled_experiments.insert(internal_name).second;
- SetEnabledFlags(prefs, enabled_experiments);
+ flags_storage->SetFlags(enabled_experiments);
}
return;
}
std::set<std::string> enabled_experiments;
- GetSanitizedEnabledFlags(prefs, &enabled_experiments);
+ GetSanitizedEnabledFlags(flags_storage, &enabled_experiments);
const Experiment* e = NULL;
for (size_t i = 0; i < num_experiments; ++i) {
@@ -1998,7 +1969,7 @@ void FlagsState::SetExperimentEnabled(
}
}
- SetEnabledFlags(prefs, enabled_experiments);
+ flags_storage->SetFlags(enabled_experiments);
}
void FlagsState::RemoveFlagsSwitches(
@@ -2009,11 +1980,11 @@ void FlagsState::RemoveFlagsSwitches(
}
}
-void FlagsState::ResetAllFlags(PrefService* prefs) {
+void FlagsState::ResetAllFlags(FlagsStorage* flags_storage) {
needs_restart_ = true;
std::set<std::string> no_experiments;
- SetEnabledFlags(prefs, no_experiments);
+ flags_storage->SetFlags(no_experiments);
}
void FlagsState::reset() {
diff --git a/chrome/browser/about_flags.h b/chrome/browser/about_flags.h
index 304fec1..2553425 100644
--- a/chrome/browser/about_flags.h
+++ b/chrome/browser/about_flags.h
@@ -19,6 +19,8 @@ class ListValue;
namespace about_flags {
+class FlagsStorage;
+
// Enumeration of OSs.
// This is exposed only for testing.
enum { kOsMac = 1 << 0, kOsWin = 1 << 1, kOsLinux = 1 << 2 , kOsCrOS = 1 << 3,
@@ -105,7 +107,8 @@ struct Experiment {
// Reads the Labs |prefs| (called "Labs" for historical reasons) and adds the
// commandline flags belonging to the active experiments to |command_line|.
-void ConvertFlagsToSwitches(PrefService* prefs, CommandLine* command_line);
+void ConvertFlagsToSwitches(FlagsStorage* flags_storage,
+ CommandLine* command_line);
// Differentiate between generic flags available on a per session base and flags
// that influence the whole machine and can be said by the admin only. This flag
@@ -116,7 +119,7 @@ enum FlagAccess { kGeneralAccessFlagsOnly, kOwnerAccessToFlags };
// Get the list of experiments. Experiments that are available on the current
// platform are appended to |supported_experiments|; all other experiments are
// appended to |unsupported_experiments|.
-void GetFlagsExperimentsData(PrefService* prefs,
+void GetFlagsExperimentsData(FlagsStorage* flags_storage,
FlagAccess access,
base::ListValue* supported_experiments,
base::ListValue* unsupported_experiments);
@@ -125,8 +128,9 @@ void GetFlagsExperimentsData(PrefService* prefs,
bool IsRestartNeededToCommitChanges();
// Enables or disables the experiment with id |internal_name|.
-void SetExperimentEnabled(
- PrefService* prefs, const std::string& internal_name, bool enable);
+void SetExperimentEnabled(FlagsStorage* flags_storage,
+ const std::string& internal_name,
+ bool enable);
// Removes all switches that were added to a command line by a previous call to
// |ConvertFlagsToSwitches()|.
@@ -134,7 +138,7 @@ void RemoveFlagsSwitches(
std::map<std::string, CommandLine::StringType>* switch_list);
// Reset all flags to the default state by clearing all flags.
-void ResetAllFlags(PrefService* prefs);
+void ResetAllFlags(FlagsStorage* flags_storage);
// Returns the value for the current platform. This is one of the values defined
// by the OS enum above.
@@ -143,7 +147,7 @@ int GetCurrentPlatform();
// Sends UMA stats about experimental flag usage. This should be called once per
// startup.
-void RecordUMAStatistics(const PrefService* prefs);
+void RecordUMAStatistics(FlagsStorage* flags_storage);
namespace testing {
diff --git a/chrome/browser/about_flags_unittest.cc b/chrome/browser/about_flags_unittest.cc
index 4251cff..0c94f45 100644
--- a/chrome/browser/about_flags_unittest.cc
+++ b/chrome/browser/about_flags_unittest.cc
@@ -8,6 +8,7 @@
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/browser/about_flags.h"
+#include "chrome/browser/pref_service_flags_storage.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "grit/chromium_strings.h"
@@ -111,7 +112,7 @@ static Experiment kExperiments[] = {
class AboutFlagsTest : public ::testing::Test {
protected:
- AboutFlagsTest() {
+ AboutFlagsTest() : flags_storage_(&prefs_) {
prefs_.registry()->RegisterListPref(prefs::kEnabledLabsExperiments);
testing::ClearState();
}
@@ -133,18 +134,19 @@ class AboutFlagsTest : public ::testing::Test {
}
TestingPrefServiceSimple prefs_;
+ PrefServiceFlagsStorage flags_storage_;
};
TEST_F(AboutFlagsTest, NoChangeNoRestart) {
EXPECT_FALSE(IsRestartNeededToCommitChanges());
- SetExperimentEnabled(&prefs_, kFlags1, false);
+ SetExperimentEnabled(&flags_storage_, kFlags1, false);
EXPECT_FALSE(IsRestartNeededToCommitChanges());
}
TEST_F(AboutFlagsTest, ChangeNeedsRestart) {
EXPECT_FALSE(IsRestartNeededToCommitChanges());
- SetExperimentEnabled(&prefs_, kFlags1, true);
+ SetExperimentEnabled(&flags_storage_, kFlags1, true);
EXPECT_TRUE(IsRestartNeededToCommitChanges());
}
@@ -153,19 +155,19 @@ TEST_F(AboutFlagsTest, MultiFlagChangeNeedsRestart) {
ASSERT_EQ(kFlags4, experiment.internal_name);
EXPECT_FALSE(IsRestartNeededToCommitChanges());
// Enable the 2nd choice of the multi-value.
- SetExperimentEnabled(&prefs_, experiment.NameForChoice(2), true);
+ SetExperimentEnabled(&flags_storage_, experiment.NameForChoice(2), true);
EXPECT_TRUE(IsRestartNeededToCommitChanges());
testing::ClearState();
EXPECT_FALSE(IsRestartNeededToCommitChanges());
// Enable the default choice now.
- SetExperimentEnabled(&prefs_, experiment.NameForChoice(0), true);
+ SetExperimentEnabled(&flags_storage_, experiment.NameForChoice(0), true);
EXPECT_TRUE(IsRestartNeededToCommitChanges());
}
TEST_F(AboutFlagsTest, AddTwoFlagsRemoveOne) {
// Add two experiments, check they're there.
- SetExperimentEnabled(&prefs_, kFlags1, true);
- SetExperimentEnabled(&prefs_, kFlags2, true);
+ SetExperimentEnabled(&flags_storage_, kFlags1, true);
+ SetExperimentEnabled(&flags_storage_, kFlags2, true);
const ListValue* experiments_list = prefs_.GetList(
prefs::kEnabledLabsExperiments);
@@ -182,7 +184,7 @@ TEST_F(AboutFlagsTest, AddTwoFlagsRemoveOne) {
EXPECT_TRUE(s0 == kFlags2 || s1 == kFlags2);
// Remove one experiment, check the other's still around.
- SetExperimentEnabled(&prefs_, kFlags2, false);
+ SetExperimentEnabled(&flags_storage_, kFlags2, false);
experiments_list = prefs_.GetList(prefs::kEnabledLabsExperiments);
ASSERT_TRUE(experiments_list != NULL);
@@ -193,21 +195,21 @@ TEST_F(AboutFlagsTest, AddTwoFlagsRemoveOne) {
TEST_F(AboutFlagsTest, AddTwoFlagsRemoveBoth) {
// Add two experiments, check the pref exists.
- SetExperimentEnabled(&prefs_, kFlags1, true);
- SetExperimentEnabled(&prefs_, kFlags2, true);
+ SetExperimentEnabled(&flags_storage_, kFlags1, true);
+ SetExperimentEnabled(&flags_storage_, kFlags2, true);
const ListValue* experiments_list = prefs_.GetList(
prefs::kEnabledLabsExperiments);
ASSERT_TRUE(experiments_list != NULL);
// Remove both, the pref should have been removed completely.
- SetExperimentEnabled(&prefs_, kFlags1, false);
- SetExperimentEnabled(&prefs_, kFlags2, false);
+ SetExperimentEnabled(&flags_storage_, kFlags1, false);
+ SetExperimentEnabled(&flags_storage_, kFlags2, false);
experiments_list = prefs_.GetList(prefs::kEnabledLabsExperiments);
EXPECT_TRUE(experiments_list == NULL || experiments_list->GetSize() == 0);
}
TEST_F(AboutFlagsTest, ConvertFlagsToSwitches) {
- SetExperimentEnabled(&prefs_, kFlags1, true);
+ SetExperimentEnabled(&flags_storage_, kFlags1, true);
CommandLine command_line(CommandLine::NO_PROGRAM);
command_line.AppendSwitch("foo");
@@ -215,7 +217,7 @@ TEST_F(AboutFlagsTest, ConvertFlagsToSwitches) {
EXPECT_TRUE(command_line.HasSwitch("foo"));
EXPECT_FALSE(command_line.HasSwitch(kSwitch1));
- ConvertFlagsToSwitches(&prefs_, &command_line);
+ ConvertFlagsToSwitches(&flags_storage_, &command_line);
EXPECT_TRUE(command_line.HasSwitch("foo"));
EXPECT_TRUE(command_line.HasSwitch(kSwitch1));
@@ -228,7 +230,7 @@ TEST_F(AboutFlagsTest, RemoveFlagSwitches) {
switch_list[switches::kFlagSwitchesEnd] = CommandLine::StringType();
switch_list["foo"] = CommandLine::StringType();
- SetExperimentEnabled(&prefs_, kFlags1, true);
+ SetExperimentEnabled(&flags_storage_, kFlags1, true);
// This shouldn't do anything before ConvertFlagsToSwitches() wasn't called.
RemoveFlagsSwitches(&switch_list);
@@ -243,7 +245,7 @@ TEST_F(AboutFlagsTest, RemoveFlagSwitches) {
// Call ConvertFlagsToSwitches(), then RemoveFlagsSwitches() again.
CommandLine command_line(CommandLine::NO_PROGRAM);
command_line.AppendSwitch("foo");
- ConvertFlagsToSwitches(&prefs_, &command_line);
+ ConvertFlagsToSwitches(&flags_storage_, &command_line);
RemoveFlagsSwitches(&switch_list);
// Now the about:flags-related switch should have been removed.
@@ -254,15 +256,15 @@ TEST_F(AboutFlagsTest, RemoveFlagSwitches) {
// Tests enabling experiments that aren't supported on the current platform.
TEST_F(AboutFlagsTest, PersistAndPrune) {
// Enable experiments 1 and 3.
- SetExperimentEnabled(&prefs_, kFlags1, true);
- SetExperimentEnabled(&prefs_, kFlags3, true);
+ SetExperimentEnabled(&flags_storage_, kFlags1, true);
+ SetExperimentEnabled(&flags_storage_, kFlags3, true);
CommandLine command_line(CommandLine::NO_PROGRAM);
EXPECT_FALSE(command_line.HasSwitch(kSwitch1));
EXPECT_FALSE(command_line.HasSwitch(kSwitch3));
// Convert the flags to switches. Experiment 3 shouldn't be among the switches
// as it is not applicable to the current platform.
- ConvertFlagsToSwitches(&prefs_, &command_line);
+ ConvertFlagsToSwitches(&flags_storage_, &command_line);
EXPECT_TRUE(command_line.HasSwitch(kSwitch1));
EXPECT_FALSE(command_line.HasSwitch(kSwitch3));
@@ -283,14 +285,14 @@ TEST_F(AboutFlagsTest, PersistAndPrune) {
// line.
TEST_F(AboutFlagsTest, CheckValues) {
// Enable experiments 1 and 2.
- SetExperimentEnabled(&prefs_, kFlags1, true);
- SetExperimentEnabled(&prefs_, kFlags2, true);
+ SetExperimentEnabled(&flags_storage_, kFlags1, true);
+ SetExperimentEnabled(&flags_storage_, kFlags2, true);
CommandLine command_line(CommandLine::NO_PROGRAM);
EXPECT_FALSE(command_line.HasSwitch(kSwitch1));
EXPECT_FALSE(command_line.HasSwitch(kSwitch2));
// Convert the flags to switches.
- ConvertFlagsToSwitches(&prefs_, &command_line);
+ ConvertFlagsToSwitches(&flags_storage_, &command_line);
EXPECT_TRUE(command_line.HasSwitch(kSwitch1));
EXPECT_EQ(std::string(), command_line.GetSwitchValueASCII(kSwitch1));
EXPECT_TRUE(command_line.HasSwitch(kSwitch2));
@@ -345,16 +347,16 @@ TEST_F(AboutFlagsTest, MultiValues) {
// be set.
{
CommandLine command_line(CommandLine::NO_PROGRAM);
- ConvertFlagsToSwitches(&prefs_, &command_line);
+ ConvertFlagsToSwitches(&flags_storage_, &command_line);
EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1));
EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch2));
}
// Enable the 2nd choice of the multi-value.
- SetExperimentEnabled(&prefs_, experiment.NameForChoice(2), true);
+ SetExperimentEnabled(&flags_storage_, experiment.NameForChoice(2), true);
{
CommandLine command_line(CommandLine::NO_PROGRAM);
- ConvertFlagsToSwitches(&prefs_, &command_line);
+ ConvertFlagsToSwitches(&flags_storage_, &command_line);
EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1));
EXPECT_TRUE(command_line.HasSwitch(kMultiSwitch2));
EXPECT_EQ(std::string(kValueForMultiSwitch2),
@@ -362,10 +364,10 @@ TEST_F(AboutFlagsTest, MultiValues) {
}
// Disable the multi-value experiment.
- SetExperimentEnabled(&prefs_, experiment.NameForChoice(0), true);
+ SetExperimentEnabled(&flags_storage_, experiment.NameForChoice(0), true);
{
CommandLine command_line(CommandLine::NO_PROGRAM);
- ConvertFlagsToSwitches(&prefs_, &command_line);
+ ConvertFlagsToSwitches(&flags_storage_, &command_line);
EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1));
EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch2));
}
@@ -378,36 +380,36 @@ TEST_F(AboutFlagsTest, EnableDisableValues) {
// Nothing selected.
{
CommandLine command_line(CommandLine::NO_PROGRAM);
- ConvertFlagsToSwitches(&prefs_, &command_line);
+ ConvertFlagsToSwitches(&flags_storage_, &command_line);
EXPECT_FALSE(command_line.HasSwitch(kSwitch1));
EXPECT_FALSE(command_line.HasSwitch(kSwitch2));
}
// "Enable" option selected.
- SetExperimentEnabled(&prefs_, experiment.NameForChoice(1), true);
+ SetExperimentEnabled(&flags_storage_, experiment.NameForChoice(1), true);
{
CommandLine command_line(CommandLine::NO_PROGRAM);
- ConvertFlagsToSwitches(&prefs_, &command_line);
+ ConvertFlagsToSwitches(&flags_storage_, &command_line);
EXPECT_TRUE(command_line.HasSwitch(kSwitch1));
EXPECT_FALSE(command_line.HasSwitch(kSwitch2));
EXPECT_EQ(kEnableDisableValue1, command_line.GetSwitchValueASCII(kSwitch1));
}
// "Disable" option selected.
- SetExperimentEnabled(&prefs_, experiment.NameForChoice(2), true);
+ SetExperimentEnabled(&flags_storage_, experiment.NameForChoice(2), true);
{
CommandLine command_line(CommandLine::NO_PROGRAM);
- ConvertFlagsToSwitches(&prefs_, &command_line);
+ ConvertFlagsToSwitches(&flags_storage_, &command_line);
EXPECT_FALSE(command_line.HasSwitch(kSwitch1));
EXPECT_TRUE(command_line.HasSwitch(kSwitch2));
EXPECT_EQ(kEnableDisableValue2, command_line.GetSwitchValueASCII(kSwitch2));
}
// "Default" option selected, same as nothing selected.
- SetExperimentEnabled(&prefs_, experiment.NameForChoice(0), true);
+ SetExperimentEnabled(&flags_storage_, experiment.NameForChoice(0), true);
{
CommandLine command_line(CommandLine::NO_PROGRAM);
- ConvertFlagsToSwitches(&prefs_, &command_line);
+ ConvertFlagsToSwitches(&flags_storage_, &command_line);
EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch1));
EXPECT_FALSE(command_line.HasSwitch(kMultiSwitch2));
}
diff --git a/chrome/browser/chrome_browser_main.cc b/chrome/browser/chrome_browser_main.cc
index 2241f72..6f36b65 100644
--- a/chrome/browser/chrome_browser_main.cc
+++ b/chrome/browser/chrome_browser_main.cc
@@ -77,6 +77,7 @@
#include "chrome/browser/performance_monitor/performance_monitor.h"
#include "chrome/browser/performance_monitor/startup_timer.h"
#include "chrome/browser/plugins/plugin_prefs.h"
+#include "chrome/browser/pref_service_flags_storage.h"
#include "chrome/browser/prefs/chrome_pref_service_factory.h"
#include "chrome/browser/prefs/command_line_pref_store.h"
#include "chrome/browser/prefs/scoped_user_pref_update.h"
@@ -834,7 +835,9 @@ int ChromeBrowserMainParts::PreCreateThreadsImpl() {
{
TRACE_EVENT0("startup",
"ChromeBrowserMainParts::PreCreateThreadsImpl:ConvertFlags");
- about_flags::ConvertFlagsToSwitches(local_state_,
+ about_flags::PrefServiceFlagsStorage flags_storage_(
+ g_browser_process->local_state());
+ about_flags::ConvertFlagsToSwitches(&flags_storage_,
CommandLine::ForCurrentProcess());
}
diff --git a/chrome/browser/flags_storage.h b/chrome/browser/flags_storage.h
new file mode 100644
index 0000000..13efbb6
--- /dev/null
+++ b/chrome/browser/flags_storage.h
@@ -0,0 +1,28 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_FLAGS_STORAGE_H_
+#define CHROME_BROWSER_FLAGS_STORAGE_H_
+
+#include <set>
+#include <string>
+
+namespace about_flags {
+
+// Base class for flags storage implementations. Enables the about_flags
+// functions to store and retrieve data from various sources like PrefService
+// and CrosSettings.
+class FlagsStorage {
+ public:
+ virtual ~FlagsStorage() {}
+
+ // Retrieves the flags as a set of strings.
+ virtual std::set<std::string> GetFlags() = 0;
+ // Stores the |flags| and returns true on success.
+ virtual bool SetFlags(std::set<std::string> flags) = 0;
+};
+
+} // namespace about_flags
+
+#endif // CHROME_BROWSER_FLAGS_STORAGE_H_
diff --git a/chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.cc b/chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.cc
index 1637252..90f3855 100644
--- a/chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.cc
+++ b/chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.cc
@@ -15,6 +15,7 @@
#include "chrome/browser/about_flags.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_browser_main.h"
+#include "chrome/browser/pref_service_flags_storage.h"
#include "chrome/browser/shell_integration.h"
#include "content/public/browser/browser_thread.h"
#include "ui/base/touch/touch_device.h"
@@ -130,7 +131,9 @@ void ChromeBrowserMainExtraPartsMetrics::PreProfileInit() {
}
void ChromeBrowserMainExtraPartsMetrics::PreBrowserStart() {
- about_flags::RecordUMAStatistics(g_browser_process->local_state());
+ about_flags::PrefServiceFlagsStorage flags_storage_(
+ g_browser_process->local_state());
+ about_flags::RecordUMAStatistics(&flags_storage_);
// Querying the default browser state can be slow, do it in the background.
content::BrowserThread::GetBlockingPool()->PostDelayedTask(
diff --git a/chrome/browser/pref_service_flags_storage.cc b/chrome/browser/pref_service_flags_storage.cc
new file mode 100644
index 0000000..7cc1f5b
--- /dev/null
+++ b/chrome/browser/pref_service_flags_storage.cc
@@ -0,0 +1,49 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/pref_service_flags_storage.h"
+
+#include "base/prefs/pref_service.h"
+#include "base/values.h"
+#include "chrome/browser/prefs/scoped_user_pref_update.h"
+#include "chrome/common/pref_names.h"
+
+namespace about_flags {
+
+PrefServiceFlagsStorage::PrefServiceFlagsStorage(
+ PrefService *prefs) : prefs_(prefs) {}
+
+PrefServiceFlagsStorage::~PrefServiceFlagsStorage() {}
+
+std::set<std::string> PrefServiceFlagsStorage::GetFlags() {
+ const ListValue* enabled_experiments = prefs_->GetList(
+ prefs::kEnabledLabsExperiments);
+ std::set<std::string> flags;
+ 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 " << prefs::kEnabledLabsExperiments;
+ continue;
+ }
+ flags.insert(experiment_name);
+ }
+ return flags;
+}
+
+bool PrefServiceFlagsStorage::SetFlags(std::set<std::string> flags) {
+ ListPrefUpdate update(prefs_, prefs::kEnabledLabsExperiments);
+ ListValue* experiments_list = update.Get();
+
+ experiments_list->Clear();
+ for (std::set<std::string>::const_iterator it = flags.begin();
+ it != flags.end(); ++it) {
+ experiments_list->Append(new StringValue(*it));
+ }
+
+ return true;
+}
+
+} // namespace about_flags
diff --git a/chrome/browser/pref_service_flags_storage.h b/chrome/browser/pref_service_flags_storage.h
new file mode 100644
index 0000000..1a5539d
--- /dev/null
+++ b/chrome/browser/pref_service_flags_storage.h
@@ -0,0 +1,31 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_PREF_SERVICE_FLAGS_STORAGE_H_
+#define CHROME_BROWSER_PREF_SERVICE_FLAGS_STORAGE_H_
+
+#include "base/compiler_specific.h"
+#include "chrome/browser/flags_storage.h"
+
+class PrefService;
+
+namespace about_flags {
+
+// Implements the FlagsStorage interface with a PrefService backend.
+// This is the implementation used on desktop Chrome for all users.
+class PrefServiceFlagsStorage : public FlagsStorage {
+ public:
+ explicit PrefServiceFlagsStorage(PrefService *prefs);
+ virtual ~PrefServiceFlagsStorage();
+
+ virtual std::set<std::string> GetFlags() OVERRIDE;
+ virtual bool SetFlags(std::set<std::string> flags) OVERRIDE;
+
+ private:
+ PrefService* prefs_;
+};
+
+} // namespace about_flags
+
+#endif // CHROME_BROWSER_PREF_SERVICE_FLAGS_STORAGE_H_
diff --git a/chrome/browser/sync/profile_sync_service.cc b/chrome/browser/sync/profile_sync_service.cc
index 0a0a131..54d8ad2 100644
--- a/chrome/browser/sync/profile_sync_service.cc
+++ b/chrome/browser/sync/profile_sync_service.cc
@@ -26,6 +26,7 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/defaults.h"
#include "chrome/browser/net/chrome_cookie_notification_details.h"
+#include "chrome/browser/pref_service_flags_storage.h"
#include "chrome/browser/prefs/pref_service_syncable.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/about_signin_internals.h"
@@ -979,6 +980,9 @@ void ProfileSyncService::OnExperimentsChanged(
<< syncer::ModelTypeSetToString(to_add);
DVLOG(2) << "Enabling types: " << syncer::ModelTypeSetToString(to_register);
+ about_flags::PrefServiceFlagsStorage flags_storage_(
+ g_browser_process->local_state());
+
for (syncer::ModelTypeSet::Iterator it = to_register.First();
it.Good(); it.Inc()) {
// Received notice to enable experimental type. Check if the type is
@@ -991,7 +995,7 @@ void ProfileSyncService::OnExperimentsChanged(
std::string experiment_name = GetExperimentNameForDataType(it.Get());
if (experiment_name.empty())
continue;
- about_flags::SetExperimentEnabled(g_browser_process->local_state(),
+ about_flags::SetExperimentEnabled(&flags_storage_,
experiment_name,
true);
}
@@ -1017,13 +1021,13 @@ void ProfileSyncService::OnExperimentsChanged(
// Now enable any non-datatype features.
if (experiments.keystore_encryption) {
- about_flags::SetExperimentEnabled(g_browser_process->local_state(),
+ about_flags::SetExperimentEnabled(&flags_storage_,
syncer::kKeystoreEncryptionFlag,
true);
}
if (experiments.favicon_sync) {
- about_flags::SetExperimentEnabled(g_browser_process->local_state(),
+ about_flags::SetExperimentEnabled(&flags_storage_,
syncer::kFaviconSyncFlag,
true);
}
diff --git a/chrome/browser/ui/webui/flags_ui.cc b/chrome/browser/ui/webui/flags_ui.cc
index 2faa0e1..6a31619 100644
--- a/chrome/browser/ui/webui/flags_ui.cc
+++ b/chrome/browser/ui/webui/flags_ui.cc
@@ -16,6 +16,7 @@
#include "chrome/browser/about_flags.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/lifetime/application_lifetime.h"
+#include "chrome/browser/pref_service_flags_storage.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_version_info.h"
#include "chrome/common/pref_names.h"
@@ -98,7 +99,7 @@ content::WebUIDataSource* CreateFlagsUIHTMLSource() {
class FlagsDOMHandler : public WebUIMessageHandler {
public:
explicit FlagsDOMHandler(PrefService* prefs, about_flags::FlagAccess access)
- : prefs_(prefs), access_(access) {}
+ : flags_storage_(prefs), access_(access) {}
virtual ~FlagsDOMHandler() {}
// WebUIMessageHandler implementation.
@@ -117,7 +118,7 @@ class FlagsDOMHandler : public WebUIMessageHandler {
void HandleResetAllFlags(const ListValue* args);
private:
- PrefService* prefs_;
+ about_flags::PrefServiceFlagsStorage flags_storage_;
about_flags::FlagAccess access_;
DISALLOW_COPY_AND_ASSIGN(FlagsDOMHandler);
@@ -141,7 +142,7 @@ void FlagsDOMHandler::RegisterMessages() {
void FlagsDOMHandler::HandleRequestFlagsExperiments(const ListValue* args) {
scoped_ptr<ListValue> supported_experiments(new ListValue);
scoped_ptr<ListValue> unsupported_experiments(new ListValue);
- about_flags::GetFlagsExperimentsData(prefs_,
+ about_flags::GetFlagsExperimentsData(&flags_storage_,
access_,
supported_experiments.get(),
unsupported_experiments.get());
@@ -176,7 +177,7 @@ void FlagsDOMHandler::HandleEnableFlagsExperimentMessage(
return;
about_flags::SetExperimentEnabled(
- prefs_,
+ &flags_storage_,
experiment_internal_name,
enable_str == "true");
}
@@ -186,7 +187,7 @@ void FlagsDOMHandler::HandleRestartBrowser(const ListValue* args) {
}
void FlagsDOMHandler::HandleResetAllFlags(const ListValue* args) {
- about_flags::ResetAllFlags(g_browser_process->local_state());
+ about_flags::ResetAllFlags(&flags_storage_);
}
} // namespace
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 1aacb27..4924151 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -557,6 +557,7 @@
'browser/first_run/upgrade_util_mac.cc',
'browser/first_run/upgrade_util_win.cc',
'browser/first_run/upgrade_util_win.h',
+ 'browser/flags_storage.h',
'browser/fullscreen.h',
'browser/fullscreen_aura.cc',
'browser/fullscreen_chromeos.cc',
@@ -1463,6 +1464,8 @@
'browser/predictors/resource_prefetcher.h',
'browser/predictors/resource_prefetcher_manager.cc',
'browser/predictors/resource_prefetcher_manager.h',
+ 'browser/pref_service_flags_storage.cc',
+ 'browser/pref_service_flags_storage.h',
'browser/prefs/browser_prefs.cc',
'browser/prefs/browser_prefs.h',
'browser/prefs/chrome_pref_service_factory.cc',