diff options
-rw-r--r-- | base/metrics/field_trial.cc | 119 | ||||
-rw-r--r-- | base/metrics/field_trial.h | 75 | ||||
-rw-r--r-- | base/metrics/field_trial_unittest.cc | 131 | ||||
-rw-r--r-- | chrome/browser/browser_main.cc | 87 | ||||
-rw-r--r-- | chrome/browser/io_thread.cc | 8 | ||||
-rw-r--r-- | chrome/browser/net/predictor_api.cc | 9 | ||||
-rw-r--r-- | chrome/browser/net/websocket_experiment/websocket_experiment_runner.cc | 9 | ||||
-rw-r--r-- | chrome/renderer/renderer_main.cc | 2 | ||||
-rw-r--r-- | net/disk_cache/backend_impl.cc | 11 |
9 files changed, 312 insertions, 139 deletions
diff --git a/base/metrics/field_trial.cc b/base/metrics/field_trial.cc index 654746c..5db88c1 100644 --- a/base/metrics/field_trial.cc +++ b/base/metrics/field_trial.cc @@ -7,14 +7,15 @@ #include "base/logging.h" #include "base/rand_util.h" #include "base/stringprintf.h" +#include "base/utf_string_conversions.h" namespace base { // static -const int FieldTrial::kNotParticipating = -1; +const int FieldTrial::kNotFinalized = -1; // static -const int FieldTrial::kAllRemainingProbability = -2; +const int FieldTrial::kDefaultGroupNumber = 0; // static bool FieldTrial::enable_benchmarking_ = false; @@ -28,30 +29,53 @@ static const char kHistogramFieldTrialSeparator('_'); // FieldTrial methods and members. FieldTrial::FieldTrial(const std::string& name, - const Probability total_probability) + const Probability total_probability, + const std::string& default_group_name, + const int year, + const int month, + const int day_of_month) : name_(name), divisor_(total_probability), + default_group_name_(default_group_name), random_(static_cast<Probability>(divisor_ * base::RandDouble())), accumulated_group_probability_(0), - next_group_number_(0), - group_(kNotParticipating) { + next_group_number_(kDefaultGroupNumber+1), + group_(kNotFinalized) { + DCHECK(!default_group_name_.empty()); FieldTrialList::Register(this); + + DCHECK_GT(year, 1970); + DCHECK_GT(month, 0); + DCHECK_LT(month, 13); + DCHECK_GT(day_of_month, 0); + DCHECK_LT(day_of_month, 32); + + base::Time::Exploded exploded; + exploded.year = year; + exploded.month = month; + exploded.day_of_week = 0; // Should be unusued. + exploded.day_of_month = day_of_month; + exploded.hour = 0; + exploded.minute = 0; + exploded.second = 0; + exploded.millisecond = 0; + + base::Time expiration_time = Time::FromLocalExploded(exploded); + disable_field_trial_ = (GetBuildTime() > expiration_time) ? true : false; } int FieldTrial::AppendGroup(const std::string& name, Probability group_probability) { DCHECK(group_probability <= divisor_); - DCHECK(group_probability >=0 || - group_probability == kAllRemainingProbability); - if (group_probability == kAllRemainingProbability) { - accumulated_group_probability_ = divisor_; - } else { - if (enable_benchmarking_) - group_probability = 0; - accumulated_group_probability_ += group_probability; - } + DCHECK_GE(group_probability, 0); + + if (enable_benchmarking_ || disable_field_trial_) + group_probability = 0; + + accumulated_group_probability_ += group_probability; + DCHECK(accumulated_group_probability_ <= divisor_); - if (group_ == kNotParticipating && accumulated_group_probability_ > random_) { + if (group_ == kNotFinalized && accumulated_group_probability_ > random_) { // This is the group that crossed the random line, so we do the assignment. group_ = next_group_number_; if (name.empty()) @@ -62,6 +86,20 @@ int FieldTrial::AppendGroup(const std::string& name, return next_group_number_++; } +int FieldTrial::group() { + if (group_ == kNotFinalized) { + accumulated_group_probability_ = divisor_; + group_ = kDefaultGroupNumber; + group_name_ = default_group_name_; + } + return group_; +} + +std::string FieldTrial::group_name() { + group(); // call group() to make group assignment was done. + return group_name_; +} + // static std::string FieldTrial::MakeName(const std::string& name_prefix, const std::string& trial_name) { @@ -76,6 +114,16 @@ void FieldTrial::EnableBenchmarking() { enable_benchmarking_ = true; } +// static +Time FieldTrial::GetBuildTime() { + Time integral_build_time; + const char* kDateTime = __DATE__ " " __TIME__; + bool result = Time::FromString(ASCIIToWide(kDateTime).c_str(), + &integral_build_time); + DCHECK(result); + return integral_build_time; +} + FieldTrial::~FieldTrial() {} //------------------------------------------------------------------------------ @@ -129,7 +177,7 @@ int FieldTrialList::FindValue(const std::string& name) { FieldTrial* field_trial = Find(name); if (field_trial) return field_trial->group(); - return FieldTrial::kNotParticipating; + return FieldTrial::kNotFinalized; } // static @@ -149,9 +197,11 @@ void FieldTrialList::StatesToString(std::string* output) { for (RegistrationList::iterator it = global_->registered_.begin(); it != global_->registered_.end(); ++it) { const std::string name = it->first; - const std::string group_name = it->second->group_name(); + std::string group_name = it->second->group_name_internal(); if (group_name.empty()) - continue; // No definitive winner in this trial. + // No definitive winner in this trial, use default_group_name as the + // group_name. + group_name = it->second->default_group_name(); DCHECK_EQ(name.find(kPersistentStringSeparator), std::string::npos); DCHECK_EQ(group_name.find(kPersistentStringSeparator), std::string::npos); output->append(name); @@ -162,34 +212,43 @@ void FieldTrialList::StatesToString(std::string* output) { } // static -bool FieldTrialList::StringAugmentsState(const std::string& prior_state) { +bool FieldTrialList::CreateTrialsInChildProcess( + const std::string& parent_trials) { DCHECK(global_); - if (prior_state.empty() || !global_) + if (parent_trials.empty() || !global_) return true; + Time::Exploded exploded; + Time two_years_from_now = + Time::NowFromSystemTime() + TimeDelta::FromDays(730); + two_years_from_now.LocalExplode(&exploded); + const int kTwoYearsFromNow = exploded.year; + size_t next_item = 0; - while (next_item < prior_state.length()) { - size_t name_end = prior_state.find(kPersistentStringSeparator, next_item); - if (name_end == prior_state.npos || next_item == name_end) + while (next_item < parent_trials.length()) { + size_t name_end = parent_trials.find(kPersistentStringSeparator, next_item); + if (name_end == parent_trials.npos || next_item == name_end) return false; - size_t group_name_end = prior_state.find(kPersistentStringSeparator, - name_end + 1); - if (group_name_end == prior_state.npos || name_end + 1 == group_name_end) + size_t group_name_end = parent_trials.find(kPersistentStringSeparator, + name_end + 1); + if (group_name_end == parent_trials.npos || name_end + 1 == group_name_end) return false; - std::string name(prior_state, next_item, name_end - next_item); - std::string group_name(prior_state, name_end + 1, + std::string name(parent_trials, next_item, name_end - next_item); + std::string group_name(parent_trials, name_end + 1, group_name_end - name_end - 1); next_item = group_name_end + 1; FieldTrial *field_trial(FieldTrialList::Find(name)); if (field_trial) { // In single process mode, we may have already created the field trial. - if (field_trial->group_name() != group_name) + if ((field_trial->group_name_internal() != group_name) && + (field_trial->default_group_name() != group_name)) return false; continue; } const int kTotalProbability = 100; - field_trial = new FieldTrial(name, kTotalProbability); + field_trial = new FieldTrial(name, kTotalProbability, group_name, + kTwoYearsFromNow, 1, 1); field_trial->AppendGroup(group_name, kTotalProbability); } return true; diff --git a/base/metrics/field_trial.h b/base/metrics/field_trial.h index 8902077..077a88c 100644 --- a/base/metrics/field_trial.h +++ b/base/metrics/field_trial.h @@ -66,36 +66,40 @@ #include <map> #include <string> +#include "base/gtest_prod_util.h" #include "base/lock.h" #include "base/ref_counted.h" #include "base/time.h" namespace base { +class FieldTrialList; + class FieldTrial : public RefCounted<FieldTrial> { public: typedef int Probability; // Probability type for being selected in a trial. // A return value to indicate that a given instance has not yet had a group // assignment (and hence is not yet participating in the trial). - static const int kNotParticipating; + static const int kNotFinalized; - // Provide an easy way to assign all remaining probability to a group. Note - // that this will force an instance to participate, and make it illegal to - // attempt to probabalistically add any other groups to the trial. When doing - // A/B tests with timings, it is often best to define all groups, so that - // histograms will get unique names via the MakeName() methods. - static const Probability kAllRemainingProbability; + // This is the group number of the 'default' group. This provides an easy way + // to assign all the remaining probability to a group ('default'). + static const int kDefaultGroupNumber; // The name is used to register the instance with the FieldTrialList class, // and can be used to find the trial (only one trial can be present for each // name). // Group probabilities that are later supplied must sum to less than or equal - // to the total_probability. - FieldTrial(const std::string& name, Probability total_probability); + // to the total_probability. Arguments year, month and day_of_month specify + // the expiration time. If the build time is after the expiration time then + // the field trial reverts to the 'default' group. + FieldTrial(const std::string& name, Probability total_probability, + const std::string& default_group_name, const int year, + const int month, const int day_of_month); // Establish the name and probability of the next group in this trial. - // Sometimes, based on construction randomization, this call may causes the + // Sometimes, based on construction randomization, this call may cause the // provided group to be *THE* group selected for use in this instance. int AppendGroup(const std::string& name, Probability group_probability); @@ -103,14 +107,18 @@ class FieldTrial : public RefCounted<FieldTrial> { std::string name() const { return name_; } // Return the randomly selected group number that was assigned. - // Return kNotParticipating if the instance is not participating in the - // experiment. - int group() const { return group_; } + // Return kDefaultGroupNumber if the instance is in the 'default' group. + // Note that this will force an instance to participate, and make it illegal + // to attempt to probabalistically add any other groups to the trial. + int group(); // If the field trial is not in an experiment, this returns the empty string. // if the group's name is empty, a name of "_" concatenated with the group // number is used as the group name. - std::string group_name() const { return group_name_; } + std::string group_name(); + + // Return the default group name of the FieldTrial. + std::string default_group_name() const { return default_group_name_; } // Helper function for the most common use: as an argument to specifiy the // name of a HISTOGRAM. Use the original histogram name as the name_prefix. @@ -121,17 +129,40 @@ class FieldTrial : public RefCounted<FieldTrial> { static void EnableBenchmarking(); private: + // Allow tests to access our innards for testing purposes. + FRIEND_TEST(FieldTrialTest, Registration); + FRIEND_TEST(FieldTrialTest, AbsoluteProbabilities); + FRIEND_TEST(FieldTrialTest, RemainingProbability); + FRIEND_TEST(FieldTrialTest, FiftyFiftyProbability); + FRIEND_TEST(FieldTrialTest, MiddleProbabilities); + FRIEND_TEST(FieldTrialTest, OneWinner); + FRIEND_TEST(FieldTrialTest, DisableProbability); + FRIEND_TEST(FieldTrialTest, Save); + FRIEND_TEST(FieldTrialTest, DuplicateRestore); + FRIEND_TEST(FieldTrialTest, MakeName); + + friend class base::FieldTrialList; + friend class RefCounted<FieldTrial>; virtual ~FieldTrial(); + // Returns the group_name. A winner need not have been chosen. + std::string group_name_internal() const { return group_name_; } + + // Get build time. + static Time GetBuildTime(); + // The name of the field trial, as can be found via the FieldTrialList. // This is empty of the trial is not in the experiment. const std::string name_; // The maximum sum of all probabilities supplied, which corresponds to 100%. // This is the scaling factor used to adjust supplied probabilities. - Probability divisor_; + const Probability divisor_; + + // The name of the default group. + const std::string default_group_name_; // The randomly selected probability that is used to select a group (or have // the instance not participate). It is the product of divisor_ and a random @@ -144,15 +175,19 @@ class FieldTrial : public RefCounted<FieldTrial> { int next_group_number_; // The pseudo-randomly assigned group number. - // This is kNotParticipating if no group has been assigned. + // This is kNotFinalized if no group has been assigned. int group_; - // A textual name for the randomly selected group, including the Trial name. - // If this Trial is not a member of an group, this string is empty. + // A textual name for the randomly selected group. If this Trial is not a + // member of an group, this string is empty. std::string group_name_; + // When disable_field_trial_ is true, field trial reverts to the 'default' + // group. + bool disable_field_trial_; + // When benchmarking is enabled, field trials all revert to the 'default' - // bucket. + // group. static bool enable_benchmarking_; DISALLOW_COPY_AND_ASSIGN(FieldTrial); @@ -199,7 +234,7 @@ class FieldTrialList { // is commonly used in a sub-process, to carry randomly selected state in a // parent process into this sub-process. // Currently only the group_name_ and name_ are restored. - static bool StringAugmentsState(const std::string& prior_state); + static bool CreateTrialsInChildProcess(const std::string& prior_trials); // The time of construction of the global map is recorded in a static variable // and is commonly used by experiments to identify the time since the start diff --git a/base/metrics/field_trial_unittest.cc b/base/metrics/field_trial_unittest.cc index a8138bb..0af6d60 100644 --- a/base/metrics/field_trial_unittest.cc +++ b/base/metrics/field_trial_unittest.cc @@ -13,7 +13,23 @@ namespace base { class FieldTrialTest : public testing::Test { public: - FieldTrialTest() : trial_list_() { } + FieldTrialTest() : trial_list_() { + Time now = Time::NowFromSystemTime(); + TimeDelta oneYear = TimeDelta::FromDays(365); + Time::Exploded exploded; + + Time next_year_time = now + oneYear; + next_year_time.LocalExplode(&exploded); + next_year_ = exploded.year; + + Time last_year_time = now - oneYear; + last_year_time.LocalExplode(&exploded); + last_year_ = exploded.year; + } + + protected: + int next_year_; + int last_year_; private: FieldTrialList trial_list_; @@ -27,20 +43,22 @@ TEST_F(FieldTrialTest, Registration) { EXPECT_FALSE(FieldTrialList::Find(name1)); EXPECT_FALSE(FieldTrialList::Find(name2)); - FieldTrial* trial1 = new FieldTrial(name1, 10); - EXPECT_EQ(FieldTrial::kNotParticipating, trial1->group()); + FieldTrial* trial1 = + new FieldTrial(name1, 10, "default name 1 test", next_year_, 12, 31); + EXPECT_EQ(FieldTrial::kNotFinalized, trial1->group_); EXPECT_EQ(name1, trial1->name()); - EXPECT_EQ("", trial1->group_name()); + EXPECT_EQ("", trial1->group_name_internal()); trial1->AppendGroup("", 7); EXPECT_EQ(trial1, FieldTrialList::Find(name1)); EXPECT_FALSE(FieldTrialList::Find(name2)); - FieldTrial* trial2 = new FieldTrial(name2, 10); - EXPECT_EQ(FieldTrial::kNotParticipating, trial2->group()); + FieldTrial* trial2 = + new FieldTrial(name2, 10, "default name 2 test", next_year_, 12, 31); + EXPECT_EQ(FieldTrial::kNotFinalized, trial2->group_); EXPECT_EQ(name2, trial2->name()); - EXPECT_EQ("", trial2->group_name()); + EXPECT_EQ("", trial2->group_name_internal()); trial2->AppendGroup("a first group", 7); @@ -51,20 +69,28 @@ TEST_F(FieldTrialTest, Registration) { TEST_F(FieldTrialTest, AbsoluteProbabilities) { char always_true[] = " always true"; + char default_always_true[] = " default always true"; char always_false[] = " always false"; + char default_always_false[] = " default always false"; for (int i = 1; i < 250; ++i) { // Try lots of names, by changing the first character of the name. always_true[0] = i; + default_always_true[0] = i; always_false[0] = i; + default_always_false[0] = i; - FieldTrial* trial_true = new FieldTrial(always_true, 10); + FieldTrial* trial_true = + new FieldTrial( + always_true, 10, default_always_true, next_year_, 12, 31); const std::string winner = "TheWinner"; int winner_group = trial_true->AppendGroup(winner, 10); EXPECT_EQ(winner_group, trial_true->group()); EXPECT_EQ(winner, trial_true->group_name()); - FieldTrial* trial_false = new FieldTrial(always_false, 10); + FieldTrial* trial_false = + new FieldTrial( + always_false, 10, default_always_false, next_year_, 12, 31); int loser_group = trial_false->AppendGroup("ALoser", 0); EXPECT_NE(loser_group, trial_false->group()); @@ -79,12 +105,13 @@ TEST_F(FieldTrialTest, RemainingProbability) { int counter = 0; do { std::string name = StringPrintf("trial%d", ++counter); - trial = new FieldTrial(name, 10); + trial = new FieldTrial(name, 10, winner, next_year_, 12, 31); trial->AppendGroup(loser, 5); // 50% chance of not being chosen. - } while (trial->group() != FieldTrial::kNotParticipating); + // If a group is not assigned, group_ will be kNotFinalized. + } while (trial->group_ != FieldTrial::kNotFinalized); - // Now add a winner with all remaining probability. - trial->AppendGroup(winner, FieldTrial::kAllRemainingProbability); + // And that 'default' group (winner) should always win. + EXPECT_EQ(FieldTrial::kDefaultGroupNumber, trial->group()); // And that winner should ALWAYS win. EXPECT_EQ(winner, trial->group_name()); @@ -100,14 +127,18 @@ TEST_F(FieldTrialTest, FiftyFiftyProbability) { int counter = 0; do { std::string name = base::StringPrintf("FiftyFifty%d", ++counter); - scoped_refptr<FieldTrial> trial(new FieldTrial(name, 2)); + std::string default_group_name = base::StringPrintf("Default FiftyFifty%d", + ++counter); + scoped_refptr<FieldTrial> trial( + new FieldTrial(name, 2, default_group_name, next_year_, 12, 31)); trial->AppendGroup("first", 1); // 50% chance of being chosen. - if (trial->group() != FieldTrial::kNotParticipating) { + // If group_ is kNotFinalized, then a group assignement hasn't been done. + if (trial->group_ != FieldTrial::kNotFinalized) { first_winner = true; continue; } trial->AppendGroup("second", 1); // Always chosen at this point. - EXPECT_NE(FieldTrial::kNotParticipating, trial->group()); + EXPECT_NE(FieldTrial::kNotFinalized, trial->group()); second_winner = true; } while ((!second_winner || !first_winner) && counter < 100); EXPECT_TRUE(second_winner); @@ -116,11 +147,14 @@ TEST_F(FieldTrialTest, FiftyFiftyProbability) { TEST_F(FieldTrialTest, MiddleProbabilities) { char name[] = " same name"; + char default_group_name[] = " default same name"; bool false_event_seen = false; bool true_event_seen = false; for (int i = 1; i < 250; ++i) { name[0] = i; - FieldTrial* trial = new FieldTrial(name, 10); + default_group_name[0] = i; + FieldTrial* trial = + new FieldTrial(name, 10, default_group_name, next_year_, 12, 31); int might_win = trial->AppendGroup("MightWin", 5); if (trial->group() == might_win) { @@ -139,16 +173,21 @@ TEST_F(FieldTrialTest, MiddleProbabilities) { TEST_F(FieldTrialTest, OneWinner) { char name[] = "Some name"; + char default_group_name[] = "Default some name"; int group_count(10); - FieldTrial* trial = new FieldTrial(name, group_count); + FieldTrial* trial = + new FieldTrial( + name, group_count, default_group_name, next_year_, 12, 31); int winner_index(-2); std::string winner_name; for (int i = 1; i <= group_count; ++i) { int might_win = trial->AppendGroup("", 1); - if (trial->group() == might_win) { + // Because we keep appending groups, we want to see if the last group that + // was added has been assigned or not. + if (trial->group_ == might_win) { EXPECT_EQ(-2, winner_index); winner_index = might_win; StringAppendF(&winner_name, "%d", might_win); @@ -160,14 +199,34 @@ TEST_F(FieldTrialTest, OneWinner) { EXPECT_EQ(trial->group_name(), winner_name); } +TEST_F(FieldTrialTest, DisableProbability) { + const std::string default_group_name = "Default group"; + const std::string loser = "Loser"; + const std::string name = "Trial"; + + // Create a field trail that has expired. + scoped_refptr<FieldTrial> trial; + trial = new FieldTrial( + name, 1000000000, default_group_name, last_year_, 1, 1); + trial->AppendGroup(loser, 999999999); // 99.9999999% chance of being chosen. + + // Because trial has expired, we should always be in the default group. + EXPECT_EQ(FieldTrial::kDefaultGroupNumber, trial->group()); + + // And that default_group_name should ALWAYS win. + EXPECT_EQ(default_group_name, trial->group_name()); +} + TEST_F(FieldTrialTest, Save) { std::string save_string; - FieldTrial* trial = new FieldTrial("Some name", 10); + FieldTrial* trial = + new FieldTrial( + "Some name", 10, "Default some name", next_year_, 12, 31); // There is no winner yet, so no textual group name is associated with trial. - EXPECT_EQ("", trial->group_name()); + EXPECT_EQ("", trial->group_name_internal()); FieldTrialList::StatesToString(&save_string); - EXPECT_EQ("", save_string); + EXPECT_EQ("Some name/Default some name/", save_string); save_string.clear(); // Create a winning group. @@ -177,7 +236,8 @@ TEST_F(FieldTrialTest, Save) { save_string.clear(); // Create a second trial and winning group. - FieldTrial* trial2 = new FieldTrial("xxx", 10); + FieldTrial* trial2 = + new FieldTrial("xxx", 10, "Default xxx", next_year_, 12, 31); trial2->AppendGroup("yyyy", 10); FieldTrialList::StatesToString(&save_string); @@ -189,7 +249,7 @@ TEST_F(FieldTrialTest, Restore) { EXPECT_TRUE(FieldTrialList::Find("Some_name") == NULL); EXPECT_TRUE(FieldTrialList::Find("xxx") == NULL); - FieldTrialList::StringAugmentsState("Some_name/Winner/xxx/yyyy/"); + FieldTrialList::CreateTrialsInChildProcess("Some_name/Winner/xxx/yyyy/"); FieldTrial* trial = FieldTrialList::Find("Some_name"); ASSERT_NE(static_cast<FieldTrial*>(NULL), trial); @@ -203,29 +263,34 @@ TEST_F(FieldTrialTest, Restore) { } TEST_F(FieldTrialTest, BogusRestore) { - EXPECT_FALSE(FieldTrialList::StringAugmentsState("MissingSlash")); - EXPECT_FALSE(FieldTrialList::StringAugmentsState("MissingGroupName/")); - EXPECT_FALSE(FieldTrialList::StringAugmentsState("MissingFinalSlash/gname")); - EXPECT_FALSE(FieldTrialList::StringAugmentsState("/noname, only group/")); + EXPECT_FALSE(FieldTrialList::CreateTrialsInChildProcess("MissingSlash")); + EXPECT_FALSE(FieldTrialList::CreateTrialsInChildProcess("MissingGroupName/")); + EXPECT_FALSE( + FieldTrialList::CreateTrialsInChildProcess("MissingFinalSlash/gname")); + EXPECT_FALSE( + FieldTrialList::CreateTrialsInChildProcess("/noname, only group/")); } TEST_F(FieldTrialTest, DuplicateRestore) { - FieldTrial* trial = new FieldTrial("Some name", 10); + FieldTrial* trial = + new FieldTrial( + "Some name", 10, "Default some name", next_year_, 12, 31); trial->AppendGroup("Winner", 10); std::string save_string; FieldTrialList::StatesToString(&save_string); EXPECT_EQ("Some name/Winner/", save_string); // It is OK if we redundantly specify a winner. - EXPECT_TRUE(FieldTrialList::StringAugmentsState(save_string)); + EXPECT_TRUE(FieldTrialList::CreateTrialsInChildProcess(save_string)); // But it is an error to try to change to a different winner. - EXPECT_FALSE(FieldTrialList::StringAugmentsState("Some name/Loser/")); + EXPECT_FALSE(FieldTrialList::CreateTrialsInChildProcess("Some name/Loser/")); } TEST_F(FieldTrialTest, MakeName) { - FieldTrial* trial = new FieldTrial("Field Trial", 10); - trial->AppendGroup("Winner", 10); + FieldTrial* trial = + new FieldTrial("Field Trial", 10, "Winner", next_year_, 12, 31); + trial->group(); EXPECT_EQ("Histogram_Winner", FieldTrial::MakeName("Histogram", "Field Trial")); } diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc index 64f0dd3..d95fc3e 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -231,8 +231,16 @@ void BrowserMainParts::ConnectionFieldTrial() { const base::FieldTrial::Probability kConnectDivisor = 100; const base::FieldTrial::Probability kConnectProbability = 1; // 1% prob. + // After June 30, 2011 builds, it will always be in default group. scoped_refptr<base::FieldTrial> connect_trial( - new base::FieldTrial("ConnCountImpact", kConnectDivisor)); + new base::FieldTrial( + "ConnCountImpact", kConnectDivisor, "conn_count_6", 2011, 6, 30)); + + // This (6) is the current default value. Having this group declared here + // makes it straightforward to modify |kConnectProbability| such that the same + // probability value will be assigned to all the other groups, while + // preserving the remainder of the of probability space to the default value. + const int connect_6 = connect_trial->kDefaultGroupNumber; const int connect_5 = connect_trial->AppendGroup("conn_count_5", kConnectProbability); @@ -242,12 +250,6 @@ void BrowserMainParts::ConnectionFieldTrial() { kConnectProbability); const int connect_9 = connect_trial->AppendGroup("conn_count_9", kConnectProbability); - // This (6) is the current default value. Having this group declared here - // makes it straightforward to modify |kConnectProbability| such that the same - // probability value will be assigned to all the other groups, while - // preserving the remainder of the of probability space to the default value. - const int connect_6 = connect_trial->AppendGroup("conn_count_6", - base::FieldTrial::kAllRemainingProbability); const int connect_trial_group = connect_trial->group(); @@ -276,8 +278,11 @@ void BrowserMainParts::SocketTimeoutFieldTrial() { // 1% probability for all experimental settings. const base::FieldTrial::Probability kSocketTimeoutProbability = 1; + // After June 30, 2011 builds, it will always be in default group. scoped_refptr<base::FieldTrial> socket_timeout_trial( - new base::FieldTrial("IdleSktToImpact", kIdleSocketTimeoutDivisor)); + new base::FieldTrial("IdleSktToImpact", kIdleSocketTimeoutDivisor, + "idle_timeout_60", 2011, 6, 30)); + const int socket_timeout_60 = socket_timeout_trial->kDefaultGroupNumber; const int socket_timeout_5 = socket_timeout_trial->AppendGroup("idle_timeout_5", @@ -288,9 +293,6 @@ void BrowserMainParts::SocketTimeoutFieldTrial() { const int socket_timeout_20 = socket_timeout_trial->AppendGroup("idle_timeout_20", kSocketTimeoutProbability); - const int socket_timeout_60 = - socket_timeout_trial->AppendGroup("idle_timeout_60", - base::FieldTrial::kAllRemainingProbability); const int idle_to_trial_group = socket_timeout_trial->group(); @@ -312,8 +314,16 @@ void BrowserMainParts::ProxyConnectionsFieldTrial() { // 25% probability const base::FieldTrial::Probability kProxyConnectionProbability = 1; + // After June 30, 2011 builds, it will always be in default group. scoped_refptr<base::FieldTrial> proxy_connection_trial( - new base::FieldTrial("ProxyConnectionImpact", kProxyConnectionsDivisor)); + new base::FieldTrial("ProxyConnectionImpact", kProxyConnectionsDivisor, + "proxy_connections_32", 2011, 6, 30)); + + // This (32 connections per proxy server) is the current default value. + // Declaring it here allows us to easily re-assign the probability space while + // maintaining that the default group always has the remainder of the "share", + // which allows for cleaner and quicker changes down the line if needed. + const int proxy_connections_32 = proxy_connection_trial->kDefaultGroupNumber; // The number of max sockets per group cannot be greater than the max number // of sockets per proxy server. We tried using 8, and it can easily @@ -325,14 +335,6 @@ void BrowserMainParts::ProxyConnectionsFieldTrial() { proxy_connection_trial->AppendGroup("proxy_connections_64", kProxyConnectionProbability); - // This (32 connections per proxy server) is the current default value. - // Declaring it here allows us to easily re-assign the probability space while - // maintaining that the default group always has the remainder of the "share", - // which allows for cleaner and quicker changes down the line if needed. - const int proxy_connections_32 = - proxy_connection_trial->AppendGroup("proxy_connections_32", - base::FieldTrial::kAllRemainingProbability); - const int proxy_connections_trial_group = proxy_connection_trial->group(); if (proxy_connections_trial_group == proxy_connections_16) { @@ -363,13 +365,18 @@ void BrowserMainParts::SpdyFieldTrial() { const base::FieldTrial::Probability kSpdyDivisor = 100; // 10% to preclude SPDY. base::FieldTrial::Probability npnhttp_probability = 10; + + // After June 30, 2011 builds, it will always be in default group. scoped_refptr<base::FieldTrial> trial( - new base::FieldTrial("SpdyImpact", kSpdyDivisor)); + new base::FieldTrial( + "SpdyImpact", kSpdyDivisor, "npn_with_spdy", 2011, 6, 30)); + + // npn with spdy support is the default. + int npn_spdy_grp = trial->kDefaultGroupNumber; + // npn with only http support, no spdy. int npn_http_grp = trial->AppendGroup("npn_with_http", npnhttp_probability); - // npn with spdy support. - int npn_spdy_grp = trial->AppendGroup("npn_with_spdy", - base::FieldTrial::kAllRemainingProbability); + int trial_grp = trial->group(); if (trial_grp == npn_http_grp) { is_spdy_trial = true; @@ -388,14 +395,17 @@ void BrowserMainParts::SpdyFieldTrial() { const base::FieldTrial::Probability kSpdyCwnd16 = 20; // fixed at 16 const base::FieldTrial::Probability kSpdyCwndMin16 = 20; // no less than 16 const base::FieldTrial::Probability kSpdyCwndMin10 = 20; // no less than 10 + + // After June 30, 2011 builds, it will always be in default group + // (cwndDynamic). scoped_refptr<base::FieldTrial> trial( - new base::FieldTrial("SpdyCwnd", kSpdyCwndDivisor)); + new base::FieldTrial( + "SpdyCwnd", kSpdyCwndDivisor, "cwndDynamic", 2011, 6, 30)); + trial->AppendGroup("cwnd32", kSpdyCwnd32); trial->AppendGroup("cwnd16", kSpdyCwnd16); trial->AppendGroup("cwndMin16", kSpdyCwndMin16); trial->AppendGroup("cwndMin10", kSpdyCwndMin10); - trial->AppendGroup("cwndDynamic", - base::FieldTrial::kAllRemainingProbability); if (parsed_command_line().HasSwitch(switches::kMaxSpdyConcurrentStreams)) { int value = 0; @@ -420,12 +430,12 @@ void BrowserMainParts::PrefetchFieldTrial() { } else { const base::FieldTrial::Probability kPrefetchDivisor = 1000; const base::FieldTrial::Probability no_prefetch_probability = 500; + // After June 30, 2011 builds, it will always be in default group. scoped_refptr<base::FieldTrial> trial( - new base::FieldTrial("Prefetch", kPrefetchDivisor)); + new base::FieldTrial("Prefetch", kPrefetchDivisor, + "ContentPrefetchEnabled", 2011, 6, 30)); + const int yes_prefetch_grp = trial->kDefaultGroupNumber; trial->AppendGroup("ContentPrefetchDisabled", no_prefetch_probability); - const int yes_prefetch_grp = - trial->AppendGroup("ContentPrefetchEnabled", - base::FieldTrial::kAllRemainingProbability); const int trial_grp = trial->group(); ResourceDispatcherHost::set_is_prefetch_enabled( trial_grp == yes_prefetch_grp); @@ -447,14 +457,14 @@ void BrowserMainParts::ConnectBackupJobsFieldTrial() { const base::FieldTrial::Probability kConnectBackupJobsDivisor = 100; // 1% probability. const base::FieldTrial::Probability kConnectBackupJobsProbability = 1; + // After June 30, 2011 builds, it will always be in defaut group. scoped_refptr<base::FieldTrial> trial( new base::FieldTrial("ConnnectBackupJobs", - kConnectBackupJobsDivisor)); + kConnectBackupJobsDivisor, "ConnectBackupJobsEnabled", 2011, 6, + 30)); + const int connect_backup_jobs_enabled = trial->kDefaultGroupNumber; trial->AppendGroup("ConnectBackupJobsDisabled", kConnectBackupJobsProbability); - const int connect_backup_jobs_enabled = - trial->AppendGroup("ConnectBackupJobsEnabled", - base::FieldTrial::kAllRemainingProbability); const int trial_group = trial->group(); net::internal::ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled( trial_group == connect_backup_jobs_enabled); @@ -1531,8 +1541,11 @@ int BrowserMain(const MainFunctionParams& parameters) { // layout globally. base::FieldTrial::Probability kSDCH_DIVISOR = 1000; base::FieldTrial::Probability kSDCH_DISABLE_PROBABILITY = 1; // 0.1% prob. + // After June 30, 2011 builds, it will always be in default group. scoped_refptr<base::FieldTrial> sdch_trial( - new base::FieldTrial("GlobalSdch", kSDCH_DIVISOR)); + new base::FieldTrial("GlobalSdch", kSDCH_DIVISOR, "global_enable_sdch", + 2011, 6, 30)); + int sdch_enabled = sdch_trial->kDefaultGroupNumber; // Use default of "" so that all domains are supported. std::string sdch_supported_domain(""); @@ -1542,8 +1555,6 @@ int BrowserMain(const MainFunctionParams& parameters) { } else { sdch_trial->AppendGroup("global_disable_sdch", kSDCH_DISABLE_PROBABILITY); - int sdch_enabled = sdch_trial->AppendGroup("global_enable_sdch", - base::FieldTrial::kAllRemainingProbability); if (sdch_enabled != sdch_trial->group()) sdch_supported_domain = "never_enabled_sdch_for_any_domain"; } diff --git a/chrome/browser/io_thread.cc b/chrome/browser/io_thread.cc index 83d229e..c468a91 100644 --- a/chrome/browser/io_thread.cc +++ b/chrome/browser/io_thread.cc @@ -70,8 +70,11 @@ net::HostResolver* CreateGlobalHostResolver(net::NetLog* net_log) { // For each option (i.e., non-default), we have a fixed probability. base::FieldTrial::Probability kProbabilityPerGroup = 100; // 10%. + // After June 30, 2011 builds, it will always be in default group + // (parallel_default). scoped_refptr<base::FieldTrial> trial( - new base::FieldTrial("DnsParallelism", kDivisor)); + new base::FieldTrial( + "DnsParallelism", kDivisor, "parallel_default", 2011, 6, 30)); // List options with different counts. // Firefox limits total to 8 in parallel, and default is currently 50. @@ -83,9 +86,6 @@ net::HostResolver* CreateGlobalHostResolver(net::NetLog* net_log) { int parallel_14 = trial->AppendGroup("parallel_14", kProbabilityPerGroup); int parallel_20 = trial->AppendGroup("parallel_20", kProbabilityPerGroup); - trial->AppendGroup("parallel_default", - base::FieldTrial::kAllRemainingProbability); - if (trial->group() == parallel_6) parallelism = 6; else if (trial->group() == parallel_7) diff --git a/chrome/browser/net/predictor_api.cc b/chrome/browser/net/predictor_api.cc index 44d5499..e16e8e9 100644 --- a/chrome/browser/net/predictor_api.cc +++ b/chrome/browser/net/predictor_api.cc @@ -551,13 +551,15 @@ PredictorInit::PredictorInit(PrefService* user_prefs, // For each option (i.e., non-default), we have a fixed probability. base::FieldTrial::Probability kProbabilityPerGroup = 100; // 10% probability. - trial_ = new base::FieldTrial("DnsImpact", kDivisor); + // After June 30, 2011 builds, it will always be in default group + // (default_enabled_prefetch). + trial_ = new base::FieldTrial("DnsImpact", kDivisor, + "default_enabled_prefetch", 2011, 6, 30); // First option is to disable prefetching completely. int disabled_prefetch = trial_->AppendGroup("disabled_prefetch", kProbabilityPerGroup); - // We're running two experiments at the same time. The first set of trials // modulates the delay-time until we declare a congestion event (and purge // our queue). The second modulates the number of concurrent resolutions @@ -586,9 +588,6 @@ PredictorInit::PredictorInit(PrefService* user_prefs, int max_6_concurrent_prefetch = trial_->AppendGroup( "max_6 concurrent_prefetch", kProbabilityPerGroup); - trial_->AppendGroup("default_enabled_prefetch", - base::FieldTrial::kAllRemainingProbability); - // We will register the incognito observer regardless of whether prefetching // is enabled, as it is also used to clear the host cache. g_off_the_record_observer.Get().Register(); diff --git a/chrome/browser/net/websocket_experiment/websocket_experiment_runner.cc b/chrome/browser/net/websocket_experiment/websocket_experiment_runner.cc index fd5088b..270700a 100644 --- a/chrome/browser/net/websocket_experiment/websocket_experiment_runner.cc +++ b/chrome/browser/net/websocket_experiment/websocket_experiment_runner.cc @@ -28,12 +28,13 @@ static scoped_refptr<WebSocketExperimentRunner> runner; void WebSocketExperimentRunner::Start() { DCHECK(!runner.get()); + // After June 30, 2011 builds, it will always be in default group. scoped_refptr<base::FieldTrial> trial( - new base::FieldTrial("WebSocketExperiment", 1000)); - trial->AppendGroup("active", 5); // 0.5% in active group. + new base::FieldTrial( + "WebSocketExperiment", 1000, "default", 2011, 6, 30)); + int active = trial->AppendGroup("active", 5); // 0.5% in active group. - bool run_experiment = - (trial->group() != base::FieldTrial::kNotParticipating); + bool run_experiment = (trial->group() == active); #ifndef NDEBUG const CommandLine& command_line = *CommandLine::ForCurrentProcess(); std::string experiment_host = command_line.GetSwitchValueASCII( diff --git a/chrome/renderer/renderer_main.cc b/chrome/renderer/renderer_main.cc index c53fd23..970aa3e 100644 --- a/chrome/renderer/renderer_main.cc +++ b/chrome/renderer/renderer_main.cc @@ -261,7 +261,7 @@ int RendererMain(const MainFunctionParams& parameters) { if (parsed_command_line.HasSwitch(switches::kForceFieldTestNameAndValue)) { std::string persistent = parsed_command_line.GetSwitchValueASCII( switches::kForceFieldTestNameAndValue); - bool ret = field_trial.StringAugmentsState(persistent); + bool ret = field_trial.CreateTrialsInChildProcess(persistent); DCHECK(ret); } diff --git a/net/disk_cache/backend_impl.cc b/net/disk_cache/backend_impl.cc index b406601..3d0e403 100644 --- a/net/disk_cache/backend_impl.cc +++ b/net/disk_cache/backend_impl.cc @@ -174,13 +174,16 @@ bool SetFieldTrialInfo(int size_group) { // Field trials involve static objects so we have to do this only once. first = false; - scoped_refptr<base::FieldTrial> trial1( - new base::FieldTrial("CacheSize", 10)); std::string group1 = base::StringPrintf("CacheSizeGroup_%d", size_group); - trial1->AppendGroup(group1, base::FieldTrial::kAllRemainingProbability); + int totalProbability = 10; + scoped_refptr<base::FieldTrial> trial1( + new base::FieldTrial("CacheSize", totalProbability, group1, 2011, 6, 30)); + trial1->AppendGroup(group1, totalProbability); + // After June 30, 2011 builds, it will always be in default group. scoped_refptr<base::FieldTrial> trial2( - new base::FieldTrial("CacheThrottle", 100)); + new base::FieldTrial( + "CacheThrottle", 100, "CacheThrottle_Default", 2011, 6, 30)); int group2a = trial2->AppendGroup("CacheThrottle_On", 10); // 10 % in. trial2->AppendGroup("CacheThrottle_Off", 10); // 10 % control. |