OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 | 5 |
6 #include "base/field_trial.h" | 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/string_util.h" |
10 | 10 |
11 using base::Time; | 11 using base::Time; |
(...skipping 17 matching lines...) Expand all Loading... |
29 random_(static_cast<Probability>(divisor_ * base::RandDouble())), | 29 random_(static_cast<Probability>(divisor_ * base::RandDouble())), |
30 accumulated_group_probability_(0), | 30 accumulated_group_probability_(0), |
31 next_group_number_(0), | 31 next_group_number_(0), |
32 group_(kNotParticipating) { | 32 group_(kNotParticipating) { |
33 FieldTrialList::Register(this); | 33 FieldTrialList::Register(this); |
34 } | 34 } |
35 | 35 |
36 int FieldTrial::AppendGroup(const std::string& name, | 36 int FieldTrial::AppendGroup(const std::string& name, |
37 Probability group_probability) { | 37 Probability group_probability) { |
38 DCHECK(group_probability <= divisor_); | 38 DCHECK(group_probability <= divisor_); |
39 accumulated_group_probability_ += group_probability; | 39 DCHECK(group_probability >=0 || |
| 40 group_probability == kAllRemainingProbability); |
| 41 if (group_probability == kAllRemainingProbability) |
| 42 accumulated_group_probability_ = divisor_; |
| 43 else |
| 44 accumulated_group_probability_ += group_probability; |
40 DCHECK(accumulated_group_probability_ <= divisor_); | 45 DCHECK(accumulated_group_probability_ <= divisor_); |
41 if (group_ == kNotParticipating && accumulated_group_probability_ > random_) { | 46 if (group_ == kNotParticipating && accumulated_group_probability_ > random_) { |
42 // This is the group that crossed the random line, so we do teh assignment. | 47 // This is the group that crossed the random line, so we do the assignment. |
43 group_ = next_group_number_; | 48 group_ = next_group_number_; |
44 if (name.empty()) | 49 if (name.empty()) |
45 StringAppendF(&group_name_, "_%d", group_); | 50 StringAppendF(&group_name_, "_%d", group_); |
46 else | 51 else |
47 group_name_ = name; | 52 group_name_ = name; |
48 } | 53 } |
49 return next_group_number_++; | 54 return next_group_number_++; |
50 } | 55 } |
51 | 56 |
52 // static | 57 // static |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 return false; | 173 return false; |
169 continue; | 174 continue; |
170 } | 175 } |
171 const int kTotalProbability = 100; | 176 const int kTotalProbability = 100; |
172 field_trial = new FieldTrial(name, kTotalProbability); | 177 field_trial = new FieldTrial(name, kTotalProbability); |
173 field_trial->AppendGroup(group_name, kTotalProbability); | 178 field_trial->AppendGroup(group_name, kTotalProbability); |
174 } | 179 } |
175 return true; | 180 return true; |
176 } | 181 } |
177 | 182 |
OLD | NEW |