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 <string> | 9 #include <string> |
10 | 10 |
(...skipping 19 matching lines...) Expand all Loading... |
30 // std::map<std::string, std::string> params; | 30 // std::map<std::string, std::string> params; |
31 // if (GetVariationParams("trial", ¶ms)) { | 31 // if (GetVariationParams("trial", ¶ms)) { |
32 // // use |params| | 32 // // use |params| |
33 // } | 33 // } |
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 != chrome_variations::kEmptyID) { | 40 // if (id != variations::kEmptyID) { |
41 // // use |id| | 41 // // use |id| |
42 // } | 42 // } |
43 | 43 |
44 namespace chrome_variations { | 44 namespace variations { |
45 | 45 |
46 typedef int VariationID; | 46 typedef int VariationID; |
47 | 47 |
48 const VariationID EMPTY_ID = 0; | 48 const VariationID EMPTY_ID = 0; |
49 | 49 |
50 // A key into the Associate/Get methods for VariationIDs. This is used to create | 50 // A key into the Associate/Get methods for VariationIDs. This is used to create |
51 // separate ID associations for separate parties interested in VariationIDs. | 51 // separate ID associations for separate parties interested in VariationIDs. |
52 enum IDCollectionKey { | 52 enum IDCollectionKey { |
53 // This collection is used by Google web properties, transmitted through the | 53 // This collection is used by Google web properties, transmitted through the |
54 // X-Client-Data header. | 54 // X-Client-Data header. |
55 GOOGLE_WEB_PROPERTIES, | 55 GOOGLE_WEB_PROPERTIES, |
56 // This collection is used by Google web properties for IDs that trigger | 56 // This collection is used by Google web properties for IDs that trigger |
57 // server side experimental behavior, transmitted through the | 57 // server side experimental behavior, transmitted through the |
58 // X-Client-Data header. | 58 // X-Client-Data header. |
59 GOOGLE_WEB_PROPERTIES_TRIGGER, | 59 GOOGLE_WEB_PROPERTIES_TRIGGER, |
60 // This collection is used by Google update services, transmitted through the | 60 // This collection is used by Google update services, transmitted through the |
61 // Google Update experiment labels. | 61 // Google Update experiment labels. |
62 GOOGLE_UPDATE_SERVICE, | 62 GOOGLE_UPDATE_SERVICE, |
63 // The total count of collections. | 63 // The total count of collections. |
64 ID_COLLECTION_COUNT, | 64 ID_COLLECTION_COUNT, |
65 }; | 65 }; |
66 | 66 |
67 // Associate a chrome_variations::VariationID value with a FieldTrial group for | 67 // Associate a variations::VariationID value with a FieldTrial group for |
68 // collection |key|. If an id was previously set for |trial_name| and | 68 // collection |key|. If an id was previously set for |trial_name| and |
69 // |group_name|, this does nothing. The group is denoted by |trial_name| and | 69 // |group_name|, this does nothing. The group is denoted by |trial_name| and |
70 // |group_name|. This must be called whenever a FieldTrial is prepared (create | 70 // |group_name|. This must be called whenever a FieldTrial is prepared (create |
71 // the trial and append groups) and needs to have a | 71 // the trial and append groups) and needs to have a variations::VariationID |
72 // chrome_variations::VariationID associated with it so Google servers can | 72 // associated with it so Google servers can recognize the FieldTrial. |
73 // recognize the FieldTrial. Thread safe. | 73 // Thread safe. |
74 void AssociateGoogleVariationID(IDCollectionKey key, | 74 void AssociateGoogleVariationID(IDCollectionKey key, |
75 const std::string& trial_name, | 75 const std::string& trial_name, |
76 const std::string& group_name, | 76 const std::string& group_name, |
77 VariationID id); | 77 VariationID id); |
78 | 78 |
79 // As above, but overwrites any previously set id. Thread safe. | 79 // As above, but overwrites any previously set id. Thread safe. |
80 void AssociateGoogleVariationIDForce(IDCollectionKey key, | 80 void AssociateGoogleVariationIDForce(IDCollectionKey key, |
81 const std::string& trial_name, | 81 const std::string& trial_name, |
82 const std::string& group_name, | 82 const std::string& group_name, |
83 VariationID id); | 83 VariationID id); |
84 | 84 |
85 // Retrieve the chrome_variations::VariationID associated with a FieldTrial | 85 // Retrieve the variations::VariationID associated with a FieldTrial group for |
86 // group for collection |key|. The group is denoted by |trial_name| and | 86 // collection |key|. The group is denoted by |trial_name| and |group_name|. |
87 // |group_name|. This will return chrome_variations::kEmptyID if there is | 87 // This will return variations::kEmptyID if there is currently no associated ID |
88 // currently no associated ID for the named group. This API can be nicely | 88 // for the named group. This API can be nicely combined with |
89 // combined with FieldTrial::GetActiveFieldTrialGroups() to enumerate the | 89 // FieldTrial::GetActiveFieldTrialGroups() to enumerate the variation IDs for |
90 // variation IDs for all active FieldTrial groups. Thread safe. | 90 // all active FieldTrial groups. Thread safe. |
91 VariationID GetGoogleVariationID(IDCollectionKey key, | 91 VariationID GetGoogleVariationID(IDCollectionKey key, |
92 const std::string& trial_name, | 92 const std::string& trial_name, |
93 const std::string& group_name); | 93 const std::string& group_name); |
94 | 94 |
95 // Associates the specified set of key-value |params| with the variation | 95 // Associates the specified set of key-value |params| with the variation |
96 // specified by |trial_name| and |group_name|. Fails and returns false if the | 96 // specified by |trial_name| and |group_name|. Fails and returns false if the |
97 // specified variation already has params associated with it or the field trial | 97 // specified variation already has params associated with it or the field trial |
98 // is already active (group() has been called on it). Thread safe. | 98 // is already active (group() has been called on it). Thread safe. |
99 bool AssociateVariationParams(const std::string& trial_name, | 99 bool AssociateVariationParams(const std::string& trial_name, |
100 const std::string& group_name, | 100 const std::string& group_name, |
(...skipping 23 matching lines...) Expand all Loading... |
124 namespace testing { | 124 namespace testing { |
125 | 125 |
126 // Clears all of the mapped associations. | 126 // Clears all of the mapped associations. |
127 void ClearAllVariationIDs(); | 127 void ClearAllVariationIDs(); |
128 | 128 |
129 // Clears all of the associated params. | 129 // Clears all of the associated params. |
130 void ClearAllVariationParams(); | 130 void ClearAllVariationParams(); |
131 | 131 |
132 } // namespace testing | 132 } // namespace testing |
133 | 133 |
134 } // namespace chrome_variations | 134 } // namespace variations |
135 | 135 |
136 #endif // COMPONENTS_VARIATIONS_VARIATIONS_ASSOCIATED_DATA_H_ | 136 #endif // COMPONENTS_VARIATIONS_VARIATIONS_ASSOCIATED_DATA_H_ |
OLD | NEW |