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 e468e4e2d808cddef99f84c3c6414a3a1205eeb0..122ad0f508927b56d2c4d64dc1dd1cca83273273 100644 |
| --- a/components/variations/variations_seed_processor.cc |
| +++ b/components/variations/variations_seed_processor.cc |
| @@ -4,10 +4,12 @@ |
| #include "components/variations/variations_seed_processor.h" |
| +#include <map> |
| #include <vector> |
| #include "base/command_line.h" |
| #include "base/metrics/field_trial.h" |
| +#include "base/strings/utf_string_conversions.h" |
| #include "components/variations/processed_study.h" |
| #include "components/variations/study_filtering.h" |
| #include "components/variations/variations_associated_data.h" |
| @@ -58,6 +60,18 @@ void RegisterVariationIds(const Study_Experiment& experiment, |
| } |
| } |
| +// Executes |override_string| on every override defined by |experiment|. |
| +void ApplyUIStringOverrides( |
| + const Study_Experiment& experiment, |
| + const VariationsSeedProcessor::UIStringOverrideCallback& override_string) { |
|
Alexei Svitkine (slow)
2014/07/15 16:44:52
Nit: Maybe clearer to rename this |override_callba
jwd
2014/07/16 21:33:05
Done.
|
| + for (int i = 0; i < experiment.override_ui_string_size(); ++i) { |
| + Study_Experiment_OverrideUIString experiment_overrides = |
|
Alexei Svitkine (slow)
2014/07/15 16:44:52
Nit: const ref, to avoid copying - also this is a
jwd
2014/07/16 21:33:05
Done.
|
| + experiment.override_ui_string(i); |
| + override_string.Run(experiment_overrides.name_hash(), |
| + base::UTF8ToUTF16(experiment_overrides.value())); |
| + } |
| +} |
| + |
| } // namespace |
| VariationsSeedProcessor::VariationsSeedProcessor() { |
| @@ -73,17 +87,19 @@ void VariationsSeedProcessor::CreateTrialsFromSeed( |
| const base::Version& version, |
| Study_Channel channel, |
| Study_FormFactor form_factor, |
| - const std::string& hardware_class) { |
| + const std::string& hardware_class, |
| + const UIStringOverrideCallback& override_string) { |
| std::vector<ProcessedStudy> filtered_studies; |
| FilterAndValidateStudies(seed, locale, reference_date, version, channel, |
| form_factor, hardware_class, &filtered_studies); |
| for (size_t i = 0; i < filtered_studies.size(); ++i) |
| - CreateTrialFromStudy(filtered_studies[i]); |
| + CreateTrialFromStudy(filtered_studies[i], override_string); |
| } |
| void VariationsSeedProcessor::CreateTrialFromStudy( |
| - const ProcessedStudy& processed_study) { |
| + const ProcessedStudy& processed_study, |
| + const UIStringOverrideCallback& override_string) { |
| const Study& study = *processed_study.study(); |
| // Check if any experiments need to be forced due to a command line |
| @@ -98,8 +114,11 @@ void VariationsSeedProcessor::CreateTrialFromStudy( |
| experiment.name())); |
| RegisterExperimentParams(study, experiment); |
| RegisterVariationIds(experiment, study.name()); |
| - if (study.activation_type() == Study_ActivationType_ACTIVATION_AUTO) |
| + if (study.activation_type() == Study_ActivationType_ACTIVATION_AUTO) { |
| trial->group(); |
| + // UI Strings can only be overridden from ACTIVATION_AUTO experiments. |
| + ApplyUIStringOverrides(experiment, override_string); |
| + } |
| DVLOG(1) << "Trial " << study.name() << " forced by flag: " |
| << experiment.forcing_flag(); |
| @@ -127,6 +146,7 @@ void VariationsSeedProcessor::CreateTrialFromStudy( |
| base::FieldTrialList::kNoExpirationYear, 1, 1, randomization_type, |
| randomization_seed, NULL)); |
| + bool hasOverrides = false; |
|
Alexei Svitkine (slow)
2014/07/15 16:44:52
Nit: has_overrides
jwd
2014/07/16 21:33:05
Done.
|
| for (int i = 0; i < study.experiment_size(); ++i) { |
| const Study_Experiment& experiment = study.experiment(i); |
| RegisterExperimentParams(study, experiment); |
| @@ -140,13 +160,30 @@ void VariationsSeedProcessor::CreateTrialFromStudy( |
| trial->AppendGroup(experiment.name(), experiment.probability_weight()); |
| RegisterVariationIds(experiment, study.name()); |
| + |
| + hasOverrides = hasOverrides || experiment.override_ui_string_size() > 0; |
| } |
| trial->SetForced(); |
| - if (processed_study.is_expired()) |
| + if (processed_study.is_expired()) { |
| trial->Disable(); |
| - else if (study.activation_type() == Study_ActivationType_ACTIVATION_AUTO) |
| - trial->group(); |
| + } else if (study.activation_type() == Study_ActivationType_ACTIVATION_AUTO) { |
| + const std::string& group_name = trial->group_name(); |
| + |
| + // Don't try to apply overrides if none of the experiments in this study had |
| + // any. |
| + if (!hasOverrides) |
| + return; |
| + |
| + // UI Strings can only be overridden from ACTIVATION_AUTO experiments. |
| + int experiment_index = processed_study.GetExperimentIndexByName(group_name); |
| + |
| + // The field trial was defined from |study|, so the active experiment's name |
| + // must be in the |study|. |
| + DCHECK_NE(experiment_index, -1); |
|
Alexei Svitkine (slow)
2014/07/15 16:44:52
Nit: Swap params.
jwd
2014/07/16 21:33:05
Done.
|
| + |
| + ApplyUIStringOverrides(study.experiment(experiment_index), override_string); |
| + } |
| } |
| } // namespace chrome_variations |