[email protected] | 3828d6f | 2011-02-24 18:32:21 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 5 | #include "chrome/browser/about_flags.h" |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 6 | |
| 7 | #include <algorithm> |
| 8 | #include <iterator> |
| 9 | #include <map> |
| 10 | #include <set> |
| 11 | |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 12 | #include "base/command_line.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 13 | #include "base/memory/singleton.h" |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 14 | #include "base/string_number_conversions.h" |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 15 | #include "base/values.h" |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 16 | #include "chrome/browser/prefs/pref_service.h" |
[email protected] | 1bc7842 | 2011-03-31 08:41:38 | [diff] [blame] | 17 | #include "chrome/browser/prefs/scoped_user_pref_update.h" |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 18 | #include "chrome/common/chrome_switches.h" |
| 19 | #include "chrome/common/pref_names.h" |
[email protected] | afd1e52 | 2011-04-27 23:29:59 | [diff] [blame] | 20 | #include "content/browser/user_metrics.h" |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 21 | #include "grit/generated_resources.h" |
[email protected] | c051a1b | 2011-01-21 23:30:17 | [diff] [blame] | 22 | #include "ui/base/l10n/l10n_util.h" |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 23 | |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 24 | namespace about_flags { |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 25 | |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 26 | // Macros to simplify specifying the type. |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 27 | #define SINGLE_VALUE_TYPE_AND_VALUE(command_line_switch, switch_value) \ |
| 28 | Experiment::SINGLE_VALUE, command_line_switch, switch_value, NULL, 0 |
| 29 | #define SINGLE_VALUE_TYPE(command_line_switch) \ |
| 30 | SINGLE_VALUE_TYPE_AND_VALUE(command_line_switch, "") |
| 31 | #define MULTI_VALUE_TYPE(choices) \ |
[email protected] | 0e6f56d | 2011-02-12 23:45:15 | [diff] [blame] | 32 | Experiment::MULTI_VALUE, "", "", choices, arraysize(choices) |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 33 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 34 | namespace { |
| 35 | |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 36 | const unsigned kOsAll = kOsMac | kOsWin | kOsLinux | kOsCrOS; |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 37 | |
[email protected] | ba816424 | 2010-11-16 21:31:00 | [diff] [blame] | 38 | // Names for former Chrome OS Labs experiments, shared with prefs migration |
| 39 | // code. |
| 40 | const char kMediaPlayerExperimentName[] = "media-player"; |
| 41 | const char kAdvancedFileSystemExperimentName[] = "advanced-file-system"; |
| 42 | const char kVerticalTabsExperimentName[] = "vertical-tabs"; |
| 43 | |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 44 | // RECORDING USER METRICS FOR FLAGS: |
| 45 | // ----------------------------------------------------------------------------- |
| 46 | // The first line of the experiment is the internal name. If you'd like to |
| 47 | // gather statistics about the usage of your flag, you should append a marker |
| 48 | // comment to the end of the feature name, like so: |
| 49 | // "my-special-feature", // FLAGS:RECORD_UMA |
| 50 | // |
| 51 | // After doing that, run //chrome/tools/extract_actions.py (see instructions at |
| 52 | // the top of that file for details) to update the chromeactions.txt file, which |
| 53 | // will enable UMA to record your feature flag. |
| 54 | // |
| 55 | // After your feature has shipped under a flag, you can locate the metrics |
| 56 | // under the action name AboutFlags_internal-action-name. Actions are recorded |
| 57 | // once per startup, so you should divide this number by AboutFlags_StartupTick |
| 58 | // to get a sense of usage. Note that this will not be the same as number of |
| 59 | // users with a given feature enabled because users can quit and relaunch |
| 60 | // the application multiple times over a given time interval. |
| 61 | // TODO(rsesek): See if there's a way to count per-user, rather than |
| 62 | // per-startup. |
| 63 | |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 64 | // To add a new experiment add to the end of kExperiments. There are two |
| 65 | // distinct types of experiments: |
| 66 | // . SINGLE_VALUE: experiment is either on or off. Use the SINGLE_VALUE_TYPE |
| 67 | // macro for this type supplying the command line to the macro. |
[email protected] | 28e35af | 2011-02-09 12:56:22 | [diff] [blame] | 68 | // . MULTI_VALUE: a list of choices, the first of which should correspond to a |
| 69 | // deactivated state for this lab (i.e. no command line option). To specify |
| 70 | // this type of experiment use the macro MULTI_VALUE_TYPE supplying it the |
| 71 | // array of choices. |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 72 | // See the documentation of Experiment for details on the fields. |
| 73 | // |
| 74 | // When adding a new choice, add it to the end of the list. |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 75 | const Experiment kExperiments[] = { |
| 76 | { |
[email protected] | aac169d | 2011-03-18 19:53:03 | [diff] [blame] | 77 | "expose-for-tabs", // FLAGS:RECORD_UMA |
| 78 | IDS_FLAGS_TABPOSE_NAME, |
| 79 | IDS_FLAGS_TABPOSE_DESCRIPTION, |
| 80 | kOsMac, |
| 81 | #if defined(OS_MACOSX) |
| 82 | // The switch exists only on OS X. |
| 83 | SINGLE_VALUE_TYPE(switches::kEnableExposeForTabs) |
| 84 | #else |
| 85 | SINGLE_VALUE_TYPE("") |
| 86 | #endif |
| 87 | }, |
| 88 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 89 | "vertical-tabs", // FLAGS:RECORD_UMA |
[email protected] | 9486c1f | 2010-10-14 19:52:12 | [diff] [blame] | 90 | IDS_FLAGS_SIDE_TABS_NAME, |
| 91 | IDS_FLAGS_SIDE_TABS_DESCRIPTION, |
[email protected] | ba816424 | 2010-11-16 21:31:00 | [diff] [blame] | 92 | kOsWin | kOsCrOS, |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 93 | SINGLE_VALUE_TYPE(switches::kEnableVerticalTabs) |
[email protected] | 65415187 | 2010-09-13 22:43:05 | [diff] [blame] | 94 | }, |
| 95 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 96 | "remoting", // FLAGS:RECORD_UMA |
[email protected] | 9486c1f | 2010-10-14 19:52:12 | [diff] [blame] | 97 | IDS_FLAGS_REMOTING_NAME, |
[email protected] | d9959986 | 2011-01-20 22:43:59 | [diff] [blame] | 98 | IDS_FLAGS_REMOTING_DESCRIPTION, |
| 99 | kOsAll, |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 100 | SINGLE_VALUE_TYPE(switches::kEnableRemoting) |
[email protected] | 52fa2d5 | 2010-09-25 14:08:56 | [diff] [blame] | 101 | }, |
[email protected] | a6f0365 | 2010-09-28 15:59:07 | [diff] [blame] | 102 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 103 | "conflicting-modules-check", // FLAGS:RECORD_UMA |
[email protected] | c1bbaa8 | 2010-11-08 11:17:05 | [diff] [blame] | 104 | IDS_FLAGS_CONFLICTS_CHECK_NAME, |
| 105 | IDS_FLAGS_CONFLICTS_CHECK_DESCRIPTION, |
| 106 | kOsWin, |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 107 | SINGLE_VALUE_TYPE(switches::kConflictingModulesCheck) |
[email protected] | c1bbaa8 | 2010-11-08 11:17:05 | [diff] [blame] | 108 | }, |
| 109 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 110 | "cloud-print-proxy", // FLAGS:RECORD_UMA |
[email protected] | 9486c1f | 2010-10-14 19:52:12 | [diff] [blame] | 111 | IDS_FLAGS_CLOUD_PRINT_PROXY_NAME, |
| 112 | IDS_FLAGS_CLOUD_PRINT_PROXY_DESCRIPTION, |
[email protected] | fa6d2a2f | 2010-11-30 21:47:19 | [diff] [blame] | 113 | #if defined(GOOGLE_CHROME_BUILD) |
[email protected] | 9f8872b3 | 2011-03-04 19:44:45 | [diff] [blame] | 114 | // For a Chrome build, we know we have a PDF plug-in on Windows, so it's |
[email protected] | be51dd25 | 2011-03-05 00:23:44 | [diff] [blame] | 115 | // fully enabled. Linux still need some final polish. |
| 116 | kOsLinux, |
[email protected] | fa6d2a2f | 2010-11-30 21:47:19 | [diff] [blame] | 117 | #else |
[email protected] | be51dd25 | 2011-03-05 00:23:44 | [diff] [blame] | 118 | // Otherwise, where we know Windows could be working if a viable PDF |
| 119 | // plug-in could be supplied, we'll keep the lab enabled. Mac always has |
| 120 | // PDF rasterization available, so no flag needed there. |
| 121 | kOsWin | kOsLinux, |
[email protected] | fa6d2a2f | 2010-11-30 21:47:19 | [diff] [blame] | 122 | #endif |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 123 | SINGLE_VALUE_TYPE(switches::kEnableCloudPrintProxy) |
[email protected] | 8b6588a | 2010-10-12 02:39:42 | [diff] [blame] | 124 | }, |
[email protected] | 580939a | 2010-10-12 18:54:37 | [diff] [blame] | 125 | { |
[email protected] | bb46153 | 2010-11-26 21:50:23 | [diff] [blame] | 126 | "crxless-web-apps", |
| 127 | IDS_FLAGS_CRXLESS_WEB_APPS_NAME, |
| 128 | IDS_FLAGS_CRXLESS_WEB_APPS_DESCRIPTION, |
| 129 | kOsAll, |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 130 | SINGLE_VALUE_TYPE(switches::kEnableCrxlessWebApps) |
[email protected] | bb46153 | 2010-11-26 21:50:23 | [diff] [blame] | 131 | }, |
| 132 | { |
[email protected] | 96c6f4c | 2011-05-18 19:36:22 | [diff] [blame^] | 133 | "ignore-gpu-blacklist", |
| 134 | IDS_FLAGS_IGNORE_GPU_BLACKLIST_NAME, |
| 135 | IDS_FLAGS_IGNORE_GPU_BLACKLIST_DESCRIPTION, |
| 136 | kOsAll, |
| 137 | SINGLE_VALUE_TYPE(switches::kIgnoreGpuBlacklist) |
| 138 | }, |
| 139 | { |
| 140 | "force-compositing-mode", |
| 141 | IDS_FLAGS_FORCE_COMPOSITING_MODE_NAME, |
| 142 | IDS_FLAGS_FORCE_COMPOSITING_MODE_DESCRIPTION, |
| 143 | kOsAll, |
| 144 | SINGLE_VALUE_TYPE(switches::kForceCompositingMode) |
| 145 | }, |
| 146 | { |
[email protected] | 5963b77 | 2011-02-09 22:55:38 | [diff] [blame] | 147 | "composited-layer-borders", |
| 148 | IDS_FLAGS_COMPOSITED_LAYER_BORDERS, |
| 149 | IDS_FLAGS_COMPOSITED_LAYER_BORDERS_DESCRIPTION, |
| 150 | kOsAll, |
| 151 | SINGLE_VALUE_TYPE(switches::kShowCompositedLayerBorders) |
| 152 | }, |
| 153 | { |
[email protected] | a8f1eaa | 2011-03-07 19:00:58 | [diff] [blame] | 154 | "show-fps-counter", |
| 155 | IDS_FLAGS_SHOW_FPS_COUNTER, |
| 156 | IDS_FLAGS_SHOW_FPS_COUNTER_DESCRIPTION, |
| 157 | kOsAll, |
| 158 | SINGLE_VALUE_TYPE(switches::kShowFPSCounter) |
| 159 | }, |
| 160 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 161 | "gpu-canvas-2d", // FLAGS:RECORD_UMA |
[email protected] | 9486c1f | 2010-10-14 19:52:12 | [diff] [blame] | 162 | IDS_FLAGS_ACCELERATED_CANVAS_2D_NAME, |
| 163 | IDS_FLAGS_ACCELERATED_CANVAS_2D_DESCRIPTION, |
[email protected] | 1af1dfe | 2010-10-19 23:49:14 | [diff] [blame] | 164 | kOsWin | kOsLinux | kOsCrOS, |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 165 | SINGLE_VALUE_TYPE(switches::kEnableAccelerated2dCanvas) |
[email protected] | 8d260e5 | 2010-10-13 01:03:05 | [diff] [blame] | 166 | }, |
[email protected] | 38e4681 | 2011-05-09 20:49:22 | [diff] [blame] | 167 | #if !defined(GOOGLE_CHROME_BUILD) |
| 168 | // Only expose this for Chromium builds where users may not have the PDF |
| 169 | // plugin. Do not give Google Chrome users the option to disable it here. |
[email protected] | 8d260e5 | 2010-10-13 01:03:05 | [diff] [blame] | 170 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 171 | "print-preview", // FLAGS:RECORD_UMA |
[email protected] | 9486c1f | 2010-10-14 19:52:12 | [diff] [blame] | 172 | IDS_FLAGS_PRINT_PREVIEW_NAME, |
| 173 | IDS_FLAGS_PRINT_PREVIEW_DESCRIPTION, |
[email protected] | 38e4681 | 2011-05-09 20:49:22 | [diff] [blame] | 174 | kOsMac | kOsWin | kOsLinux, // This switch is not available in CrOS. |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 175 | SINGLE_VALUE_TYPE(switches::kEnablePrintPreview) |
[email protected] | 2fe15fcb | 2010-10-21 20:39:53 | [diff] [blame] | 176 | }, |
[email protected] | 38e4681 | 2011-05-09 20:49:22 | [diff] [blame] | 177 | #endif |
[email protected] | 2fe15fcb | 2010-10-21 20:39:53 | [diff] [blame] | 178 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 179 | "enable-nacl", // FLAGS:RECORD_UMA |
[email protected] | 4ff87d20 | 2010-11-06 01:28:40 | [diff] [blame] | 180 | IDS_FLAGS_ENABLE_NACL_NAME, |
| 181 | IDS_FLAGS_ENABLE_NACL_DESCRIPTION, |
| 182 | kOsAll, |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 183 | SINGLE_VALUE_TYPE(switches::kEnableNaCl) |
[email protected] | 4ff87d20 | 2010-11-06 01:28:40 | [diff] [blame] | 184 | }, |
| 185 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 186 | "dns-server", // FLAGS:RECORD_UMA |
[email protected] | 2fe15fcb | 2010-10-21 20:39:53 | [diff] [blame] | 187 | IDS_FLAGS_DNS_SERVER_NAME, |
| 188 | IDS_FLAGS_DNS_SERVER_DESCRIPTION, |
| 189 | kOsLinux, |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 190 | SINGLE_VALUE_TYPE(switches::kDnsServer) |
[email protected] | 2fe15fcb | 2010-10-21 20:39:53 | [diff] [blame] | 191 | }, |
[email protected] | 177aceb | 2010-11-03 16:17:41 | [diff] [blame] | 192 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 193 | "extension-apis", // FLAGS:RECORD_UMA |
[email protected] | 11dd68cd5 | 2010-11-12 01:15:32 | [diff] [blame] | 194 | IDS_FLAGS_EXPERIMENTAL_EXTENSION_APIS_NAME, |
| 195 | IDS_FLAGS_EXPERIMENTAL_EXTENSION_APIS_DESCRIPTION, |
| 196 | kOsAll, |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 197 | SINGLE_VALUE_TYPE(switches::kEnableExperimentalExtensionApis) |
[email protected] | 11dd68cd5 | 2010-11-12 01:15:32 | [diff] [blame] | 198 | }, |
[email protected] | 3627b06d | 2010-11-12 16:36:16 | [diff] [blame] | 199 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 200 | "click-to-play", // FLAGS:RECORD_UMA |
[email protected] | 3627b06d | 2010-11-12 16:36:16 | [diff] [blame] | 201 | IDS_FLAGS_CLICK_TO_PLAY_NAME, |
| 202 | IDS_FLAGS_CLICK_TO_PLAY_DESCRIPTION, |
| 203 | kOsAll, |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 204 | SINGLE_VALUE_TYPE(switches::kEnableClickToPlay) |
[email protected] | 3627b06d | 2010-11-12 16:36:16 | [diff] [blame] | 205 | }, |
[email protected] | 80bd24e | 2010-11-30 09:34:38 | [diff] [blame] | 206 | { |
| 207 | "disable-hyperlink-auditing", |
| 208 | IDS_FLAGS_DISABLE_HYPERLINK_AUDITING_NAME, |
| 209 | IDS_FLAGS_DISABLE_HYPERLINK_AUDITING_DESCRIPTION, |
| 210 | kOsAll, |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 211 | SINGLE_VALUE_TYPE(switches::kNoPings) |
[email protected] | feb28fef | 2010-12-01 10:52:51 | [diff] [blame] | 212 | }, |
| 213 | { |
| 214 | "experimental-location-features", // FLAGS:RECORD_UMA |
| 215 | IDS_FLAGS_EXPERIMENTAL_LOCATION_FEATURES_NAME, |
| 216 | IDS_FLAGS_EXPERIMENTAL_LOCATION_FEATURES_DESCRIPTION, |
| 217 | kOsMac | kOsWin | kOsLinux, // Currently does nothing on CrOS. |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 218 | SINGLE_VALUE_TYPE(switches::kExperimentalLocationFeatures) |
| 219 | }, |
| 220 | { |
[email protected] | 4c6452d | 2011-01-12 08:47:57 | [diff] [blame] | 221 | "block-reading-third-party-cookies", |
| 222 | IDS_FLAGS_BLOCK_ALL_THIRD_PARTY_COOKIES_NAME, |
| 223 | IDS_FLAGS_BLOCK_ALL_THIRD_PARTY_COOKIES_DESCRIPTION, |
| 224 | kOsAll, |
| 225 | SINGLE_VALUE_TYPE(switches::kBlockReadingThirdPartyCookies) |
| 226 | }, |
[email protected] | 0422796 | 2011-01-20 02:03:09 | [diff] [blame] | 227 | { |
| 228 | "disable-interactive-form-validation", |
| 229 | IDS_FLAGS_DISABLE_INTERACTIVE_FORM_VALIDATION_NAME, |
| 230 | IDS_FLAGS_DISABLE_INTERACTIVE_FORM_VALIDATION_DESCRIPTION, |
| 231 | kOsAll, |
| 232 | SINGLE_VALUE_TYPE(switches::kDisableInteractiveFormValidation) |
| 233 | }, |
[email protected] | 8df5119 | 2011-01-22 20:05:03 | [diff] [blame] | 234 | { |
| 235 | "webaudio", |
| 236 | IDS_FLAGS_WEBAUDIO_NAME, |
| 237 | IDS_FLAGS_WEBAUDIO_DESCRIPTION, |
[email protected] | 54afa74 | 2011-04-29 21:21:34 | [diff] [blame] | 238 | // This switch is currently not available in CrOS. |
| 239 | // TODO(crogers): FFmpeg Windows DLLs need to be rebuilt for chromium. |
| 240 | #if defined(GOOGLE_CHROME_BUILD) |
| 241 | kOsMac | kOsWin | kOsLinux, |
| 242 | #else |
| 243 | kOsMac | kOsLinux, |
| 244 | #endif |
[email protected] | 8df5119 | 2011-01-22 20:05:03 | [diff] [blame] | 245 | SINGLE_VALUE_TYPE(switches::kEnableWebAudio) |
| 246 | }, |
[email protected] | 3828d6f | 2011-02-24 18:32:21 | [diff] [blame] | 247 | { |
[email protected] | 6c54e7e4 | 2011-03-02 20:52:34 | [diff] [blame] | 248 | "p2papi", |
| 249 | IDS_FLAGS_P2P_API_NAME, |
| 250 | IDS_FLAGS_P2P_API_DESCRIPTION, |
| 251 | kOsAll, |
[email protected] | a026daa | 2011-04-20 15:49:51 | [diff] [blame] | 252 | #if defined(ENABLE_P2P_APIS) |
[email protected] | 6c54e7e4 | 2011-03-02 20:52:34 | [diff] [blame] | 253 | SINGLE_VALUE_TYPE(switches::kEnableP2PApi) |
[email protected] | a026daa | 2011-04-20 15:49:51 | [diff] [blame] | 254 | #else |
| 255 | SINGLE_VALUE_TYPE("") |
| 256 | #endif |
[email protected] | 6c54e7e4 | 2011-03-02 20:52:34 | [diff] [blame] | 257 | }, |
[email protected] | 07d490bc | 2011-03-07 17:05:26 | [diff] [blame] | 258 | { |
| 259 | "focus-existing-tab-on-open", // FLAGS:RECORD_UMA |
| 260 | IDS_FLAGS_FOCUS_EXISTING_TAB_ON_OPEN_NAME, |
| 261 | IDS_FLAGS_FOCUS_EXISTING_TAB_ON_OPEN_DESCRIPTION, |
| 262 | kOsAll, |
| 263 | SINGLE_VALUE_TYPE(switches::kFocusExistingTabOnOpen) |
| 264 | }, |
[email protected] | d5dcfb3 | 2011-03-19 00:49:24 | [diff] [blame] | 265 | { |
[email protected] | ac86c98 | 2011-05-11 13:26:05 | [diff] [blame] | 266 | "compact-navigation", |
| 267 | IDS_FLAGS_ENABLE_COMPACT_NAVIGATION, |
| 268 | IDS_FLAGS_ENABLE_COMPACT_NAVIGATION_DESCRIPTION, |
| 269 | kOsWin, // TODO(stevet): Add other platforms when ready. |
| 270 | SINGLE_VALUE_TYPE(switches::kEnableCompactNavigation) |
| 271 | }, |
| 272 | { |
[email protected] | d5dcfb3 | 2011-03-19 00:49:24 | [diff] [blame] | 273 | "new-tab-page-4", |
| 274 | IDS_FLAGS_NEW_TAB_PAGE_4_NAME, |
| 275 | IDS_FLAGS_NEW_TAB_PAGE_4_DESCRIPTION, |
| 276 | kOsAll, |
| 277 | SINGLE_VALUE_TYPE(switches::kNewTabPage4) |
| 278 | }, |
[email protected] | 5aea186 | 2011-03-23 23:55:39 | [diff] [blame] | 279 | { |
| 280 | "tab-groups-context-menu", |
| 281 | IDS_FLAGS_TAB_GROUPS_CONTEXT_MENU_NAME, |
| 282 | IDS_FLAGS_TAB_GROUPS_CONTEXT_MENU_DESCRIPTION, |
| 283 | kOsWin, |
| 284 | SINGLE_VALUE_TYPE(switches::kEnableTabGroupsContextMenu) |
| 285 | }, |
[email protected] | e9bf9d9 | 2011-03-31 20:57:15 | [diff] [blame] | 286 | { |
| 287 | "ppapi-flash-in-process", |
| 288 | IDS_FLAGS_PPAPI_FLASH_IN_PROCESS_NAME, |
| 289 | IDS_FLAGS_PPAPI_FLASH_IN_PROCESS_DESCRIPTION, |
[email protected] | f2d3ce0d | 2011-04-01 18:19:30 | [diff] [blame] | 290 | kOsAll, |
[email protected] | e9bf9d9 | 2011-03-31 20:57:15 | [diff] [blame] | 291 | SINGLE_VALUE_TYPE(switches::kPpapiFlashInProcess) |
| 292 | }, |
[email protected] | 331d4e58 | 2011-05-13 22:44:58 | [diff] [blame] | 293 | #if defined(TOOLKIT_GTK) |
| 294 | { |
| 295 | "global-gnome-menu", |
| 296 | IDS_FLAGS_LINUX_GLOBAL_MENUBAR_NAME, |
| 297 | IDS_FLAGS_LINUX_GLOBAL_MENUBAR_DESCRIPTION, |
| 298 | kOsLinux, |
| 299 | SINGLE_VALUE_TYPE(switches::kGlobalGnomeMenu) |
| 300 | }, |
| 301 | #endif |
[email protected] | ce573714 | 2011-04-14 23:35:09 | [diff] [blame] | 302 | { |
[email protected] | c364790 | 2011-04-15 06:40:33 | [diff] [blame] | 303 | "enable-vpn", |
| 304 | IDS_FLAGS_ENABLE_VPN_NAME, |
| 305 | IDS_FLAGS_ENABLE_VPN_DESCRIPTION, |
| 306 | kOsCrOS, |
| 307 | #if defined(OS_CHROMEOS) |
| 308 | // The switch exists only on Chrome OS. |
| 309 | SINGLE_VALUE_TYPE(switches::kEnableVPN) |
| 310 | #else |
| 311 | SINGLE_VALUE_TYPE("") |
| 312 | #endif |
| 313 | }, |
[email protected] | 20b5df96 | 2011-04-18 22:07:43 | [diff] [blame] | 314 | { |
| 315 | "multi-profiles", |
| 316 | IDS_FLAGS_MULTI_PROFILES_NAME, |
| 317 | IDS_FLAGS_MULTI_PROFILES_DESCRIPTION, |
| 318 | kOsAll, |
| 319 | SINGLE_VALUE_TYPE(switches::kMultiProfiles) |
| 320 | }, |
[email protected] | cc057b0 | 2011-04-21 17:19:04 | [diff] [blame] | 321 | { |
[email protected] | 08338b86 | 2011-05-05 20:22:23 | [diff] [blame] | 322 | "restrict-instant-to-search", |
| 323 | IDS_FLAGS_RESTRICT_INSTANT_TO_SEARCH_NAME, |
| 324 | IDS_FLAGS_RESTRICT_INSTANT_TO_SEARCH_DESCRIPTION, |
| 325 | kOsAll, |
| 326 | SINGLE_VALUE_TYPE(switches::kRestrictInstantToSearch) |
| 327 | }, |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 328 | }; |
| 329 | |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 330 | const Experiment* experiments = kExperiments; |
| 331 | size_t num_experiments = arraysize(kExperiments); |
| 332 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 333 | // Stores and encapsulates the little state that about:flags has. |
| 334 | class FlagsState { |
| 335 | public: |
| 336 | FlagsState() : needs_restart_(false) {} |
| 337 | void ConvertFlagsToSwitches(PrefService* prefs, CommandLine* command_line); |
| 338 | bool IsRestartNeededToCommitChanges(); |
| 339 | void SetExperimentEnabled( |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 340 | PrefService* prefs, const std::string& internal_name, bool enable); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 341 | void RemoveFlagsSwitches( |
| 342 | std::map<std::string, CommandLine::StringType>* switch_list); |
| 343 | void reset(); |
| 344 | |
| 345 | // Returns the singleton instance of this class |
[email protected] | 8e8bb6d | 2010-12-13 08:18:55 | [diff] [blame] | 346 | static FlagsState* GetInstance() { |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 347 | return Singleton<FlagsState>::get(); |
| 348 | } |
| 349 | |
| 350 | private: |
| 351 | bool needs_restart_; |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 352 | std::map<std::string, std::string> flags_switches_; |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 353 | |
| 354 | DISALLOW_COPY_AND_ASSIGN(FlagsState); |
| 355 | }; |
| 356 | |
[email protected] | c7b7800a | 2010-10-07 18:51:35 | [diff] [blame] | 357 | // Extracts the list of enabled lab experiments from preferences and stores them |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 358 | // in a set. |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 359 | void GetEnabledFlags(const PrefService* prefs, std::set<std::string>* result) { |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 360 | const ListValue* enabled_experiments = prefs->GetList( |
| 361 | prefs::kEnabledLabsExperiments); |
| 362 | if (!enabled_experiments) |
| 363 | return; |
| 364 | |
| 365 | for (ListValue::const_iterator it = enabled_experiments->begin(); |
| 366 | it != enabled_experiments->end(); |
| 367 | ++it) { |
| 368 | std::string experiment_name; |
| 369 | if (!(*it)->GetAsString(&experiment_name)) { |
| 370 | LOG(WARNING) << "Invalid entry in " << prefs::kEnabledLabsExperiments; |
| 371 | continue; |
| 372 | } |
| 373 | result->insert(experiment_name); |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | // Takes a set of enabled lab experiments |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 378 | void SetEnabledFlags( |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 379 | PrefService* prefs, const std::set<std::string>& enabled_experiments) { |
[email protected] | 1bc7842 | 2011-03-31 08:41:38 | [diff] [blame] | 380 | ListPrefUpdate update(prefs, prefs::kEnabledLabsExperiments); |
| 381 | ListValue* experiments_list = update.Get(); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 382 | |
| 383 | experiments_list->Clear(); |
| 384 | for (std::set<std::string>::const_iterator it = enabled_experiments.begin(); |
| 385 | it != enabled_experiments.end(); |
| 386 | ++it) { |
| 387 | experiments_list->Append(new StringValue(*it)); |
| 388 | } |
| 389 | } |
| 390 | |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 391 | // Returns the name used in prefs for the choice at the specified index. |
| 392 | std::string NameForChoice(const Experiment& e, int index) { |
[email protected] | 2ce9c8975 | 2011-02-25 18:24:34 | [diff] [blame] | 393 | DCHECK_EQ(Experiment::MULTI_VALUE, e.type); |
| 394 | DCHECK_LT(index, e.num_choices); |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 395 | return std::string(e.internal_name) + about_flags::testing::kMultiSeparator + |
| 396 | base::IntToString(index); |
| 397 | } |
| 398 | |
| 399 | // Adds the internal names for the specified experiment to |names|. |
| 400 | void AddInternalName(const Experiment& e, std::set<std::string>* names) { |
| 401 | if (e.type == Experiment::SINGLE_VALUE) { |
| 402 | names->insert(e.internal_name); |
| 403 | } else { |
[email protected] | 2ce9c8975 | 2011-02-25 18:24:34 | [diff] [blame] | 404 | DCHECK_EQ(Experiment::MULTI_VALUE, e.type); |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 405 | for (int i = 0; i < e.num_choices; ++i) |
| 406 | names->insert(NameForChoice(e, i)); |
| 407 | } |
| 408 | } |
| 409 | |
[email protected] | 28e35af | 2011-02-09 12:56:22 | [diff] [blame] | 410 | // Confirms that an experiment is valid, used in a DCHECK in |
| 411 | // SanitizeList below. |
| 412 | bool ValidateExperiment(const Experiment& e) { |
| 413 | switch (e.type) { |
| 414 | case Experiment::SINGLE_VALUE: |
| 415 | DCHECK_EQ(0, e.num_choices); |
| 416 | DCHECK(!e.choices); |
| 417 | break; |
| 418 | case Experiment::MULTI_VALUE: |
| 419 | DCHECK_GT(e.num_choices, 0); |
| 420 | DCHECK(e.choices); |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 421 | DCHECK(e.choices[0].command_line_switch); |
| 422 | DCHECK_EQ('\0', e.choices[0].command_line_switch[0]); |
[email protected] | 28e35af | 2011-02-09 12:56:22 | [diff] [blame] | 423 | break; |
| 424 | default: |
| 425 | NOTREACHED(); |
| 426 | } |
| 427 | return true; |
| 428 | } |
| 429 | |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 430 | // Removes all experiments from prefs::kEnabledLabsExperiments that are |
| 431 | // unknown, to prevent this list to become very long as experiments are added |
| 432 | // and removed. |
| 433 | void SanitizeList(PrefService* prefs) { |
| 434 | std::set<std::string> known_experiments; |
[email protected] | 28e35af | 2011-02-09 12:56:22 | [diff] [blame] | 435 | for (size_t i = 0; i < num_experiments; ++i) { |
| 436 | DCHECK(ValidateExperiment(experiments[i])); |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 437 | AddInternalName(experiments[i], &known_experiments); |
[email protected] | 28e35af | 2011-02-09 12:56:22 | [diff] [blame] | 438 | } |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 439 | |
| 440 | std::set<std::string> enabled_experiments; |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 441 | GetEnabledFlags(prefs, &enabled_experiments); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 442 | |
| 443 | std::set<std::string> new_enabled_experiments; |
| 444 | std::set_intersection( |
| 445 | known_experiments.begin(), known_experiments.end(), |
| 446 | enabled_experiments.begin(), enabled_experiments.end(), |
| 447 | std::inserter(new_enabled_experiments, new_enabled_experiments.begin())); |
| 448 | |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 449 | SetEnabledFlags(prefs, new_enabled_experiments); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 450 | } |
| 451 | |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 452 | void GetSanitizedEnabledFlags( |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 453 | PrefService* prefs, std::set<std::string>* result) { |
| 454 | SanitizeList(prefs); |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 455 | GetEnabledFlags(prefs, result); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 456 | } |
| 457 | |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 458 | // Variant of GetSanitizedEnabledFlags that also removes any flags that aren't |
| 459 | // enabled on the current platform. |
| 460 | void GetSanitizedEnabledFlagsForCurrentPlatform( |
| 461 | PrefService* prefs, std::set<std::string>* result) { |
| 462 | GetSanitizedEnabledFlags(prefs, result); |
| 463 | |
| 464 | // Filter out any experiments that aren't enabled on the current platform. We |
| 465 | // don't remove these from prefs else syncing to a platform with a different |
| 466 | // set of experiments would be lossy. |
| 467 | std::set<std::string> platform_experiments; |
| 468 | int current_platform = GetCurrentPlatform(); |
| 469 | for (size_t i = 0; i < num_experiments; ++i) { |
| 470 | if (experiments[i].supported_platforms & current_platform) |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 471 | AddInternalName(experiments[i], &platform_experiments); |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | std::set<std::string> new_enabled_experiments; |
| 475 | std::set_intersection( |
| 476 | platform_experiments.begin(), platform_experiments.end(), |
| 477 | result->begin(), result->end(), |
| 478 | std::inserter(new_enabled_experiments, new_enabled_experiments.begin())); |
| 479 | |
| 480 | result->swap(new_enabled_experiments); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 481 | } |
| 482 | |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 483 | // Returns the Value representing the choice data in the specified experiment. |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 484 | Value* CreateChoiceData(const Experiment& experiment, |
[email protected] | 28e35af | 2011-02-09 12:56:22 | [diff] [blame] | 485 | const std::set<std::string>& enabled_experiments) { |
[email protected] | 2ce9c8975 | 2011-02-25 18:24:34 | [diff] [blame] | 486 | DCHECK_EQ(Experiment::MULTI_VALUE, experiment.type); |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 487 | ListValue* result = new ListValue; |
| 488 | for (int i = 0; i < experiment.num_choices; ++i) { |
| 489 | const Experiment::Choice& choice = experiment.choices[i]; |
| 490 | DictionaryValue* value = new DictionaryValue; |
| 491 | std::string name = NameForChoice(experiment, i); |
| 492 | value->SetString("description", |
| 493 | l10n_util::GetStringUTF16(choice.description_id)); |
| 494 | value->SetString("internal_name", name); |
[email protected] | 28e35af | 2011-02-09 12:56:22 | [diff] [blame] | 495 | value->SetBoolean("selected", enabled_experiments.count(name) > 0); |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 496 | result->Append(value); |
| 497 | } |
| 498 | return result; |
| 499 | } |
| 500 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 501 | } // namespace |
| 502 | |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 503 | void ConvertFlagsToSwitches(PrefService* prefs, CommandLine* command_line) { |
[email protected] | 8e8bb6d | 2010-12-13 08:18:55 | [diff] [blame] | 504 | FlagsState::GetInstance()->ConvertFlagsToSwitches(prefs, command_line); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 505 | } |
| 506 | |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 507 | ListValue* GetFlagsExperimentsData(PrefService* prefs) { |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 508 | std::set<std::string> enabled_experiments; |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 509 | GetSanitizedEnabledFlags(prefs, &enabled_experiments); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 510 | |
| 511 | int current_platform = GetCurrentPlatform(); |
| 512 | |
| 513 | ListValue* experiments_data = new ListValue(); |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 514 | for (size_t i = 0; i < num_experiments; ++i) { |
| 515 | const Experiment& experiment = experiments[i]; |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 516 | if (!(experiment.supported_platforms & current_platform)) |
| 517 | continue; |
| 518 | |
| 519 | DictionaryValue* data = new DictionaryValue(); |
| 520 | data->SetString("internal_name", experiment.internal_name); |
| 521 | data->SetString("name", |
| 522 | l10n_util::GetStringUTF16(experiment.visible_name_id)); |
| 523 | data->SetString("description", |
| 524 | l10n_util::GetStringUTF16( |
| 525 | experiment.visible_description_id)); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 526 | |
[email protected] | 28e35af | 2011-02-09 12:56:22 | [diff] [blame] | 527 | switch (experiment.type) { |
| 528 | case Experiment::SINGLE_VALUE: |
| 529 | data->SetBoolean( |
| 530 | "enabled", |
| 531 | enabled_experiments.count(experiment.internal_name) > 0); |
| 532 | break; |
| 533 | case Experiment::MULTI_VALUE: |
| 534 | data->Set("choices", CreateChoiceData(experiment, enabled_experiments)); |
| 535 | break; |
| 536 | default: |
| 537 | NOTREACHED(); |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 538 | } |
| 539 | |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 540 | experiments_data->Append(data); |
| 541 | } |
| 542 | return experiments_data; |
| 543 | } |
| 544 | |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 545 | bool IsRestartNeededToCommitChanges() { |
[email protected] | 8e8bb6d | 2010-12-13 08:18:55 | [diff] [blame] | 546 | return FlagsState::GetInstance()->IsRestartNeededToCommitChanges(); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | void SetExperimentEnabled( |
[email protected] | c7b7800a | 2010-10-07 18:51:35 | [diff] [blame] | 550 | PrefService* prefs, const std::string& internal_name, bool enable) { |
[email protected] | 8e8bb6d | 2010-12-13 08:18:55 | [diff] [blame] | 551 | FlagsState::GetInstance()->SetExperimentEnabled(prefs, internal_name, enable); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | void RemoveFlagsSwitches( |
| 555 | std::map<std::string, CommandLine::StringType>* switch_list) { |
[email protected] | 8e8bb6d | 2010-12-13 08:18:55 | [diff] [blame] | 556 | FlagsState::GetInstance()->RemoveFlagsSwitches(switch_list); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 557 | } |
| 558 | |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 559 | int GetCurrentPlatform() { |
| 560 | #if defined(OS_MACOSX) |
| 561 | return kOsMac; |
| 562 | #elif defined(OS_WIN) |
| 563 | return kOsWin; |
| 564 | #elif defined(OS_CHROMEOS) // Needs to be before the OS_LINUX check. |
| 565 | return kOsCrOS; |
| 566 | #elif defined(OS_LINUX) |
| 567 | return kOsLinux; |
| 568 | #else |
| 569 | #error Unknown platform |
| 570 | #endif |
| 571 | } |
| 572 | |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 573 | void RecordUMAStatistics(const PrefService* prefs) { |
| 574 | std::set<std::string> flags; |
| 575 | GetEnabledFlags(prefs, &flags); |
| 576 | for (std::set<std::string>::iterator it = flags.begin(); it != flags.end(); |
| 577 | ++it) { |
| 578 | std::string action("AboutFlags_"); |
| 579 | action += *it; |
| 580 | UserMetrics::RecordComputedAction(action); |
| 581 | } |
| 582 | // Since flag metrics are recorded every startup, add a tick so that the |
| 583 | // stats can be made meaningful. |
| 584 | if (flags.size()) |
| 585 | UserMetrics::RecordAction(UserMetricsAction("AboutFlags_StartupTick")); |
[email protected] | 970b2fd | 2011-01-22 18:06:45 | [diff] [blame] | 586 | UserMetrics::RecordAction(UserMetricsAction("StartupTick")); |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 587 | } |
| 588 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 589 | ////////////////////////////////////////////////////////////////////////////// |
| 590 | // FlagsState implementation. |
| 591 | |
| 592 | namespace { |
| 593 | |
| 594 | void FlagsState::ConvertFlagsToSwitches( |
| 595 | PrefService* prefs, CommandLine* command_line) { |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 596 | if (command_line->HasSwitch(switches::kNoExperiments)) |
| 597 | return; |
| 598 | |
| 599 | std::set<std::string> enabled_experiments; |
[email protected] | ba816424 | 2010-11-16 21:31:00 | [diff] [blame] | 600 | |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 601 | GetSanitizedEnabledFlagsForCurrentPlatform(prefs, &enabled_experiments); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 602 | |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 603 | typedef std::map<std::string, std::pair<std::string, std::string> > |
| 604 | NameToSwitchAndValueMap; |
| 605 | NameToSwitchAndValueMap name_to_switch_map; |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 606 | for (size_t i = 0; i < num_experiments; ++i) { |
| 607 | const Experiment& e = experiments[i]; |
| 608 | if (e.type == Experiment::SINGLE_VALUE) { |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 609 | name_to_switch_map[e.internal_name] = |
| 610 | std::pair<std::string, std::string>(e.command_line_switch, |
| 611 | e.command_line_value); |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 612 | } else { |
| 613 | for (int j = 0; j < e.num_choices; ++j) |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 614 | name_to_switch_map[NameForChoice(e, j)] = |
| 615 | std::pair<std::string, std::string>( |
| 616 | e.choices[j].command_line_switch, |
| 617 | e.choices[j].command_line_value); |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 618 | } |
| 619 | } |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 620 | |
| 621 | command_line->AppendSwitch(switches::kFlagSwitchesBegin); |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 622 | flags_switches_.insert( |
| 623 | std::pair<std::string, std::string>(switches::kFlagSwitchesBegin, |
| 624 | std::string())); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 625 | for (std::set<std::string>::iterator it = enabled_experiments.begin(); |
| 626 | it != enabled_experiments.end(); |
| 627 | ++it) { |
| 628 | const std::string& experiment_name = *it; |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 629 | NameToSwitchAndValueMap::const_iterator name_to_switch_it = |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 630 | name_to_switch_map.find(experiment_name); |
| 631 | if (name_to_switch_it == name_to_switch_map.end()) { |
| 632 | NOTREACHED(); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 633 | continue; |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 634 | } |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 635 | |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 636 | const std::pair<std::string, std::string>& |
| 637 | switch_and_value_pair = name_to_switch_it->second; |
| 638 | |
| 639 | command_line->AppendSwitchASCII(switch_and_value_pair.first, |
| 640 | switch_and_value_pair.second); |
| 641 | flags_switches_[switch_and_value_pair.first] = switch_and_value_pair.second; |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 642 | } |
| 643 | command_line->AppendSwitch(switches::kFlagSwitchesEnd); |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 644 | flags_switches_.insert( |
| 645 | std::pair<std::string, std::string>(switches::kFlagSwitchesEnd, |
| 646 | std::string())); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | bool FlagsState::IsRestartNeededToCommitChanges() { |
| 650 | return needs_restart_; |
| 651 | } |
| 652 | |
| 653 | void FlagsState::SetExperimentEnabled( |
| 654 | PrefService* prefs, const std::string& internal_name, bool enable) { |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 655 | needs_restart_ = true; |
| 656 | |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 657 | size_t at_index = internal_name.find(about_flags::testing::kMultiSeparator); |
| 658 | if (at_index != std::string::npos) { |
| 659 | DCHECK(enable); |
| 660 | // We're being asked to enable a multi-choice experiment. Disable the |
| 661 | // currently selected choice. |
| 662 | DCHECK_NE(at_index, 0u); |
[email protected] | 28e35af | 2011-02-09 12:56:22 | [diff] [blame] | 663 | const std::string experiment_name = internal_name.substr(0, at_index); |
| 664 | SetExperimentEnabled(prefs, experiment_name, false); |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 665 | |
[email protected] | 28e35af | 2011-02-09 12:56:22 | [diff] [blame] | 666 | // And enable the new choice, if it is not the default first choice. |
| 667 | if (internal_name != experiment_name + "@0") { |
| 668 | std::set<std::string> enabled_experiments; |
| 669 | GetSanitizedEnabledFlags(prefs, &enabled_experiments); |
| 670 | enabled_experiments.insert(internal_name); |
| 671 | SetEnabledFlags(prefs, enabled_experiments); |
| 672 | } |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 673 | return; |
| 674 | } |
| 675 | |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 676 | std::set<std::string> enabled_experiments; |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 677 | GetSanitizedEnabledFlags(prefs, &enabled_experiments); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 678 | |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 679 | const Experiment* e = NULL; |
| 680 | for (size_t i = 0; i < num_experiments; ++i) { |
| 681 | if (experiments[i].internal_name == internal_name) { |
| 682 | e = experiments + i; |
| 683 | break; |
| 684 | } |
| 685 | } |
| 686 | DCHECK(e); |
| 687 | |
| 688 | if (e->type == Experiment::SINGLE_VALUE) { |
| 689 | if (enable) |
| 690 | enabled_experiments.insert(internal_name); |
| 691 | else |
| 692 | enabled_experiments.erase(internal_name); |
| 693 | } else { |
| 694 | if (enable) { |
| 695 | // Enable the first choice. |
| 696 | enabled_experiments.insert(NameForChoice(*e, 0)); |
| 697 | } else { |
| 698 | // Find the currently enabled choice and disable it. |
| 699 | for (int i = 0; i < e->num_choices; ++i) { |
| 700 | std::string choice_name = NameForChoice(*e, i); |
| 701 | if (enabled_experiments.find(choice_name) != |
| 702 | enabled_experiments.end()) { |
| 703 | enabled_experiments.erase(choice_name); |
| 704 | // Continue on just in case there's a bug and more than one |
| 705 | // experiment for this choice was enabled. |
| 706 | } |
| 707 | } |
| 708 | } |
| 709 | } |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 710 | |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 711 | SetEnabledFlags(prefs, enabled_experiments); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 712 | } |
| 713 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 714 | void FlagsState::RemoveFlagsSwitches( |
| 715 | std::map<std::string, CommandLine::StringType>* switch_list) { |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 716 | for (std::map<std::string, std::string>::const_iterator |
| 717 | it = flags_switches_.begin(); it != flags_switches_.end(); ++it) { |
| 718 | switch_list->erase(it->first); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 719 | } |
| 720 | } |
| 721 | |
| 722 | void FlagsState::reset() { |
| 723 | needs_restart_ = false; |
| 724 | flags_switches_.clear(); |
| 725 | } |
| 726 | |
[email protected] | 38e4681 | 2011-05-09 20:49:22 | [diff] [blame] | 727 | } // namespace |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 728 | |
| 729 | namespace testing { |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 730 | |
| 731 | // WARNING: '@' is also used in the html file. If you update this constant you |
| 732 | // also need to update the html file. |
| 733 | const char kMultiSeparator[] = "@"; |
| 734 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 735 | void ClearState() { |
[email protected] | 8e8bb6d | 2010-12-13 08:18:55 | [diff] [blame] | 736 | FlagsState::GetInstance()->reset(); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 737 | } |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 738 | |
| 739 | void SetExperiments(const Experiment* e, size_t count) { |
| 740 | if (!e) { |
| 741 | experiments = kExperiments; |
| 742 | num_experiments = arraysize(kExperiments); |
| 743 | } else { |
| 744 | experiments = e; |
| 745 | num_experiments = count; |
| 746 | } |
| 747 | } |
| 748 | |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 749 | const Experiment* GetExperiments(size_t* count) { |
| 750 | *count = num_experiments; |
| 751 | return experiments; |
| 752 | } |
| 753 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 754 | } // namespace testing |
| 755 | |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 756 | } // namespace about_flags |