OLD | NEW |
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/logging.h" | 8 #include "base/logging.h" |
8 #include "base/rand_util.h" | 9 #include "base/rand_util.h" |
9 #include "base/sha1.h" | 10 #include "base/sha1.h" |
| 11 #include "base/stringprintf.h" |
10 #include "base/string_util.h" | 12 #include "base/string_util.h" |
11 #include "base/stringprintf.h" | |
12 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
13 | 14 |
14 namespace base { | 15 namespace base { |
15 | 16 |
16 // static | 17 // static |
17 const int FieldTrial::kNotFinalized = -1; | 18 const int FieldTrial::kNotFinalized = -1; |
18 | 19 |
19 // static | 20 // static |
20 const int FieldTrial::kDefaultGroupNumber = 0; | 21 const int FieldTrial::kDefaultGroupNumber = 0; |
21 | 22 |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 | 148 |
148 // static | 149 // static |
149 void FieldTrial::EnableBenchmarking() { | 150 void FieldTrial::EnableBenchmarking() { |
150 DCHECK_EQ(0u, FieldTrialList::GetFieldTrialCount()); | 151 DCHECK_EQ(0u, FieldTrialList::GetFieldTrialCount()); |
151 enable_benchmarking_ = true; | 152 enable_benchmarking_ = true; |
152 } | 153 } |
153 | 154 |
154 FieldTrial::~FieldTrial() {} | 155 FieldTrial::~FieldTrial() {} |
155 | 156 |
156 // static | 157 // static |
157 Time FieldTrial::GetBuildTime() { | |
158 Time integral_build_time; | |
159 const char* kDateTime = __DATE__ " " __TIME__; | |
160 bool result = Time::FromString(kDateTime, &integral_build_time); | |
161 DCHECK(result); | |
162 return integral_build_time; | |
163 } | |
164 | |
165 // static | |
166 double FieldTrial::HashClientId(const std::string& client_id, | 158 double FieldTrial::HashClientId(const std::string& client_id, |
167 const std::string& trial_name) { | 159 const std::string& trial_name) { |
168 // SHA-1 is designed to produce a uniformly random spread in its output space, | 160 // SHA-1 is designed to produce a uniformly random spread in its output space, |
169 // even for nearly-identical inputs, so it helps massage whatever client_id | 161 // even for nearly-identical inputs, so it helps massage whatever client_id |
170 // and trial_name we get into something with a uniform distribution, which | 162 // and trial_name we get into something with a uniform distribution, which |
171 // is desirable so that we don't skew any part of the 0-100% spectrum. | 163 // is desirable so that we don't skew any part of the 0-100% spectrum. |
172 std::string input(client_id + trial_name); | 164 std::string input(client_id + trial_name); |
173 unsigned char sha1_hash[kSHA1Length]; | 165 unsigned char sha1_hash[kSHA1Length]; |
174 SHA1HashBytes(reinterpret_cast<const unsigned char*>(input.c_str()), | 166 SHA1HashBytes(reinterpret_cast<const unsigned char*>(input.c_str()), |
175 input.size(), | 167 input.size(), |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 } | 378 } |
387 | 379 |
388 FieldTrial* FieldTrialList::PreLockedFind(const std::string& name) { | 380 FieldTrial* FieldTrialList::PreLockedFind(const std::string& name) { |
389 RegistrationList::iterator it = registered_.find(name); | 381 RegistrationList::iterator it = registered_.find(name); |
390 if (registered_.end() == it) | 382 if (registered_.end() == it) |
391 return NULL; | 383 return NULL; |
392 return it->second; | 384 return it->second; |
393 } | 385 } |
394 | 386 |
395 } // namespace base | 387 } // namespace base |
OLD | NEW |