Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: chrome/browser/metrics/variations_service.cc

Issue 10576003: VariationsService now supports wildcard in min/max version (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: refactoring in version.cc Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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.CompareToWildcardString(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.CompareToWildcardString(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
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::IsValidWildcardString(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::IsValidWildcardString(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
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698