| 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 if (ShouldAddStudy(seed.study(i), current_version_info, reference_date)) | 99 if (ShouldAddStudy(seed.study(i), current_version_info, reference_date)) |
| 100 CreateTrialFromStudy(seed.study(i), reference_date); | 100 CreateTrialFromStudy(seed.study(i), reference_date); |
| 101 } | 101 } |
| 102 | 102 |
| 103 return true; | 103 return true; |
| 104 } | 104 } |
| 105 | 105 |
| 106 void VariationsService::StartFetchingVariationsSeed() { | 106 void VariationsService::StartFetchingVariationsSeed() { |
| 107 if (net::NetworkChangeNotifier::IsOffline()) | 107 if (net::NetworkChangeNotifier::IsOffline()) |
| 108 return; | 108 return; |
| 109 | |
| 110 pending_seed_request_.reset(net::URLFetcher::Create( | 109 pending_seed_request_.reset(net::URLFetcher::Create( |
| 111 GURL(kDefaultVariationsServer), net::URLFetcher::GET, this)); | 110 GURL(kDefaultVariationsServer), net::URLFetcher::GET, this)); |
| 112 pending_seed_request_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 111 pending_seed_request_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
| 113 net::LOAD_DO_NOT_SAVE_COOKIES); | 112 net::LOAD_DO_NOT_SAVE_COOKIES); |
| 114 pending_seed_request_->SetRequestContext( | 113 pending_seed_request_->SetRequestContext( |
| 115 g_browser_process->system_request_context()); | 114 g_browser_process->system_request_context()); |
| 116 pending_seed_request_->SetMaxRetries(kMaxRetrySeedFetch); | 115 pending_seed_request_->SetMaxRetries(kMaxRetrySeedFetch); |
| 117 pending_seed_request_->Start(); | 116 pending_seed_request_->Start(); |
| 118 } | 117 } |
| 119 | 118 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 bool VariationsService::CheckStudyVersion( | 232 bool VariationsService::CheckStudyVersion( |
| 234 const chrome_variations::Study_Filter& filter, | 233 const chrome_variations::Study_Filter& filter, |
| 235 const std::string& version_string) { | 234 const std::string& version_string) { |
| 236 const Version version(version_string); | 235 const Version version(version_string); |
| 237 if (!version.IsValid()) { | 236 if (!version.IsValid()) { |
| 238 NOTREACHED(); | 237 NOTREACHED(); |
| 239 return false; | 238 return false; |
| 240 } | 239 } |
| 241 | 240 |
| 242 if (filter.has_min_version()) { | 241 if (filter.has_min_version()) { |
| 243 const Version min_version(filter.min_version()); | 242 if (version.CompareToWildcardString(filter.min_version()) < 0) |
| 244 if (!min_version.IsValid()) | |
| 245 return false; | |
| 246 if (version.CompareTo(min_version) < 0) | |
| 247 return false; | 243 return false; |
| 248 } | 244 } |
| 249 | 245 |
| 250 if (filter.has_max_version()) { | 246 if (filter.has_max_version()) { |
| 251 const Version max_version(filter.max_version()); | 247 if (version.CompareToWildcardString(filter.max_version()) > 0) |
| 252 if (!max_version.IsValid()) | |
| 253 return false; | |
| 254 if (version.CompareTo(max_version) > 0) | |
| 255 return false; | 248 return false; |
| 256 } | 249 } |
| 257 | 250 |
| 258 return true; | 251 return true; |
| 259 } | 252 } |
| 260 | 253 |
| 261 // static | 254 // static |
| 262 bool VariationsService::CheckStudyStartDate( | 255 bool VariationsService::CheckStudyStartDate( |
| 263 const chrome_variations::Study_Filter& filter, | 256 const chrome_variations::Study_Filter& filter, |
| 264 const base::Time& date_time) { | 257 const base::Time& date_time) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 284 | 277 |
| 285 // static | 278 // static |
| 286 bool VariationsService::ValidateStudyAndComputeTotalProbability( | 279 bool VariationsService::ValidateStudyAndComputeTotalProbability( |
| 287 const chrome_variations::Study& study, | 280 const chrome_variations::Study& study, |
| 288 base::FieldTrial::Probability* total_probability) { | 281 base::FieldTrial::Probability* total_probability) { |
| 289 // At the moment, a missing default_experiment_name makes the study invalid. | 282 // At the moment, a missing default_experiment_name makes the study invalid. |
| 290 if (study.default_experiment_name().empty()) { | 283 if (study.default_experiment_name().empty()) { |
| 291 DVLOG(1) << study.name() << " has no default experiment defined."; | 284 DVLOG(1) << study.name() << " has no default experiment defined."; |
| 292 return false; | 285 return false; |
| 293 } | 286 } |
| 287 if (study.filter().has_min_version() && |
| 288 !Version::IsValidWildcardString(study.filter().min_version())) { |
| 289 DVLOG(1) << study.filter().min_version() << " invalid min version."; |
| 290 return false; |
| 291 } |
| 292 if (study.filter().has_max_version() && |
| 293 !Version::IsValidWildcardString(study.filter().max_version())) { |
| 294 DVLOG(1) << study.filter().max_version() << " invalid max version."; |
| 295 return false; |
| 296 } |
| 294 | 297 |
| 295 const std::string& default_group_name = study.default_experiment_name(); | 298 const std::string& default_group_name = study.default_experiment_name(); |
| 296 base::FieldTrial::Probability divisor = 0; | 299 base::FieldTrial::Probability divisor = 0; |
| 297 | 300 |
| 298 bool found_default_group = false; | 301 bool found_default_group = false; |
| 299 std::set<std::string> experiment_names; | 302 std::set<std::string> experiment_names; |
| 300 for (int i = 0; i < study.experiment_size(); ++i) { | 303 for (int i = 0; i < study.experiment_size(); ++i) { |
| 301 if (study.experiment(i).name().empty()) { | 304 if (study.experiment(i).name().empty()) { |
| 302 DVLOG(1) << study.name() << " is missing experiment " << i << " name"; | 305 DVLOG(1) << study.name() << " is missing experiment " << i << " name"; |
| 303 return false; | 306 return false; |
| 304 } | 307 } |
| 308 |
| 305 if (!experiment_names.insert(study.experiment(i).name()).second) { | 309 if (!experiment_names.insert(study.experiment(i).name()).second) { |
| 306 DVLOG(1) << study.name() << " has a repeated experiment name " | 310 DVLOG(1) << study.name() << " has a repeated experiment name " |
| 307 << study.experiment(i).name(); | 311 << study.experiment(i).name(); |
| 308 return false; | 312 return false; |
| 309 } | 313 } |
| 310 divisor += study.experiment(i).probability_weight(); | 314 divisor += study.experiment(i).probability_weight(); |
| 311 if (study.experiment(i).name() == default_group_name) | 315 if (study.experiment(i).name() == default_group_name) |
| 312 found_default_group = true; | 316 found_default_group = true; |
| 313 } | 317 } |
| 314 | 318 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 experiments_helper::AssociateGoogleVariationIDForce(study.name(), | 377 experiments_helper::AssociateGoogleVariationIDForce(study.name(), |
| 374 experiment.name(), | 378 experiment.name(), |
| 375 variation_id); | 379 variation_id); |
| 376 } | 380 } |
| 377 } | 381 } |
| 378 | 382 |
| 379 trial->SetForced(); | 383 trial->SetForced(); |
| 380 if (IsStudyExpired(study, reference_date)) | 384 if (IsStudyExpired(study, reference_date)) |
| 381 trial->Disable(); | 385 trial->Disable(); |
| 382 } | 386 } |
| OLD | NEW |