Chromium Code Reviews| 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 #ifndef BASE_METRICS_FIELD_TRIAL_PARAM_ASSOCIATOR_H_ | 5 #ifndef BASE_METRICS_FIELD_TRIAL_PARAM_ASSOCIATOR_H_ |
| 6 #define BASE_METRICS_FIELD_TRIAL_PARAM_ASSOCIATOR_H_ | 6 #define BASE_METRICS_FIELD_TRIAL_PARAM_ASSOCIATOR_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/base_export.h" | 12 #include "base/base_export.h" |
| 13 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
| 14 #include "base/metrics/field_trial.h" | |
| 14 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
| 15 | 16 |
| 16 namespace base { | 17 namespace base { |
| 17 | 18 |
| 18 // Keeps track of the parameters of all field trials and ensures access to them | 19 // Keeps track of the parameters of all field trials and ensures access to them |
| 19 // is thread-safe. | 20 // is thread-safe. |
| 20 class BASE_EXPORT FieldTrialParamAssociator { | 21 class BASE_EXPORT FieldTrialParamAssociator { |
| 21 public: | 22 public: |
| 22 FieldTrialParamAssociator(); | 23 FieldTrialParamAssociator(); |
| 23 ~FieldTrialParamAssociator(); | 24 ~FieldTrialParamAssociator(); |
| 24 | 25 |
| 25 // Key-value mapping type for field trial parameters. | 26 // Key-value mapping type for field trial parameters. |
| 26 typedef std::map<std::string, std::string> FieldTrialParams; | 27 typedef std::map<std::string, std::string> FieldTrialParams; |
| 27 | 28 |
| 28 // Retrieve the singleton. | 29 // Retrieve the singleton. |
| 29 static FieldTrialParamAssociator* GetInstance(); | 30 static FieldTrialParamAssociator* GetInstance(); |
| 30 | 31 |
| 31 // Sets parameters for the given field trial name and group. | 32 // Sets parameters for the given field trial name and group. |
| 32 bool AssociateFieldTrialParams(const std::string& trial_name, | 33 bool AssociateFieldTrialParams(const std::string& trial_name, |
| 33 const std::string& group_name, | 34 const std::string& group_name, |
| 34 const FieldTrialParams& params); | 35 const FieldTrialParams& params); |
| 35 | 36 |
| 36 // Gets the parameters for a field trial and its chosen group. | 37 // Gets the parameters for a field trial and its chosen group. If not found in |
| 38 // field_trial_params_, then tries to looks it up in shared memory. | |
| 37 bool GetFieldTrialParams(const std::string& trial_name, | 39 bool GetFieldTrialParams(const std::string& trial_name, |
| 38 FieldTrialParams* params); | 40 FieldTrialParams* params); |
| 39 | 41 |
| 42 // Gets the parameters for a field trial and its chosen group. Does not | |
| 43 // fallback to looking it up in shared memory. This should only be used if you | |
| 44 // know for sure the params are in the mapping, like if you're in the browser | |
| 45 // process, and even then you should probably just use GetFieldTrialParams(). | |
|
bcwhite
2016/11/23 21:03:52
So... When _should_ this method be used?
lawrencewu
2016/11/23 21:49:20
Pretty much never, except for where it's currently
| |
| 46 bool GetFieldTrialParamsWithoutFallback(const std::string& trial_name, | |
| 47 const std::string& group_name, | |
| 48 FieldTrialParams* params); | |
| 49 | |
| 50 // Clears the internal field_trial_params_ mapping, plus removes all params in | |
| 51 // shared memory. | |
| 52 void ClearAllParamsForTesting(); | |
| 53 | |
| 40 // Clears the internal field_trial_params_ mapping. | 54 // Clears the internal field_trial_params_ mapping. |
| 41 void ClearAllParamsForTesting(); | 55 void ClearAllCachedParamsForTesting(); |
| 42 | 56 |
| 43 private: | 57 private: |
| 44 friend struct DefaultSingletonTraits<FieldTrialParamAssociator>; | 58 friend struct DefaultSingletonTraits<FieldTrialParamAssociator>; |
| 45 | 59 |
| 46 // (field_trial_name, field_trial_group) | 60 // (field_trial_name, field_trial_group) |
| 47 typedef std::pair<std::string, std::string> FieldTrialKey; | 61 typedef std::pair<std::string, std::string> FieldTrialKey; |
| 48 | 62 |
| 49 Lock lock_; | 63 Lock lock_; |
| 50 std::map<FieldTrialKey, FieldTrialParams> field_trial_params_; | 64 std::map<FieldTrialKey, FieldTrialParams> field_trial_params_; |
| 51 | 65 |
| 52 DISALLOW_COPY_AND_ASSIGN(FieldTrialParamAssociator); | 66 DISALLOW_COPY_AND_ASSIGN(FieldTrialParamAssociator); |
| 53 }; | 67 }; |
| 54 | 68 |
| 55 } // namespace base | 69 } // namespace base |
| 56 | 70 |
| 57 #endif // BASE_METRICS_FIELD_TRIAL_PARAM_ASSOCIATOR_H_ | 71 #endif // BASE_METRICS_FIELD_TRIAL_PARAM_ASSOCIATOR_H_ |
| OLD | NEW |