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

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

Issue 1941963002: Add variations params api to get params from features. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: added tests Created 4 years, 7 months 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 <string> 9 #include <string>
10 10
(...skipping 23 matching lines...) Expand all
34 // 34 //
35 // std::string value = GetVariationParamValue("trial", "param_x"); 35 // std::string value = GetVariationParamValue("trial", "param_x");
36 // // use |value|, which will be "" if it does not exist 36 // // use |value|, which will be "" if it does not exist
37 // 37 //
38 // VariationID id = GetGoogleVariationID(GOOGLE_WEB_PROPERTIES, "trial", 38 // VariationID id = GetGoogleVariationID(GOOGLE_WEB_PROPERTIES, "trial",
39 // "group1"); 39 // "group1");
40 // if (id != variations::kEmptyID) { 40 // if (id != variations::kEmptyID) {
41 // // use |id| 41 // // use |id|
42 // } 42 // }
43 43
44 namespace base {
45 struct Feature;
46 }
47
44 namespace variations { 48 namespace variations {
45 49
46 typedef int VariationID; 50 typedef int VariationID;
47 51
48 const VariationID EMPTY_ID = 0; 52 const VariationID EMPTY_ID = 0;
49 53
50 // A key into the Associate/Get methods for VariationIDs. This is used to create 54 // A key into the Associate/Get methods for VariationIDs. This is used to create
51 // separate ID associations for separate parties interested in VariationIDs. 55 // separate ID associations for separate parties interested in VariationIDs.
52 enum IDCollectionKey { 56 enum IDCollectionKey {
53 // This collection is used by Google web properties, transmitted through the 57 // This collection is used by Google web properties, transmitted through the
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 // Retrieves the set of key-value |params| for the variation associated with 120 // Retrieves the set of key-value |params| for the variation associated with
117 // the specified field trial, based on its selected group. If the field trial 121 // the specified field trial, based on its selected group. If the field trial
118 // does not exist or its selected group does not have any parameters associated 122 // does not exist or its selected group does not have any parameters associated
119 // with it, returns false and does not modify |params|. Calling this function 123 // with it, returns false and does not modify |params|. Calling this function
120 // will result in the field trial being marked as active if found (i.e. group() 124 // will result in the field trial being marked as active if found (i.e. group()
121 // will be called on it), if it wasn't already. Currently, this information is 125 // will be called on it), if it wasn't already. Currently, this information is
122 // only available from the browser process. Thread safe. 126 // only available from the browser process. Thread safe.
123 bool GetVariationParams(const std::string& trial_name, 127 bool GetVariationParams(const std::string& trial_name,
124 std::map<std::string, std::string>* params); 128 std::map<std::string, std::string>* params);
125 129
130 // Retvieves the set of key-value |params| for the variation associated with the
Alexei Svitkine (slow) 2016/05/03 17:04:25 Nit: Retrieves
jwd 2016/05/03 20:12:27 Done.
131 // specified |feature|. A feature is associated with at most one variation,
132 // through the variation's associated field trial, and selected group. See
133 // base/feature_list.h for more information on features. If the feature is not
134 // enabled, or if there's no associated variation params, returns false and does
135 // not modify |params|. Calling this function will result in the associated
136 // field trial being marked as active if found (i.e. group() will be called on
137 // it), if it wasn't already. Currently, this information is only available from
138 // the browser process. Thread safe.
139 bool GetVariationParamsByFeature(const base::Feature& feature,
140 std::map<std::string, std::string>* params);
141
126 // Retrieves a specific parameter value corresponding to |param_name| for the 142 // Retrieves a specific parameter value corresponding to |param_name| for the
127 // variation associated with the specified field trial, based on its selected 143 // variation associated with the specified field trial, based on its selected
128 // group. If the field trial does not exist or the specified parameter does not 144 // group. If the field trial does not exist or the specified parameter does not
129 // exist, returns an empty string. Calling this function will result in the 145 // exist, returns an empty string. Calling this function will result in the
130 // field trial being marked as active if found (i.e. group() will be called on 146 // field trial being marked as active if found (i.e. group() will be called on
131 // it), if it wasn't already. Currently, this information is only available from 147 // it), if it wasn't already. Currently, this information is only available from
132 // the browser process. Thread safe. 148 // the browser process. Thread safe.
133 std::string GetVariationParamValue(const std::string& trial_name, 149 std::string GetVariationParamValue(const std::string& trial_name,
134 const std::string& param_name); 150 const std::string& param_name);
135 151
152 // Retrieves a specific parameter value corresponding to |param_name| for the
153 // variation associated with the specified |feature|. A feature is associated
154 // with at most one variation, through the variation's associated field trial,
155 // and selected group. See base/feature_list.h for more information on
156 // features. If the feature is not enabled, or if there's no associated
157 // variation params, returns false and does not modify |params|. Calling this
158 // function will result in the associated field trial being marked as active if
159 // found (i.e. group() will be called on it), if it wasn't already. Currently,
160 // this information is only available from the browser process. Thread safe.
161 std::string GetVariationParamValueByFeature(const base::Feature& feature,
162 const std::string& param_name);
163
136 // Expose some functions for testing. 164 // Expose some functions for testing.
137 namespace testing { 165 namespace testing {
138 166
139 // Clears all of the mapped associations. 167 // Clears all of the mapped associations.
140 void ClearAllVariationIDs(); 168 void ClearAllVariationIDs();
141 169
142 // Clears all of the associated params. 170 // Clears all of the associated params.
143 void ClearAllVariationParams(); 171 void ClearAllVariationParams();
144 172
145 } // namespace testing 173 } // namespace testing
146 174
147 } // namespace variations 175 } // namespace variations
148 176
149 #endif // COMPONENTS_VARIATIONS_VARIATIONS_ASSOCIATED_DATA_H_ 177 #endif // COMPONENTS_VARIATIONS_VARIATIONS_ASSOCIATED_DATA_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698