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

Unified Diff: base/metrics/field_trial.h

Issue 6216004: Feature to disable field trials in old versions of Chromium. Field trials... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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 | « no previous file | base/metrics/field_trial.cc » ('j') | net/disk_cache/backend_impl.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/metrics/field_trial.h
===================================================================
--- base/metrics/field_trial.h (revision 71223)
+++ base/metrics/field_trial.h (working copy)
@@ -66,6 +66,7 @@
#include <map>
#include <string>
+#include "base/gtest_prod_util.h"
#include "base/lock.h"
#include "base/ref_counted.h"
#include "base/time.h"
@@ -77,22 +78,24 @@
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;
+ // assignment (and hence group assignment is not yet finalized in the trial).
+ 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;
+ // Every field trial is reserved a kDefaultGroupNumber. If a group assigement
+ // is not done, when group() is called, all the remaining probability is
+ // assigned to a group and its number is kDefaultGroupNumber.
+ // 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 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);
+ 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
@@ -103,9 +106,10 @@
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. This
+ // call finalizes the FieldTrial and group assignment is completed when this
+ // method is called.
+ 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
@@ -121,10 +125,36 @@
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 RefCounted<FieldTrial>;
+ // Create a Field Trial that runs forever (expires in 12/31/2099).
+ FieldTrial(const std::string& name, Probability total_probability,
+ const std::string& default_group_name);
+
+ // Determine if the field trial is to be disabled or not based on
+ // expiration time (year, month, day_of_month) and build time of the module.
+ // This method sets disable_field_trial_ to true, if the build time is after
+ // expiration_time_. If disable_field_trial_ is true then the field trial
+ // reverts to the 'default' bucket.
+ void Initialize(const int year, const int month, const int day_of_month);
+
virtual ~FieldTrial();
+ // 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_;
@@ -133,6 +163,9 @@
// This is the scaling factor used to adjust supplied probabilities.
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
// number between [0, 1).
@@ -144,13 +177,21 @@
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.
std::string group_name_;
+ // The default value (all remaining probabilities) can be selected after the
+ // expiration_time, which is based on the build time of the module.
+ base::Time expiration_time_;
+
+ // When disable_field_trial_ is true, field trial reverts to the 'default'
+ // bucket.
+ bool disable_field_trial_;
+
// When benchmarking is enabled, field trials all revert to the 'default'
// bucket.
static bool enable_benchmarking_;
« no previous file with comments | « no previous file | base/metrics/field_trial.cc » ('j') | net/disk_cache/backend_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698