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

Side by Side Diff: base/field_trial.cc

Issue 7638: Construct a field trial to see if HIGH or MEDIUM memory model "works better"... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 2 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
« no previous file with comments | « base/field_trial.h ('k') | base/field_trial_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(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 }
OLDNEW
« no previous file with comments | « base/field_trial.h ('k') | base/field_trial_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698