| 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 | 17 |
| 18 class PrefService; | 18 class PrefService; |
| 19 | 19 |
| 20 namespace base { | 20 namespace base { |
| 21 class ListValue; | 21 class ListValue; |
| 22 } | 22 } |
| 23 | 23 |
| 24 namespace flags_ui { | 24 namespace flags_ui { |
| 25 class FlagsStorage; | 25 class FlagsStorage; |
| 26 } | 26 } |
| 27 | 27 |
| 28 namespace about_flags { | 28 namespace about_flags { |
| 29 | 29 |
| 30 // Experiment is used internally by about_flags to describe an experiment (and | 30 // FeatureEntry is used by about_flags to describe an experimental feature. |
| 31 // for testing). | 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 // |
| 32 // This is exposed only for testing. | 36 // This is exposed only for testing. |
| 33 struct Experiment { | 37 struct FeatureEntry { |
| 34 enum Type { | 38 enum Type { |
| 35 // An experiment with a single value. This is typically what you want. | 39 // A feature with a single flag value. This is typically what you want. |
| 36 SINGLE_VALUE, | 40 SINGLE_VALUE, |
| 37 | 41 |
| 38 // A default enabled experiment with a single value to disable it. This is | 42 // A default enabled feature with a single flag value to disable it. Please |
| 39 // for default enabled SINGLE_VALUE experiments. Please consider whether | 43 // consider whether you really need a flag to disable the feature, and even |
| 40 // you really need a flag to disable the experiment, and even if so remove | 44 // if so remove the disable flag as soon as it is no longer needed. |
| 41 // the disable flag as soon as it is no longer needed. | |
| 42 SINGLE_DISABLE_VALUE, | 45 SINGLE_DISABLE_VALUE, |
| 43 | 46 |
| 44 // The experiment has multiple values only one of which is ever enabled. | 47 // The feature has multiple values only one of which is ever enabled. |
| 45 // The first of the values should correspond to a deactivated state for this | 48 // 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 | 49 // feature (i.e. no command line option). For MULTI_VALUE entries, the |
| 47 // command_line of the Experiment is not used. If the experiment is enabled | 50 // command_line of the FeatureEntry is not used. If the experiment is |
| 48 // the command line of the selected Choice is enabled. | 51 // enabled the command line of the selected Choice is enabled. |
| 49 MULTI_VALUE, | 52 MULTI_VALUE, |
| 50 | 53 |
| 51 // The experiment has three possible values: Default, Enabled and Disabled. | 54 // The feature has three possible values: Default, Enabled and Disabled. |
| 52 // This should be used for experiments that may have their own logic to | 55 // This should be used for features that may have their own logic to decide |
| 53 // decide if the feature should be on when not explicitly specified via | 56 // if the feature should be on when not explicitly specified via about |
| 54 // about flags - for example via FieldTrials. | 57 // flags - for example via FieldTrials. |
| 55 ENABLE_DISABLE_VALUE, | 58 ENABLE_DISABLE_VALUE, |
| 56 }; | 59 }; |
| 57 | 60 |
| 58 // Used for MULTI_VALUE types to describe one of the possible values the user | 61 // Used for MULTI_VALUE types to describe one of the possible values the user |
| 59 // can select. | 62 // can select. |
| 60 struct Choice { | 63 struct Choice { |
| 61 // ID of the message containing the choice name. | 64 // ID of the message containing the choice name. |
| 62 int description_id; | 65 int description_id; |
| 63 | 66 |
| 64 // Command line switch and value to enabled for this choice. | 67 // Command line switch and value to enabled for this choice. |
| 65 const char* command_line_switch; | 68 const char* command_line_switch; |
| 66 // Simple switches that have no value should use "" for command_line_value. | 69 // Simple switches that have no value should use "" for command_line_value. |
| 67 const char* command_line_value; | 70 const char* command_line_value; |
| 68 }; | 71 }; |
| 69 | 72 |
| 70 // The internal name of the experiment. This is never shown to the user. | 73 // The internal name of the feature entry. This is never shown to the user. |
| 71 // It _is_ however stored in the prefs file, so you shouldn't change the | 74 // It _is_ however stored in the prefs file, so you shouldn't change the |
| 72 // name of existing flags. | 75 // name of existing flags. |
| 73 const char* internal_name; | 76 const char* internal_name; |
| 74 | 77 |
| 75 // String id of the message containing the experiment's name. | 78 // String id of the message containing the feature's name. |
| 76 int visible_name_id; | 79 int visible_name_id; |
| 77 | 80 |
| 78 // String id of the message containing the experiment's description. | 81 // String id of the message containing the feature's description. |
| 79 int visible_description_id; | 82 int visible_description_id; |
| 80 | 83 |
| 81 // The platforms the experiment is available on | 84 // The platforms the feature is available on. |
| 82 // Needs to be more than a compile-time #ifdef because of profile sync. | 85 // Needs to be more than a compile-time #ifdef because of profile sync. |
| 83 unsigned supported_platforms; // bitmask | 86 unsigned supported_platforms; // bitmask |
| 84 | 87 |
| 85 // Type of experiment. | 88 // Type of entry. |
| 86 Type type; | 89 Type type; |
| 87 | 90 |
| 88 // The commandline switch and value that are added when this flag is active. | 91 // 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 | 92 // This is different from |internal_name| so that the commandline flag can be |
| 90 // renamed without breaking the prefs file. | 93 // renamed without breaking the prefs file. |
| 91 // This is used if type is SINGLE_VALUE or ENABLE_DISABLE_VALUE. | 94 // This is used if type is SINGLE_VALUE or ENABLE_DISABLE_VALUE. |
| 92 const char* command_line_switch; | 95 const char* command_line_switch; |
| 93 // Simple switches that have no value should use "" for command_line_value. | 96 // Simple switches that have no value should use "" for command_line_value. |
| 94 const char* command_line_value; | 97 const char* command_line_value; |
| 95 | 98 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 109 std::string NameForChoice(int index) const; | 112 std::string NameForChoice(int index) const; |
| 110 | 113 |
| 111 // Returns the human readable description for the choice at |index|. | 114 // Returns the human readable description for the choice at |index|. |
| 112 base::string16 DescriptionForChoice(int index) const; | 115 base::string16 DescriptionForChoice(int index) const; |
| 113 }; | 116 }; |
| 114 | 117 |
| 115 // A flag controlling the behavior of the |ConvertFlagsToSwitches| function - | 118 // A flag controlling the behavior of the |ConvertFlagsToSwitches| function - |
| 116 // whether it should add the sentinel switches around flags. | 119 // whether it should add the sentinel switches around flags. |
| 117 enum SentinelsMode { kNoSentinels, kAddSentinels }; | 120 enum SentinelsMode { kNoSentinels, kAddSentinels }; |
| 118 | 121 |
| 119 // Reads the Labs |prefs| (called "Labs" for historical reasons) and adds the | 122 // Reads the state from |flags_storage| and adds the command line flags |
| 120 // commandline flags belonging to the active experiments to |command_line|. | 123 // belonging to the active feature entries to |command_line|. |
| 121 void ConvertFlagsToSwitches(flags_ui::FlagsStorage* flags_storage, | 124 void ConvertFlagsToSwitches(flags_ui::FlagsStorage* flags_storage, |
| 122 base::CommandLine* command_line, | 125 base::CommandLine* command_line, |
| 123 SentinelsMode sentinels); | 126 SentinelsMode sentinels); |
| 124 | 127 |
| 125 // Compares a set of switches of the two provided command line objects and | 128 // Compares a set of switches of the two provided command line objects and |
| 126 // returns true if they are the same and false otherwise. | 129 // returns true if they are the same and false otherwise. |
| 127 // If |out_difference| is not NULL, it's filled with set_symmetric_difference | 130 // If |out_difference| is not NULL, it's filled with set_symmetric_difference |
| 128 // between sets. | 131 // between sets. |
| 129 bool AreSwitchesIdenticalToCurrentCommandLine( | 132 bool AreSwitchesIdenticalToCurrentCommandLine( |
| 130 const base::CommandLine& new_cmdline, | 133 const base::CommandLine& new_cmdline, |
| 131 const base::CommandLine& active_cmdline, | 134 const base::CommandLine& active_cmdline, |
| 132 std::set<base::CommandLine::StringType>* out_difference); | 135 std::set<base::CommandLine::StringType>* out_difference); |
| 133 | 136 |
| 134 // Differentiate between generic flags available on a per session base and flags | 137 // 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 | 138 // 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 | 139 // 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. | 140 // with the |kOsCrOSOwnerOnly| label should be enabled in the UI or not. |
| 138 enum FlagAccess { kGeneralAccessFlagsOnly, kOwnerAccessToFlags }; | 141 enum FlagAccess { kGeneralAccessFlagsOnly, kOwnerAccessToFlags }; |
| 139 | 142 |
| 140 // Get the list of experiments. Experiments that are available on the current | 143 // Gets the list of feature entries. Entries that are available for the current |
| 141 // platform are appended to |supported_experiments|; all other experiments are | 144 // platform are appended to |supported_entries|; all other entries are appended |
| 142 // appended to |unsupported_experiments|. | 145 // to |unsupported_entries|. |
| 143 void GetFlagsExperimentsData(flags_ui::FlagsStorage* flags_storage, | 146 void GetFlagFeatureEntries(flags_ui::FlagsStorage* flags_storage, |
| 144 FlagAccess access, | 147 FlagAccess access, |
| 145 base::ListValue* supported_experiments, | 148 base::ListValue* supported_entries, |
| 146 base::ListValue* unsupported_experiments); | 149 base::ListValue* unsupported_entries); |
| 147 | 150 |
| 148 // Returns true if one of the experiment flags has been flipped since startup. | 151 // Returns true if one of the feature entry flags has been flipped since |
| 152 // startup. |
| 149 bool IsRestartNeededToCommitChanges(); | 153 bool IsRestartNeededToCommitChanges(); |
| 150 | 154 |
| 151 // Enables or disables the experiment with id |internal_name|. | 155 // Enables or disables the current with id |internal_name|. |
| 152 void SetExperimentEnabled(flags_ui::FlagsStorage* flags_storage, | 156 void SetFeatureEntryEnabled(flags_ui::FlagsStorage* flags_storage, |
| 153 const std::string& internal_name, | 157 const std::string& internal_name, |
| 154 bool enable); | 158 bool enable); |
| 155 | 159 |
| 156 // Removes all switches that were added to a command line by a previous call to | 160 // Removes all switches that were added to a command line by a previous call to |
| 157 // |ConvertFlagsToSwitches()|. | 161 // |ConvertFlagsToSwitches()|. |
| 158 void RemoveFlagsSwitches( | 162 void RemoveFlagsSwitches( |
| 159 std::map<std::string, base::CommandLine::StringType>* switch_list); | 163 std::map<std::string, base::CommandLine::StringType>* switch_list); |
| 160 | 164 |
| 161 // Reset all flags to the default state by clearing all flags. | 165 // Reset all flags to the default state by clearing all flags. |
| 162 void ResetAllFlags(flags_ui::FlagsStorage* flags_storage); | 166 void ResetAllFlags(flags_ui::FlagsStorage* flags_storage); |
| 163 | 167 |
| 164 // Returns the value for the current platform. This is one of the values defined | 168 // Returns the value for the current platform. This is one of the values defined |
| (...skipping 13 matching lines...) Expand all Loading... |
| 178 // |command_line_difference| is the result of | 182 // |command_line_difference| is the result of |
| 179 // AreSwitchesIdenticalToCurrentCommandLine(). | 183 // AreSwitchesIdenticalToCurrentCommandLine(). |
| 180 void ReportCustomFlags(const std::string& uma_histogram_hame, | 184 void ReportCustomFlags(const std::string& uma_histogram_hame, |
| 181 const std::set<std::string>& command_line_difference); | 185 const std::set<std::string>& command_line_difference); |
| 182 | 186 |
| 183 namespace testing { | 187 namespace testing { |
| 184 | 188 |
| 185 // Clears internal global state, for unit tests. | 189 // Clears internal global state, for unit tests. |
| 186 void ClearState(); | 190 void ClearState(); |
| 187 | 191 |
| 188 // Sets the list of experiments. Pass in NULL to use the default set. This does | 192 // Sets the list of feature entries. Pass in null to use the default set. This |
| 189 // NOT take ownership of the supplied Experiments. | 193 // does NOT take ownership of the supplied |entries|. |
| 190 void SetExperiments(const Experiment* e, size_t count); | 194 void SetFeatureEntries(const FeatureEntry* entries, size_t count); |
| 191 | 195 |
| 192 // Returns the current set of experiments. | 196 // Returns the current set of feature entries. |
| 193 const Experiment* GetExperiments(size_t* count); | 197 const FeatureEntry* GetFeatureEntries(size_t* count); |
| 194 | 198 |
| 195 // Separator used for multi values. Multi values are represented in prefs as | 199 // Separator used for multi values. Multi values are represented in prefs as |
| 196 // name-of-experiment + kMultiSeparator + selected_index. | 200 // name-of-experiment + kMultiSeparator + selected_index. |
| 197 extern const char kMultiSeparator[]; | 201 extern const char kMultiSeparator[]; |
| 198 | 202 |
| 199 // This value is reported as switch histogram ID if switch name has unknown | 203 // This value is reported as switch histogram ID if switch name has unknown |
| 200 // format. | 204 // format. |
| 201 extern const base::HistogramBase::Sample kBadSwitchFormatHistogramId; | 205 extern const base::HistogramBase::Sample kBadSwitchFormatHistogramId; |
| 202 | 206 |
| 203 } // namespace testing | 207 } // namespace testing |
| 204 | 208 |
| 205 } // namespace about_flags | 209 } // namespace about_flags |
| 206 | 210 |
| 207 #endif // CHROME_BROWSER_ABOUT_FLAGS_H_ | 211 #endif // CHROME_BROWSER_ABOUT_FLAGS_H_ |
| OLD | NEW |