OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 |
| 6 #include "base/field_trial.h" |
| 7 #include "base/logging.h" |
| 8 #include "base/rand_util.h" |
| 9 |
| 10 //------------------------------------------------------------------------------ |
| 11 // FieldTrialList methods and members. |
| 12 |
| 13 // static |
| 14 FieldTrialList* FieldTrialList::global_ = NULL; |
| 15 |
| 16 // static |
| 17 int FieldTrialList::constructor_count_ = 0; |
| 18 |
| 19 FieldTrialList::FieldTrialList() |
| 20 : application_start_time_(Time::Now()) { |
| 21 DCHECK(!constructor_count_); |
| 22 ++constructor_count_; |
| 23 global_ = this; |
| 24 } |
| 25 |
| 26 FieldTrialList::~FieldTrialList() { |
| 27 while (!registered_.empty()) { |
| 28 RegistrationList::iterator it = registered_.begin(); |
| 29 it->second->Release(); |
| 30 registered_.erase(it->first); |
| 31 } |
| 32 DCHECK(this == global_); |
| 33 global_ = NULL; |
| 34 } |
| 35 |
| 36 // static |
| 37 void FieldTrialList::Register(FieldTrial* trial) { |
| 38 DCHECK(global_->CalledOnValidThread()); |
| 39 DCHECK(!Find(trial->name())); |
| 40 trial->AddRef(); |
| 41 global_->registered_[trial->name()] = trial; |
| 42 } |
| 43 |
| 44 // static |
| 45 FieldTrial* FieldTrialList::Find(const std::wstring& name) { |
| 46 DCHECK(global_->CalledOnValidThread()); |
| 47 RegistrationList::iterator it = global_->registered_.find(name); |
| 48 if (global_->registered_.end() == it) |
| 49 return NULL; |
| 50 return it->second; |
| 51 } |
| 52 |
| 53 //------------------------------------------------------------------------------ |
| 54 // FieldTrial methods and members. |
| 55 |
| 56 FieldTrial::FieldTrial(const std::wstring& name, double probability) |
| 57 : name_(name) { |
| 58 double rand = base::RandDouble(); |
| 59 DCHECK(rand >= 0.0 && rand < 1.0); |
| 60 boolean_value_ = rand < probability; |
| 61 FieldTrialList::Register(this); |
| 62 } |
OLD | NEW |