Chromium Code Reviews| Index: base/metrics/field_trial.h |
| diff --git a/base/metrics/field_trial.h b/base/metrics/field_trial.h |
| index 50508d241425e558f4f4d737cf352947a86f0bef..8b87730483f1561dea85634f9ea7dfc8fe4d2d90 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. |
| @@ -119,9 +119,10 @@ class BASE_EXPORT FieldTrial : public RefCounted<FieldTrial> { |
| // Using this constructor creates a startup-randomized FieldTrial. If you |
|
Alexei Svitkine (slow)
2012/03/23 18:41:55
Update this comment, since this is no longer a con
MAD
2012/03/23 20:20:12
Done.
|
| // 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); |
| + static FieldTrial* CreateInstance( |
| + 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 |
| @@ -156,8 +157,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 +194,9 @@ class BASE_EXPORT FieldTrial : public RefCounted<FieldTrial> { |
| friend class RefCounted<FieldTrial>; |
| + 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 +251,9 @@ class BASE_EXPORT FieldTrial : public RefCounted<FieldTrial> { |
| // group. |
| bool enable_field_trial_; |
| + // When forced_ is true, we relaxed some of the checks for double init. |
| + bool forced_; |
| + |
| // When benchmarking is enabled, field trials all revert to the 'default' |
| // group. |
| static bool enable_benchmarking_; |
| @@ -263,7 +270,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,10 +299,6 @@ 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); |
| - |
| // 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. |
| static FieldTrial* Find(const std::string& name); |
| @@ -311,11 +314,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,16 +328,13 @@ 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 |
| @@ -384,12 +385,19 @@ class BASE_EXPORT FieldTrialList { |
| static const std::string& client_id(); |
| private: |
| + friend class base::FieldTrial; |
| + |
| // A map from FieldTrial names to the actual instances. |
| typedef std::map<std::string, FieldTrial*> RegistrationList; |
| // 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 only be called by FieldTrial::CreateInstance. |
| + 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 |