Chromium Code Reviews| Index: components/variations/variations_seed_processor.cc |
| diff --git a/components/variations/variations_seed_processor.cc b/components/variations/variations_seed_processor.cc |
| index e7a33cad035433b67603eabfccb819868d54ca38..3204f590b1e095a063588c1e0a2613af8af97367 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 if there is variation id associated with |experiment|, register the |
| +// variation id. |
| +void RegisterVariationIds(const Study_Experiment& experiment, |
| + const std::string& trial_name) { |
|
Alexei Svitkine (slow)
2013/11/14 22:34:33
Nit: Remove extra space before trial_name
yao
2013/11/14 23:41:15
Done.
|
| + 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; |
| + Study_Filter filter = study.filter(); |
|
Alexei Svitkine (slow)
2013/11/14 22:34:33
This does a copy. Use a reference (const Study_Fil
yao
2013/11/14 23:41:15
Done.
|
| + 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,9 @@ void VariationsSeedProcessor::CreateTrialFromStudy( |
| RegisterExperimentParams(study, experiment); |
| DVLOG(1) << "Trial " << study.name() << " forced by flag: " |
| << experiment.forcing_flag(); |
| + if (AllowVariationIdWithForcingFlag(study)) { |
|
Alexei Svitkine (slow)
2013/11/14 22:34:33
No need for {}'s.
yao
2013/11/14 23:41:15
Done.
|
| + RegisterVariationIds(experiment, study.name()); |
| + } |
| return; |
| } |
| } |
| @@ -253,30 +300,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(); |