Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/variations/variations_seed_processor.h" | 5 #include "components/variations/variations_seed_processor.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
| 11 #include "base/strings/utf_string_conversions.h" | |
| 11 #include "components/variations/processed_study.h" | 12 #include "components/variations/processed_study.h" |
| 12 #include "components/variations/study_filtering.h" | 13 #include "components/variations/study_filtering.h" |
| 13 #include "components/variations/variations_associated_data.h" | 14 #include "components/variations/variations_associated_data.h" |
| 14 | 15 |
| 15 namespace chrome_variations { | 16 namespace chrome_variations { |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 // Associates the variations params of |experiment|, if present. | 20 // Associates the variations params of |experiment|, if present. |
| 20 void RegisterExperimentParams(const Study& study, | 21 void RegisterExperimentParams(const Study& study, |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 51 if (experiment.has_google_update_experiment_id()) { | 52 if (experiment.has_google_update_experiment_id()) { |
| 52 const VariationID variation_id = | 53 const VariationID variation_id = |
| 53 static_cast<VariationID>(experiment.google_update_experiment_id()); | 54 static_cast<VariationID>(experiment.google_update_experiment_id()); |
| 54 AssociateGoogleVariationIDForce(GOOGLE_UPDATE_SERVICE, | 55 AssociateGoogleVariationIDForce(GOOGLE_UPDATE_SERVICE, |
| 55 trial_name, | 56 trial_name, |
| 56 experiment.name(), | 57 experiment.name(), |
| 57 variation_id); | 58 variation_id); |
| 58 } | 59 } |
| 59 } | 60 } |
| 60 | 61 |
| 62 void ApplyUIStringOverrides( | |
|
Alexei Svitkine (slow)
2014/07/04 15:48:51
Add a comment please.
jwd
2014/07/07 15:52:20
Done.
| |
| 63 const Study_Experiment& experiment, | |
| 64 const VariationsSeedProcessor::UIStringOverrideCallback& override_string) { | |
| 65 for (int i = 0; i < experiment.override_ui_string_size(); ++i) { | |
| 66 Study_Experiment_OverrideUIString experiment_overrides = | |
|
Alexei Svitkine (slow)
2014/07/03 17:54:40
Nit: Remove extra space.
jwd
2014/07/07 15:52:20
Done.
| |
| 67 experiment.override_ui_string(i); | |
| 68 override_string.Run(experiment_overrides.name_hash(), | |
| 69 base::ASCIIToUTF16(experiment_overrides.value())); | |
|
Alexei Svitkine (slow)
2014/07/03 17:54:41
The value may not be ascii. Use UTF8ToUTF16.
jwd
2014/07/07 15:52:20
Done.
| |
| 70 } | |
| 71 } | |
| 72 | |
| 61 } // namespace | 73 } // namespace |
| 62 | 74 |
| 63 VariationsSeedProcessor::VariationsSeedProcessor() { | 75 VariationsSeedProcessor::VariationsSeedProcessor() { |
| 64 } | 76 } |
| 65 | 77 |
| 66 VariationsSeedProcessor::~VariationsSeedProcessor() { | 78 VariationsSeedProcessor::~VariationsSeedProcessor() { |
| 67 } | 79 } |
| 68 | 80 |
| 69 void VariationsSeedProcessor::CreateTrialsFromSeed( | 81 void VariationsSeedProcessor::CreateTrialsFromSeed( |
| 70 const VariationsSeed& seed, | 82 const VariationsSeed& seed, |
| 71 const std::string& locale, | 83 const std::string& locale, |
| 72 const base::Time& reference_date, | 84 const base::Time& reference_date, |
| 73 const base::Version& version, | 85 const base::Version& version, |
| 74 Study_Channel channel, | 86 Study_Channel channel, |
| 75 Study_FormFactor form_factor, | 87 Study_FormFactor form_factor, |
| 76 const std::string& hardware_class) { | 88 const std::string& hardware_class, |
| 89 const UIStringOverrideCallback& override_string) { | |
| 77 std::vector<ProcessedStudy> filtered_studies; | 90 std::vector<ProcessedStudy> filtered_studies; |
| 78 FilterAndValidateStudies(seed, locale, reference_date, version, channel, | 91 FilterAndValidateStudies(seed, locale, reference_date, version, channel, |
| 79 form_factor, hardware_class, &filtered_studies); | 92 form_factor, hardware_class, &filtered_studies); |
| 80 | 93 |
| 81 for (size_t i = 0; i < filtered_studies.size(); ++i) | 94 for (size_t i = 0; i < filtered_studies.size(); ++i) |
| 82 CreateTrialFromStudy(filtered_studies[i]); | 95 CreateTrialFromStudy(filtered_studies[i], override_string); |
| 83 } | 96 } |
| 84 | 97 |
| 85 void VariationsSeedProcessor::CreateTrialFromStudy( | 98 void VariationsSeedProcessor::CreateTrialFromStudy( |
| 86 const ProcessedStudy& processed_study) { | 99 const ProcessedStudy& processed_study, |
| 100 const UIStringOverrideCallback& override_string) { | |
| 87 const Study& study = *processed_study.study(); | 101 const Study& study = *processed_study.study(); |
| 88 | 102 |
| 89 // Check if any experiments need to be forced due to a command line | 103 // Check if any experiments need to be forced due to a command line |
| 90 // flag. Force the first experiment with an existing flag. | 104 // flag. Force the first experiment with an existing flag. |
| 91 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 105 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 92 for (int i = 0; i < study.experiment_size(); ++i) { | 106 for (int i = 0; i < study.experiment_size(); ++i) { |
| 93 const Study_Experiment& experiment = study.experiment(i); | 107 const Study_Experiment& experiment = study.experiment(i); |
| 94 if (experiment.has_forcing_flag() && | 108 if (experiment.has_forcing_flag() && |
| 95 command_line->HasSwitch(experiment.forcing_flag())) { | 109 command_line->HasSwitch(experiment.forcing_flag())) { |
| 96 scoped_refptr<base::FieldTrial> trial( | 110 scoped_refptr<base::FieldTrial> trial( |
| 97 base::FieldTrialList::CreateFieldTrial(study.name(), | 111 base::FieldTrialList::CreateFieldTrial(study.name(), |
| 98 experiment.name())); | 112 experiment.name())); |
| 99 RegisterExperimentParams(study, experiment); | 113 RegisterExperimentParams(study, experiment); |
| 100 RegisterVariationIds(experiment, study.name()); | 114 RegisterVariationIds(experiment, study.name()); |
| 101 if (study.activation_type() == Study_ActivationType_ACTIVATION_AUTO) | 115 if (study.activation_type() == Study_ActivationType_ACTIVATION_AUTO) { |
| 102 trial->group(); | 116 trial->group(); |
| 117 // UI Strings can only be overridden from ACTIVATION_AUTO experiments. | |
| 118 ApplyUIStringOverrides(experiment, override_string); | |
| 119 } | |
| 103 | 120 |
| 104 DVLOG(1) << "Trial " << study.name() << " forced by flag: " | 121 DVLOG(1) << "Trial " << study.name() << " forced by flag: " |
| 105 << experiment.forcing_flag(); | 122 << experiment.forcing_flag(); |
| 106 return; | 123 return; |
| 107 } | 124 } |
| 108 } | 125 } |
| 109 | 126 |
| 110 uint32 randomization_seed = 0; | 127 uint32 randomization_seed = 0; |
| 111 base::FieldTrial::RandomizationType randomization_type = | 128 base::FieldTrial::RandomizationType randomization_type = |
| 112 base::FieldTrial::SESSION_RANDOMIZED; | 129 base::FieldTrial::SESSION_RANDOMIZED; |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 136 if (experiment.has_forcing_flag()) | 153 if (experiment.has_forcing_flag()) |
| 137 continue; | 154 continue; |
| 138 | 155 |
| 139 if (experiment.name() != study.default_experiment_name()) | 156 if (experiment.name() != study.default_experiment_name()) |
| 140 trial->AppendGroup(experiment.name(), experiment.probability_weight()); | 157 trial->AppendGroup(experiment.name(), experiment.probability_weight()); |
| 141 | 158 |
| 142 RegisterVariationIds(experiment, study.name()); | 159 RegisterVariationIds(experiment, study.name()); |
| 143 } | 160 } |
| 144 | 161 |
| 145 trial->SetForced(); | 162 trial->SetForced(); |
| 146 if (processed_study.is_expired()) | 163 if (processed_study.is_expired()) |
|
Alexei Svitkine (slow)
2014/07/04 15:48:51
Nit: Add {}'s here.
jwd
2014/07/07 15:52:20
Done.
| |
| 147 trial->Disable(); | 164 trial->Disable(); |
| 148 else if (study.activation_type() == Study_ActivationType_ACTIVATION_AUTO) | 165 else if (study.activation_type() == Study_ActivationType_ACTIVATION_AUTO) { |
| 149 trial->group(); | 166 const std::string& group_name = trial->group_name(); |
| 167 | |
| 168 // UI Strings can only be overridden from ACTIVATION_AUTO experiments. | |
| 169 int experiment_index = processed_study.GetExperimentIndexByName(group_name); | |
|
Alexei Svitkine (slow)
2014/07/04 15:48:51
Maybe add a bool to keep track if any experiment h
jwd
2014/07/07 15:52:20
Done.
| |
| 170 | |
| 171 // The field trial was defined from |study|, so the active experiment's name | |
| 172 // must be in the |study|. | |
| 173 DCHECK_GE(experiment_index, 0); | |
|
Alexei Svitkine (slow)
2014/07/04 15:48:52
Change to NE(-1,
jwd
2014/07/07 15:52:20
Done.
| |
| 174 | |
| 175 ApplyUIStringOverrides(study.experiment(experiment_index), override_string); | |
| 176 } | |
| 150 } | 177 } |
| 151 | 178 |
| 152 } // namespace chrome_variations | 179 } // namespace chrome_variations |
| OLD | NEW |