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

Unified Diff: base/metrics/field_trial.h

Issue 9705074: Supporting command line argument to force field trials (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: No more static default group number Created 8 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 | « no previous file | base/metrics/field_trial.cc » ('j') | base/metrics/field_trial.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/metrics/field_trial.h
diff --git a/base/metrics/field_trial.h b/base/metrics/field_trial.h
index 50508d241425e558f4f4d737cf352947a86f0bef..e1c6c5f4a050f2b0d4a280d66df6a47fc557194c 100644
--- a/base/metrics/field_trial.h
+++ b/base/metrics/field_trial.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -103,26 +103,6 @@ class BASE_EXPORT FieldTrial : public RefCounted<FieldTrial> {
// assignment (and hence is not yet participating in the trial).
static const int kNotFinalized;
- // 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). |name| and |default_group_name| may not be empty.
- //
- // Group probabilities that are later supplied must sum to less than or equal
- // 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.
- //
- // Using this constructor creates a startup-randomized FieldTrial. If you
- // want a one-time randomized trial, call UseOneTimeRandomization() right
- // after construction.
- 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);
-
// Changes the field trial to use one-time randomization, i.e. produce the
// same result for the current trial on every run of this client. Must be
// called right after construction.
@@ -145,7 +125,6 @@ class BASE_EXPORT FieldTrial : public RefCounted<FieldTrial> {
std::string name() const { return name_; }
// Return the randomly selected group number that was assigned.
- // 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 probabilistically add any other groups to the trial.
int group();
@@ -156,8 +135,8 @@ class BASE_EXPORT FieldTrial : public RefCounted<FieldTrial> {
// Gets the unique identifier of the Field Trial, but only if a group was
// officially chosen, otherwise name_group_id is left untouched and false
- // is returned. When true is returned, the name and group ids were successfuly
- // set in name_group_id.
+ // is returned. When true is returned, the name and group ids were
+ // successfully set in name_group_id.
bool GetNameGroupId(NameGroupId* name_group_id);
// Return the default group name of the FieldTrial.
@@ -193,6 +172,14 @@ class BASE_EXPORT FieldTrial : public RefCounted<FieldTrial> {
friend class RefCounted<FieldTrial>;
+ // This is the group number of the 'default' group when a choice wasn't forced
+ // by a call to FieldTrialList::CreateFieldTrial. It is kept private so that
+ // consumers don't use it by mistake in cases where the group was forced.
+ static const int kDefaultGroupNumber;
+
+ 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);
virtual ~FieldTrial();
// Returns the group_name. A winner need not have been chosen.
@@ -247,6 +234,10 @@ class BASE_EXPORT FieldTrial : public RefCounted<FieldTrial> {
// group.
bool enable_field_trial_;
+ // When forced_ is true, we return the chosen group from AppendGroup when
+ // appropriate.
+ bool forced_;
+
// When benchmarking is enabled, field trials all revert to the 'default'
// group.
static bool enable_benchmarking_;
@@ -263,7 +254,7 @@ class BASE_EXPORT FieldTrial : public RefCounted<FieldTrial> {
// Only one instance of this class exists.
class BASE_EXPORT FieldTrialList {
public:
- // Define a separator charactor to use when creating a persistent form of an
+ // Define a separator character to use when creating a persistent form of an
// instance. This is intended for use as a command line argument, passed to a
// second process to mimic our state (i.e., provide the same group name).
static const char kPersistentStringSeparator; // Currently a slash.
@@ -292,9 +283,26 @@ class BASE_EXPORT FieldTrialList {
// Destructor Release()'s references to all registered FieldTrial instances.
~FieldTrialList();
- // Register() stores a pointer to the given trial in a global map.
- // This method also AddRef's the indicated trial.
- static void Register(FieldTrial* trial);
+ // Creates a new FieldTrial instance if none exists already. If one exists,
+ // it has to be because it was forced by CreateFieldTrial.
+ //
+ // 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). |name| and |default_group_name| may not be empty but
Alexei Svitkine (slow) 2012/03/29 19:19:07 Nit: Either remove the |'s around |name| and |defa
MAD 2012/04/02 18:31:15 Done.
+ // default_group_number can be NULL if the value is not needed.
Alexei Svitkine (slow) 2012/03/29 19:19:07 Please explain what |default_group_number| is for,
MAD 2012/04/02 18:31:15 Done.
+ //
+ // Group probabilities that are later supplied must sum to less than or equal
+ // 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.
+ //
+ // Use this static method to get a startup-randomized FieldTrial or a
+ // previously created forced FieldTrial. If you want a one-time randomized
+ // trial, call UseOneTimeRandomization() right after creation.
+ static FieldTrial* GetFieldTrialInstance(
+ const std::string& name, FieldTrial::Probability total_probability,
+ const std::string& default_group_name, int* default_group_number,
+ const int year, const int month, const int day_of_month);
// The Find() method can be used to test to see if a named Trial was already
// registered, or to retrieve a pointer to it from the global map.
@@ -311,11 +319,12 @@ class BASE_EXPORT FieldTrialList {
// Returns true if the named trial has been registered.
static bool TrialExists(const std::string& name);
- // Create a persistent representation of all FieldTrial instances and the
- // |client_id()| state for resurrection in another process. This allows
- // randomization to be done in one process, and secondary processes can be
- // synchronized on the result. The resulting string contains the
- // |client_id()|, the names, the trial name, and a "/" separator.
+ // Creates a persistent representation of all FieldTrial instances for
+ // resurrection in another process. This allows randomization to be done in
+ // one process, and secondary processes can be synchronized on the result.
+ // The resulting string contains the name and group name pairs for all trials,
+ // with "/" used to separate all names and to terminate the string. This
+ // string is parsed by CreateTrialsFromString().
static void StatesToString(std::string* output);
// Returns an array of Unique IDs for each Field Trial that has a chosen
@@ -324,24 +333,20 @@ class BASE_EXPORT FieldTrialList {
static void GetFieldTrialNameGroupIds(
std::vector<FieldTrial::NameGroupId>* name_group_ids);
- // Use a previously generated state string (re: StatesToString()) augment the
- // current list of field tests to include the supplied tests, and using a 100%
- // probability for each test, force them to have the same group string. This
- // is commonly used in a non-browser process, to carry randomly selected state
- // in a browser process into this non-browser process. This method calls
- // CreateFieldTrial to create the FieldTrial in the non-browser process.
- // Currently only the group_name_ and name_ are restored, as well as the
- // |client_id()| state, that could be used for one-time randomized trials
- // set up only in child processes.
- static bool CreateTrialsInChildProcess(const std::string& prior_trials);
+ // Use a state string (re: StatesToString()) to augment the current list of
+ // field tests to include the supplied tests, and using a 100% probability for
+ // each test, force them to have the same group string. This is commonly 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.
+ static bool CreateTrialsFromString(const std::string& prior_trials);
// Create a FieldTrial with the given |name| and using 100% probability for
// the FieldTrial, force FieldTrial to have the same group string as
// |group_name|. This is commonly used in a non-browser process, to carry
// randomly selected state in a browser process into this non-browser process.
- // Currently only the group_name_ and name_ are set in the FieldTrial. It
- // returns NULL if there is a FieldTrial that is already registered with the
- // same |name| but has different finalized group string (|group_name|).
+ // It returns NULL if there is a FieldTrial that is already registered with
+ // the same |name| but has different finalized group string (|group_name|).
static FieldTrial* CreateFieldTrial(const std::string& name,
const std::string& group_name);
@@ -390,6 +395,11 @@ class BASE_EXPORT FieldTrialList {
// Helper function should be called only while holding lock_.
FieldTrial* PreLockedFind(const std::string& name);
+ // Register() stores a pointer to the given trial in a global map.
+ // This method also AddRef's the indicated trial.
+ // This should always be called after creating a new FieldTrial instance.
+ static void Register(FieldTrial* trial);
+
static FieldTrialList* global_; // The singleton of this class.
// This will tell us if there is an attempt to register a field
« no previous file with comments | « no previous file | base/metrics/field_trial.cc » ('j') | base/metrics/field_trial.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698