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