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 <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 25 matching lines...) Expand all Loading... |
36 #else | 36 #else |
37 #error Unknown platform | 37 #error Unknown platform |
38 #endif | 38 #endif |
39 } | 39 } |
40 | 40 |
41 // Converts |date_time| in Study date format to base::Time. | 41 // Converts |date_time| in Study date format to base::Time. |
42 base::Time ConvertStudyDateToBaseTime(int64 date_time) { | 42 base::Time ConvertStudyDateToBaseTime(int64 date_time) { |
43 return base::Time::UnixEpoch() + base::TimeDelta::FromSeconds(date_time); | 43 return base::Time::UnixEpoch() + base::TimeDelta::FromSeconds(date_time); |
44 } | 44 } |
45 | 45 |
| 46 // Associates the variations params of |experiment|, if present. |
| 47 void RegisterExperimentParams(const Study& study, |
| 48 const Study_Experiment& experiment) { |
| 49 std::map<std::string, std::string> params; |
| 50 for (int i = 0; i < experiment.param_size(); ++i) { |
| 51 if (experiment.param(i).has_name() && experiment.param(i).has_value()) |
| 52 params[experiment.param(i).name()] = experiment.param(i).value(); |
| 53 } |
| 54 if (!params.empty()) |
| 55 AssociateVariationParams(study.name(), experiment.name(), params); |
| 56 } |
| 57 |
46 } // namespace | 58 } // namespace |
47 | 59 |
48 VariationsSeedProcessor::VariationsSeedProcessor() { | 60 VariationsSeedProcessor::VariationsSeedProcessor() { |
49 } | 61 } |
50 | 62 |
51 VariationsSeedProcessor::~VariationsSeedProcessor() { | 63 VariationsSeedProcessor::~VariationsSeedProcessor() { |
52 } | 64 } |
53 | 65 |
54 void VariationsSeedProcessor::CreateTrialsFromSeed( | 66 void VariationsSeedProcessor::CreateTrialsFromSeed( |
55 const VariationsSeed& seed, | 67 const VariationsSeed& seed, |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 return; | 173 return; |
162 | 174 |
163 // Check if any experiments need to be forced due to a command line | 175 // Check if any experiments need to be forced due to a command line |
164 // flag. Force the first experiment with an existing flag. | 176 // flag. Force the first experiment with an existing flag. |
165 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 177 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
166 for (int i = 0; i < study.experiment_size(); ++i) { | 178 for (int i = 0; i < study.experiment_size(); ++i) { |
167 const Study_Experiment& experiment = study.experiment(i); | 179 const Study_Experiment& experiment = study.experiment(i); |
168 if (experiment.has_forcing_flag() && | 180 if (experiment.has_forcing_flag() && |
169 command_line->HasSwitch(experiment.forcing_flag())) { | 181 command_line->HasSwitch(experiment.forcing_flag())) { |
170 base::FieldTrialList::CreateFieldTrial(study.name(), experiment.name()); | 182 base::FieldTrialList::CreateFieldTrial(study.name(), experiment.name()); |
| 183 RegisterExperimentParams(study, experiment); |
171 DVLOG(1) << "Trial " << study.name() << " forced by flag: " | 184 DVLOG(1) << "Trial " << study.name() << " forced by flag: " |
172 << experiment.forcing_flag(); | 185 << experiment.forcing_flag(); |
173 return; | 186 return; |
174 } | 187 } |
175 } | 188 } |
176 | 189 |
177 uint32 randomization_seed = 0; | 190 uint32 randomization_seed = 0; |
178 base::FieldTrial::RandomizationType randomization_type = | 191 base::FieldTrial::RandomizationType randomization_type = |
179 base::FieldTrial::SESSION_RANDOMIZED; | 192 base::FieldTrial::SESSION_RANDOMIZED; |
180 if (study.has_consistency() && | 193 if (study.has_consistency() && |
181 study.consistency() == Study_Consistency_PERMANENT) { | 194 study.consistency() == Study_Consistency_PERMANENT) { |
182 randomization_type = base::FieldTrial::ONE_TIME_RANDOMIZED; | 195 randomization_type = base::FieldTrial::ONE_TIME_RANDOMIZED; |
183 if (study.has_randomization_seed()) | 196 if (study.has_randomization_seed()) |
184 randomization_seed = study.randomization_seed(); | 197 randomization_seed = study.randomization_seed(); |
185 } | 198 } |
186 | 199 |
187 // The trial is created without specifying an expiration date because the | 200 // The trial is created without specifying an expiration date because the |
188 // expiration check in field_trial.cc is based on the build date. Instead, | 201 // expiration check in field_trial.cc is based on the build date. Instead, |
189 // the expiration check using |reference_date| is done explicitly below. | 202 // the expiration check using |reference_date| is done explicitly below. |
190 scoped_refptr<base::FieldTrial> trial( | 203 scoped_refptr<base::FieldTrial> trial( |
191 base::FieldTrialList::FactoryGetFieldTrialWithRandomizationSeed( | 204 base::FieldTrialList::FactoryGetFieldTrialWithRandomizationSeed( |
192 study.name(), total_probability, study.default_experiment_name(), | 205 study.name(), total_probability, study.default_experiment_name(), |
193 base::FieldTrialList::kNoExpirationYear, 1, 1, randomization_type, | 206 base::FieldTrialList::kNoExpirationYear, 1, 1, randomization_type, |
194 randomization_seed, NULL)); | 207 randomization_seed, NULL)); |
195 | 208 |
196 for (int i = 0; i < study.experiment_size(); ++i) { | 209 for (int i = 0; i < study.experiment_size(); ++i) { |
197 const Study_Experiment& experiment = study.experiment(i); | 210 const Study_Experiment& experiment = study.experiment(i); |
198 | 211 RegisterExperimentParams(study, experiment); |
199 std::map<std::string, std::string> params; | |
200 for (int j = 0; j < experiment.param_size(); j++) { | |
201 if (experiment.param(j).has_name() && experiment.param(j).has_value()) | |
202 params[experiment.param(j).name()] = experiment.param(j).value(); | |
203 } | |
204 if (!params.empty()) | |
205 AssociateVariationParams(study.name(), experiment.name(), params); | |
206 | 212 |
207 // Groups with flags can't be selected randomly, so we don't add them to | 213 // Groups with flags can't be selected randomly, so we don't add them to |
208 // the field trial. | 214 // the field trial. |
209 if (experiment.has_forcing_flag()) | 215 if (experiment.has_forcing_flag()) |
210 continue; | 216 continue; |
211 | 217 |
212 if (experiment.name() != study.default_experiment_name()) | 218 if (experiment.name() != study.default_experiment_name()) |
213 trial->AppendGroup(experiment.name(), experiment.probability_weight()); | 219 trial->AppendGroup(experiment.name(), experiment.probability_weight()); |
214 | 220 |
215 if (experiment.has_google_web_experiment_id()) { | 221 if (experiment.has_google_web_experiment_id()) { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 // The default group was not found in the list of groups. This study is not | 341 // The default group was not found in the list of groups. This study is not |
336 // valid. | 342 // valid. |
337 return false; | 343 return false; |
338 } | 344 } |
339 | 345 |
340 *total_probability = divisor; | 346 *total_probability = divisor; |
341 return true; | 347 return true; |
342 } | 348 } |
343 | 349 |
344 } // namespace chrome_variations | 350 } // namespace chrome_variations |
OLD | NEW |