diff options
author | yiyaoliu@chromium.org <yiyaoliu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-18 09:32:45 +0000 |
---|---|---|
committer | yiyaoliu@chromium.org <yiyaoliu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-18 09:32:45 +0000 |
commit | 0aafa3e3975355803e3eeee4815411523d801c75 (patch) | |
tree | 63534ae1d3c571c29d2eec325ab8c9fd77e2a810 /components/variations/variations_seed_processor.cc | |
parent | 3350d7177b17f2e27142363ba7c892432f869b3b (diff) | |
download | chromium_src-0aafa3e3975355803e3eeee4815411523d801c75.zip chromium_src-0aafa3e3975355803e3eeee4815411523d801c75.tar.gz chromium_src-0aafa3e3975355803e3eeee4815411523d801c75.tar.bz2 |
Allow variation id with forcing flag for special setup & unit tests.
BUG=317879
Review URL: https://codereview.chromium.org/71753004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@235680 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'components/variations/variations_seed_processor.cc')
-rw-r--r-- | components/variations/variations_seed_processor.cc | 67 |
1 files changed, 49 insertions, 18 deletions
diff --git a/components/variations/variations_seed_processor.cc b/components/variations/variations_seed_processor.cc index e7a33ca..6174558 100644 --- a/components/variations/variations_seed_processor.cc +++ b/components/variations/variations_seed_processor.cc @@ -56,6 +56,28 @@ void RegisterExperimentParams(const Study& study, AssociateVariationParams(study.name(), experiment.name(), params); } +// If there are variation ids associated with |experiment|, register the +// variation ids. +void RegisterVariationIds(const Study_Experiment& experiment, + const std::string& trial_name) { + if (experiment.has_google_web_experiment_id()) { + const VariationID variation_id = + static_cast<VariationID>(experiment.google_web_experiment_id()); + AssociateGoogleVariationIDForce(GOOGLE_WEB_PROPERTIES, + trial_name, + experiment.name(), + variation_id); + } + if (experiment.has_google_update_experiment_id()) { + const VariationID variation_id = + static_cast<VariationID>(experiment.google_update_experiment_id()); + AssociateGoogleVariationIDForce(GOOGLE_UPDATE_SERVICE, + trial_name, + experiment.name(), + variation_id); + } +} + } // namespace VariationsSeedProcessor::VariationsSeedProcessor() { @@ -64,6 +86,28 @@ VariationsSeedProcessor::VariationsSeedProcessor() { VariationsSeedProcessor::~VariationsSeedProcessor() { } +bool VariationsSeedProcessor::AllowVariationIdWithForcingFlag( + const Study& study) { + if (!study.has_filter()) + return false; + const Study_Filter& filter = study.filter(); + if (filter.platform_size() == 0 || filter.channel_size() == 0) + return false; + for (int i = 0; i < filter.platform_size(); ++i) { + if (filter.platform(i) != Study_Platform_PLATFORM_ANDROID && + filter.platform(i) != Study_Platform_PLATFORM_IOS) { + return false; + } + } + for (int i = 0; i < filter.channel_size(); ++i) { + if (filter.channel(i) != Study_Channel_CANARY && + filter.channel(i) != Study_Channel_DEV) { + return false; + } + } + return true; +} + void VariationsSeedProcessor::CreateTrialsFromSeed( const VariationsSeed& seed, const std::string& locale, @@ -225,6 +269,8 @@ void VariationsSeedProcessor::CreateTrialFromStudy( RegisterExperimentParams(study, experiment); DVLOG(1) << "Trial " << study.name() << " forced by flag: " << experiment.forcing_flag(); + if (AllowVariationIdWithForcingFlag(study)) + RegisterVariationIds(experiment, study.name()); return; } } @@ -253,30 +299,15 @@ void VariationsSeedProcessor::CreateTrialFromStudy( const Study_Experiment& experiment = study.experiment(i); RegisterExperimentParams(study, experiment); - // Groups with flags can't be selected randomly, so we don't add them to - // the field trial. + // Groups with forcing flags have probability 0 and will never be selected. + // Therefore, there's no need to add them to the field trial. if (experiment.has_forcing_flag()) continue; if (experiment.name() != study.default_experiment_name()) trial->AppendGroup(experiment.name(), experiment.probability_weight()); - if (experiment.has_google_web_experiment_id()) { - const VariationID variation_id = - static_cast<VariationID>(experiment.google_web_experiment_id()); - AssociateGoogleVariationIDForce(GOOGLE_WEB_PROPERTIES, - study.name(), - experiment.name(), - variation_id); - } - if (experiment.has_google_update_experiment_id()) { - const VariationID variation_id = - static_cast<VariationID>(experiment.google_update_experiment_id()); - AssociateGoogleVariationIDForce(GOOGLE_UPDATE_SERVICE, - study.name(), - experiment.name(), - variation_id); - } + RegisterVariationIds(experiment, study.name()); } trial->SetForced(); |