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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
57 } | 57 } |
58 | 58 |
59 } // namespace | 59 } // namespace |
60 | 60 |
61 VariationsSeedProcessor::VariationsSeedProcessor() { | 61 VariationsSeedProcessor::VariationsSeedProcessor() { |
62 } | 62 } |
63 | 63 |
64 VariationsSeedProcessor::~VariationsSeedProcessor() { | 64 VariationsSeedProcessor::~VariationsSeedProcessor() { |
65 } | 65 } |
66 | 66 |
67 bool VariationsSeedProcessor::AllowVariationIdWithForcingFlag( | |
Alexei Svitkine (slow)
2013/11/14 16:54:15
This and the other function can just be free-stand
yao
2013/11/14 20:51:12
Done.
| |
68 const Study& study) { | |
69 if (!study.has_filter()) | |
70 return false; | |
71 Study_Filter filter = study.filter(); | |
72 if (filter.platform_size() == 0 || filter.channel_size() == 0) { | |
Alexei Svitkine (slow)
2013/11/14 16:54:15
This doesn't need {}'s. (single line if and single
yao
2013/11/14 20:51:12
Done.
| |
73 return false; | |
74 } | |
75 for (int i = 0; i < filter.platform_size(); ++i) { | |
76 if (filter.platform(i) != Study_Platform_PLATFORM_ANDROID && | |
77 filter.platform(i) != Study_Platform_PLATFORM_IOS) | |
Alexei Svitkine (slow)
2013/11/14 16:54:15
This does need {}'s - multi-line if. (Same below).
yao
2013/11/14 20:51:12
Done.
| |
78 return false; | |
79 } | |
80 for (int i = 0; i < filter.channel_size(); ++i) { | |
81 if (filter.channel(i) != Study_Channel_CANARY && | |
82 filter.channel(i) != Study_Channel_DEV) | |
83 return false; | |
84 } | |
85 return true; | |
86 } | |
87 | |
67 void VariationsSeedProcessor::CreateTrialsFromSeed( | 88 void VariationsSeedProcessor::CreateTrialsFromSeed( |
68 const VariationsSeed& seed, | 89 const VariationsSeed& seed, |
69 const std::string& locale, | 90 const std::string& locale, |
70 const base::Time& reference_date, | 91 const base::Time& reference_date, |
71 const base::Version& version, | 92 const base::Version& version, |
72 Study_Channel channel, | 93 Study_Channel channel, |
73 Study_FormFactor form_factor) { | 94 Study_FormFactor form_factor) { |
74 std::vector<ProcessedStudy> filtered_studies; | 95 std::vector<ProcessedStudy> filtered_studies; |
75 FilterAndValidateStudies(seed, locale, reference_date, version, channel, | 96 FilterAndValidateStudies(seed, locale, reference_date, version, channel, |
76 form_factor, &filtered_studies); | 97 form_factor, &filtered_studies); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
203 } | 224 } |
204 | 225 |
205 if (filter.has_max_version()) { | 226 if (filter.has_max_version()) { |
206 if (version.CompareToWildcardString(filter.max_version()) > 0) | 227 if (version.CompareToWildcardString(filter.max_version()) > 0) |
207 return false; | 228 return false; |
208 } | 229 } |
209 | 230 |
210 return true; | 231 return true; |
211 } | 232 } |
212 | 233 |
234 void VariationsSeedProcessor::CheckVariationId( | |
Alexei Svitkine (slow)
2013/11/14 16:54:15
This should be called RegisterVariationIds().
yao
2013/11/14 20:51:12
Done.
| |
235 const Study_Experiment& experiment, | |
236 const std::string& trial_name) { | |
237 if (experiment.has_google_web_experiment_id()) { | |
238 const VariationID variation_id = | |
239 static_cast<VariationID>(experiment.google_web_experiment_id()); | |
240 AssociateGoogleVariationIDForce(GOOGLE_WEB_PROPERTIES, | |
241 trial_name, | |
242 experiment.name(), | |
243 variation_id); | |
244 } | |
245 if (experiment.has_google_update_experiment_id()) { | |
246 const VariationID variation_id = | |
247 static_cast<VariationID>(experiment.google_update_experiment_id()); | |
248 AssociateGoogleVariationIDForce(GOOGLE_UPDATE_SERVICE, | |
249 trial_name, | |
250 experiment.name(), | |
251 variation_id); | |
252 } | |
253 } | |
254 | |
213 void VariationsSeedProcessor::CreateTrialFromStudy( | 255 void VariationsSeedProcessor::CreateTrialFromStudy( |
214 const ProcessedStudy& processed_study) { | 256 const ProcessedStudy& processed_study) { |
215 const Study& study = *processed_study.study; | 257 const Study& study = *processed_study.study; |
258 bool allowBoth = AllowVariationIdWithForcingFlag(study); | |
Alexei Svitkine (slow)
2013/11/14 16:54:15
Can we do this check lazily? (e.g. block below whe
yao
2013/11/14 20:51:12
Done.
| |
216 | 259 |
217 // Check if any experiments need to be forced due to a command line | 260 // Check if any experiments need to be forced due to a command line |
218 // flag. Force the first experiment with an existing flag. | 261 // flag. Force the first experiment with an existing flag. |
219 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 262 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
220 for (int i = 0; i < study.experiment_size(); ++i) { | 263 for (int i = 0; i < study.experiment_size(); ++i) { |
221 const Study_Experiment& experiment = study.experiment(i); | 264 const Study_Experiment& experiment = study.experiment(i); |
222 if (experiment.has_forcing_flag() && | 265 if (experiment.has_forcing_flag() && |
223 command_line->HasSwitch(experiment.forcing_flag())) { | 266 command_line->HasSwitch(experiment.forcing_flag())) { |
224 base::FieldTrialList::CreateFieldTrial(study.name(), experiment.name()); | 267 base::FieldTrialList::CreateFieldTrial(study.name(), experiment.name()); |
225 RegisterExperimentParams(study, experiment); | 268 RegisterExperimentParams(study, experiment); |
226 DVLOG(1) << "Trial " << study.name() << " forced by flag: " | 269 DVLOG(1) << "Trial " << study.name() << " forced by flag: " |
227 << experiment.forcing_flag(); | 270 << experiment.forcing_flag(); |
271 if (allowBoth) { | |
272 CheckVariationId(experiment, study.name()); | |
273 } | |
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; |
(...skipping 10 matching lines...) Expand all Loading... | |
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 flags can't be selected randomly, so we don't add them to |
257 // the field trial. | 303 // the field trial. |
258 if (experiment.has_forcing_flag()) | 304 if (experiment.has_forcing_flag() && !allowBoth) |
Alexei Svitkine (slow)
2013/11/14 16:54:15
I think we don't need this logic in this case. It'
yao
2013/11/14 20:51:12
Done.
| |
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 CheckVariationId(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 |