summaryrefslogtreecommitdiffstats
path: root/base/field_trial.cc
diff options
context:
space:
mode:
Diffstat (limited to 'base/field_trial.cc')
-rw-r--r--base/field_trial.cc62
1 files changed, 62 insertions, 0 deletions
diff --git a/base/field_trial.cc b/base/field_trial.cc
new file mode 100644
index 0000000..103e539
--- /dev/null
+++ b/base/field_trial.cc
@@ -0,0 +1,62 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+
+#include "base/field_trial.h"
+#include "base/logging.h"
+#include "base/rand_util.h"
+
+//------------------------------------------------------------------------------
+// FieldTrialList methods and members.
+
+// static
+FieldTrialList* FieldTrialList::global_ = NULL;
+
+// static
+int FieldTrialList::constructor_count_ = 0;
+
+FieldTrialList::FieldTrialList()
+ : application_start_time_(Time::Now()) {
+ DCHECK(!constructor_count_);
+ ++constructor_count_;
+ global_ = this;
+}
+
+FieldTrialList::~FieldTrialList() {
+ while (!registered_.empty()) {
+ RegistrationList::iterator it = registered_.begin();
+ it->second->Release();
+ registered_.erase(it->first);
+ }
+ DCHECK(this == global_);
+ global_ = NULL;
+}
+
+// static
+void FieldTrialList::Register(FieldTrial* trial) {
+ DCHECK(global_->CalledOnValidThread());
+ DCHECK(!Find(trial->name()));
+ trial->AddRef();
+ global_->registered_[trial->name()] = trial;
+}
+
+// static
+FieldTrial* FieldTrialList::Find(const std::wstring& name) {
+ DCHECK(global_->CalledOnValidThread());
+ RegistrationList::iterator it = global_->registered_.find(name);
+ if (global_->registered_.end() == it)
+ return NULL;
+ return it->second;
+}
+
+//------------------------------------------------------------------------------
+// FieldTrial methods and members.
+
+FieldTrial::FieldTrial(const std::wstring& name, double probability)
+ : name_(name) {
+ double rand = base::RandDouble();
+ DCHECK(rand >= 0.0 && rand < 1.0);
+ boolean_value_ = rand < probability;
+ FieldTrialList::Register(this);
+}