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 <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 if there is variation id associated with |experiment|, register the | |
| 60 // variation id. | |
| 61 void RegisterVariationIds(const Study_Experiment& experiment, | |
| 62 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.
| |
| 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 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.
| |
| 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)) { | |
|
Alexei Svitkine (slow)
2013/11/14 22:34:33
No need for {}'s.
yao
2013/11/14 23:41:15
Done.
| |
| 273 RegisterVariationIds(experiment, study.name()); | |
| 274 } | |
| 228 return; | 275 return; |
| 229 } | 276 } |
| 230 } | 277 } |
| 231 | 278 |
| 232 uint32 randomization_seed = 0; | 279 uint32 randomization_seed = 0; |
| 233 base::FieldTrial::RandomizationType randomization_type = | 280 base::FieldTrial::RandomizationType randomization_type = |
| 234 base::FieldTrial::SESSION_RANDOMIZED; | 281 base::FieldTrial::SESSION_RANDOMIZED; |
| 235 if (study.has_consistency() && | 282 if (study.has_consistency() && |
| 236 study.consistency() == Study_Consistency_PERMANENT) { | 283 study.consistency() == Study_Consistency_PERMANENT) { |
| 237 randomization_type = base::FieldTrial::ONE_TIME_RANDOMIZED; | 284 randomization_type = base::FieldTrial::ONE_TIME_RANDOMIZED; |
| 238 if (study.has_randomization_seed()) | 285 if (study.has_randomization_seed()) |
| 239 randomization_seed = study.randomization_seed(); | 286 randomization_seed = study.randomization_seed(); |
| 240 } | 287 } |
| 241 | 288 |
| 242 // The trial is created without specifying an expiration date because the | 289 // 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, | 290 // expiration check in field_trial.cc is based on the build date. Instead, |
| 244 // the expiration check using |reference_date| is done explicitly below. | 291 // the expiration check using |reference_date| is done explicitly below. |
| 245 scoped_refptr<base::FieldTrial> trial( | 292 scoped_refptr<base::FieldTrial> trial( |
| 246 base::FieldTrialList::FactoryGetFieldTrialWithRandomizationSeed( | 293 base::FieldTrialList::FactoryGetFieldTrialWithRandomizationSeed( |
| 247 study.name(), processed_study.total_probability, | 294 study.name(), processed_study.total_probability, |
| 248 study.default_experiment_name(), | 295 study.default_experiment_name(), |
| 249 base::FieldTrialList::kNoExpirationYear, 1, 1, randomization_type, | 296 base::FieldTrialList::kNoExpirationYear, 1, 1, randomization_type, |
| 250 randomization_seed, NULL)); | 297 randomization_seed, NULL)); |
| 251 | 298 |
| 252 for (int i = 0; i < study.experiment_size(); ++i) { | 299 for (int i = 0; i < study.experiment_size(); ++i) { |
| 253 const Study_Experiment& experiment = study.experiment(i); | 300 const Study_Experiment& experiment = study.experiment(i); |
| 254 RegisterExperimentParams(study, experiment); | 301 RegisterExperimentParams(study, experiment); |
| 255 | 302 |
| 256 // Groups with flags can't be selected randomly, so we don't add them to | 303 // Groups with forcing flags have probability 0 and will never be selected. |
| 257 // the field trial. | 304 // Therefore, there's no need to add them to the field trial. |
| 258 if (experiment.has_forcing_flag()) | 305 if (experiment.has_forcing_flag()) |
| 259 continue; | 306 continue; |
| 260 | 307 |
| 261 if (experiment.name() != study.default_experiment_name()) | 308 if (experiment.name() != study.default_experiment_name()) |
| 262 trial->AppendGroup(experiment.name(), experiment.probability_weight()); | 309 trial->AppendGroup(experiment.name(), experiment.probability_weight()); |
| 263 | 310 |
| 264 if (experiment.has_google_web_experiment_id()) { | 311 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 } | 312 } |
| 281 | 313 |
| 282 trial->SetForced(); | 314 trial->SetForced(); |
| 283 if (processed_study.is_expired) | 315 if (processed_study.is_expired) |
| 284 trial->Disable(); | 316 trial->Disable(); |
| 285 else if (study.activation_type() == Study_ActivationType_ACTIVATION_AUTO) | 317 else if (study.activation_type() == Study_ActivationType_ACTIVATION_AUTO) |
| 286 trial->group(); | 318 trial->group(); |
| 287 } | 319 } |
| 288 | 320 |
| 289 bool VariationsSeedProcessor::IsStudyExpired(const Study& study, | 321 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 | 423 // The default group was not found in the list of groups. This study is not |
| 392 // valid. | 424 // valid. |
| 393 return false; | 425 return false; |
| 394 } | 426 } |
| 395 | 427 |
| 396 *total_probability = divisor; | 428 *total_probability = divisor; |
| 397 return true; | 429 return true; |
| 398 } | 430 } |
| 399 | 431 |
| 400 } // namespace chrome_variations | 432 } // namespace chrome_variations |
| OLD | NEW |