OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/metrics/field_trial_param_associator.h" |
| 6 |
| 7 #include "base/metrics/field_trial.h" |
| 8 |
| 9 namespace base { |
| 10 |
| 11 FieldTrialParamAssociator::FieldTrialParamAssociator() {} |
| 12 FieldTrialParamAssociator::~FieldTrialParamAssociator() {} |
| 13 |
| 14 // static |
| 15 FieldTrialParamAssociator* FieldTrialParamAssociator::GetInstance() { |
| 16 return Singleton<FieldTrialParamAssociator, |
| 17 LeakySingletonTraits<FieldTrialParamAssociator>>::get(); |
| 18 } |
| 19 |
| 20 bool FieldTrialParamAssociator::AssociateFieldTrialParams( |
| 21 const std::string& trial_name, |
| 22 const std::string& group_name, |
| 23 const FieldTrialParams& params) { |
| 24 AutoLock scoped_lock(lock_); |
| 25 |
| 26 if (FieldTrialList::IsTrialActive(trial_name)) |
| 27 return false; |
| 28 |
| 29 const FieldTrialKey key(trial_name, group_name); |
| 30 if (ContainsKey(field_trial_params_, key)) |
| 31 return false; |
| 32 |
| 33 field_trial_params_[key] = params; |
| 34 return true; |
| 35 } |
| 36 |
| 37 bool FieldTrialParamAssociator::GetFieldTrialParams( |
| 38 const std::string& trial_name, |
| 39 FieldTrialParams* params) { |
| 40 AutoLock scoped_lock(lock_); |
| 41 |
| 42 const std::string group_name = FieldTrialList::FindFullName(trial_name); |
| 43 const FieldTrialKey key(trial_name, group_name); |
| 44 if (!ContainsKey(field_trial_params_, key)) |
| 45 return false; |
| 46 |
| 47 *params = field_trial_params_[key]; |
| 48 return true; |
| 49 } |
| 50 |
| 51 void FieldTrialParamAssociator::ClearAllParamsForTesting() { |
| 52 AutoLock scoped_lock(lock_); |
| 53 field_trial_params_.clear(); |
| 54 } |
| 55 |
| 56 } // namespace base |
OLD | NEW |