Chromium Code Reviews| Index: base/metrics/field_trial.h |
| =================================================================== |
| --- base/metrics/field_trial.h (revision 151948) |
| +++ base/metrics/field_trial.h (working copy) |
| @@ -94,6 +94,18 @@ |
| public: |
| typedef int Probability; // Probability type for being selected in a trial. |
| + // EntropyProvider is an interface for providing entropy for one-time |
| + // randomized (persistent) field trials. |
| + class BASE_EXPORT EntropyProvider { |
| + public: |
| + virtual ~EntropyProvider() {} |
|
Ilya Sherman
2012/08/17 07:34:28
nit: Virtual functions should never be inlined.
Alexei Svitkine (slow)
2012/08/17 14:08:59
Done. I also fixed this for FieldTrialList::Observ
|
| + |
| + // Returns a double in the range of [0, 1) based on |trial_name| that will |
| + // be used for the dice roll for the specified field trial. A given instance |
| + // should always return the same value given the same input |trial_name|. |
| + virtual double GetEntropyForTrial(const std::string& trial_name) = 0; |
| + }; |
| + |
| // A pair representing a Field Trial and its selected group. |
| struct SelectedGroup { |
| std::string trial; |
| @@ -188,7 +200,8 @@ |
| // consumers don't use it by mistake in cases where the group was forced. |
| static const int kDefaultGroupNumber; |
| - FieldTrial(const std::string& name, |
| + FieldTrial(EntropyProvider* entropy_provider, |
|
Ilya Sherman
2012/08/17 07:34:28
nit: Unless you're planning to modify the |entropy
Alexei Svitkine (slow)
2012/08/17 14:08:59
Done.
|
| + const std::string& name, |
| Probability total_probability, |
| const std::string& default_group_name); |
| virtual ~FieldTrial(); |
| @@ -202,11 +215,9 @@ |
| // Returns the group_name. A winner need not have been chosen. |
| std::string group_name_internal() const { return group_name_; } |
| - // Calculates a uniformly-distributed double between [0.0, 1.0) given |
| - // a |client_id| and a |trial_name| (the latter is used as salt to avoid |
| - // separate one-time randomized trials from all having the same results). |
| - static double HashClientId(const std::string& client_id, |
| - const std::string& trial_name); |
| + // Entropy provider that will be used if the field trial uses one-time |
| + // randomization. Weak pointer, owned by FieldTrialList. |
| + EntropyProvider* entropy_provider_; |
|
Ilya Sherman
2012/08/17 07:34:28
nit: const EntropyProvider* const?
Alexei Svitkine (slow)
2012/08/17 14:08:59
Done.
|
| // The name of the field trial, as can be found via the FieldTrialList. |
| const std::string name_; |
| @@ -278,11 +289,11 @@ |
| // This singleton holds the global list of registered FieldTrials. |
| // |
| - // |client_id| should be an opaque, diverse ID for this client that does not |
| - // change between sessions, to enable one-time randomized trials. The empty |
| - // string may be provided, in which case one-time randomized trials will |
| - // not be available. |
| - explicit FieldTrialList(const std::string& client_id); |
| + // To support one-time randomized field trials, specify a non-NULL |
| + // |entropy_provider| which should be a source of uniformly distributed |
| + // entropy values. |
| + explicit FieldTrialList(FieldTrial::EntropyProvider* entropy_provider); |
| + |
| // Destructor Release()'s references to all registered FieldTrial instances. |
| ~FieldTrialList(); |
| @@ -393,12 +404,6 @@ |
| // when constructing the FieldTrialList singleton. |
| static bool IsOneTimeRandomizationEnabled(); |
| - // Returns an opaque, diverse ID for this client that does not change |
| - // between sessions. |
| - // |
| - // Returns the empty string if one-time randomization is not enabled. |
| - static const std::string& client_id(); |
| - |
| private: |
| // A map from FieldTrial names to the actual instances. |
| typedef std::map<std::string, FieldTrial*> RegistrationList; |
| @@ -428,9 +433,9 @@ |
| base::Lock lock_; |
| RegistrationList registered_; |
| - // An opaque, diverse ID for this client that does not change |
| - // between sessions, or the empty string if not initialized. |
| - std::string client_id_; |
| + // Entropy provider to be used for one-time randomized field trials. If NULL, |
| + // one-time randomization is not supported. |
| + scoped_ptr<FieldTrial::EntropyProvider> entropy_provider_; |
| // List of observers to be notified when a group is selected for a FieldTrial. |
| scoped_refptr<ObserverListThreadSafe<Observer> > observer_list_; |