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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/build_time.h" | 9 #include "base/build_time.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
216 | 216 |
217 bool FieldTrial::GetActiveGroup(ActiveGroup* active_group) const { | 217 bool FieldTrial::GetActiveGroup(ActiveGroup* active_group) const { |
218 if (!group_reported_ || !enable_field_trial_) | 218 if (!group_reported_ || !enable_field_trial_) |
219 return false; | 219 return false; |
220 DCHECK_NE(group_, kNotFinalized); | 220 DCHECK_NE(group_, kNotFinalized); |
221 active_group->trial_name = trial_name_; | 221 active_group->trial_name = trial_name_; |
222 active_group->group_name = group_name_; | 222 active_group->group_name = group_name_; |
223 return true; | 223 return true; |
224 } | 224 } |
225 | 225 |
226 bool FieldTrial::GetState(FieldTrialState* field_trial_state) const { | |
227 if (!enable_field_trial_) | |
228 return false; | |
229 field_trial_state->trial_name = trial_name_; | |
230 field_trial_state->group_name = group_name_; | |
231 field_trial_state->activated = group_reported_; | |
232 return true; | |
233 } | |
234 | |
226 //------------------------------------------------------------------------------ | 235 //------------------------------------------------------------------------------ |
227 // FieldTrialList methods and members. | 236 // FieldTrialList methods and members. |
228 | 237 |
229 // static | 238 // static |
230 FieldTrialList* FieldTrialList::global_ = NULL; | 239 FieldTrialList* FieldTrialList::global_ = NULL; |
231 | 240 |
232 // static | 241 // static |
233 bool FieldTrialList::used_without_global_ = false; | 242 bool FieldTrialList::used_without_global_ = false; |
234 | 243 |
235 FieldTrialList::Observer::~Observer() { | 244 FieldTrialList::Observer::~Observer() { |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
380 DCHECK_EQ(std::string::npos, | 389 DCHECK_EQ(std::string::npos, |
381 it->group_name.find(kPersistentStringSeparator)); | 390 it->group_name.find(kPersistentStringSeparator)); |
382 output->append(it->trial_name); | 391 output->append(it->trial_name); |
383 output->append(1, kPersistentStringSeparator); | 392 output->append(1, kPersistentStringSeparator); |
384 output->append(it->group_name); | 393 output->append(it->group_name); |
385 output->append(1, kPersistentStringSeparator); | 394 output->append(1, kPersistentStringSeparator); |
386 } | 395 } |
387 } | 396 } |
388 | 397 |
389 // static | 398 // static |
399 void FieldTrialList::AllStatesToString(std::string* output) { | |
400 if (!global_) | |
401 return; | |
402 AutoLock auto_lock(global_->lock_); | |
403 | |
404 for (const auto& registered : global_->registered_) { | |
405 FieldTrial::FieldTrialState trial; | |
406 if (registered.second->GetState(&trial)) { | |
Alexei Svitkine (slow)
2014/11/10 18:30:43
Nit: Early return/continue is preferred.
Georges Khalil
2014/11/10 19:22:29
Done.
| |
407 DCHECK_EQ(std::string::npos, | |
408 trial.trial_name.find(kPersistentStringSeparator)); | |
409 DCHECK_EQ(std::string::npos, | |
410 trial.group_name.find(kPersistentStringSeparator)); | |
411 if (trial.activated) | |
412 output->append(1, kActivationMarker); | |
413 output->append(trial.trial_name); | |
414 output->append(1, kPersistentStringSeparator); | |
415 output->append(trial.group_name); | |
416 output->append(1, kPersistentStringSeparator); | |
417 } | |
418 } | |
419 } | |
420 | |
421 // static | |
390 void FieldTrialList::GetActiveFieldTrialGroups( | 422 void FieldTrialList::GetActiveFieldTrialGroups( |
391 FieldTrial::ActiveGroups* active_groups) { | 423 FieldTrial::ActiveGroups* active_groups) { |
392 DCHECK(active_groups->empty()); | 424 DCHECK(active_groups->empty()); |
393 if (!global_) | 425 if (!global_) |
394 return; | 426 return; |
395 AutoLock auto_lock(global_->lock_); | 427 AutoLock auto_lock(global_->lock_); |
396 | 428 |
397 for (RegistrationMap::iterator it = global_->registered_.begin(); | 429 for (RegistrationMap::iterator it = global_->registered_.begin(); |
398 it != global_->registered_.end(); ++it) { | 430 it != global_->registered_.end(); ++it) { |
399 FieldTrial::ActiveGroup active_group; | 431 FieldTrial::ActiveGroup active_group; |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
548 return; | 580 return; |
549 } | 581 } |
550 AutoLock auto_lock(global_->lock_); | 582 AutoLock auto_lock(global_->lock_); |
551 DCHECK(!global_->PreLockedFind(trial->trial_name())); | 583 DCHECK(!global_->PreLockedFind(trial->trial_name())); |
552 trial->AddRef(); | 584 trial->AddRef(); |
553 trial->SetTrialRegistered(); | 585 trial->SetTrialRegistered(); |
554 global_->registered_[trial->trial_name()] = trial; | 586 global_->registered_[trial->trial_name()] = trial; |
555 } | 587 } |
556 | 588 |
557 } // namespace base | 589 } // namespace base |
OLD | NEW |