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 <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 DCHECK(all_groups->empty()); | |
| 401 if (!global_) | |
| 402 return; | |
| 403 AutoLock auto_lock(global_->lock_); | |
| 404 | |
| 405 FieldTrial::AllGroups all_groups; | |
| 406 for (const auto& registered : global_->registered_) { | |
| 407 FieldTrial::FieldTrialState field_trial_state; | |
| 408 if (registered.second->GetState(&field_trial_state)) | |
| 409 all_groups.push_back(field_trial_state); | |
| 410 } | |
| 411 | |
| 412 for (const FieldTrial::FieldTrialState& trial : all_groups) { | |
|
Alexei Svitkine (slow)
2014/11/07 15:51:02
Nit: My suggestion is actually to combine the two
Georges Khalil
2014/11/07 16:44:23
Done.
| |
| 413 DCHECK_EQ(std::string::npos, | |
| 414 trial.trial_name.find(kPersistentStringSeparator)); | |
| 415 DCHECK_EQ(std::string::npos, | |
| 416 trial.group_name.find(kPersistentStringSeparator)); | |
| 417 if (trial.activated) | |
| 418 output->append(1, kActivationMarker); | |
| 419 output->append(trial.trial_name); | |
| 420 output->append(1, kPersistentStringSeparator); | |
| 421 output->append(trial.group_name); | |
| 422 output->append(1, kPersistentStringSeparator); | |
| 423 } | |
| 424 } | |
| 425 | |
| 426 // static | |
| 390 void FieldTrialList::GetActiveFieldTrialGroups( | 427 void FieldTrialList::GetActiveFieldTrialGroups( |
| 391 FieldTrial::ActiveGroups* active_groups) { | 428 FieldTrial::ActiveGroups* active_groups) { |
| 392 DCHECK(active_groups->empty()); | 429 DCHECK(active_groups->empty()); |
| 393 if (!global_) | 430 if (!global_) |
| 394 return; | 431 return; |
| 395 AutoLock auto_lock(global_->lock_); | 432 AutoLock auto_lock(global_->lock_); |
| 396 | 433 |
| 397 for (RegistrationMap::iterator it = global_->registered_.begin(); | 434 for (RegistrationMap::iterator it = global_->registered_.begin(); |
| 398 it != global_->registered_.end(); ++it) { | 435 it != global_->registered_.end(); ++it) { |
| 399 FieldTrial::ActiveGroup active_group; | 436 FieldTrial::ActiveGroup active_group; |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 548 return; | 585 return; |
| 549 } | 586 } |
| 550 AutoLock auto_lock(global_->lock_); | 587 AutoLock auto_lock(global_->lock_); |
| 551 DCHECK(!global_->PreLockedFind(trial->trial_name())); | 588 DCHECK(!global_->PreLockedFind(trial->trial_name())); |
| 552 trial->AddRef(); | 589 trial->AddRef(); |
| 553 trial->SetTrialRegistered(); | 590 trial->SetTrialRegistered(); |
| 554 global_->registered_[trial->trial_name()] = trial; | 591 global_->registered_[trial->trial_name()] = trial; |
| 555 } | 592 } |
| 556 | 593 |
| 557 } // namespace base | 594 } // namespace base |
| OLD | NEW |