| 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 <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/string16.h" |
| 12 | 13 |
| 13 class PrefService; | 14 class PrefService; |
| 14 | 15 |
| 15 namespace base { | 16 namespace base { |
| 16 class ListValue; | 17 class ListValue; |
| 17 } | 18 } |
| 18 | 19 |
| 19 namespace about_flags { | 20 namespace about_flags { |
| 20 | 21 |
| 21 // Enumeration of OSs. | 22 // Enumeration of OSs. |
| 22 // This is exposed only for testing. | 23 // This is exposed only for testing. |
| 23 enum { kOsMac = 1 << 0, kOsWin = 1 << 1, kOsLinux = 1 << 2 , kOsCrOS = 1 << 3, | 24 enum { kOsMac = 1 << 0, kOsWin = 1 << 1, kOsLinux = 1 << 2 , kOsCrOS = 1 << 3, |
| 24 kOsAndroid = 1 << 4 }; | 25 kOsAndroid = 1 << 4 }; |
| 25 | 26 |
| 26 // Experiment is used internally by about_flags to describe an experiment (and | 27 // Experiment is used internally by about_flags to describe an experiment (and |
| 27 // for testing). | 28 // for testing). |
| 28 // This is exposed only for testing. | 29 // This is exposed only for testing. |
| 29 struct Experiment { | 30 struct Experiment { |
| 30 enum Type { | 31 enum Type { |
| 31 // An experiment with a single value. This is typically what you want. | 32 // An experiment with a single value. This is typically what you want. |
| 32 SINGLE_VALUE, | 33 SINGLE_VALUE, |
| 33 | 34 |
| 34 // The experiment has multiple values only one of which is ever enabled. | 35 // The experiment has multiple values only one of which is ever enabled. |
| 35 // The first of the values should correspond to a deactivated state for this | 36 // The first of the values should correspond to a deactivated state for this |
| 36 // lab (i.e. no command line option). For MULTI_VALUE experiments the | 37 // lab (i.e. no command line option). For MULTI_VALUE experiments the |
| 37 // command_line of the Experiment is not used. If the experiment is enabled | 38 // command_line of the Experiment is not used. If the experiment is enabled |
| 38 // the command line of the selected Choice is enabled. | 39 // the command line of the selected Choice is enabled. |
| 39 MULTI_VALUE, | 40 MULTI_VALUE, |
| 41 |
| 42 // The experiment has three possible values: Default, Enabled and Disabled. |
| 43 // This should be used for experiments that may have their own logic to |
| 44 // decide if the feature should be on when not explicitly specified via |
| 45 // about flags - for example via FieldTrials. |
| 46 ENABLE_DISABLE_VALUE, |
| 40 }; | 47 }; |
| 41 | 48 |
| 42 // Used for MULTI_VALUE types to describe one of the possible values the user | 49 // Used for MULTI_VALUE types to describe one of the possible values the user |
| 43 // can select. | 50 // can select. |
| 44 struct Choice { | 51 struct Choice { |
| 45 // ID of the message containing the choice name. | 52 // ID of the message containing the choice name. |
| 46 int description_id; | 53 int description_id; |
| 47 | 54 |
| 48 // Command line switch and value to enabled for this choice. | 55 // Command line switch and value to enabled for this choice. |
| 49 const char* command_line_switch; | 56 const char* command_line_switch; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 62 // String id of the message containing the experiment's description. | 69 // String id of the message containing the experiment's description. |
| 63 int visible_description_id; | 70 int visible_description_id; |
| 64 | 71 |
| 65 // The platforms the experiment is available on | 72 // The platforms the experiment is available on |
| 66 // Needs to be more than a compile-time #ifdef because of profile sync. | 73 // Needs to be more than a compile-time #ifdef because of profile sync. |
| 67 unsigned supported_platforms; // bitmask | 74 unsigned supported_platforms; // bitmask |
| 68 | 75 |
| 69 // Type of experiment. | 76 // Type of experiment. |
| 70 Type type; | 77 Type type; |
| 71 | 78 |
| 72 // The commandline switch and value that are added when this lab is active. | 79 // The commandline switch and value that are added when this flag is active. |
| 73 // This is different from |internal_name| so that the commandline flag can be | 80 // This is different from |internal_name| so that the commandline flag can be |
| 74 // renamed without breaking the prefs file. | 81 // renamed without breaking the prefs file. |
| 75 // This is used if type is SINGLE_VALUE. | 82 // This is used if type is SINGLE_VALUE or ENABLE_DISABLE_VALUE. |
| 76 const char* command_line_switch; | 83 const char* command_line_switch; |
| 77 // Simple switches that have no value should use "" for command_line_value. | 84 // Simple switches that have no value should use "" for command_line_value. |
| 78 const char* command_line_value; | 85 const char* command_line_value; |
| 79 | 86 |
| 87 // For ENABLE_DISABLE_VALUE, the command line switch and value to explictly |
| 88 // disable the feature. |
| 89 const char* disable_command_line_switch; |
| 90 const char* disable_command_line_value; |
| 91 |
| 80 // This is used if type is MULTI_VALUE. | 92 // This is used if type is MULTI_VALUE. |
| 81 const Choice* choices; | 93 const Choice* choices; |
| 82 | 94 |
| 83 // Number of |choices|. | 95 // Number of |choices|. |
| 84 // This is used if type is MULTI_VALUE. | 96 // This is used if type is MULTI_VALUE. |
| 85 int num_choices; | 97 int num_choices; |
| 98 |
| 99 // Returns the name used in prefs for the choice at the specified |index|. |
| 100 std::string NameForChoice(int index) const; |
| 101 |
| 102 // Returns the human readable description for the choice at |index|. |
| 103 string16 DescriptionForChoice(int index) const; |
| 86 }; | 104 }; |
| 87 | 105 |
| 88 // Reads the Labs |prefs| (called "Labs" for historical reasons) and adds the | 106 // Reads the Labs |prefs| (called "Labs" for historical reasons) and adds the |
| 89 // commandline flags belonging to the active experiments to |command_line|. | 107 // commandline flags belonging to the active experiments to |command_line|. |
| 90 void ConvertFlagsToSwitches(PrefService* prefs, CommandLine* command_line); | 108 void ConvertFlagsToSwitches(PrefService* prefs, CommandLine* command_line); |
| 91 | 109 |
| 92 // Get a list of all available experiments. The caller owns the result. | 110 // Get a list of all available experiments. The caller owns the result. |
| 93 base::ListValue* GetFlagsExperimentsData(PrefService* prefs); | 111 base::ListValue* GetFlagsExperimentsData(PrefService* prefs); |
| 94 | 112 |
| 95 // Returns true if one of the experiment flags has been flipped since startup. | 113 // Returns true if one of the experiment flags has been flipped since startup. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 110 // Returns the value for the current platform. This is one of the values defined | 128 // Returns the value for the current platform. This is one of the values defined |
| 111 // by the OS enum above. | 129 // by the OS enum above. |
| 112 // This is exposed only for testing. | 130 // This is exposed only for testing. |
| 113 int GetCurrentPlatform(); | 131 int GetCurrentPlatform(); |
| 114 | 132 |
| 115 // Sends UMA stats about experimental flag usage. This should be called once per | 133 // Sends UMA stats about experimental flag usage. This should be called once per |
| 116 // startup. | 134 // startup. |
| 117 void RecordUMAStatistics(const PrefService* prefs); | 135 void RecordUMAStatistics(const PrefService* prefs); |
| 118 | 136 |
| 119 namespace testing { | 137 namespace testing { |
| 138 |
| 120 // Clears internal global state, for unit tests. | 139 // Clears internal global state, for unit tests. |
| 121 void ClearState(); | 140 void ClearState(); |
| 122 | 141 |
| 123 // Sets the list of experiments. Pass in NULL to use the default set. This does | 142 // Sets the list of experiments. Pass in NULL to use the default set. This does |
| 124 // NOT take ownership of the supplied Experiments. | 143 // NOT take ownership of the supplied Experiments. |
| 125 void SetExperiments(const Experiment* e, size_t count); | 144 void SetExperiments(const Experiment* e, size_t count); |
| 126 | 145 |
| 127 // Returns the current set of experiments. | 146 // Returns the current set of experiments. |
| 128 const Experiment* GetExperiments(size_t* count); | 147 const Experiment* GetExperiments(size_t* count); |
| 129 | 148 |
| 130 // Separator used for multi values. Multi values are represented in prefs as | 149 // Separator used for multi values. Multi values are represented in prefs as |
| 131 // name-of-experiment + kMultiSeparator + selected_index. | 150 // name-of-experiment + kMultiSeparator + selected_index. |
| 132 extern const char kMultiSeparator[]; | 151 extern const char kMultiSeparator[]; |
| 133 | 152 |
| 134 } // namespace testing | 153 } // namespace testing |
| 135 | 154 |
| 136 } // namespace about_flags | 155 } // namespace about_flags |
| 137 | 156 |
| 138 #endif // CHROME_BROWSER_ABOUT_FLAGS_H_ | 157 #endif // CHROME_BROWSER_ABOUT_FLAGS_H_ |
| OLD | NEW |