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