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