OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 | 10 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 register_without_global_ = true; | 110 register_without_global_ = true; |
111 return; | 111 return; |
112 } | 112 } |
113 AutoLock auto_lock(global_->lock_); | 113 AutoLock auto_lock(global_->lock_); |
114 DCHECK(!global_->PreLockedFind(trial->name())); | 114 DCHECK(!global_->PreLockedFind(trial->name())); |
115 trial->AddRef(); | 115 trial->AddRef(); |
116 global_->registered_[trial->name()] = trial; | 116 global_->registered_[trial->name()] = trial; |
117 } | 117 } |
118 | 118 |
119 // static | 119 // static |
| 120 FieldTrial* FieldTrialList::Find(const std::string& name) { |
| 121 if (!global_) |
| 122 return NULL; |
| 123 AutoLock auto_lock(global_->lock_); |
| 124 return global_->PreLockedFind(name); |
| 125 } |
| 126 |
| 127 // static |
120 int FieldTrialList::FindValue(const std::string& name) { | 128 int FieldTrialList::FindValue(const std::string& name) { |
121 FieldTrial* field_trial = Find(name); | 129 FieldTrial* field_trial = Find(name); |
122 if (field_trial) | 130 if (field_trial) |
123 return field_trial->group(); | 131 return field_trial->group(); |
124 return FieldTrial::kNotParticipating; | 132 return FieldTrial::kNotParticipating; |
125 } | 133 } |
126 | 134 |
127 // static | 135 // static |
128 std::string FieldTrialList::FindFullName(const std::string& name) { | 136 std::string FieldTrialList::FindFullName(const std::string& name) { |
129 FieldTrial* field_trial = Find(name); | 137 FieldTrial* field_trial = Find(name); |
130 if (field_trial) | 138 if (field_trial) |
131 return field_trial->group_name(); | 139 return field_trial->group_name(); |
132 return ""; | 140 return ""; |
133 } | 141 } |
134 | 142 |
135 // static | 143 // static |
136 FieldTrial* FieldTrialList::Find(const std::string& name) { | |
137 if (!global_) | |
138 return NULL; | |
139 AutoLock auto_lock(global_->lock_); | |
140 return global_->PreLockedFind(name); | |
141 } | |
142 | |
143 FieldTrial* FieldTrialList::PreLockedFind(const std::string& name) { | |
144 RegistrationList::iterator it = registered_.find(name); | |
145 if (registered_.end() == it) | |
146 return NULL; | |
147 return it->second; | |
148 } | |
149 | |
150 // static | |
151 void FieldTrialList::StatesToString(std::string* output) { | 144 void FieldTrialList::StatesToString(std::string* output) { |
152 if (!global_) | 145 if (!global_) |
153 return; | 146 return; |
154 DCHECK(output->empty()); | 147 DCHECK(output->empty()); |
155 AutoLock auto_lock(global_->lock_); | 148 AutoLock auto_lock(global_->lock_); |
156 for (RegistrationList::iterator it = global_->registered_.begin(); | 149 for (RegistrationList::iterator it = global_->registered_.begin(); |
157 it != global_->registered_.end(); ++it) { | 150 it != global_->registered_.end(); ++it) { |
158 const std::string name = it->first; | 151 const std::string name = it->first; |
159 const std::string group_name = it->second->group_name(); | 152 const std::string group_name = it->second->group_name(); |
160 if (group_name.empty()) | 153 if (group_name.empty()) |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 } | 196 } |
204 | 197 |
205 // static | 198 // static |
206 size_t FieldTrialList::GetFieldTrialCount() { | 199 size_t FieldTrialList::GetFieldTrialCount() { |
207 if (!global_) | 200 if (!global_) |
208 return 0; | 201 return 0; |
209 AutoLock auto_lock(global_->lock_); | 202 AutoLock auto_lock(global_->lock_); |
210 return global_->registered_.size(); | 203 return global_->registered_.size(); |
211 } | 204 } |
212 | 205 |
| 206 FieldTrial* FieldTrialList::PreLockedFind(const std::string& name) { |
| 207 RegistrationList::iterator it = registered_.find(name); |
| 208 if (registered_.end() == it) |
| 209 return NULL; |
| 210 return it->second; |
| 211 } |
| 212 |
213 } // namespace base | 213 } // namespace base |
OLD | NEW |