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_BROWSER_ABOUT_FLAGS_H_ | 5 #ifndef CHROME_BROWSER_ABOUT_FLAGS_H_ |
6 #define CHROME_BROWSER_ABOUT_FLAGS_H_ | 6 #define CHROME_BROWSER_ABOUT_FLAGS_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
| 9 #include <set> |
9 #include <string> | 10 #include <string> |
10 | 11 |
11 #include "base/command_line.h" | 12 #include "base/command_line.h" |
12 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 14 #include "chrome/browser/about_flags_switches_histogram_ids.h" |
13 | 15 |
14 class PrefService; | 16 class PrefService; |
15 | 17 |
16 namespace base { | 18 namespace base { |
17 class ListValue; | 19 class ListValue; |
18 } | 20 } |
19 | 21 |
20 namespace about_flags { | 22 namespace about_flags { |
21 | 23 |
22 class FlagsStorage; | 24 class FlagsStorage; |
(...skipping 28 matching lines...) Expand all Loading... |
51 // Used for MULTI_VALUE types to describe one of the possible values the user | 53 // Used for MULTI_VALUE types to describe one of the possible values the user |
52 // can select. | 54 // can select. |
53 struct Choice { | 55 struct Choice { |
54 // ID of the message containing the choice name. | 56 // ID of the message containing the choice name. |
55 int description_id; | 57 int description_id; |
56 | 58 |
57 // Command line switch and value to enabled for this choice. | 59 // Command line switch and value to enabled for this choice. |
58 const char* command_line_switch; | 60 const char* command_line_switch; |
59 // Simple switches that have no value should use "" for command_line_value. | 61 // Simple switches that have no value should use "" for command_line_value. |
60 const char* command_line_value; | 62 const char* command_line_value; |
| 63 |
| 64 // ID of command_line_switch in UMA histograms. |
| 65 // On ChromeOS experiments lead to chrome process restart when user logs in. |
| 66 // IDs of switches that lead to restart are reported. |
| 67 // Must be zero for entries without command_line_switches. |
| 68 const SwitchesUmaHistogramId command_line_switch_histogram_id; |
61 }; | 69 }; |
62 | 70 |
63 // The internal name of the experiment. This is never shown to the user. | 71 // The internal name of the experiment. This is never shown to the user. |
64 // It _is_ however stored in the prefs file, so you shouldn't change the | 72 // It _is_ however stored in the prefs file, so you shouldn't change the |
65 // name of existing flags. | 73 // name of existing flags. |
66 const char* internal_name; | 74 const char* internal_name; |
67 | 75 |
68 // String id of the message containing the experiment's name. | 76 // String id of the message containing the experiment's name. |
69 int visible_name_id; | 77 int visible_name_id; |
70 | 78 |
71 // String id of the message containing the experiment's description. | 79 // String id of the message containing the experiment's description. |
72 int visible_description_id; | 80 int visible_description_id; |
73 | 81 |
74 // The platforms the experiment is available on | 82 // The platforms the experiment is available on |
75 // Needs to be more than a compile-time #ifdef because of profile sync. | 83 // Needs to be more than a compile-time #ifdef because of profile sync. |
76 unsigned supported_platforms; // bitmask | 84 unsigned supported_platforms; // bitmask |
77 | 85 |
78 // Type of experiment. | 86 // Type of experiment. |
79 Type type; | 87 Type type; |
80 | 88 |
81 // The commandline switch and value that are added when this flag is active. | 89 // The commandline switch and value that are added when this flag is active. |
82 // This is different from |internal_name| so that the commandline flag can be | 90 // This is different from |internal_name| so that the commandline flag can be |
83 // renamed without breaking the prefs file. | 91 // renamed without breaking the prefs file. |
84 // This is used if type is SINGLE_VALUE or ENABLE_DISABLE_VALUE. | 92 // This is used if type is SINGLE_VALUE or ENABLE_DISABLE_VALUE. |
85 const char* command_line_switch; | 93 const char* command_line_switch; |
86 // Simple switches that have no value should use "" for command_line_value. | 94 // Simple switches that have no value should use "" for command_line_value. |
87 const char* command_line_value; | 95 const char* command_line_value; |
| 96 // ID of command_line_switch in UMA histograms. |
| 97 // (See Choice::command_line_switch_histogram_id.) |
| 98 // Must be zero for entries without command_line_switches. |
| 99 const int command_line_switch_histogram_id; |
88 | 100 |
89 // For ENABLE_DISABLE_VALUE, the command line switch and value to explictly | 101 // For ENABLE_DISABLE_VALUE, the command line switch and value to explictly |
90 // disable the feature. | 102 // disable the feature. |
91 const char* disable_command_line_switch; | 103 const char* disable_command_line_switch; |
92 const char* disable_command_line_value; | 104 const char* disable_command_line_value; |
| 105 const int disable_command_line_switch_histogram_id; |
93 | 106 |
94 // This is used if type is MULTI_VALUE. | 107 // This is used if type is MULTI_VALUE. |
95 const Choice* choices; | 108 const Choice* choices; |
96 | 109 |
97 // Number of |choices|. | 110 // Number of |choices|. |
98 // This is used if type is MULTI_VALUE. | 111 // This is used if type is MULTI_VALUE. |
99 int num_choices; | 112 int num_choices; |
100 | 113 |
101 // Returns the name used in prefs for the choice at the specified |index|. | 114 // Returns the name used in prefs for the choice at the specified |index|. |
102 std::string NameForChoice(int index) const; | 115 std::string NameForChoice(int index) const; |
103 | 116 |
104 // Returns the human readable description for the choice at |index|. | 117 // Returns the human readable description for the choice at |index|. |
105 base::string16 DescriptionForChoice(int index) const; | 118 base::string16 DescriptionForChoice(int index) const; |
106 }; | 119 }; |
107 | 120 |
108 // A flag controlling the behavior of the |ConvertFlagsToSwitches| function - | 121 // A flag controlling the behavior of the |ConvertFlagsToSwitches| function - |
109 // whether it should add the sentinel switches around flags. | 122 // whether it should add the sentinel switches around flags. |
110 enum SentinelsMode { kNoSentinels, kAddSentinels }; | 123 enum SentinelsMode { kNoSentinels, kAddSentinels }; |
111 | 124 |
| 125 // A simple map 'command line switch' -> 'histogram ID'. |
| 126 typedef std::map<std::string, int> SwitchesHistogramIDs; |
| 127 |
112 // Reads the Labs |prefs| (called "Labs" for historical reasons) and adds the | 128 // Reads the Labs |prefs| (called "Labs" for historical reasons) and adds the |
113 // commandline flags belonging to the active experiments to |command_line|. | 129 // commandline flags belonging to the active experiments to |command_line|. |
114 void ConvertFlagsToSwitches(FlagsStorage* flags_storage, | 130 void ConvertFlagsToSwitches(FlagsStorage* flags_storage, |
115 base::CommandLine* command_line, | 131 base::CommandLine* command_line, |
116 SentinelsMode sentinels); | 132 SentinelsMode sentinels); |
117 | 133 |
| 134 // Returns a map <command_line_switch, switch_histogram_id>. |
| 135 // Map is created if it doesn't exist. |
| 136 const SwitchesHistogramIDs& GetSwitchesHistogramIds(); |
| 137 |
118 // Compares a set of switches of the two provided command line objects and | 138 // Compares a set of switches of the two provided command line objects and |
119 // returns true if they are the same and false otherwise. | 139 // returns true if they are the same and false otherwise. |
| 140 // If |out_difference| is not NULL, it's filled with set_symmetric_difference |
| 141 // between sets. |
120 bool AreSwitchesIdenticalToCurrentCommandLine( | 142 bool AreSwitchesIdenticalToCurrentCommandLine( |
121 const base::CommandLine& new_cmdline, | 143 const base::CommandLine& new_cmdline, |
122 const base::CommandLine& active_cmdline); | 144 const base::CommandLine& active_cmdline, |
| 145 std::set<CommandLine::StringType>* out_difference); |
123 | 146 |
124 // Differentiate between generic flags available on a per session base and flags | 147 // Differentiate between generic flags available on a per session base and flags |
125 // that influence the whole machine and can be said by the admin only. This flag | 148 // that influence the whole machine and can be said by the admin only. This flag |
126 // is relevant for ChromeOS for now only and dictates whether entries marked | 149 // is relevant for ChromeOS for now only and dictates whether entries marked |
127 // with the |kOsCrOSOwnerOnly| label should be enabled in the UI or not. | 150 // with the |kOsCrOSOwnerOnly| label should be enabled in the UI or not. |
128 enum FlagAccess { kGeneralAccessFlagsOnly, kOwnerAccessToFlags }; | 151 enum FlagAccess { kGeneralAccessFlagsOnly, kOwnerAccessToFlags }; |
129 | 152 |
130 // Get the list of experiments. Experiments that are available on the current | 153 // Get the list of experiments. Experiments that are available on the current |
131 // platform are appended to |supported_experiments|; all other experiments are | 154 // platform are appended to |supported_experiments|; all other experiments are |
132 // appended to |unsupported_experiments|. | 155 // appended to |unsupported_experiments|. |
(...skipping 20 matching lines...) Expand all Loading... |
153 | 176 |
154 // Returns the value for the current platform. This is one of the values defined | 177 // Returns the value for the current platform. This is one of the values defined |
155 // by the OS enum above. | 178 // by the OS enum above. |
156 // This is exposed only for testing. | 179 // This is exposed only for testing. |
157 int GetCurrentPlatform(); | 180 int GetCurrentPlatform(); |
158 | 181 |
159 // Sends UMA stats about experimental flag usage. This should be called once per | 182 // Sends UMA stats about experimental flag usage. This should be called once per |
160 // startup. | 183 // startup. |
161 void RecordUMAStatistics(FlagsStorage* flags_storage); | 184 void RecordUMAStatistics(FlagsStorage* flags_storage); |
162 | 185 |
| 186 // Sends stats (as UMA histogram) about command_line_difference. |
| 187 // This is used on ChromeOS to report flags that lead to browser restart. |
| 188 // |command_line_difference| is the result of |
| 189 // AreSwitchesIdenticalToCurrentCommandLine(). |
| 190 void ReportCustomFlags(const std::string& uma_histogram_hame, |
| 191 const std::set<std::string>& command_line_difference); |
| 192 |
163 namespace testing { | 193 namespace testing { |
164 | 194 |
165 // Clears internal global state, for unit tests. | 195 // Clears internal global state, for unit tests. |
166 void ClearState(); | 196 void ClearState(); |
167 | 197 |
168 // Sets the list of experiments. Pass in NULL to use the default set. This does | 198 // Sets the list of experiments. Pass in NULL to use the default set. This does |
169 // NOT take ownership of the supplied Experiments. | 199 // NOT take ownership of the supplied Experiments. |
170 void SetExperiments(const Experiment* e, size_t count); | 200 void SetExperiments(const Experiment* e, size_t count); |
171 | 201 |
172 // Returns the current set of experiments. | 202 // Returns the current set of experiments. |
173 const Experiment* GetExperiments(size_t* count); | 203 const Experiment* GetExperiments(size_t* count); |
174 | 204 |
175 // Separator used for multi values. Multi values are represented in prefs as | 205 // Separator used for multi values. Multi values are represented in prefs as |
176 // name-of-experiment + kMultiSeparator + selected_index. | 206 // name-of-experiment + kMultiSeparator + selected_index. |
177 extern const char kMultiSeparator[]; | 207 extern const char kMultiSeparator[]; |
178 | 208 |
179 } // namespace testing | 209 } // namespace testing |
180 | 210 |
181 } // namespace about_flags | 211 } // namespace about_flags |
182 | 212 |
183 #endif // CHROME_BROWSER_ABOUT_FLAGS_H_ | 213 #endif // CHROME_BROWSER_ABOUT_FLAGS_H_ |
OLD | NEW |