diff options
author | asvitkine@chromium.org <asvitkine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-11 20:59:50 +0000 |
---|---|---|
committer | asvitkine@chromium.org <asvitkine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-11 20:59:50 +0000 |
commit | 6fded22b9a94b0b9bb1658310cc239b97c4276c8 (patch) | |
tree | 1302b01fbe1a4a1880df571c49d67bc155fec7f0 /base | |
parent | ff402386115448de1e4cbcf6fd62251b91ababa6 (diff) | |
download | chromium_src-6fded22b9a94b0b9bb1658310cc239b97c4276c8.zip chromium_src-6fded22b9a94b0b9bb1658310cc239b97c4276c8.tar.gz chromium_src-6fded22b9a94b0b9bb1658310cc239b97c4276c8.tar.bz2 |
Support custom randomization seed for VariationsService trials.
BUG=229486
TEST=New unit test.
Review URL: https://chromiumcodereview.appspot.com/13928017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@193739 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/metrics/field_trial.cc | 8 | ||||
-rw-r--r-- | base/metrics/field_trial.h | 21 |
2 files changed, 23 insertions, 6 deletions
diff --git a/base/metrics/field_trial.cc b/base/metrics/field_trial.cc index 1f4f9ae..c87935e 100644 --- a/base/metrics/field_trial.cc +++ b/base/metrics/field_trial.cc @@ -75,6 +75,11 @@ FieldTrial::EntropyProvider::~EntropyProvider() { } void FieldTrial::UseOneTimeRandomization() { + UseOneTimeRandomizationWithCustomSeed(0); +} + +void FieldTrial::UseOneTimeRandomizationWithCustomSeed( + uint32 randomization_seed) { // No need to specify randomization when the group choice was forced. if (forced_) return; @@ -89,7 +94,8 @@ void FieldTrial::UseOneTimeRandomization() { } random_ = static_cast<Probability>( - divisor_ * entropy_provider->GetEntropyForTrial(trial_name_)); + divisor_ * entropy_provider->GetEntropyForTrial(trial_name_, + randomization_seed)); } void FieldTrial::Disable() { diff --git a/base/metrics/field_trial.h b/base/metrics/field_trial.h index a4e1f53..b9a5b66 100644 --- a/base/metrics/field_trial.h +++ b/base/metrics/field_trial.h @@ -101,10 +101,13 @@ class BASE_EXPORT FieldTrial : public RefCounted<FieldTrial> { public: virtual ~EntropyProvider(); - // 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) const = 0; + // Returns a double in the range of [0, 1) to be used for the dice roll for + // the specified field trial. If |randomization_seed| is not 0, it will be + // used in preference to |trial_name| for generating the entropy by entropy + // providers that support it. A given instance should always return the same + // value given the same input |trial_name| and |randomization_seed| values. + virtual double GetEntropyForTrial(const std::string& trial_name, + uint32 randomization_seed) const = 0; }; // A pair representing a Field Trial and its selected group. @@ -121,9 +124,17 @@ class BASE_EXPORT FieldTrial : public RefCounted<FieldTrial> { // 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. + // called right after construction, before any groups are added. void UseOneTimeRandomization(); + // 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, with a + // custom randomization seed for the trial. The |randomization_seed| value + // should never be the same for two trials, else this would result in + // correlated group assignments. Must be called right after construction, + // before any groups are added. + void UseOneTimeRandomizationWithCustomSeed(uint32 randomization_seed); + // Disables this trial, meaning it always determines the default group // has been selected. May be called immediately after construction, or // at any time after initialization (should not be interleaved with |