Update mojo surfaces bindings and mojo/cc/ glue
[chromium-blink-merge.git] / chrome / browser / about_flags.h
blob7a229a7e140326c481505d797361c76725ede75d
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/strings/string16.h"
17 class PrefService;
19 namespace base {
20 class ListValue;
23 namespace about_flags {
25 class FlagsStorage;
27 // This value is reported as switch histogram ID if switch name has unknown
28 // format.
29 extern const uint32_t kBadSwitchFormatHistogramId;
31 // Enumeration of OSs.
32 // This is exposed only for testing.
33 enum { kOsMac = 1 << 0, kOsWin = 1 << 1, kOsLinux = 1 << 2 , kOsCrOS = 1 << 3,
34 kOsAndroid = 1 << 4, kOsCrOSOwnerOnly = 1 << 5 };
36 // Experiment is used internally by about_flags to describe an experiment (and
37 // for testing).
38 // This is exposed only for testing.
39 struct Experiment {
40 enum Type {
41 // An experiment with a single value. This is typically what you want.
42 SINGLE_VALUE,
44 // The experiment has multiple values only one of which is ever enabled.
45 // The first of the values should correspond to a deactivated state for this
46 // lab (i.e. no command line option). For MULTI_VALUE experiments the
47 // command_line of the Experiment is not used. If the experiment is enabled
48 // the command line of the selected Choice is enabled.
49 MULTI_VALUE,
51 // The experiment has three possible values: Default, Enabled and Disabled.
52 // This should be used for experiments that may have their own logic to
53 // decide if the feature should be on when not explicitly specified via
54 // about flags - for example via FieldTrials.
55 ENABLE_DISABLE_VALUE,
58 // Used for MULTI_VALUE types to describe one of the possible values the user
59 // can select.
60 struct Choice {
61 // ID of the message containing the choice name.
62 int description_id;
64 // Command line switch and value to enabled for this choice.
65 const char* command_line_switch;
66 // Simple switches that have no value should use "" for command_line_value.
67 const char* command_line_value;
70 // The internal name of the experiment. This is never shown to the user.
71 // It _is_ however stored in the prefs file, so you shouldn't change the
72 // name of existing flags.
73 const char* internal_name;
75 // String id of the message containing the experiment's name.
76 int visible_name_id;
78 // String id of the message containing the experiment's description.
79 int visible_description_id;
81 // The platforms the experiment is available on
82 // Needs to be more than a compile-time #ifdef because of profile sync.
83 unsigned supported_platforms; // bitmask
85 // Type of experiment.
86 Type type;
88 // The commandline switch and value that are added when this flag is active.
89 // This is different from |internal_name| so that the commandline flag can be
90 // renamed without breaking the prefs file.
91 // This is used if type is SINGLE_VALUE or ENABLE_DISABLE_VALUE.
92 const char* command_line_switch;
93 // Simple switches that have no value should use "" for command_line_value.
94 const char* command_line_value;
96 // For ENABLE_DISABLE_VALUE, the command line switch and value to explictly
97 // disable the feature.
98 const char* disable_command_line_switch;
99 const char* disable_command_line_value;
101 // This is used if type is MULTI_VALUE.
102 const Choice* choices;
104 // Number of |choices|.
105 // This is used if type is MULTI_VALUE.
106 int num_choices;
108 // Returns the name used in prefs for the choice at the specified |index|.
109 std::string NameForChoice(int index) const;
111 // Returns the human readable description for the choice at |index|.
112 base::string16 DescriptionForChoice(int index) const;
115 // A flag controlling the behavior of the |ConvertFlagsToSwitches| function -
116 // whether it should add the sentinel switches around flags.
117 enum SentinelsMode { kNoSentinels, kAddSentinels };
119 // Reads the Labs |prefs| (called "Labs" for historical reasons) and adds the
120 // commandline flags belonging to the active experiments to |command_line|.
121 void ConvertFlagsToSwitches(FlagsStorage* flags_storage,
122 base::CommandLine* command_line,
123 SentinelsMode sentinels);
125 // Compares a set of switches of the two provided command line objects and
126 // returns true if they are the same and false otherwise.
127 // If |out_difference| is not NULL, it's filled with set_symmetric_difference
128 // between sets.
129 bool AreSwitchesIdenticalToCurrentCommandLine(
130 const base::CommandLine& new_cmdline,
131 const base::CommandLine& active_cmdline,
132 std::set<CommandLine::StringType>* out_difference);
134 // Differentiate between generic flags available on a per session base and flags
135 // that influence the whole machine and can be said by the admin only. This flag
136 // is relevant for ChromeOS for now only and dictates whether entries marked
137 // with the |kOsCrOSOwnerOnly| label should be enabled in the UI or not.
138 enum FlagAccess { kGeneralAccessFlagsOnly, kOwnerAccessToFlags };
140 // Get the list of experiments. Experiments that are available on the current
141 // platform are appended to |supported_experiments|; all other experiments are
142 // appended to |unsupported_experiments|.
143 void GetFlagsExperimentsData(FlagsStorage* flags_storage,
144 FlagAccess access,
145 base::ListValue* supported_experiments,
146 base::ListValue* unsupported_experiments);
148 // Returns true if one of the experiment flags has been flipped since startup.
149 bool IsRestartNeededToCommitChanges();
151 // Enables or disables the experiment with id |internal_name|.
152 void SetExperimentEnabled(FlagsStorage* flags_storage,
153 const std::string& internal_name,
154 bool enable);
156 // Removes all switches that were added to a command line by a previous call to
157 // |ConvertFlagsToSwitches()|.
158 void RemoveFlagsSwitches(
159 std::map<std::string, base::CommandLine::StringType>* switch_list);
161 // Reset all flags to the default state by clearing all flags.
162 void ResetAllFlags(FlagsStorage* flags_storage);
164 // Returns the value for the current platform. This is one of the values defined
165 // by the OS enum above.
166 // This is exposed only for testing.
167 int GetCurrentPlatform();
169 // Sends UMA stats about experimental flag usage. This should be called once per
170 // startup.
171 void RecordUMAStatistics(FlagsStorage* flags_storage);
173 // Returns the UMA id for the specified switch name.
174 uint32_t GetSwitchUMAId(const std::string& switch_name);
176 // Sends stats (as UMA histogram) about command_line_difference.
177 // This is used on ChromeOS to report flags that lead to browser restart.
178 // |command_line_difference| is the result of
179 // AreSwitchesIdenticalToCurrentCommandLine().
180 void ReportCustomFlags(const std::string& uma_histogram_hame,
181 const std::set<std::string>& command_line_difference);
183 namespace testing {
185 // Clears internal global state, for unit tests.
186 void ClearState();
188 // Sets the list of experiments. Pass in NULL to use the default set. This does
189 // NOT take ownership of the supplied Experiments.
190 void SetExperiments(const Experiment* e, size_t count);
192 // Returns the current set of experiments.
193 const Experiment* GetExperiments(size_t* count);
195 // Separator used for multi values. Multi values are represented in prefs as
196 // name-of-experiment + kMultiSeparator + selected_index.
197 extern const char kMultiSeparator[];
199 } // namespace testing
201 } // namespace about_flags
203 #endif // CHROME_BROWSER_ABOUT_FLAGS_H_