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

Side by Side Diff: base/metrics/field_trial.cc

Issue 9117037: Added a Unique ID for a Field Trial containing it's hashed name and the selected group ID. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 11 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/build_time.h" 7 #include "base/build_time.h"
8 #include "base/hash_tables.h"
8 #include "base/logging.h" 9 #include "base/logging.h"
9 #include "base/rand_util.h" 10 #include "base/rand_util.h"
10 #include "base/sha1.h" 11 #include "base/sha1.h"
11 #include "base/stringprintf.h" 12 #include "base/stringprintf.h"
12 #include "base/string_util.h" 13 #include "base/string_util.h"
13 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
14 15
15 namespace base { 16 namespace base {
16 17
17 // static 18 // static
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 } 132 }
132 return group_; 133 return group_;
133 } 134 }
134 135
135 std::string FieldTrial::group_name() { 136 std::string FieldTrial::group_name() {
136 group(); // call group() to make sure group assignment was done. 137 group(); // call group() to make sure group assignment was done.
137 DCHECK(!group_name_.empty()); 138 DCHECK(!group_name_.empty());
138 return group_name_; 139 return group_name_;
139 } 140 }
140 141
142 bool FieldTrial::GetUID(UID* uid) {
143 if (group_ == kNotFinalized)
144 return false;
145 *uid = std::make_pair(BASE_HASH_NAMESPACE::hash_value(name_), group_);
jar (doing other things) 2012/01/24 19:19:45 IMO, you should consider generating the hash once
MAD 2012/01/24 20:30:24 Yes, good point, I agree... Done...
146 return true;
147 }
148
141 // static 149 // static
142 std::string FieldTrial::MakeName(const std::string& name_prefix, 150 std::string FieldTrial::MakeName(const std::string& name_prefix,
143 const std::string& trial_name) { 151 const std::string& trial_name) {
144 std::string big_string(name_prefix); 152 std::string big_string(name_prefix);
145 big_string.append(1, kHistogramFieldTrialSeparator); 153 big_string.append(1, kHistogramFieldTrialSeparator);
146 return big_string.append(FieldTrialList::FindFullName(trial_name)); 154 return big_string.append(FieldTrialList::FindFullName(trial_name));
147 } 155 }
148 156
149 // static 157 // static
150 void FieldTrial::EnableBenchmarking() { 158 void FieldTrial::EnableBenchmarking() {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 DCHECK_EQ(name.find(kPersistentStringSeparator), std::string::npos); 273 DCHECK_EQ(name.find(kPersistentStringSeparator), std::string::npos);
266 DCHECK_EQ(group_name.find(kPersistentStringSeparator), std::string::npos); 274 DCHECK_EQ(group_name.find(kPersistentStringSeparator), std::string::npos);
267 output->append(name); 275 output->append(name);
268 output->append(1, kPersistentStringSeparator); 276 output->append(1, kPersistentStringSeparator);
269 output->append(group_name); 277 output->append(group_name);
270 output->append(1, kPersistentStringSeparator); 278 output->append(1, kPersistentStringSeparator);
271 } 279 }
272 } 280 }
273 281
274 // static 282 // static
283 void FieldTrialList::GetFieldTrialUIDs(std::vector<FieldTrial::UID>* uids) {
284 if (!global_)
285 return;
286 DCHECK(uids->empty());
287 AutoLock auto_lock(global_->lock_);
jar (doing other things) 2012/01/24 19:19:45 This is probably ok. I'm always careful to do as
MAD 2012/01/24 20:30:24 Done...
288
289 for (RegistrationList::iterator it = global_->registered_.begin();
290 it != global_->registered_.end(); ++it) {
291 FieldTrial::UID uid;
292 if (it->second->GetUID(&uid))
293 uids->push_back(uid);
294 }
295 }
296
297 // static
275 bool FieldTrialList::CreateTrialsInChildProcess( 298 bool FieldTrialList::CreateTrialsInChildProcess(
276 const std::string& parent_trials) { 299 const std::string& parent_trials) {
277 DCHECK(global_); 300 DCHECK(global_);
278 if (parent_trials.empty() || !global_) 301 if (parent_trials.empty() || !global_)
279 return true; 302 return true;
280 303
281 size_t next_item = 0; 304 size_t next_item = 0;
282 while (next_item < parent_trials.length()) { 305 while (next_item < parent_trials.length()) {
283 size_t name_end = parent_trials.find(kPersistentStringSeparator, next_item); 306 size_t name_end = parent_trials.find(kPersistentStringSeparator, next_item);
284 if (name_end == parent_trials.npos || next_item == name_end) 307 if (name_end == parent_trials.npos || next_item == name_end)
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 } 401 }
379 402
380 FieldTrial* FieldTrialList::PreLockedFind(const std::string& name) { 403 FieldTrial* FieldTrialList::PreLockedFind(const std::string& name) {
381 RegistrationList::iterator it = registered_.find(name); 404 RegistrationList::iterator it = registered_.find(name);
382 if (registered_.end() == it) 405 if (registered_.end() == it)
383 return NULL; 406 return NULL;
384 return it->second; 407 return it->second;
385 } 408 }
386 409
387 } // namespace base 410 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698