Chromium Code Reviews| Index: base/metrics/field_trial.cc |
| =================================================================== |
| --- base/metrics/field_trial.cc (revision 151948) |
| +++ base/metrics/field_trial.cc (working copy) |
| @@ -53,10 +53,12 @@ |
| //------------------------------------------------------------------------------ |
| // FieldTrial methods and members. |
| -FieldTrial::FieldTrial(const std::string& name, |
| +FieldTrial::FieldTrial(EntropyProvider* entropy_provider, |
| + const std::string& name, |
| const Probability total_probability, |
| const std::string& default_group_name) |
| - : name_(name), |
| + : entropy_provider_(entropy_provider), |
| + name_(name), |
| divisor_(total_probability), |
| default_group_name_(default_group_name), |
| random_(static_cast<Probability>(divisor_ * RandDouble())), |
| @@ -83,7 +85,7 @@ |
| } |
| random_ = static_cast<Probability>( |
| - divisor_ * HashClientId(FieldTrialList::client_id(), name_)); |
| + divisor_ * entropy_provider_->GetEntropyForTrial(name_)); |
|
SteveT
2012/08/16 20:55:42
Could |entropy_provider_| be NULL?
Alexei Svitkine (slow)
2012/08/16 21:27:11
If it is, then FieldTrialList::IsOneTimeRandomizat
|
| } |
| void FieldTrial::Disable() { |
| @@ -198,27 +200,6 @@ |
| DVLOG(1) << "Field trial: " << name_ << " Group choice:" << group_name_; |
| } |
| -// static |
| -double FieldTrial::HashClientId(const std::string& client_id, |
| - const std::string& trial_name) { |
| - // SHA-1 is designed to produce a uniformly random spread in its output space, |
| - // even for nearly-identical inputs, so it helps massage whatever client_id |
| - // and trial_name we get into something with a uniform distribution, which |
| - // is desirable so that we don't skew any part of the 0-100% spectrum. |
| - std::string input(client_id + trial_name); |
| - unsigned char sha1_hash[kSHA1Length]; |
| - SHA1HashBytes(reinterpret_cast<const unsigned char*>(input.c_str()), |
| - input.size(), |
| - sha1_hash); |
| - |
| - COMPILE_ASSERT(sizeof(uint64) < sizeof(sha1_hash), need_more_data); |
| - uint64 bits; |
| - memcpy(&bits, sha1_hash, sizeof(bits)); |
| - bits = base::ByteSwapToLE64(bits); |
| - |
| - return BitsToOpenEndedUnitInterval(bits); |
| -} |
| - |
| //------------------------------------------------------------------------------ |
| // FieldTrialList methods and members. |
| @@ -228,9 +209,9 @@ |
| // static |
| bool FieldTrialList::used_without_global_ = false; |
| -FieldTrialList::FieldTrialList(const std::string& client_id) |
| +FieldTrialList::FieldTrialList(FieldTrial::EntropyProvider* entropy_provider) |
| : application_start_time_(TimeTicks::Now()), |
| - client_id_(client_id), |
| + entropy_provider_(entropy_provider), |
| observer_list_(new ObserverListThreadSafe<FieldTrialList::Observer>( |
| ObserverListBase<FieldTrialList::Observer>::NOTIFY_EXISTING_ONLY)) { |
| DCHECK(!global_); |
| @@ -279,8 +260,9 @@ |
| return existing_trial; |
| } |
| - FieldTrial* field_trial = |
| - new FieldTrial(name, total_probability, default_group_name); |
| + FieldTrial* field_trial = new FieldTrial(global_->entropy_provider_.get(), |
| + name, total_probability, |
| + default_group_name); |
| if (GetBuildTime() > CreateTimeFromParams(year, month, day_of_month)) |
| field_trial->Disable(); |
| FieldTrialList::Register(field_trial); |
| @@ -399,7 +381,8 @@ |
| return field_trial; |
| } |
| const int kTotalProbability = 100; |
| - field_trial = new FieldTrial(name, kTotalProbability, group_name); |
| + field_trial = new FieldTrial(global_->entropy_provider_.get(), |
| + name, kTotalProbability, group_name); |
| // This is where we may assign a group number different from |
| // kDefaultGroupNumber to the default group. |
| field_trial->AppendGroup(group_name, kTotalProbability); |
| @@ -452,18 +435,9 @@ |
| return false; |
| } |
| - return !global_->client_id_.empty(); |
| + return global_->entropy_provider_.get() != NULL; |
| } |
| -// static |
| -const std::string& FieldTrialList::client_id() { |
| - DCHECK(global_); |
| - if (!global_) |
| - return EmptyString(); |
| - |
| - return global_->client_id_; |
| -} |
| - |
| FieldTrial* FieldTrialList::PreLockedFind(const std::string& name) { |
| RegistrationList::iterator it = registered_.find(name); |
| if (registered_.end() == it) |