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

Side by Side Diff: base/metrics/field_trial.cc

Issue 1984003002: Use low entropy for studies that send experiment IDs to Google properties. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « base/metrics/field_trial.h ('k') | base/test/mock_entropy_provider.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/metrics/field_trial.h" 5 #include "base/metrics/field_trial.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/build_time.h" 9 #include "base/build_time.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 FieldTrial* FieldTrialList::FactoryGetFieldTrial( 374 FieldTrial* FieldTrialList::FactoryGetFieldTrial(
375 const std::string& trial_name, 375 const std::string& trial_name,
376 FieldTrial::Probability total_probability, 376 FieldTrial::Probability total_probability,
377 const std::string& default_group_name, 377 const std::string& default_group_name,
378 const int year, 378 const int year,
379 const int month, 379 const int month,
380 const int day_of_month, 380 const int day_of_month,
381 FieldTrial::RandomizationType randomization_type, 381 FieldTrial::RandomizationType randomization_type,
382 int* default_group_number) { 382 int* default_group_number) {
383 return FactoryGetFieldTrialWithRandomizationSeed( 383 return FactoryGetFieldTrialWithRandomizationSeed(
384 trial_name, total_probability, default_group_name, 384 trial_name, total_probability, default_group_name, year, month,
385 year, month, day_of_month, randomization_type, 0, default_group_number); 385 day_of_month, randomization_type, 0, default_group_number, NULL);
386 } 386 }
387 387
388 // static 388 // static
389 FieldTrial* FieldTrialList::FactoryGetFieldTrialWithRandomizationSeed( 389 FieldTrial* FieldTrialList::FactoryGetFieldTrialWithRandomizationSeed(
390 const std::string& trial_name, 390 const std::string& trial_name,
391 FieldTrial::Probability total_probability, 391 FieldTrial::Probability total_probability,
392 const std::string& default_group_name, 392 const std::string& default_group_name,
393 const int year, 393 const int year,
394 const int month, 394 const int month,
395 const int day_of_month, 395 const int day_of_month,
396 FieldTrial::RandomizationType randomization_type, 396 FieldTrial::RandomizationType randomization_type,
397 uint32_t randomization_seed, 397 uint32_t randomization_seed,
398 int* default_group_number) { 398 int* default_group_number,
399 const FieldTrial::EntropyProvider* override_entropy_provider) {
399 if (default_group_number) 400 if (default_group_number)
400 *default_group_number = FieldTrial::kDefaultGroupNumber; 401 *default_group_number = FieldTrial::kDefaultGroupNumber;
401 // Check if the field trial has already been created in some other way. 402 // Check if the field trial has already been created in some other way.
402 FieldTrial* existing_trial = Find(trial_name); 403 FieldTrial* existing_trial = Find(trial_name);
403 if (existing_trial) { 404 if (existing_trial) {
404 CHECK(existing_trial->forced_); 405 CHECK(existing_trial->forced_);
405 // If the default group name differs between the existing forced trial 406 // If the default group name differs between the existing forced trial
406 // and this trial, then use a different value for the default group number. 407 // and this trial, then use a different value for the default group number.
407 if (default_group_number && 408 if (default_group_number &&
408 default_group_name != existing_trial->default_group_name()) { 409 default_group_name != existing_trial->default_group_name()) {
(...skipping 13 matching lines...) Expand all
422 static_assert(kNonConflictingGroupNumber != FieldTrial::kNotFinalized, 423 static_assert(kNonConflictingGroupNumber != FieldTrial::kNotFinalized,
423 "The 'non-conflicting' group number conflicts"); 424 "The 'non-conflicting' group number conflicts");
424 *default_group_number = kNonConflictingGroupNumber; 425 *default_group_number = kNonConflictingGroupNumber;
425 } 426 }
426 } 427 }
427 return existing_trial; 428 return existing_trial;
428 } 429 }
429 430
430 double entropy_value; 431 double entropy_value;
431 if (randomization_type == FieldTrial::ONE_TIME_RANDOMIZED) { 432 if (randomization_type == FieldTrial::ONE_TIME_RANDOMIZED) {
433 // If an override entropy provider is given, use it.
432 const FieldTrial::EntropyProvider* entropy_provider = 434 const FieldTrial::EntropyProvider* entropy_provider =
433 GetEntropyProviderForOneTimeRandomization(); 435 override_entropy_provider ? override_entropy_provider
436 : GetEntropyProviderForOneTimeRandomization();
434 CHECK(entropy_provider); 437 CHECK(entropy_provider);
435 entropy_value = entropy_provider->GetEntropyForTrial(trial_name, 438 entropy_value = entropy_provider->GetEntropyForTrial(trial_name,
436 randomization_seed); 439 randomization_seed);
437 } else { 440 } else {
438 DCHECK_EQ(FieldTrial::SESSION_RANDOMIZED, randomization_type); 441 DCHECK_EQ(FieldTrial::SESSION_RANDOMIZED, randomization_type);
439 DCHECK_EQ(0U, randomization_seed); 442 DCHECK_EQ(0U, randomization_seed);
440 entropy_value = RandDouble(); 443 entropy_value = RandDouble();
441 } 444 }
442 445
443 FieldTrial* field_trial = new FieldTrial(trial_name, total_probability, 446 FieldTrial* field_trial = new FieldTrial(trial_name, total_probability,
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 return; 710 return;
708 } 711 }
709 AutoLock auto_lock(global_->lock_); 712 AutoLock auto_lock(global_->lock_);
710 CHECK(!global_->PreLockedFind(trial->trial_name())) << trial->trial_name(); 713 CHECK(!global_->PreLockedFind(trial->trial_name())) << trial->trial_name();
711 trial->AddRef(); 714 trial->AddRef();
712 trial->SetTrialRegistered(); 715 trial->SetTrialRegistered();
713 global_->registered_[trial->trial_name()] = trial; 716 global_->registered_[trial->trial_name()] = trial;
714 } 717 }
715 718
716 } // namespace base 719 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/field_trial.h ('k') | base/test/mock_entropy_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698