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 <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
11 #include <set> | 11 #include <set> |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/metrics/histogram_base.h" | 15 #include "base/metrics/histogram_base.h" |
16 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
| 17 #include "components/flags_ui/feature_entry.h" |
17 | 18 |
18 class PrefService; | 19 class PrefService; |
19 | 20 |
20 namespace base { | 21 namespace base { |
21 struct Feature; | |
22 class ListValue; | 22 class ListValue; |
23 } | 23 } |
24 | 24 |
25 namespace flags_ui { | 25 namespace flags_ui { |
26 class FlagsStorage; | 26 class FlagsStorage; |
27 } | 27 } |
28 | 28 |
29 namespace about_flags { | 29 namespace about_flags { |
30 | 30 |
31 // FeatureEntry is used by about_flags to describe an experimental feature. | |
32 // | |
33 // Note that features should eventually be either turned on by default with no | |
34 // about_flags entries or deleted. Most feature entries should only be around | |
35 // for a few milestones, until their full launch. | |
36 // | |
37 // This is exposed only for testing. | |
38 struct FeatureEntry { | |
39 enum Type { | |
40 // A feature with a single flag value. This is typically what you want. | |
41 SINGLE_VALUE, | |
42 | |
43 // A default enabled feature with a single flag value to disable it. Please | |
44 // consider whether you really need a flag to disable the feature, and even | |
45 // if so remove the disable flag as soon as it is no longer needed. | |
46 SINGLE_DISABLE_VALUE, | |
47 | |
48 // The feature has multiple values only one of which is ever enabled. | |
49 // The first of the values should correspond to a deactivated state for this | |
50 // feature (i.e. no command line option). For MULTI_VALUE entries, the | |
51 // command_line of the FeatureEntry is not used. If the experiment is | |
52 // enabled the command line of the selected Choice is enabled. | |
53 MULTI_VALUE, | |
54 | |
55 // The feature has three possible values: Default, Enabled and Disabled. | |
56 // This should be used for features that may have their own logic to decide | |
57 // if the feature should be on when not explicitly specified via about | |
58 // flags - for example via FieldTrials. | |
59 ENABLE_DISABLE_VALUE, | |
60 | |
61 // Corresponds to a base::Feature, per base/feature_list.h. The entry will | |
62 // have three states: Default, Enabled, Disabled. When not specified or set | |
63 // to Default, the normal default value of the feature is used. | |
64 FEATURE_VALUE, | |
65 }; | |
66 | |
67 // Used for MULTI_VALUE types to describe one of the possible values the user | |
68 // can select. | |
69 struct Choice { | |
70 // ID of the message containing the choice name. | |
71 int description_id; | |
72 | |
73 // Command line switch and value to enabled for this choice. | |
74 const char* command_line_switch; | |
75 // Simple switches that have no value should use "" for command_line_value. | |
76 const char* command_line_value; | |
77 }; | |
78 | |
79 // The internal name of the feature entry. This is never shown to the user. | |
80 // It _is_ however stored in the prefs file, so you shouldn't change the | |
81 // name of existing flags. | |
82 const char* internal_name; | |
83 | |
84 // String id of the message containing the feature's name. | |
85 int visible_name_id; | |
86 | |
87 // String id of the message containing the feature's description. | |
88 int visible_description_id; | |
89 | |
90 // The platforms the feature is available on. | |
91 // Needs to be more than a compile-time #ifdef because of profile sync. | |
92 unsigned supported_platforms; // bitmask | |
93 | |
94 // Type of entry. | |
95 Type type; | |
96 | |
97 // The commandline switch and value that are added when this flag is active. | |
98 // This is different from |internal_name| so that the commandline flag can be | |
99 // renamed without breaking the prefs file. | |
100 // This is used if type is SINGLE_VALUE or ENABLE_DISABLE_VALUE. | |
101 const char* command_line_switch; | |
102 // Simple switches that have no value should use "" for command_line_value. | |
103 const char* command_line_value; | |
104 | |
105 // For ENABLE_DISABLE_VALUE, the command line switch and value to explicitly | |
106 // disable the feature. | |
107 const char* disable_command_line_switch; | |
108 const char* disable_command_line_value; | |
109 | |
110 // For FEATURE_VALUE, the base::Feature this entry corresponds to. | |
111 const base::Feature* feature; | |
112 | |
113 // This is used if type is MULTI_VALUE. | |
114 const Choice* choices; | |
115 | |
116 // Number of |choices|. | |
117 // This is used if type is MULTI_VALUE. | |
118 int num_choices; | |
119 | |
120 // Returns the name used in prefs for the choice at the specified |index|. | |
121 std::string NameForChoice(int index) const; | |
122 | |
123 // Returns the human readable description for the choice at |index|. | |
124 base::string16 DescriptionForChoice(int index) const; | |
125 }; | |
126 | |
127 // A flag controlling the behavior of the |ConvertFlagsToSwitches| function - | 31 // A flag controlling the behavior of the |ConvertFlagsToSwitches| function - |
128 // whether it should add the sentinel switches around flags. | 32 // whether it should add the sentinel switches around flags. |
129 enum SentinelsMode { kNoSentinels, kAddSentinels }; | 33 enum SentinelsMode { kNoSentinels, kAddSentinels }; |
130 | 34 |
131 // Reads the state from |flags_storage| and adds the command line flags | 35 // Reads the state from |flags_storage| and adds the command line flags |
132 // belonging to the active feature entries to |command_line|. | 36 // belonging to the active feature entries to |command_line|. |
133 void ConvertFlagsToSwitches(flags_ui::FlagsStorage* flags_storage, | 37 void ConvertFlagsToSwitches(flags_ui::FlagsStorage* flags_storage, |
134 base::CommandLine* command_line, | 38 base::CommandLine* command_line, |
135 SentinelsMode sentinels); | 39 SentinelsMode sentinels); |
136 | 40 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 void ReportCustomFlags(const std::string& uma_histogram_hame, | 97 void ReportCustomFlags(const std::string& uma_histogram_hame, |
194 const std::set<std::string>& command_line_difference); | 98 const std::set<std::string>& command_line_difference); |
195 | 99 |
196 namespace testing { | 100 namespace testing { |
197 | 101 |
198 // Clears internal global state, for unit tests. | 102 // Clears internal global state, for unit tests. |
199 void ClearState(); | 103 void ClearState(); |
200 | 104 |
201 // Sets the list of feature entries. Pass in null to use the default set. This | 105 // Sets the list of feature entries. Pass in null to use the default set. This |
202 // does NOT take ownership of the supplied |entries|. | 106 // does NOT take ownership of the supplied |entries|. |
203 void SetFeatureEntries(const FeatureEntry* entries, size_t count); | 107 void SetFeatureEntries(const flags_ui::FeatureEntry* entries, size_t count); |
204 | 108 |
205 // Returns the current set of feature entries. | 109 // Returns the current set of feature entries. |
206 const FeatureEntry* GetFeatureEntries(size_t* count); | 110 const flags_ui::FeatureEntry* GetFeatureEntries(size_t* count); |
207 | |
208 // Separator used for multi values. Multi values are represented in prefs as | |
209 // name-of-experiment + kMultiSeparator + selected_index. | |
210 extern const char kMultiSeparator[]; | |
211 | 111 |
212 // This value is reported as switch histogram ID if switch name has unknown | 112 // This value is reported as switch histogram ID if switch name has unknown |
213 // format. | 113 // format. |
214 extern const base::HistogramBase::Sample kBadSwitchFormatHistogramId; | 114 extern const base::HistogramBase::Sample kBadSwitchFormatHistogramId; |
215 | 115 |
216 } // namespace testing | 116 } // namespace testing |
217 | 117 |
218 } // namespace about_flags | 118 } // namespace about_flags |
219 | 119 |
220 #endif // CHROME_BROWSER_ABOUT_FLAGS_H_ | 120 #endif // CHROME_BROWSER_ABOUT_FLAGS_H_ |
OLD | NEW |