| 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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 bool VariationsService::CheckStudyVersion( | 233 bool VariationsService::CheckStudyVersion( |
| 234 const chrome_variations::Study_Filter& filter, | 234 const chrome_variations::Study_Filter& filter, |
| 235 const std::string& version_string) { | 235 const std::string& version_string) { |
| 236 const Version version(version_string); | 236 const Version version(version_string); |
| 237 if (!version.IsValid()) { | 237 if (!version.IsValid()) { |
| 238 NOTREACHED(); | 238 NOTREACHED(); |
| 239 return false; | 239 return false; |
| 240 } | 240 } |
| 241 | 241 |
| 242 if (filter.has_min_version()) { | 242 if (filter.has_min_version()) { |
| 243 const Version min_version(filter.min_version()); | 243 if (version.CompareToWildcard(filter.min_version()) < 0) |
| 244 if (!min_version.IsValid()) | |
| 245 return false; | |
| 246 if (version.CompareTo(min_version) < 0) | |
| 247 return false; | 244 return false; |
| 248 } | 245 } |
| 249 | 246 |
| 250 if (filter.has_max_version()) { | 247 if (filter.has_max_version()) { |
| 251 const Version max_version(filter.max_version()); | 248 if (version.CompareToWildcard(filter.max_version()) > 0) |
| 252 if (!max_version.IsValid()) | |
| 253 return false; | |
| 254 if (version.CompareTo(max_version) > 0) | |
| 255 return false; | 249 return false; |
| 256 } | 250 } |
| 257 | 251 |
| 258 return true; | 252 return true; |
| 259 } | 253 } |
| 260 | 254 |
| 261 // static | 255 // static |
| 262 bool VariationsService::CheckStudyStartDate( | 256 bool VariationsService::CheckStudyStartDate( |
| 263 const chrome_variations::Study_Filter& filter, | 257 const chrome_variations::Study_Filter& filter, |
| 264 const base::Time& date_time) { | 258 const base::Time& date_time) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 284 | 278 |
| 285 // static | 279 // static |
| 286 bool VariationsService::ValidateStudyAndComputeTotalProbability( | 280 bool VariationsService::ValidateStudyAndComputeTotalProbability( |
| 287 const chrome_variations::Study& study, | 281 const chrome_variations::Study& study, |
| 288 base::FieldTrial::Probability* total_probability) { | 282 base::FieldTrial::Probability* total_probability) { |
| 289 // At the moment, a missing default_experiment_name makes the study invalid. | 283 // At the moment, a missing default_experiment_name makes the study invalid. |
| 290 if (study.default_experiment_name().empty()) { | 284 if (study.default_experiment_name().empty()) { |
| 291 DVLOG(1) << study.name() << " has no default experiment defined."; | 285 DVLOG(1) << study.name() << " has no default experiment defined."; |
| 292 return false; | 286 return false; |
| 293 } | 287 } |
| 288 if (study.filter().has_min_version() && |
| 289 !Version::IsValidWildcard(study.filter().min_version())) { |
| 290 DVLOG(1) << study.filter().min_version() << " invalid min version."; |
| 291 return false; |
| 292 } |
| 293 if (study.filter().has_max_version() && |
| 294 !Version::IsValidWildcard(study.filter().max_version())) { |
| 295 DVLOG(1) << study.filter().max_version() << " invalid max version."; |
| 296 return false; |
| 297 } |
| 294 | 298 |
| 295 const std::string& default_group_name = study.default_experiment_name(); | 299 const std::string& default_group_name = study.default_experiment_name(); |
| 296 base::FieldTrial::Probability divisor = 0; | 300 base::FieldTrial::Probability divisor = 0; |
| 297 | 301 |
| 298 bool found_default_group = false; | 302 bool found_default_group = false; |
| 299 std::set<std::string> experiment_names; | 303 std::set<std::string> experiment_names; |
| 300 for (int i = 0; i < study.experiment_size(); ++i) { | 304 for (int i = 0; i < study.experiment_size(); ++i) { |
| 301 if (study.experiment(i).name().empty()) { | 305 if (study.experiment(i).name().empty()) { |
| 302 DVLOG(1) << study.name() << " is missing experiment " << i << " name"; | 306 DVLOG(1) << study.name() << " is missing experiment " << i << " name"; |
| 303 return false; | 307 return false; |
| 304 } | 308 } |
| 309 |
| 305 if (!experiment_names.insert(study.experiment(i).name()).second) { | 310 if (!experiment_names.insert(study.experiment(i).name()).second) { |
| 306 DVLOG(1) << study.name() << " has a repeated experiment name " | 311 DVLOG(1) << study.name() << " has a repeated experiment name " |
| 307 << study.experiment(i).name(); | 312 << study.experiment(i).name(); |
| 308 return false; | 313 return false; |
| 309 } | 314 } |
| 310 divisor += study.experiment(i).probability_weight(); | 315 divisor += study.experiment(i).probability_weight(); |
| 311 if (study.experiment(i).name() == default_group_name) | 316 if (study.experiment(i).name() == default_group_name) |
| 312 found_default_group = true; | 317 found_default_group = true; |
| 313 } | 318 } |
| 314 | 319 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 experiments_helper::AssociateGoogleVariationIDForce(study.name(), | 378 experiments_helper::AssociateGoogleVariationIDForce(study.name(), |
| 374 experiment.name(), | 379 experiment.name(), |
| 375 variation_id); | 380 variation_id); |
| 376 } | 381 } |
| 377 } | 382 } |
| 378 | 383 |
| 379 trial->SetForced(); | 384 trial->SetForced(); |
| 380 if (IsStudyExpired(study, reference_date)) | 385 if (IsStudyExpired(study, reference_date)) |
| 381 trial->Disable(); | 386 trial->Disable(); |
| 382 } | 387 } |
| OLD | NEW |