| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 COMPONENTS_VARIATIONS_VARIATIONS_ASSOCIATED_DATA_H_ | 5 #ifndef COMPONENTS_VARIATIONS_VARIATIONS_ASSOCIATED_DATA_H_ |
| 6 #define COMPONENTS_VARIATIONS_VARIATIONS_ASSOCIATED_DATA_H_ | 6 #define COMPONENTS_VARIATIONS_VARIATIONS_ASSOCIATED_DATA_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/metrics/field_trial.h" | |
| 14 #include "components/variations/active_field_trials.h" | 13 #include "components/variations/active_field_trials.h" |
| 15 | 14 |
| 16 // This file provides various helpers that extend the functionality around | 15 // This file provides various helpers that extend the functionality around |
| 17 // base::FieldTrial. | 16 // base::FieldTrial. |
| 18 // | 17 // |
| 19 // This includes several simple APIs to handle getting and setting additional | 18 // This includes several simple APIs to handle getting and setting additional |
| 20 // data related to Chrome variations, such as parameters and Google variation | 19 // data related to Chrome variations, such as parameters and Google variation |
| 21 // IDs. These APIs are meant to extend the base::FieldTrial APIs to offer extra | 20 // IDs. These APIs are meant to extend the base::FieldTrial APIs to offer extra |
| 22 // functionality that is not offered by the simpler base::FieldTrial APIs. | 21 // functionality that is not offered by the simpler base::FieldTrial APIs. |
| 23 // | 22 // |
| (...skipping 14 matching lines...) Expand all Loading... |
| 38 // // use |value|, which will be "" if it does not exist | 37 // // use |value|, which will be "" if it does not exist |
| 39 // | 38 // |
| 40 // VariationID id = GetGoogleVariationID(GOOGLE_WEB_PROPERTIES, "trial", | 39 // VariationID id = GetGoogleVariationID(GOOGLE_WEB_PROPERTIES, "trial", |
| 41 // "group1"); | 40 // "group1"); |
| 42 // if (id != variations::kEmptyID) { | 41 // if (id != variations::kEmptyID) { |
| 43 // // use |id| | 42 // // use |id| |
| 44 // } | 43 // } |
| 45 | 44 |
| 46 namespace base { | 45 namespace base { |
| 47 struct Feature; | 46 struct Feature; |
| 48 } | 47 class FieldTrialList; |
| 48 } // namespace base |
| 49 | 49 |
| 50 namespace variations { | 50 namespace variations { |
| 51 | 51 |
| 52 typedef int VariationID; | 52 typedef int VariationID; |
| 53 class VariationsHttpHeaderProvider; | 53 class VariationsHttpHeaderProvider; |
| 54 | 54 |
| 55 const VariationID EMPTY_ID = 0; | 55 const VariationID EMPTY_ID = 0; |
| 56 | 56 |
| 57 // A key into the Associate/Get methods for VariationIDs. This is used to create | 57 // A key into the Associate/Get methods for VariationIDs. This is used to create |
| 58 // separate ID associations for separate parties interested in VariationIDs. | 58 // separate ID associations for separate parties interested in VariationIDs. |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 // exist, returns an empty string.Calling this function will result in the | 160 // exist, returns an empty string.Calling this function will result in the |
| 161 // associated field trial being marked as active if found (i.e. group() will be | 161 // associated field trial being marked as active if found (i.e. group() will be |
| 162 // called on it), if it wasn't already. Currently, this information is only | 162 // called on it), if it wasn't already. Currently, this information is only |
| 163 // available from the browser process. Thread safe. | 163 // available from the browser process. Thread safe. |
| 164 std::string GetVariationParamValueByFeature(const base::Feature& feature, | 164 std::string GetVariationParamValueByFeature(const base::Feature& feature, |
| 165 const std::string& param_name); | 165 const std::string& param_name); |
| 166 | 166 |
| 167 // Expose some functions for testing. | 167 // Expose some functions for testing. |
| 168 namespace testing { | 168 namespace testing { |
| 169 | 169 |
| 170 // Use this class as a member in your test class to set variation params for | 170 // Clears all of the mapped associations. Deprecated, try to use |
| 171 // your tests. You can directly set the parameters in the constructor (if they | 171 // VariationParamsManager instead as it does a lot of work for you |
| 172 // are used by other members upon construction). You can change them later | 172 // automatically. |
| 173 // arbitrarily many times using the SetVariationParams function. Internally, it | |
| 174 // creates a FieldTrialList as a member. It works well for multiple tests of a | |
| 175 // given test class, as it clears the parameters when this class is destructed. | |
| 176 // Note that it clears all parameters (not just those registered here). | |
| 177 class VariationParamsManager { | |
| 178 public: | |
| 179 VariationParamsManager(const std::string& trial_name, | |
| 180 const std::map<std::string, std::string>& params); | |
| 181 ~VariationParamsManager(); | |
| 182 | |
| 183 // Associates |params| with the given |trial_name|. It creates a new group, | |
| 184 // used only for testing. Between two calls of this function, | |
| 185 // ClearAllVariationParams() has to be called. | |
| 186 void SetVariationParams(const std::string& trial_name, | |
| 187 const std::map<std::string, std::string>& params); | |
| 188 | |
| 189 private: | |
| 190 std::unique_ptr<base::FieldTrialList> field_trial_list_; | |
| 191 | |
| 192 DISALLOW_COPY_AND_ASSIGN(VariationParamsManager); | |
| 193 }; | |
| 194 | |
| 195 // Clears all of the mapped associations. | |
| 196 void ClearAllVariationIDs(); | 173 void ClearAllVariationIDs(); |
| 197 | 174 |
| 198 // Clears all of the associated params. | 175 // Clears all of the associated params. Deprecated, try to use |
| 176 // VariationParamsManager instead as it does a lot of work for you |
| 177 // automatically. |
| 199 void ClearAllVariationParams(); | 178 void ClearAllVariationParams(); |
| 200 | 179 |
| 201 } // namespace testing | 180 } // namespace testing |
| 202 | 181 |
| 203 } // namespace variations | 182 } // namespace variations |
| 204 | 183 |
| 205 #endif // COMPONENTS_VARIATIONS_VARIATIONS_ASSOCIATED_DATA_H_ | 184 #endif // COMPONENTS_VARIATIONS_VARIATIONS_ASSOCIATED_DATA_H_ |
| OLD | NEW |