[Eraser strings] Remove unused Supervised User infobar and corresponding strings
[chromium-blink-merge.git] / chrome / browser / about_flags.h
blob6be0e9662ea235040c67935e82f36da58035ee0a
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_ABOUT_FLAGS_H_
6 #define CHROME_BROWSER_ABOUT_FLAGS_H_
8 #include <stdint.h>
10 #include <map>
11 #include <set>
12 #include <string>
14 #include "base/command_line.h"
15 #include "base/metrics/histogram_base.h"
16 #include "base/strings/string16.h"
18 class PrefService;
20 namespace base {
21 class ListValue;
24 namespace about_flags {
26 class FlagsStorage;
28 // Experiment is used internally by about_flags to describe an experiment (and
29 // for testing).
30 // This is exposed only for testing.
31 struct Experiment {
32 enum Type {
33 // An experiment with a single value. This is typically what you want.
34 SINGLE_VALUE,
36 // A default enabled experiment with a single value to disable it. This is
37 // for default enabled SINGLE_VALUE experiments. Please consider whether
38 // you really need a flag to disable the experiment, and even if so remove
39 // the disable flag as soon as it is no longer needed.
40 SINGLE_DISABLE_VALUE,
42 // The experiment has multiple values only one of which is ever enabled.
43 // The first of the values should correspond to a deactivated state for this
44 // lab (i.e. no command line option). For MULTI_VALUE experiments the
45 // command_line of the Experiment is not used. If the experiment is enabled
46 // the command line of the selected Choice is enabled.
47 MULTI_VALUE,
49 // The experiment has three possible values: Default, Enabled and Disabled.
50 // This should be used for experiments that may have their own logic to
51 // decide if the feature should be on when not explicitly specified via
52 // about flags - for example via FieldTrials.
53 ENABLE_DISABLE_VALUE,
56 // Used for MULTI_VALUE types to describe one of the possible values the user
57 // can select.
58 struct Choice {
59 // ID of the message containing the choice name.
60 int description_id;
62 // Command line switch and value to enabled for this choice.
63 const char* command_line_switch;
64 // Simple switches that have no value should use "" for command_line_value.
65 const char* command_line_value;
68 // The internal name of the experiment. This is never shown to the user.
69 // It _is_ however stored in the prefs file, so you shouldn't change the
70 // name of existing flags.
71 const char* internal_name;
73 // String id of the message containing the experiment's name.
74 int visible_name_id;
76 // String id of the message containing the experiment's description.
77 int visible_description_id;
79 // The platforms the experiment is available on
80 // Needs to be more than a compile-time #ifdef because of profile sync.
81 unsigned supported_platforms; // bitmask
83 // Type of experiment.
84 Type type;
86 // The commandline switch and value that are added when this flag is active.
87 // This is different from |internal_name| so that the commandline flag can be
88 // renamed without breaking the prefs file.
89 // This is used if type is SINGLE_VALUE or ENABLE_DISABLE_VALUE.
90 const char* command_line_switch;
91 // Simple switches that have no value should use "" for command_line_value.
92 const char* command_line_value;
94 // For ENABLE_DISABLE_VALUE, the command line switch and value to explicitly
95 // disable the feature.
96 const char* disable_command_line_switch;
97 const char* disable_command_line_value;
99 // This is used if type is MULTI_VALUE.
100 const Choice* choices;
102 // Number of |choices|.
103 // This is used if type is MULTI_VALUE.
104 int num_choices;
106 // Returns the name used in prefs for the choice at the specified |index|.
107 std::string NameForChoice(int index) const;
109 // Returns the human readable description for the choice at |index|.
110 base::string16 DescriptionForChoice(int index) const;
113 // A flag controlling the behavior of the |ConvertFlagsToSwitches| function -
114 // whether it should add the sentinel switches around flags.
115 enum SentinelsMode { kNoSentinels, kAddSentinels };
117 // Reads the Labs |prefs| (called "Labs" for historical reasons) and adds the
118 // commandline flags belonging to the active experiments to |command_line|.
119 void ConvertFlagsToSwitches(FlagsStorage* flags_storage,
120 base::CommandLine* command_line,
121 SentinelsMode sentinels);
123 // Compares a set of switches of the two provided command line objects and
124 // returns true if they are the same and false otherwise.
125 // If |out_difference| is not NULL, it's filled with set_symmetric_difference
126 // between sets.
127 bool AreSwitchesIdenticalToCurrentCommandLine(
128 const base::CommandLine& new_cmdline,
129 const base::CommandLine& active_cmdline,
130 std::set<base::CommandLine::StringType>* out_difference);
132 // Differentiate between generic flags available on a per session base and flags
133 // that influence the whole machine and can be said by the admin only. This flag
134 // is relevant for ChromeOS for now only and dictates whether entries marked
135 // with the |kOsCrOSOwnerOnly| label should be enabled in the UI or not.
136 enum FlagAccess { kGeneralAccessFlagsOnly, kOwnerAccessToFlags };
138 // Get the list of experiments. Experiments that are available on the current
139 // platform are appended to |supported_experiments|; all other experiments are
140 // appended to |unsupported_experiments|.
141 void GetFlagsExperimentsData(FlagsStorage* flags_storage,
142 FlagAccess access,
143 base::ListValue* supported_experiments,
144 base::ListValue* unsupported_experiments);
146 // Returns true if one of the experiment flags has been flipped since startup.
147 bool IsRestartNeededToCommitChanges();
149 // Enables or disables the experiment with id |internal_name|.
150 void SetExperimentEnabled(FlagsStorage* flags_storage,
151 const std::string& internal_name,
152 bool enable);
154 // Removes all switches that were added to a command line by a previous call to
155 // |ConvertFlagsToSwitches()|.
156 void RemoveFlagsSwitches(
157 std::map<std::string, base::CommandLine::StringType>* switch_list);
159 // Reset all flags to the default state by clearing all flags.
160 void ResetAllFlags(FlagsStorage* flags_storage);
162 // Returns the value for the current platform. This is one of the values defined
163 // by the OS enum above.
164 // This is exposed only for testing.
165 int GetCurrentPlatform();
167 // Sends UMA stats about experimental flag usage. This should be called once per
168 // startup.
169 void RecordUMAStatistics(FlagsStorage* flags_storage);
171 // Returns the UMA id for the specified switch name.
172 base::HistogramBase::Sample GetSwitchUMAId(const std::string& switch_name);
174 // Sends stats (as UMA histogram) about command_line_difference.
175 // This is used on ChromeOS to report flags that lead to browser restart.
176 // |command_line_difference| is the result of
177 // AreSwitchesIdenticalToCurrentCommandLine().
178 void ReportCustomFlags(const std::string& uma_histogram_hame,
179 const std::set<std::string>& command_line_difference);
181 namespace testing {
183 // Clears internal global state, for unit tests.
184 void ClearState();
186 // Sets the list of experiments. Pass in NULL to use the default set. This does
187 // NOT take ownership of the supplied Experiments.
188 void SetExperiments(const Experiment* e, size_t count);
190 // Returns the current set of experiments.
191 const Experiment* GetExperiments(size_t* count);
193 // Separator used for multi values. Multi values are represented in prefs as
194 // name-of-experiment + kMultiSeparator + selected_index.
195 extern const char kMultiSeparator[];
197 // This value is reported as switch histogram ID if switch name has unknown
198 // format.
199 extern const base::HistogramBase::Sample kBadSwitchFormatHistogramId;
201 } // namespace testing
203 } // namespace about_flags
205 #endif // CHROME_BROWSER_ABOUT_FLAGS_H_