Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(186)

Side by Side Diff: components/variations/variations_associated_data.h

Issue 2321273003: Extend VariationParamsManager to support feature associations. (Closed)
Patch Set: Fixing windows build? Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 } // namespace base
49 48
50 namespace variations { 49 namespace variations {
51 50
52 typedef int VariationID; 51 typedef int VariationID;
53 class VariationsHttpHeaderProvider; 52 class VariationsHttpHeaderProvider;
54 53
55 const VariationID EMPTY_ID = 0; 54 const VariationID EMPTY_ID = 0;
56 55
57 // A key into the Associate/Get methods for VariationIDs. This is used to create 56 // A key into the Associate/Get methods for VariationIDs. This is used to create
58 // separate ID associations for separate parties interested in VariationIDs. 57 // separate ID associations for separate parties interested in VariationIDs.
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 // exist, returns an empty string.Calling this function will result in the 156 // exist, returns an empty string.Calling this function will result in the
158 // associated field trial being marked as active if found (i.e. group() will be 157 // associated field trial being marked as active if found (i.e. group() will be
159 // called on it), if it wasn't already. Currently, this information is only 158 // called on it), if it wasn't already. Currently, this information is only
160 // available from the browser process. Thread safe. 159 // available from the browser process. Thread safe.
161 std::string GetVariationParamValueByFeature(const base::Feature& feature, 160 std::string GetVariationParamValueByFeature(const base::Feature& feature,
162 const std::string& param_name); 161 const std::string& param_name);
163 162
164 // Expose some functions for testing. 163 // Expose some functions for testing.
165 namespace testing { 164 namespace testing {
166 165
167 // Use this class as a member in your test class to set variation params for 166 // Clears all of the mapped associations. Deprecated, try to use
168 // your tests. You can directly set the parameters in the constructor (if they 167 // VariationParamsManager instead as it does a lot of work for you
169 // are used by other members upon construction). You can change them later 168 // automatically.
170 // arbitrarily many times using the SetVariationParams function. Internally, it
171 // creates a FieldTrialList as a member. It works well for multiple tests of a
172 // given test class, as it clears the parameters when this class is destructed.
173 // Note that it clears all parameters (not just those registered here).
174 class VariationParamsManager {
175 public:
176 VariationParamsManager(const std::string& trial_name,
177 const std::map<std::string, std::string>& params);
178 ~VariationParamsManager();
179
180 // Associates |params| with the given |trial_name|. It creates a new group,
181 // used only for testing. Between two calls of this function,
182 // ClearAllVariationParams() has to be called.
183 void SetVariationParams(const std::string& trial_name,
184 const std::map<std::string, std::string>& params);
185
186 private:
187 std::unique_ptr<base::FieldTrialList> field_trial_list_;
188
189 DISALLOW_COPY_AND_ASSIGN(VariationParamsManager);
190 };
191
192 // Clears all of the mapped associations.
193 void ClearAllVariationIDs(); 169 void ClearAllVariationIDs();
194 170
195 // Clears all of the associated params. 171 // Clears all of the associated params. Deprecated, try to use
172 // VariationParamsManager instead as it does a lot of work for you
173 // automatically.
196 void ClearAllVariationParams(); 174 void ClearAllVariationParams();
197 175
198 } // namespace testing 176 } // namespace testing
199 177
200 } // namespace variations 178 } // namespace variations
201 179
202 #endif // COMPONENTS_VARIATIONS_VARIATIONS_ASSOCIATED_DATA_H_ 180 #endif // COMPONENTS_VARIATIONS_VARIATIONS_ASSOCIATED_DATA_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698