diff options
author | georgesak <georgesak@chromium.org> | 2014-11-05 08:43:18 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-11-05 16:43:32 +0000 |
commit | 1664ab5550a40432d0770d3162b5fae54fd61750 (patch) | |
tree | 40d7e0de7967fbaa43c90a51e5a55c1d0443220f /base/metrics | |
parent | 6b3f25737f6e99a23b0bb01f84e35d70c1ab0aca (diff) | |
download | chromium_src-1664ab5550a40432d0770d3162b5fae54fd61750.zip chromium_src-1664ab5550a40432d0770d3162b5fae54fd61750.tar.gz chromium_src-1664ab5550a40432d0770d3162b5fae54fd61750.tar.bz2 |
Added a marker for field trials passed on the command line to force their activation.
BUG=430233
Review URL: https://codereview.chromium.org/700933002
Cr-Commit-Position: refs/heads/master@{#302813}
Diffstat (limited to 'base/metrics')
-rw-r--r-- | base/metrics/field_trial.cc | 16 | ||||
-rw-r--r-- | base/metrics/field_trial.h | 14 | ||||
-rw-r--r-- | base/metrics/field_trial_unittest.cc | 23 |
3 files changed, 47 insertions, 6 deletions
diff --git a/base/metrics/field_trial.cc b/base/metrics/field_trial.cc index c82f33d..7efca7a3 100644 --- a/base/metrics/field_trial.cc +++ b/base/metrics/field_trial.cc @@ -67,6 +67,7 @@ const int FieldTrial::kDefaultGroupNumber = 0; bool FieldTrial::enable_benchmarking_ = false; const char FieldTrialList::kPersistentStringSeparator('/'); +const char FieldTrialList::kActivationMarker('*'); int FieldTrialList::kNoExpirationYear = 0; //------------------------------------------------------------------------------ @@ -421,7 +422,18 @@ bool FieldTrialList::CreateTrialsFromString( return false; if (group_name_end == trials_string.npos) group_name_end = trials_string.length(); - std::string name(trials_string, next_item, name_end - next_item); + + // Verify if the trial should be activated or not. + std::string name; + bool force_activation = false; + if (trials_string[next_item] == kActivationMarker) { + // Name cannot be only the indicator. + if (name_end - next_item == 1) + return false; + next_item++; + force_activation = true; + } + name.append(trials_string, next_item, name_end - next_item); std::string group_name(trials_string, name_end + 1, group_name_end - name_end - 1); next_item = group_name_end + 1; @@ -432,7 +444,7 @@ bool FieldTrialList::CreateTrialsFromString( FieldTrial* trial = CreateFieldTrial(name, group_name); if (!trial) return false; - if (mode == ACTIVATE_TRIALS) { + if (mode == ACTIVATE_TRIALS || force_activation) { // Call |group()| to mark the trial as "used" and notify observers, if // any. This is useful to ensure that field trials created in child // processes are properly reported in crash reports. diff --git a/base/metrics/field_trial.h b/base/metrics/field_trial.h index 25ee0c1..e2e5439 100644 --- a/base/metrics/field_trial.h +++ b/base/metrics/field_trial.h @@ -291,7 +291,8 @@ class BASE_EXPORT FieldTrial : public RefCounted<FieldTrial> { class BASE_EXPORT FieldTrialList { public: // Specifies whether field trials should be activated (marked as "used"), when - // created using |CreateTrialsFromString()|. + // created using |CreateTrialsFromString()|. Has no effect on trials that are + // prefixed with |kActivationMarker|, which will always be activated." enum FieldTrialActivationMode { DONT_ACTIVATE_TRIALS, ACTIVATE_TRIALS, @@ -302,6 +303,10 @@ class BASE_EXPORT FieldTrialList { // second process to mimic our state (i.e., provide the same group name). static const char kPersistentStringSeparator; // Currently a slash. + // Define a marker character to be used as a prefix to a trial name on the + // command line which forces its activation. + static const char kActivationMarker; // Currently an asterisk. + // Year that is guaranteed to not be expired when instantiating a field trial // via |FactoryGetFieldTrial()|. Set to two years from the build date. static int kNoExpirationYear; @@ -412,9 +417,10 @@ class BASE_EXPORT FieldTrialList { // used in a non-browser process, to carry randomly selected state in a // browser process into this non-browser process, but could also be invoked // through a command line argument to the browser process. The created field - // trials are marked as "used" for the purposes of active trial reporting if - // |mode| is ACTIVATE_TRIALS. Trial names in |ignored_trial_names| are ignored - // when parsing |prior_trials|. + // trials are all marked as "used" for the purposes of active trial reporting + // if |mode| is ACTIVATE_TRIALS, otherwise each trial will be marked as "used" + // if it is prefixed with |kActivationMarker|. Trial names in + // |ignored_trial_names| are ignored when parsing |prior_trials|. static bool CreateTrialsFromString( const std::string& prior_trials, FieldTrialActivationMode mode, diff --git a/base/metrics/field_trial_unittest.cc b/base/metrics/field_trial_unittest.cc index 1ed3f89..ce95c2a 100644 --- a/base/metrics/field_trial_unittest.cc +++ b/base/metrics/field_trial_unittest.cc @@ -428,6 +428,12 @@ TEST_F(FieldTrialTest, BogusRestore) { EXPECT_FALSE(FieldTrialList::CreateTrialsFromString( "noname, only group/", FieldTrialList::DONT_ACTIVATE_TRIALS, std::set<std::string>())); + EXPECT_FALSE(FieldTrialList::CreateTrialsFromString( + "/emptyname", FieldTrialList::DONT_ACTIVATE_TRIALS, + std::set<std::string>())); + EXPECT_FALSE(FieldTrialList::CreateTrialsFromString( + "*/emptyname", FieldTrialList::DONT_ACTIVATE_TRIALS, + std::set<std::string>())); } TEST_F(FieldTrialTest, DuplicateRestore) { @@ -490,6 +496,23 @@ TEST_F(FieldTrialTest, CreateTrialsFromStringNotActive) { EXPECT_EQ("zyx", active_groups[1].group_name); } +TEST_F(FieldTrialTest, CreateTrialsFromStringForceActivation) { + ASSERT_FALSE(FieldTrialList::TrialExists("Abc")); + ASSERT_FALSE(FieldTrialList::TrialExists("def")); + ASSERT_FALSE(FieldTrialList::TrialExists("Xyz")); + ASSERT_TRUE(FieldTrialList::CreateTrialsFromString( + "*Abc/cba/def/fed/*Xyz/zyx/", FieldTrialList::DONT_ACTIVATE_TRIALS, + std::set<std::string>())); + + FieldTrial::ActiveGroups active_groups; + FieldTrialList::GetActiveFieldTrialGroups(&active_groups); + ASSERT_EQ(2U, active_groups.size()); + EXPECT_EQ("Abc", active_groups[0].trial_name); + EXPECT_EQ("cba", active_groups[0].group_name); + EXPECT_EQ("Xyz", active_groups[1].trial_name); + EXPECT_EQ("zyx", active_groups[1].group_name); +} + TEST_F(FieldTrialTest, CreateTrialsFromStringActiveObserver) { ASSERT_FALSE(FieldTrialList::TrialExists("Abc")); |