| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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_param_associator.h" | 5 #include "base/metrics/field_trial_param_associator.h" |
| 6 | 6 |
| 7 #include "base/metrics/field_trial.h" | 7 #include "base/metrics/field_trial.h" |
| 8 | 8 |
| 9 namespace base { | 9 namespace base { |
| 10 | 10 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 if (ContainsKey(field_trial_params_, key)) | 30 if (ContainsKey(field_trial_params_, key)) |
| 31 return false; | 31 return false; |
| 32 | 32 |
| 33 field_trial_params_[key] = params; | 33 field_trial_params_[key] = params; |
| 34 return true; | 34 return true; |
| 35 } | 35 } |
| 36 | 36 |
| 37 bool FieldTrialParamAssociator::GetFieldTrialParams( | 37 bool FieldTrialParamAssociator::GetFieldTrialParams( |
| 38 const std::string& trial_name, | 38 const std::string& trial_name, |
| 39 FieldTrialParams* params) { | 39 FieldTrialParams* params) { |
| 40 FieldTrial* field_trial = FieldTrialList::Find(trial_name); |
| 41 if (!field_trial) |
| 42 return false; |
| 43 |
| 44 // First try the local map, falling back to getting it from shared memory. |
| 45 if (GetFieldTrialParamsWithoutFallback(trial_name, field_trial->group_name(), |
| 46 params)) { |
| 47 return true; |
| 48 } |
| 49 |
| 50 // TODO(lawrencewu): add the params to field_trial_params_ for next time. |
| 51 return FieldTrialList::GetParamsFromSharedMemory(field_trial, params); |
| 52 } |
| 53 |
| 54 bool FieldTrialParamAssociator::GetFieldTrialParamsWithoutFallback( |
| 55 const std::string& trial_name, |
| 56 const std::string& group_name, |
| 57 FieldTrialParams* params) { |
| 40 AutoLock scoped_lock(lock_); | 58 AutoLock scoped_lock(lock_); |
| 41 | 59 |
| 42 const std::string group_name = FieldTrialList::FindFullName(trial_name); | |
| 43 const FieldTrialKey key(trial_name, group_name); | 60 const FieldTrialKey key(trial_name, group_name); |
| 44 if (!ContainsKey(field_trial_params_, key)) | 61 if (!ContainsKey(field_trial_params_, key)) |
| 45 return false; | 62 return false; |
| 46 | 63 |
| 47 *params = field_trial_params_[key]; | 64 *params = field_trial_params_[key]; |
| 48 return true; | 65 return true; |
| 49 } | 66 } |
| 50 | 67 |
| 51 void FieldTrialParamAssociator::ClearAllParamsForTesting() { | 68 void FieldTrialParamAssociator::ClearAllParamsForTesting() { |
| 52 AutoLock scoped_lock(lock_); | 69 AutoLock scoped_lock(lock_); |
| 53 field_trial_params_.clear(); | 70 field_trial_params_.clear(); |
| 71 FieldTrialList::ClearParamsFromSharedMemoryForTesting(); |
| 72 } |
| 73 |
| 74 void FieldTrialParamAssociator::ClearAllCachedParamsForTesting() { |
| 75 AutoLock scoped_lock(lock_); |
| 76 field_trial_params_.clear(); |
| 54 } | 77 } |
| 55 | 78 |
| 56 } // namespace base | 79 } // namespace base |
| OLD | NEW |