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> |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 typedef std::map<std::string, std::string> FieldTrialParams; | 26 typedef std::map<std::string, std::string> FieldTrialParams; |
| 27 | 27 |
| 28 // Retrieve the singleton. | 28 // Retrieve the singleton. |
| 29 static FieldTrialParamAssociator* GetInstance(); | 29 static FieldTrialParamAssociator* GetInstance(); |
| 30 | 30 |
| 31 // Sets parameters for the given field trial name and group. | 31 // Sets parameters for the given field trial name and group. |
| 32 bool AssociateFieldTrialParams(const std::string& trial_name, | 32 bool AssociateFieldTrialParams(const std::string& trial_name, |
| 33 const std::string& group_name, | 33 const std::string& group_name, |
| 34 const FieldTrialParams& params); | 34 const FieldTrialParams& params); |
| 35 | 35 |
| 36 // Gets the parameters for a field trial and its chosen group. | 36 // Gets the parameters for a field trial. If the parameters are not in the |
| 37 // mapping, then check the field trial entry in shared memory for the | |
| 38 // parameters and cache them here. | |
| 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 // Same as above. | |
| 43 bool GetFieldTrialParams(const std::string& trial_name, | |
|
Alexei Svitkine (slow)
2016/11/01 19:13:27
Overloads are discouraged by the style guide. Chan
lawrencewu
2016/11/01 19:59:58
Expanded the comment and changed the function to G
| |
| 44 const std::string& group_name, | |
| 45 FieldTrialParams* params); | |
| 46 | |
| 40 // Clears the internal field_trial_params_ mapping. | 47 // Clears the internal field_trial_params_ mapping. |
| 41 void ClearAllParamsForTesting(); | 48 void ClearAllParamsForTesting(); |
| 42 | 49 |
| 43 private: | 50 private: |
| 44 friend struct DefaultSingletonTraits<FieldTrialParamAssociator>; | 51 friend struct DefaultSingletonTraits<FieldTrialParamAssociator>; |
| 45 | 52 |
| 46 // (field_trial_name, field_trial_group) | 53 // (field_trial_name, field_trial_group) |
| 47 typedef std::pair<std::string, std::string> FieldTrialKey; | 54 typedef std::pair<std::string, std::string> FieldTrialKey; |
| 48 | 55 |
| 56 // Looks up the field trial entry in shared memory and gets the params from | |
| 57 // there. | |
| 58 bool GetParamsFromSharedMemory(const std::string& trial_name, | |
| 59 const std::string& group_name, | |
| 60 FieldTrialParams* params); | |
| 61 | |
| 62 // Sets the parameters for |trial_name| and |group_name|. Caller must lock. | |
| 63 bool AssociateParamsWhileLocked(const std::string& trial_name, | |
| 64 const std::string& group_name, | |
| 65 const FieldTrialParams& params); | |
| 66 | |
| 49 Lock lock_; | 67 Lock lock_; |
| 50 std::map<FieldTrialKey, FieldTrialParams> field_trial_params_; | 68 std::map<FieldTrialKey, FieldTrialParams> field_trial_params_; |
| 51 | 69 |
| 52 DISALLOW_COPY_AND_ASSIGN(FieldTrialParamAssociator); | 70 DISALLOW_COPY_AND_ASSIGN(FieldTrialParamAssociator); |
| 53 }; | 71 }; |
| 54 | 72 |
| 55 } // namespace base | 73 } // namespace base |
| 56 | 74 |
| 57 #endif // BASE_METRICS_FIELD_TRIAL_PARAM_ASSOCIATOR_H_ | 75 #endif // BASE_METRICS_FIELD_TRIAL_PARAM_ASSOCIATOR_H_ |
| OLD | NEW |