OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_COMMON_METRICS_EXPERIMENTS_HELPER_H_ | 5 #ifndef CHROME_COMMON_METRICS_VARIATIONS_UTIL_H_ |
6 #define CHROME_COMMON_METRICS_EXPERIMENTS_HELPER_H_ | 6 #define CHROME_COMMON_METRICS_VARIATIONS_UTIL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/metrics/field_trial.h" | 11 #include "base/metrics/field_trial.h" |
12 #include "base/string16.h" | 12 #include "base/string16.h" |
13 #include "chrome/common/metrics/variation_ids.h" | 13 #include "chrome/common/metrics/variation_ids.h" |
14 | 14 |
15 // This namespace provides various helpers that extend the functionality around | 15 // This namespace provides various helpers that extend the functionality around |
16 // base::FieldTrial. | 16 // base::FieldTrial. |
17 // | 17 // |
18 // This includes a simple API used to handle getting and setting | 18 // This includes a simple API used to handle getting and setting |
19 // data related to Google-specific experiments in the browser. This is meant to | 19 // data related to Google-specific variations in the browser. This is meant to |
20 // be an extension to the base::FieldTrial for Google-specific functionality. | 20 // be an extension to the base::FieldTrial for Google-specific functionality. |
21 // | 21 // |
22 // These calls are meant to be made directly after appending all your groups to | 22 // These calls are meant to be made directly after appending all your groups to |
23 // a FieldTrial (for associating IDs) and any time after the group selection has | 23 // a FieldTrial (for associating IDs) and any time after the group selection has |
24 // been done (for retrieving IDs). | 24 // been done (for retrieving IDs). |
25 // | 25 // |
26 // Typical usage looks like this: | 26 // Typical usage looks like this: |
27 // | 27 // |
28 // // Set up your trial and groups as usual. | 28 // // Set up your trial and groups as usual. |
29 // FieldTrial* trial = FieldTrialList::FactoryGetFieldTrial( | 29 // FieldTrial* trial = FieldTrialList::FactoryGetFieldTrial( |
30 // "trial", 1000, "default", 2012, 12, 31, NULL); | 30 // "trial", 1000, "default", 2012, 12, 31, NULL); |
31 // const int kHighMemGroup = trial->AppendGroup("HighMem", 20); | 31 // const int kHighMemGroup = trial->AppendGroup("HighMem", 20); |
32 // const int kLowMemGroup = trial->AppendGroup("LowMem", 20); | 32 // const int kLowMemGroup = trial->AppendGroup("LowMem", 20); |
33 // // All groups are now created. We want to associate | 33 // // All groups are now created. We want to associate |
34 // // chrome_variation::VariationIDs with them, so do that now. | 34 // // chrome_variation::VariationIDs with them, so do that now. |
35 // AssociateGoogleVariationID("trial", "default", chrome_variations::kValueA); | 35 // AssociateGoogleVariationID("trial", "default", chrome_variations::kValueA); |
36 // AssociateGoogleVariationID("trial", "HighMem", chrome_variations::kValueB); | 36 // AssociateGoogleVariationID("trial", "HighMem", chrome_variations::kValueB); |
37 // AssociateGoogleVariationID("trial", "LowMem", chrome_variations::kValueC); | 37 // AssociateGoogleVariationID("trial", "LowMem", chrome_variations::kValueC); |
38 // | 38 // |
39 // // Elsewhere, we are interested in retrieving the VariationID associated | 39 // // Elsewhere, we are interested in retrieving the VariationID associated |
40 // // with |trial|. | 40 // // with |trial|. |
41 // chrome_variations::VariationID id = | 41 // chrome_variations::VariationID id = |
42 // GetGoogleVariationID(trial->name(), trial->group_name()); | 42 // GetGoogleVariationID(trial->name(), trial->group_name()); |
43 // // Do stuff with |id|... | 43 // // Do stuff with |id|... |
44 // | 44 // |
45 // The AssociateGoogleVariationID and GetGoogleVariationID API methods are | 45 // The AssociateGoogleVariationID and GetGoogleVariationID API methods are |
46 // thread safe. | 46 // thread safe. |
47 | 47 |
48 namespace experiments_helper { | 48 namespace chrome_variations { |
49 | 49 |
50 // The Unique ID of a trial and its selected group, where the name and group | 50 // The Unique ID of a trial and its selected group, where the name and group |
51 // identifiers are hashes of the trial and group name strings. | 51 // identifiers are hashes of the trial and group name strings. |
52 struct SelectedGroupId { | 52 struct SelectedGroupId { |
53 uint32 name; | 53 uint32 name; |
54 uint32 group; | 54 uint32 group; |
55 }; | 55 }; |
56 | 56 |
57 // We need to supply a Compare class for templates since SelectedGroupId is a | 57 // We need to supply a Compare class for templates since SelectedGroupId is a |
58 // user-defined type. | 58 // user-defined type. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 // Retrieve the chrome_variations::VariationID associated with a FieldTrial | 93 // Retrieve the chrome_variations::VariationID associated with a FieldTrial |
94 // group. The group is denoted by |trial_name| and |group_name|. This will | 94 // group. The group is denoted by |trial_name| and |group_name|. This will |
95 // return chrome_variations::kEmptyID if there is currently no associated ID | 95 // return chrome_variations::kEmptyID if there is currently no associated ID |
96 // for the named group. This API can be nicely combined with | 96 // for the named group. This API can be nicely combined with |
97 // FieldTrial::GetFieldTrialSelectedGroupIds to enumerate the | 97 // FieldTrial::GetFieldTrialSelectedGroupIds to enumerate the |
98 // variation IDs for all active FieldTrial groups. | 98 // variation IDs for all active FieldTrial groups. |
99 chrome_variations::VariationID GetGoogleVariationID( | 99 chrome_variations::VariationID GetGoogleVariationID( |
100 const std::string& trial_name, | 100 const std::string& trial_name, |
101 const std::string& group_name); | 101 const std::string& group_name); |
102 | 102 |
103 // Generates experiment chunks from |experiment_strings| that are suitable for | 103 // Generates variation chunks from |variation_strings| that are suitable for |
104 // crash reporting. | 104 // crash reporting. |
105 void GenerateExperimentChunks(const std::vector<string16>& experiment_strings, | 105 void GenerateVariationChunks(const std::vector<string16>& variation_strings, |
106 std::vector<string16>* chunks); | 106 std::vector<string16>* chunks); |
107 | 107 |
108 // Get the current set of chosen FieldTrial groups (aka experiments) and send | 108 // Get the current set of chosen FieldTrial groups (aka variations) and send |
109 // them to the child process logging module so it can save it for crash dumps. | 109 // them to the child process logging module so it can save it for crash dumps. |
110 void SetChildProcessLoggingExperimentList(); | 110 void SetChildProcessLoggingVariationList(); |
111 | 111 |
112 } // namespace experiments_helper | 112 } // namespace chrome_variations |
113 | 113 |
114 // Expose some functions for testing. These functions just wrap functionality | 114 // Expose some functions for testing. These functions just wrap functionality |
115 // that is implemented above. | 115 // that is implemented above. |
116 namespace testing { | 116 namespace testing { |
117 | 117 |
118 void TestGetFieldTrialSelectedGroupIdsForSelectedGroups( | 118 void TestGetFieldTrialSelectedGroupIdsForSelectedGroups( |
119 const base::FieldTrial::SelectedGroups& selected_groups, | 119 const base::FieldTrial::SelectedGroups& selected_groups, |
120 std::vector<experiments_helper::SelectedGroupId>* name_group_ids); | 120 std::vector<chrome_variations::SelectedGroupId>* name_group_ids); |
121 | 121 |
122 uint32 TestHashName(const std::string& name); | 122 uint32 TestHashName(const std::string& name); |
123 | 123 |
124 } // namespace testing | 124 } // namespace testing |
125 | 125 |
126 #endif // CHROME_COMMON_METRICS_EXPERIMENTS_HELPER_H_ | 126 #endif // CHROME_COMMON_METRICS_VARIATIONS_UTIL_H_ |
OLD | NEW |