Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/metrics/variations_service.h" | 5 #include "chrome/browser/metrics/variations_service.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/build_time.h" | 10 #include "base/build_time.h" |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 275 bool VariationsService::CheckStudyVersion( | 275 bool VariationsService::CheckStudyVersion( |
| 276 const chrome_variations::Study_Filter& filter, | 276 const chrome_variations::Study_Filter& filter, |
| 277 const std::string& version_string) { | 277 const std::string& version_string) { |
| 278 const Version version(version_string); | 278 const Version version(version_string); |
| 279 if (!version.IsValid()) { | 279 if (!version.IsValid()) { |
| 280 NOTREACHED(); | 280 NOTREACHED(); |
| 281 return false; | 281 return false; |
| 282 } | 282 } |
| 283 | 283 |
| 284 if (filter.has_min_version()) { | 284 if (filter.has_min_version()) { |
| 285 const Version min_version(filter.min_version()); | 285 if (version.CompareToWildcardString(filter.min_version()) < 0) |
| 286 if (!min_version.IsValid()) | |
| 287 return false; | |
| 288 if (version.CompareTo(min_version) < 0) | |
| 289 return false; | 286 return false; |
| 290 } | 287 } |
| 291 | 288 |
| 292 if (filter.has_max_version()) { | 289 if (filter.has_max_version()) { |
| 293 const Version max_version(filter.max_version()); | 290 if (version.CompareToWildcardString(filter.max_version()) > 0) |
| 294 if (!max_version.IsValid()) | |
| 295 return false; | |
| 296 if (version.CompareTo(max_version) > 0) | |
| 297 return false; | 291 return false; |
| 298 } | 292 } |
| 299 | 293 |
| 300 return true; | 294 return true; |
| 301 } | 295 } |
| 302 | 296 |
| 303 // static | 297 // static |
| 304 bool VariationsService::CheckStudyStartDate( | 298 bool VariationsService::CheckStudyStartDate( |
| 305 const chrome_variations::Study_Filter& filter, | 299 const chrome_variations::Study_Filter& filter, |
| 306 const base::Time& date_time) { | 300 const base::Time& date_time) { |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 326 | 320 |
| 327 // static | 321 // static |
| 328 bool VariationsService::ValidateStudyAndComputeTotalProbability( | 322 bool VariationsService::ValidateStudyAndComputeTotalProbability( |
| 329 const chrome_variations::Study& study, | 323 const chrome_variations::Study& study, |
| 330 base::FieldTrial::Probability* total_probability) { | 324 base::FieldTrial::Probability* total_probability) { |
| 331 // At the moment, a missing default_experiment_name makes the study invalid. | 325 // At the moment, a missing default_experiment_name makes the study invalid. |
| 332 if (study.default_experiment_name().empty()) { | 326 if (study.default_experiment_name().empty()) { |
| 333 DVLOG(1) << study.name() << " has no default experiment defined."; | 327 DVLOG(1) << study.name() << " has no default experiment defined."; |
| 334 return false; | 328 return false; |
| 335 } | 329 } |
| 330 if (study.filter().has_min_version() && | |
| 331 !Version::IsValidWildcardString(study.filter().min_version())) { | |
| 332 DVLOG(1) << study.filter().min_version() << " invalid min version."; | |
|
Alexei Svitkine (slow)
2012/06/26 18:22:03
Please log the study.name() like the other cases.
Mathieu
2012/06/27 15:40:06
Done.
| |
| 333 return false; | |
| 334 } | |
| 335 if (study.filter().has_max_version() && | |
| 336 !Version::IsValidWildcardString(study.filter().max_version())) { | |
| 337 DVLOG(1) << study.filter().max_version() << " invalid max version."; | |
|
Alexei Svitkine (slow)
2012/06/26 18:22:03
Please log the study.name() like the other cases.
Mathieu
2012/06/27 15:40:06
Done.
| |
| 338 return false; | |
| 339 } | |
| 336 | 340 |
| 337 const std::string& default_group_name = study.default_experiment_name(); | 341 const std::string& default_group_name = study.default_experiment_name(); |
| 338 base::FieldTrial::Probability divisor = 0; | 342 base::FieldTrial::Probability divisor = 0; |
| 339 | 343 |
| 340 bool found_default_group = false; | 344 bool found_default_group = false; |
| 341 std::set<std::string> experiment_names; | 345 std::set<std::string> experiment_names; |
| 342 for (int i = 0; i < study.experiment_size(); ++i) { | 346 for (int i = 0; i < study.experiment_size(); ++i) { |
| 343 if (study.experiment(i).name().empty()) { | 347 if (study.experiment(i).name().empty()) { |
| 344 DVLOG(1) << study.name() << " is missing experiment " << i << " name"; | 348 DVLOG(1) << study.name() << " is missing experiment " << i << " name"; |
| 345 return false; | 349 return false; |
| 346 } | 350 } |
| 351 | |
|
Alexei Svitkine (slow)
2012/06/26 18:22:03
Nit: Remove unnecessary newline change here.
Mathieu
2012/06/27 15:40:06
Done.
| |
| 347 if (!experiment_names.insert(study.experiment(i).name()).second) { | 352 if (!experiment_names.insert(study.experiment(i).name()).second) { |
| 348 DVLOG(1) << study.name() << " has a repeated experiment name " | 353 DVLOG(1) << study.name() << " has a repeated experiment name " |
| 349 << study.experiment(i).name(); | 354 << study.experiment(i).name(); |
| 350 return false; | 355 return false; |
| 351 } | 356 } |
| 352 divisor += study.experiment(i).probability_weight(); | 357 divisor += study.experiment(i).probability_weight(); |
| 353 if (study.experiment(i).name() == default_group_name) | 358 if (study.experiment(i).name() == default_group_name) |
| 354 found_default_group = true; | 359 found_default_group = true; |
| 355 } | 360 } |
| 356 | 361 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 415 experiments_helper::AssociateGoogleVariationIDForce(study.name(), | 420 experiments_helper::AssociateGoogleVariationIDForce(study.name(), |
| 416 experiment.name(), | 421 experiment.name(), |
| 417 variation_id); | 422 variation_id); |
| 418 } | 423 } |
| 419 } | 424 } |
| 420 | 425 |
| 421 trial->SetForced(); | 426 trial->SetForced(); |
| 422 if (IsStudyExpired(study, reference_date)) | 427 if (IsStudyExpired(study, reference_date)) |
| 423 trial->Disable(); | 428 trial->Disable(); |
| 424 } | 429 } |
| OLD | NEW |