OLD | NEW |
1 // Copyright (c) 2006-2009 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/field_trial.h" |
5 | 6 |
6 #include "base/field_trial.h" | |
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/string_util.h" | 9 #include "base/stringprintf.h" |
10 | 10 |
11 using base::TimeTicks; | 11 using base::TimeTicks; |
12 | 12 |
13 // static | 13 // static |
14 const int FieldTrial::kNotParticipating = -1; | 14 const int FieldTrial::kNotParticipating = -1; |
15 | 15 |
16 // static | 16 // static |
17 const int FieldTrial::kAllRemainingProbability = -2; | 17 const int FieldTrial::kAllRemainingProbability = -2; |
18 | 18 |
19 // static | 19 // static |
(...skipping 22 matching lines...) Expand all Loading... |
42 group_probability == kAllRemainingProbability); | 42 group_probability == kAllRemainingProbability); |
43 if (group_probability == kAllRemainingProbability) | 43 if (group_probability == kAllRemainingProbability) |
44 accumulated_group_probability_ = divisor_; | 44 accumulated_group_probability_ = divisor_; |
45 else | 45 else |
46 accumulated_group_probability_ += group_probability; | 46 accumulated_group_probability_ += group_probability; |
47 DCHECK(accumulated_group_probability_ <= divisor_); | 47 DCHECK(accumulated_group_probability_ <= divisor_); |
48 if (group_ == kNotParticipating && accumulated_group_probability_ > random_) { | 48 if (group_ == kNotParticipating && accumulated_group_probability_ > random_) { |
49 // This is the group that crossed the random line, so we do the assignment. | 49 // This is the group that crossed the random line, so we do the assignment. |
50 group_ = next_group_number_; | 50 group_ = next_group_number_; |
51 if (name.empty()) | 51 if (name.empty()) |
52 StringAppendF(&group_name_, "%d", group_); | 52 base::StringAppendF(&group_name_, "%d", group_); |
53 else | 53 else |
54 group_name_ = name; | 54 group_name_ = name; |
55 } | 55 } |
56 return next_group_number_++; | 56 return next_group_number_++; |
57 } | 57 } |
58 | 58 |
59 // static | 59 // static |
60 std::string FieldTrial::MakeName(const std::string& name_prefix, | 60 std::string FieldTrial::MakeName(const std::string& name_prefix, |
61 const std::string& trial_name) { | 61 const std::string& trial_name) { |
62 std::string big_string(name_prefix); | 62 std::string big_string(name_prefix); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 return false; | 180 return false; |
181 continue; | 181 continue; |
182 } | 182 } |
183 const int kTotalProbability = 100; | 183 const int kTotalProbability = 100; |
184 field_trial = new FieldTrial(name, kTotalProbability); | 184 field_trial = new FieldTrial(name, kTotalProbability); |
185 field_trial->AppendGroup(group_name, kTotalProbability); | 185 field_trial->AppendGroup(group_name, kTotalProbability); |
186 } | 186 } |
187 return true; | 187 return true; |
188 } | 188 } |
189 | 189 |
OLD | NEW |