| 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 // If the group name is empty (hasn't been finalized yet), use the default |
| 231 // group name instead. |
| 232 if (!group_name_.empty()) |
| 233 field_trial_state->group_name = group_name_; |
| 234 else |
| 235 field_trial_state->group_name = default_group_name_; |
| 236 field_trial_state->activated = group_reported_; |
| 237 return true; |
| 238 } |
| 239 |
| 226 //------------------------------------------------------------------------------ | 240 //------------------------------------------------------------------------------ |
| 227 // FieldTrialList methods and members. | 241 // FieldTrialList methods and members. |
| 228 | 242 |
| 229 // static | 243 // static |
| 230 FieldTrialList* FieldTrialList::global_ = NULL; | 244 FieldTrialList* FieldTrialList::global_ = NULL; |
| 231 | 245 |
| 232 // static | 246 // static |
| 233 bool FieldTrialList::used_without_global_ = false; | 247 bool FieldTrialList::used_without_global_ = false; |
| 234 | 248 |
| 235 FieldTrialList::Observer::~Observer() { | 249 FieldTrialList::Observer::~Observer() { |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 DCHECK_EQ(std::string::npos, | 394 DCHECK_EQ(std::string::npos, |
| 381 it->group_name.find(kPersistentStringSeparator)); | 395 it->group_name.find(kPersistentStringSeparator)); |
| 382 output->append(it->trial_name); | 396 output->append(it->trial_name); |
| 383 output->append(1, kPersistentStringSeparator); | 397 output->append(1, kPersistentStringSeparator); |
| 384 output->append(it->group_name); | 398 output->append(it->group_name); |
| 385 output->append(1, kPersistentStringSeparator); | 399 output->append(1, kPersistentStringSeparator); |
| 386 } | 400 } |
| 387 } | 401 } |
| 388 | 402 |
| 389 // static | 403 // static |
| 404 void FieldTrialList::AllStatesToString(std::string* output) { |
| 405 if (!global_) |
| 406 return; |
| 407 AutoLock auto_lock(global_->lock_); |
| 408 |
| 409 for (const auto& registered : global_->registered_) { |
| 410 FieldTrial::FieldTrialState trial; |
| 411 if (!registered.second->GetState(&trial)) |
| 412 continue; |
| 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 |