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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 const Study_Experiment& experiment) { | 49 const Study_Experiment& experiment) { |
50 std::map<std::string, std::string> params; | 50 std::map<std::string, std::string> params; |
51 for (int i = 0; i < experiment.param_size(); ++i) { | 51 for (int i = 0; i < experiment.param_size(); ++i) { |
52 if (experiment.param(i).has_name() && experiment.param(i).has_value()) | 52 if (experiment.param(i).has_name() && experiment.param(i).has_value()) |
53 params[experiment.param(i).name()] = experiment.param(i).value(); | 53 params[experiment.param(i).name()] = experiment.param(i).value(); |
54 } | 54 } |
55 if (!params.empty()) | 55 if (!params.empty()) |
56 AssociateVariationParams(study.name(), experiment.name(), params); | 56 AssociateVariationParams(study.name(), experiment.name(), params); |
57 } | 57 } |
58 | 58 |
| 59 // If there are variation ids associated with |experiment|, register the |
| 60 // variation ids. |
| 61 void RegisterVariationIds(const Study_Experiment& experiment, |
| 62 const std::string& trial_name) { |
| 63 if (experiment.has_google_web_experiment_id()) { |
| 64 const VariationID variation_id = |
| 65 static_cast<VariationID>(experiment.google_web_experiment_id()); |
| 66 AssociateGoogleVariationIDForce(GOOGLE_WEB_PROPERTIES, |
| 67 trial_name, |
| 68 experiment.name(), |
| 69 variation_id); |
| 70 } |
| 71 if (experiment.has_google_update_experiment_id()) { |
| 72 const VariationID variation_id = |
| 73 static_cast<VariationID>(experiment.google_update_experiment_id()); |
| 74 AssociateGoogleVariationIDForce(GOOGLE_UPDATE_SERVICE, |
| 75 trial_name, |
| 76 experiment.name(), |
| 77 variation_id); |
| 78 } |
| 79 } |
| 80 |
59 } // namespace | 81 } // namespace |
60 | 82 |
61 VariationsSeedProcessor::VariationsSeedProcessor() { | 83 VariationsSeedProcessor::VariationsSeedProcessor() { |
62 } | 84 } |
63 | 85 |
64 VariationsSeedProcessor::~VariationsSeedProcessor() { | 86 VariationsSeedProcessor::~VariationsSeedProcessor() { |
65 } | 87 } |
66 | 88 |
| 89 bool VariationsSeedProcessor::AllowVariationIdWithForcingFlag( |
| 90 const Study& study) { |
| 91 if (!study.has_filter()) |
| 92 return false; |
| 93 const Study_Filter& filter = study.filter(); |
| 94 if (filter.platform_size() == 0 || filter.channel_size() == 0) |
| 95 return false; |
| 96 for (int i = 0; i < filter.platform_size(); ++i) { |
| 97 if (filter.platform(i) != Study_Platform_PLATFORM_ANDROID && |
| 98 filter.platform(i) != Study_Platform_PLATFORM_IOS) { |
| 99 return false; |
| 100 } |
| 101 } |
| 102 for (int i = 0; i < filter.channel_size(); ++i) { |
| 103 if (filter.channel(i) != Study_Channel_CANARY && |
| 104 filter.channel(i) != Study_Channel_DEV) { |
| 105 return false; |
| 106 } |
| 107 } |
| 108 return true; |
| 109 } |
| 110 |
67 void VariationsSeedProcessor::CreateTrialsFromSeed( | 111 void VariationsSeedProcessor::CreateTrialsFromSeed( |
68 const VariationsSeed& seed, | 112 const VariationsSeed& seed, |
69 const std::string& locale, | 113 const std::string& locale, |
70 const base::Time& reference_date, | 114 const base::Time& reference_date, |
71 const base::Version& version, | 115 const base::Version& version, |
72 Study_Channel channel, | 116 Study_Channel channel, |
73 Study_FormFactor form_factor) { | 117 Study_FormFactor form_factor) { |
74 std::vector<ProcessedStudy> filtered_studies; | 118 std::vector<ProcessedStudy> filtered_studies; |
75 FilterAndValidateStudies(seed, locale, reference_date, version, channel, | 119 FilterAndValidateStudies(seed, locale, reference_date, version, channel, |
76 form_factor, &filtered_studies); | 120 form_factor, &filtered_studies); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 // flag. Force the first experiment with an existing flag. | 262 // flag. Force the first experiment with an existing flag. |
219 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 263 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
220 for (int i = 0; i < study.experiment_size(); ++i) { | 264 for (int i = 0; i < study.experiment_size(); ++i) { |
221 const Study_Experiment& experiment = study.experiment(i); | 265 const Study_Experiment& experiment = study.experiment(i); |
222 if (experiment.has_forcing_flag() && | 266 if (experiment.has_forcing_flag() && |
223 command_line->HasSwitch(experiment.forcing_flag())) { | 267 command_line->HasSwitch(experiment.forcing_flag())) { |
224 base::FieldTrialList::CreateFieldTrial(study.name(), experiment.name()); | 268 base::FieldTrialList::CreateFieldTrial(study.name(), experiment.name()); |
225 RegisterExperimentParams(study, experiment); | 269 RegisterExperimentParams(study, experiment); |
226 DVLOG(1) << "Trial " << study.name() << " forced by flag: " | 270 DVLOG(1) << "Trial " << study.name() << " forced by flag: " |
227 << experiment.forcing_flag(); | 271 << experiment.forcing_flag(); |
| 272 if (AllowVariationIdWithForcingFlag(study)) |
| 273 RegisterVariationIds(experiment, study.name()); |
228 return; | 274 return; |
229 } | 275 } |
230 } | 276 } |
231 | 277 |
232 uint32 randomization_seed = 0; | 278 uint32 randomization_seed = 0; |
233 base::FieldTrial::RandomizationType randomization_type = | 279 base::FieldTrial::RandomizationType randomization_type = |
234 base::FieldTrial::SESSION_RANDOMIZED; | 280 base::FieldTrial::SESSION_RANDOMIZED; |
235 if (study.has_consistency() && | 281 if (study.has_consistency() && |
236 study.consistency() == Study_Consistency_PERMANENT) { | 282 study.consistency() == Study_Consistency_PERMANENT) { |
237 randomization_type = base::FieldTrial::ONE_TIME_RANDOMIZED; | 283 randomization_type = base::FieldTrial::ONE_TIME_RANDOMIZED; |
238 if (study.has_randomization_seed()) | 284 if (study.has_randomization_seed()) |
239 randomization_seed = study.randomization_seed(); | 285 randomization_seed = study.randomization_seed(); |
240 } | 286 } |
241 | 287 |
242 // The trial is created without specifying an expiration date because the | 288 // The trial is created without specifying an expiration date because the |
243 // expiration check in field_trial.cc is based on the build date. Instead, | 289 // expiration check in field_trial.cc is based on the build date. Instead, |
244 // the expiration check using |reference_date| is done explicitly below. | 290 // the expiration check using |reference_date| is done explicitly below. |
245 scoped_refptr<base::FieldTrial> trial( | 291 scoped_refptr<base::FieldTrial> trial( |
246 base::FieldTrialList::FactoryGetFieldTrialWithRandomizationSeed( | 292 base::FieldTrialList::FactoryGetFieldTrialWithRandomizationSeed( |
247 study.name(), processed_study.total_probability, | 293 study.name(), processed_study.total_probability, |
248 study.default_experiment_name(), | 294 study.default_experiment_name(), |
249 base::FieldTrialList::kNoExpirationYear, 1, 1, randomization_type, | 295 base::FieldTrialList::kNoExpirationYear, 1, 1, randomization_type, |
250 randomization_seed, NULL)); | 296 randomization_seed, NULL)); |
251 | 297 |
252 for (int i = 0; i < study.experiment_size(); ++i) { | 298 for (int i = 0; i < study.experiment_size(); ++i) { |
253 const Study_Experiment& experiment = study.experiment(i); | 299 const Study_Experiment& experiment = study.experiment(i); |
254 RegisterExperimentParams(study, experiment); | 300 RegisterExperimentParams(study, experiment); |
255 | 301 |
256 // Groups with flags can't be selected randomly, so we don't add them to | 302 // Groups with forcing flags have probability 0 and will never be selected. |
257 // the field trial. | 303 // Therefore, there's no need to add them to the field trial. |
258 if (experiment.has_forcing_flag()) | 304 if (experiment.has_forcing_flag()) |
259 continue; | 305 continue; |
260 | 306 |
261 if (experiment.name() != study.default_experiment_name()) | 307 if (experiment.name() != study.default_experiment_name()) |
262 trial->AppendGroup(experiment.name(), experiment.probability_weight()); | 308 trial->AppendGroup(experiment.name(), experiment.probability_weight()); |
263 | 309 |
264 if (experiment.has_google_web_experiment_id()) { | 310 RegisterVariationIds(experiment, study.name()); |
265 const VariationID variation_id = | |
266 static_cast<VariationID>(experiment.google_web_experiment_id()); | |
267 AssociateGoogleVariationIDForce(GOOGLE_WEB_PROPERTIES, | |
268 study.name(), | |
269 experiment.name(), | |
270 variation_id); | |
271 } | |
272 if (experiment.has_google_update_experiment_id()) { | |
273 const VariationID variation_id = | |
274 static_cast<VariationID>(experiment.google_update_experiment_id()); | |
275 AssociateGoogleVariationIDForce(GOOGLE_UPDATE_SERVICE, | |
276 study.name(), | |
277 experiment.name(), | |
278 variation_id); | |
279 } | |
280 } | 311 } |
281 | 312 |
282 trial->SetForced(); | 313 trial->SetForced(); |
283 if (processed_study.is_expired) | 314 if (processed_study.is_expired) |
284 trial->Disable(); | 315 trial->Disable(); |
285 else if (study.activation_type() == Study_ActivationType_ACTIVATION_AUTO) | 316 else if (study.activation_type() == Study_ActivationType_ACTIVATION_AUTO) |
286 trial->group(); | 317 trial->group(); |
287 } | 318 } |
288 | 319 |
289 bool VariationsSeedProcessor::IsStudyExpired(const Study& study, | 320 bool VariationsSeedProcessor::IsStudyExpired(const Study& study, |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 // The default group was not found in the list of groups. This study is not | 422 // The default group was not found in the list of groups. This study is not |
392 // valid. | 423 // valid. |
393 return false; | 424 return false; |
394 } | 425 } |
395 | 426 |
396 *total_probability = divisor; | 427 *total_probability = divisor; |
397 return true; | 428 return true; |
398 } | 429 } |
399 | 430 |
400 } // namespace chrome_variations | 431 } // namespace chrome_variations |
OLD | NEW |