Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 138 if (group_ == kNotFinalized && accumulated_group_probability_ > random_) { | 138 if (group_ == kNotFinalized && accumulated_group_probability_ > random_) { |
| 139 // This is the group that crossed the random line, so we do the assignment. | 139 // This is the group that crossed the random line, so we do the assignment. |
| 140 SetGroupChoice(name, next_group_number_); | 140 SetGroupChoice(name, next_group_number_); |
| 141 } | 141 } |
| 142 return next_group_number_++; | 142 return next_group_number_++; |
| 143 } | 143 } |
| 144 | 144 |
| 145 int FieldTrial::group() { | 145 int FieldTrial::group() { |
| 146 FinalizeGroupChoice(); | 146 FinalizeGroupChoice(); |
| 147 if (!group_reported_) { | 147 if (!group_reported_) { |
| 148 FieldTrialList::NotifyFieldTrialGroupSelection(name_, group_name_); | 148 if (enable_field_trial_) |
|
Ilya Sherman
2012/11/09 22:45:59
optional nit: Maybe combine this with the if-stmt
Alexei Svitkine (slow)
2012/11/09 23:42:39
I thought of that, but then |group_reported_| woul
| |
| 149 FieldTrialList::NotifyFieldTrialGroupSelection(name_, group_name_); | |
| 149 group_reported_ = true; | 150 group_reported_ = true; |
| 150 } | 151 } |
| 151 return group_; | 152 return group_; |
| 152 } | 153 } |
| 153 | 154 |
| 154 std::string FieldTrial::group_name() { | 155 std::string FieldTrial::group_name() { |
| 155 // Call |group()| to ensure group gets assigned and observers are notified. | 156 // Call |group()| to ensure group gets assigned and observers are notified. |
| 156 group(); | 157 group(); |
| 157 DCHECK(!group_name_.empty()); | 158 DCHECK(!group_name_.empty()); |
| 158 return group_name_; | 159 return group_name_; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 if (group_ != kNotFinalized) | 203 if (group_ != kNotFinalized) |
| 203 return; | 204 return; |
| 204 accumulated_group_probability_ = divisor_; | 205 accumulated_group_probability_ = divisor_; |
| 205 // Here it's OK to use |kDefaultGroupNumber| since we can't be forced and not | 206 // Here it's OK to use |kDefaultGroupNumber| since we can't be forced and not |
| 206 // finalized. | 207 // finalized. |
| 207 DCHECK(!forced_); | 208 DCHECK(!forced_); |
| 208 SetGroupChoice(default_group_name_, kDefaultGroupNumber); | 209 SetGroupChoice(default_group_name_, kDefaultGroupNumber); |
| 209 } | 210 } |
| 210 | 211 |
| 211 bool FieldTrial::GetActiveGroup(ActiveGroup* active_group) const { | 212 bool FieldTrial::GetActiveGroup(ActiveGroup* active_group) const { |
| 212 if (!group_reported_) | 213 if (!group_reported_ || !enable_field_trial_) |
| 213 return false; | 214 return false; |
| 214 DCHECK_NE(group_, kNotFinalized); | 215 DCHECK_NE(group_, kNotFinalized); |
| 215 active_group->trial = name_; | 216 active_group->trial = name_; |
| 216 active_group->group = group_name_; | 217 active_group->group = group_name_; |
| 217 return true; | 218 return true; |
| 218 } | 219 } |
| 219 | 220 |
| 220 //------------------------------------------------------------------------------ | 221 //------------------------------------------------------------------------------ |
| 221 // FieldTrialList methods and members. | 222 // FieldTrialList methods and members. |
| 222 | 223 |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 460 used_without_global_ = true; | 461 used_without_global_ = true; |
| 461 return; | 462 return; |
| 462 } | 463 } |
| 463 AutoLock auto_lock(global_->lock_); | 464 AutoLock auto_lock(global_->lock_); |
| 464 DCHECK(!global_->PreLockedFind(trial->name())); | 465 DCHECK(!global_->PreLockedFind(trial->name())); |
| 465 trial->AddRef(); | 466 trial->AddRef(); |
| 466 global_->registered_[trial->name()] = trial; | 467 global_->registered_[trial->name()] = trial; |
| 467 } | 468 } |
| 468 | 469 |
| 469 } // namespace base | 470 } // namespace base |
| OLD | NEW |