[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 | { |
[email protected] | f2557bd | 2011-06-01 02:33:07 | [diff] [blame] | 253 | "preload-instant-search", |
| 254 | IDS_FLAGS_PRELOAD_INSTANT_SEARCH_NAME, |
| 255 | IDS_FLAGS_PRELOAD_INSTANT_SEARCH_DESCRIPTION, |
| 256 | kOsAll, |
| 257 | SINGLE_VALUE_TYPE(switches::kPreloadInstantSearch) |
| 258 | }, |
[email protected] | 354e33b | 2011-06-15 00:29:10 | [diff] [blame] | 259 | { |
| 260 | "static-ip-config", |
| 261 | IDS_FLAGS_STATIC_IP_CONFIG_NAME, |
| 262 | IDS_FLAGS_STATIC_IP_CONFIG_DESCRIPTION, |
| 263 | kOsCrOS, |
| 264 | #if defined(OS_CHROMEOS) |
| 265 | // This switch exists only on Chrome OS. |
| 266 | SINGLE_VALUE_TYPE(switches::kEnableStaticIPConfig) |
| 267 | #else |
| 268 | SINGLE_VALUE_TYPE("") |
| 269 | #endif |
| 270 | }, |
[email protected] | 3eb5728c | 2011-06-20 22:32:24 | [diff] [blame] | 271 | { |
| 272 | "show-autofill-type-predictions", |
| 273 | IDS_FLAGS_SHOW_AUTOFILL_TYPE_PREDICTIONS_NAME, |
| 274 | IDS_FLAGS_SHOW_AUTOFILL_TYPE_PREDICTIONS_DESCRIPTION, |
| 275 | kOsAll, |
| 276 | SINGLE_VALUE_TYPE(switches::kShowAutofillTypePredictions) |
| 277 | }, |
[email protected] | bff4d3e | 2011-06-21 23:58:52 | [diff] [blame] | 278 | { |
[email protected] | 9a6180d7d | 2011-09-07 01:40:33 | [diff] [blame] | 279 | "sync-tabs", |
| 280 | IDS_FLAGS_SYNC_TABS_NAME, |
| 281 | IDS_FLAGS_SYNC_TABS_DESCRIPTION, |
[email protected] | 5b0ec7f | 2011-08-11 02:17:17 | [diff] [blame] | 282 | kOsAll, |
[email protected] | 9a6180d7d | 2011-09-07 01:40:33 | [diff] [blame] | 283 | SINGLE_VALUE_TYPE(switches::kEnableSyncTabs) |
[email protected] | 5b0ec7f | 2011-08-11 02:17:17 | [diff] [blame] | 284 | }, |
| 285 | { |
[email protected] | aae9eeb1 | 2011-10-21 21:59:26 | [diff] [blame] | 286 | "sync-app-notifications", |
| 287 | IDS_FLAGS_SYNC_APP_NOTIFICATIONS_NAME, |
| 288 | IDS_FLAGS_SYNC_APP_NOTIFICATIONS_DESCRIPTION, |
| 289 | kOsAll, |
[email protected] | 0b6fba8 | 2011-11-18 01:31:11 | [diff] [blame] | 290 | SINGLE_VALUE_TYPE(switches::kDisableSyncAppNotifications) |
[email protected] | aae9eeb1 | 2011-10-21 21:59:26 | [diff] [blame] | 291 | }, |
| 292 | { |
[email protected] | a22ebd81 | 2011-06-23 00:05:39 | [diff] [blame] | 293 | "enable-smooth-scrolling", // FLAGS:RECORD_UMA |
| 294 | IDS_FLAGS_ENABLE_SMOOTH_SCROLLING_NAME, |
| 295 | IDS_FLAGS_ENABLE_SMOOTH_SCROLLING_DESCRIPTION, |
| 296 | // Can't expose the switch unless the code is compiled in. |
[email protected] | 554b706 | 2011-09-03 03:09:40 | [diff] [blame] | 297 | // On by default for the Mac (different implementation in WebKit). |
[email protected] | 554b706 | 2011-09-03 03:09:40 | [diff] [blame] | 298 | kOsWin | kOsLinux | kOsCrOS, |
[email protected] | a22ebd81 | 2011-06-23 00:05:39 | [diff] [blame] | 299 | SINGLE_VALUE_TYPE(switches::kEnableSmoothScrolling) |
| 300 | }, |
[email protected] | 81a6b0b | 2011-06-24 17:55:40 | [diff] [blame] | 301 | { |
[email protected] | ae1eb29a | 2011-08-17 17:50:57 | [diff] [blame] | 302 | "prerender-from-omnibox", // FLAGS:RECORD_UMA |
[email protected] | 81a6b0b | 2011-06-24 17:55:40 | [diff] [blame] | 303 | IDS_FLAGS_PRERENDER_FROM_OMNIBOX_NAME, |
| 304 | IDS_FLAGS_PRERENDER_FROM_OMNIBOX_DESCRIPTION, |
| 305 | kOsAll, |
[email protected] | 778ef7c | 2011-10-11 15:37:05 | [diff] [blame] | 306 | MULTI_VALUE_TYPE(kPrerenderFromOmniboxChoices) |
[email protected] | 81a6b0b | 2011-06-24 17:55:40 | [diff] [blame] | 307 | }, |
[email protected] | 4091663 | 2011-07-02 01:11:01 | [diff] [blame] | 308 | { |
[email protected] | 845be52 | 2011-10-27 19:01:19 | [diff] [blame] | 309 | "disable-panels", |
[email protected] | d5c1406 | 2011-10-27 00:02:13 | [diff] [blame] | 310 | IDS_FLAGS_DISABLE_PANELS_NAME, |
| 311 | IDS_FLAGS_DISABLE_PANELS_DESCRIPTION, |
[email protected] | 73fb1fc5 | 2011-07-09 00:06:54 | [diff] [blame] | 312 | kOsAll, |
[email protected] | d5c1406 | 2011-10-27 00:02:13 | [diff] [blame] | 313 | SINGLE_VALUE_TYPE(switches::kDisablePanels) |
[email protected] | 73fb1fc5 | 2011-07-09 00:06:54 | [diff] [blame] | 314 | }, |
[email protected] | e3749d1 | 2011-07-25 22:22:12 | [diff] [blame] | 315 | { |
[email protected] | 9931875b | 2011-11-02 00:19:48 | [diff] [blame] | 316 | "disable-shortcuts-provider", |
| 317 | IDS_FLAGS_DISABLE_SHORTCUTS_PROVIDER, |
| 318 | IDS_FLAGS_DISABLE_SHORTCUTS_PROVIDER_DESCRIPTION, |
[email protected] | e3749d1 | 2011-07-25 22:22:12 | [diff] [blame] | 319 | kOsAll, |
[email protected] | 9931875b | 2011-11-02 00:19:48 | [diff] [blame] | 320 | SINGLE_VALUE_TYPE(switches::kDisableShortcutsProvider) |
[email protected] | e3749d1 | 2011-07-25 22:22:12 | [diff] [blame] | 321 | }, |
[email protected] | 1a2966b9 | 2011-08-09 06:50:19 | [diff] [blame] | 322 | #if defined(OS_CHROMEOS) |
| 323 | { |
[email protected] | cd681c4 | 2011-09-29 02:49:44 | [diff] [blame] | 324 | "enable-bluetooth", |
| 325 | IDS_FLAGS_ENABLE_BLUETOOTH_NAME, |
| 326 | IDS_FLAGS_ENABLE_BLUETOOTH_DESCRIPTION, |
| 327 | kOsCrOS, |
| 328 | SINGLE_VALUE_TYPE(switches::kEnableBluetooth) |
| 329 | }, |
[email protected] | 1a2966b9 | 2011-08-09 06:50:19 | [diff] [blame] | 330 | #endif |
[email protected] | 80eb426 | 2011-08-03 16:10:41 | [diff] [blame] | 331 | { |
| 332 | "memory-widget", |
| 333 | IDS_FLAGS_MEMORY_WIDGET_NAME, |
| 334 | IDS_FLAGS_MEMORY_WIDGET_DESCRIPTION, |
| 335 | kOsCrOS, |
| 336 | #if defined(OS_CHROMEOS) |
| 337 | // This switch exists only on Chrome OS. |
| 338 | SINGLE_VALUE_TYPE(switches::kMemoryWidget) |
| 339 | #else |
| 340 | SINGLE_VALUE_TYPE("") |
| 341 | #endif |
[email protected] | a0e4b07 | 2011-08-17 01:47:07 | [diff] [blame] | 342 | }, |
[email protected] | a0e4b07 | 2011-08-17 01:47:07 | [diff] [blame] | 343 | { |
| 344 | "downloads-new-ui", // FLAGS:RECORD_UMA |
| 345 | IDS_FLAGS_DOWNLOADS_NEW_UI_NAME, |
| 346 | IDS_FLAGS_DOWNLOADS_NEW_UI_DESCRIPTION, |
| 347 | kOsAll, |
| 348 | SINGLE_VALUE_TYPE(switches::kDownloadsNewUI) |
| 349 | }, |
[email protected] | b7bb44f | 2011-09-01 05:17:03 | [diff] [blame] | 350 | { |
| 351 | "enable-autologin", |
| 352 | IDS_FLAGS_ENABLE_AUTOLOGIN_NAME, |
| 353 | IDS_FLAGS_ENABLE_AUTOLOGIN_DESCRIPTION, |
| 354 | kOsMac | kOsWin | kOsLinux, |
| 355 | SINGLE_VALUE_TYPE(switches::kEnableAutologin) |
| 356 | }, |
[email protected] | b984117 | 2011-09-26 23:36:09 | [diff] [blame] | 357 | { |
| 358 | "use-more-webui", |
| 359 | IDS_FLAGS_USE_MORE_WEBUI_NAME, |
| 360 | IDS_FLAGS_USE_MORE_WEBUI_DESCRIPTION, |
| 361 | kOsAll, |
| 362 | SINGLE_VALUE_TYPE(switches::kUseMoreWebUI) |
| 363 | }, |
[email protected] | 407a38f | 2011-11-23 18:28:29 | [diff] [blame] | 364 | // TODO(flackr): Remove this flag and views screen locker when the WebUI |
| 365 | // locker is mature (crbug.com/105263). |
[email protected] | 89c64cd | 2011-10-04 01:41:10 | [diff] [blame] | 366 | { |
[email protected] | 407a38f | 2011-11-23 18:28:29 | [diff] [blame] | 367 | "disable-webui-lock-screen", |
[email protected] | d411c01d | 2011-10-18 16:00:27 | [diff] [blame] | 368 | IDS_FLAGS_WEBUI_LOCK_NAME, |
| 369 | IDS_FLAGS_WEBUI_LOCK_DESCRIPTION, |
| 370 | kOsCrOS, |
| 371 | #if defined(OS_CHROMEOS) |
[email protected] | 407a38f | 2011-11-23 18:28:29 | [diff] [blame] | 372 | SINGLE_VALUE_TYPE(switches::kDisableWebUILockScreen) |
[email protected] | d411c01d | 2011-10-18 16:00:27 | [diff] [blame] | 373 | #else |
| 374 | SINGLE_VALUE_TYPE("") |
| 375 | #endif |
| 376 | }, |
| 377 | { |
[email protected] | 89c64cd | 2011-10-04 01:41:10 | [diff] [blame] | 378 | "enable-ntp-bookmark-features", |
| 379 | IDS_FLAGS_ENABLE_NTP_BOOKMARK_FEATURES_NAME, |
| 380 | IDS_FLAGS_ENABLE_NTP_BOOKMARK_FEATURES_DESCRIPTION, |
| 381 | kOsAll, |
| 382 | SINGLE_VALUE_TYPE(switches::kEnableNTPBookmarkFeatures) |
| 383 | }, |
[email protected] | f5da41d | 2011-10-08 17:40:07 | [diff] [blame] | 384 | { |
| 385 | "enable-video-track", |
| 386 | IDS_FLAGS_ENABLE_VIDEO_TRACK_NAME, |
| 387 | IDS_FLAGS_ENABLE_VIDEO_TRACK_DESCRIPTION, |
| 388 | kOsAll, |
| 389 | SINGLE_VALUE_TYPE(switches::kEnableVideoTrack) |
| 390 | }, |
[email protected] | 08b8336 | 2011-10-19 05:23:17 | [diff] [blame] | 391 | { |
| 392 | "extension-alerts", |
| 393 | IDS_FLAGS_ENABLE_EXTENSION_ALERTS_NAME, |
| 394 | IDS_FLAGS_ENABLE_EXTENSION_ALERTS_DESCRIPTION, |
| 395 | kOsAll, |
| 396 | SINGLE_VALUE_TYPE(switches::kEnableExtensionAlerts) |
| 397 | }, |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 398 | { |
| 399 | "enable-http-pipelining", |
| 400 | IDS_FLAGS_ENABLE_HTTP_PIPELINING_NAME, |
| 401 | IDS_FLAGS_ENABLE_HTTP_PIPELINING_DESCRIPTION, |
| 402 | kOsAll, |
| 403 | SINGLE_VALUE_TYPE(switches::kEnableHttpPipelining) |
| 404 | }, |
[email protected] | e3aaa9378 | 2011-10-26 16:04:28 | [diff] [blame] | 405 | #if defined(OS_CHROMEOS) |
| 406 | { |
| 407 | "enable-photo-editor", |
| 408 | IDS_FLAGS_ENABLE_PHOTO_EDITOR_NAME, |
| 409 | IDS_FLAGS_ENABLE_PHOTO_EDITOR_DESCRIPTION, |
| 410 | kOsCrOS, |
| 411 | SINGLE_VALUE_TYPE(switches::kEnablePhotoEditor) |
| 412 | }, |
| 413 | #endif |
[email protected] | 6aa03b3 | 2011-10-27 21:44:44 | [diff] [blame] | 414 | { |
| 415 | "enable-media-source", |
| 416 | IDS_FLAGS_ENABLE_MEDIA_SOURCE_NAME, |
| 417 | IDS_FLAGS_ENABLE_MEDIA_SOURCE_DESCRIPTION, |
| 418 | kOsAll, |
| 419 | SINGLE_VALUE_TYPE(switches::kEnableMediaSource) |
| 420 | }, |
[email protected] | e4e68dbb | 2011-11-18 01:50:22 | [diff] [blame] | 421 | { |
| 422 | "enable-pointer-lock", |
| 423 | IDS_FLAGS_ENABLE_POINTER_LOCK_NAME, |
| 424 | IDS_FLAGS_ENABLE_POINTER_LOCK_DESCRIPTION, |
| 425 | kOsAll, |
| 426 | SINGLE_VALUE_TYPE(switches::kEnablePointerLock) |
| 427 | }, |
[email protected] | 8cc10df | 2011-11-03 23:57:50 | [diff] [blame] | 428 | #if defined(USE_AURA) |
| 429 | { |
| 430 | "aura-windows", |
| 431 | IDS_FLAGS_AURA_WINDOWS_NAME, |
| 432 | IDS_FLAGS_AURA_WINDOWS_DESCRIPTION, |
| 433 | kOsWin | kOsLinux | kOsCrOS, |
| 434 | SINGLE_VALUE_TYPE(switches::kAuraWindows) |
| 435 | }, |
| 436 | #endif |
[email protected] | edb051d | 2011-11-24 23:20:51 | [diff] [blame^] | 437 | { |
| 438 | "enable-gamepad", |
| 439 | IDS_FLAGS_ENABLE_GAMEPAD_NAME, |
| 440 | IDS_FLAGS_ENABLE_GAMEPAD_DESCRIPTION, |
| 441 | kOsWin, |
| 442 | SINGLE_VALUE_TYPE(switches::kEnableGamepad) |
| 443 | }, |
[email protected] | a0e4b07 | 2011-08-17 01:47:07 | [diff] [blame] | 444 | }; |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 445 | |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 446 | const Experiment* experiments = kExperiments; |
| 447 | size_t num_experiments = arraysize(kExperiments); |
| 448 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 449 | // Stores and encapsulates the little state that about:flags has. |
| 450 | class FlagsState { |
| 451 | public: |
| 452 | FlagsState() : needs_restart_(false) {} |
| 453 | void ConvertFlagsToSwitches(PrefService* prefs, CommandLine* command_line); |
| 454 | bool IsRestartNeededToCommitChanges(); |
| 455 | void SetExperimentEnabled( |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 456 | PrefService* prefs, const std::string& internal_name, bool enable); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 457 | void RemoveFlagsSwitches( |
| 458 | std::map<std::string, CommandLine::StringType>* switch_list); |
| 459 | void reset(); |
| 460 | |
| 461 | // Returns the singleton instance of this class |
[email protected] | 8e8bb6d | 2010-12-13 08:18:55 | [diff] [blame] | 462 | static FlagsState* GetInstance() { |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 463 | return Singleton<FlagsState>::get(); |
| 464 | } |
| 465 | |
| 466 | private: |
| 467 | bool needs_restart_; |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 468 | std::map<std::string, std::string> flags_switches_; |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 469 | |
| 470 | DISALLOW_COPY_AND_ASSIGN(FlagsState); |
| 471 | }; |
| 472 | |
[email protected] | c7b7800a | 2010-10-07 18:51:35 | [diff] [blame] | 473 | // Extracts the list of enabled lab experiments from preferences and stores them |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 474 | // in a set. |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 475 | void GetEnabledFlags(const PrefService* prefs, std::set<std::string>* result) { |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 476 | const ListValue* enabled_experiments = prefs->GetList( |
| 477 | prefs::kEnabledLabsExperiments); |
| 478 | if (!enabled_experiments) |
| 479 | return; |
| 480 | |
| 481 | for (ListValue::const_iterator it = enabled_experiments->begin(); |
| 482 | it != enabled_experiments->end(); |
| 483 | ++it) { |
| 484 | std::string experiment_name; |
| 485 | if (!(*it)->GetAsString(&experiment_name)) { |
| 486 | LOG(WARNING) << "Invalid entry in " << prefs::kEnabledLabsExperiments; |
| 487 | continue; |
| 488 | } |
| 489 | result->insert(experiment_name); |
| 490 | } |
| 491 | } |
| 492 | |
| 493 | // Takes a set of enabled lab experiments |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 494 | void SetEnabledFlags( |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 495 | PrefService* prefs, const std::set<std::string>& enabled_experiments) { |
[email protected] | 1bc7842 | 2011-03-31 08:41:38 | [diff] [blame] | 496 | ListPrefUpdate update(prefs, prefs::kEnabledLabsExperiments); |
| 497 | ListValue* experiments_list = update.Get(); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 498 | |
| 499 | experiments_list->Clear(); |
| 500 | for (std::set<std::string>::const_iterator it = enabled_experiments.begin(); |
| 501 | it != enabled_experiments.end(); |
| 502 | ++it) { |
| 503 | experiments_list->Append(new StringValue(*it)); |
| 504 | } |
| 505 | } |
| 506 | |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 507 | // Returns the name used in prefs for the choice at the specified index. |
| 508 | std::string NameForChoice(const Experiment& e, int index) { |
[email protected] | 2ce9c8975 | 2011-02-25 18:24:34 | [diff] [blame] | 509 | DCHECK_EQ(Experiment::MULTI_VALUE, e.type); |
| 510 | DCHECK_LT(index, e.num_choices); |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 511 | return std::string(e.internal_name) + about_flags::testing::kMultiSeparator + |
| 512 | base::IntToString(index); |
| 513 | } |
| 514 | |
| 515 | // Adds the internal names for the specified experiment to |names|. |
| 516 | void AddInternalName(const Experiment& e, std::set<std::string>* names) { |
| 517 | if (e.type == Experiment::SINGLE_VALUE) { |
| 518 | names->insert(e.internal_name); |
| 519 | } else { |
[email protected] | 2ce9c8975 | 2011-02-25 18:24:34 | [diff] [blame] | 520 | DCHECK_EQ(Experiment::MULTI_VALUE, e.type); |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 521 | for (int i = 0; i < e.num_choices; ++i) |
| 522 | names->insert(NameForChoice(e, i)); |
| 523 | } |
| 524 | } |
| 525 | |
[email protected] | 28e35af | 2011-02-09 12:56:22 | [diff] [blame] | 526 | // Confirms that an experiment is valid, used in a DCHECK in |
| 527 | // SanitizeList below. |
| 528 | bool ValidateExperiment(const Experiment& e) { |
| 529 | switch (e.type) { |
| 530 | case Experiment::SINGLE_VALUE: |
| 531 | DCHECK_EQ(0, e.num_choices); |
| 532 | DCHECK(!e.choices); |
| 533 | break; |
| 534 | case Experiment::MULTI_VALUE: |
| 535 | DCHECK_GT(e.num_choices, 0); |
| 536 | DCHECK(e.choices); |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 537 | DCHECK(e.choices[0].command_line_switch); |
| 538 | DCHECK_EQ('\0', e.choices[0].command_line_switch[0]); |
[email protected] | 28e35af | 2011-02-09 12:56:22 | [diff] [blame] | 539 | break; |
| 540 | default: |
| 541 | NOTREACHED(); |
| 542 | } |
| 543 | return true; |
| 544 | } |
| 545 | |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 546 | // Removes all experiments from prefs::kEnabledLabsExperiments that are |
| 547 | // unknown, to prevent this list to become very long as experiments are added |
| 548 | // and removed. |
| 549 | void SanitizeList(PrefService* prefs) { |
| 550 | std::set<std::string> known_experiments; |
[email protected] | 28e35af | 2011-02-09 12:56:22 | [diff] [blame] | 551 | for (size_t i = 0; i < num_experiments; ++i) { |
| 552 | DCHECK(ValidateExperiment(experiments[i])); |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 553 | AddInternalName(experiments[i], &known_experiments); |
[email protected] | 28e35af | 2011-02-09 12:56:22 | [diff] [blame] | 554 | } |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 555 | |
| 556 | std::set<std::string> enabled_experiments; |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 557 | GetEnabledFlags(prefs, &enabled_experiments); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 558 | |
| 559 | std::set<std::string> new_enabled_experiments; |
| 560 | std::set_intersection( |
| 561 | known_experiments.begin(), known_experiments.end(), |
| 562 | enabled_experiments.begin(), enabled_experiments.end(), |
| 563 | std::inserter(new_enabled_experiments, new_enabled_experiments.begin())); |
| 564 | |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 565 | SetEnabledFlags(prefs, new_enabled_experiments); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 566 | } |
| 567 | |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 568 | void GetSanitizedEnabledFlags( |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 569 | PrefService* prefs, std::set<std::string>* result) { |
| 570 | SanitizeList(prefs); |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 571 | GetEnabledFlags(prefs, result); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 572 | } |
| 573 | |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 574 | // Variant of GetSanitizedEnabledFlags that also removes any flags that aren't |
| 575 | // enabled on the current platform. |
| 576 | void GetSanitizedEnabledFlagsForCurrentPlatform( |
| 577 | PrefService* prefs, std::set<std::string>* result) { |
| 578 | GetSanitizedEnabledFlags(prefs, result); |
| 579 | |
| 580 | // Filter out any experiments that aren't enabled on the current platform. We |
| 581 | // don't remove these from prefs else syncing to a platform with a different |
| 582 | // set of experiments would be lossy. |
| 583 | std::set<std::string> platform_experiments; |
| 584 | int current_platform = GetCurrentPlatform(); |
| 585 | for (size_t i = 0; i < num_experiments; ++i) { |
| 586 | if (experiments[i].supported_platforms & current_platform) |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 587 | AddInternalName(experiments[i], &platform_experiments); |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | std::set<std::string> new_enabled_experiments; |
| 591 | std::set_intersection( |
| 592 | platform_experiments.begin(), platform_experiments.end(), |
| 593 | result->begin(), result->end(), |
| 594 | std::inserter(new_enabled_experiments, new_enabled_experiments.begin())); |
| 595 | |
| 596 | result->swap(new_enabled_experiments); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 597 | } |
| 598 | |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 599 | // Returns the Value representing the choice data in the specified experiment. |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 600 | Value* CreateChoiceData(const Experiment& experiment, |
[email protected] | 28e35af | 2011-02-09 12:56:22 | [diff] [blame] | 601 | const std::set<std::string>& enabled_experiments) { |
[email protected] | 2ce9c8975 | 2011-02-25 18:24:34 | [diff] [blame] | 602 | DCHECK_EQ(Experiment::MULTI_VALUE, experiment.type); |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 603 | ListValue* result = new ListValue; |
| 604 | for (int i = 0; i < experiment.num_choices; ++i) { |
| 605 | const Experiment::Choice& choice = experiment.choices[i]; |
| 606 | DictionaryValue* value = new DictionaryValue; |
| 607 | std::string name = NameForChoice(experiment, i); |
| 608 | value->SetString("description", |
| 609 | l10n_util::GetStringUTF16(choice.description_id)); |
| 610 | value->SetString("internal_name", name); |
[email protected] | 28e35af | 2011-02-09 12:56:22 | [diff] [blame] | 611 | value->SetBoolean("selected", enabled_experiments.count(name) > 0); |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 612 | result->Append(value); |
| 613 | } |
| 614 | return result; |
| 615 | } |
| 616 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 617 | } // namespace |
| 618 | |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 619 | void ConvertFlagsToSwitches(PrefService* prefs, CommandLine* command_line) { |
[email protected] | 8e8bb6d | 2010-12-13 08:18:55 | [diff] [blame] | 620 | FlagsState::GetInstance()->ConvertFlagsToSwitches(prefs, command_line); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 621 | } |
| 622 | |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 623 | ListValue* GetFlagsExperimentsData(PrefService* prefs) { |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 624 | std::set<std::string> enabled_experiments; |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 625 | GetSanitizedEnabledFlags(prefs, &enabled_experiments); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 626 | |
| 627 | int current_platform = GetCurrentPlatform(); |
| 628 | |
| 629 | ListValue* experiments_data = new ListValue(); |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 630 | for (size_t i = 0; i < num_experiments; ++i) { |
| 631 | const Experiment& experiment = experiments[i]; |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 632 | if (!(experiment.supported_platforms & current_platform)) |
| 633 | continue; |
| 634 | |
| 635 | DictionaryValue* data = new DictionaryValue(); |
| 636 | data->SetString("internal_name", experiment.internal_name); |
| 637 | data->SetString("name", |
| 638 | l10n_util::GetStringUTF16(experiment.visible_name_id)); |
| 639 | data->SetString("description", |
| 640 | l10n_util::GetStringUTF16( |
| 641 | experiment.visible_description_id)); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 642 | |
[email protected] | 28e35af | 2011-02-09 12:56:22 | [diff] [blame] | 643 | switch (experiment.type) { |
| 644 | case Experiment::SINGLE_VALUE: |
| 645 | data->SetBoolean( |
| 646 | "enabled", |
| 647 | enabled_experiments.count(experiment.internal_name) > 0); |
| 648 | break; |
| 649 | case Experiment::MULTI_VALUE: |
| 650 | data->Set("choices", CreateChoiceData(experiment, enabled_experiments)); |
| 651 | break; |
| 652 | default: |
| 653 | NOTREACHED(); |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 654 | } |
| 655 | |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 656 | experiments_data->Append(data); |
| 657 | } |
| 658 | return experiments_data; |
| 659 | } |
| 660 | |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 661 | bool IsRestartNeededToCommitChanges() { |
[email protected] | 8e8bb6d | 2010-12-13 08:18:55 | [diff] [blame] | 662 | return FlagsState::GetInstance()->IsRestartNeededToCommitChanges(); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 663 | } |
| 664 | |
| 665 | void SetExperimentEnabled( |
[email protected] | c7b7800a | 2010-10-07 18:51:35 | [diff] [blame] | 666 | PrefService* prefs, const std::string& internal_name, bool enable) { |
[email protected] | 8e8bb6d | 2010-12-13 08:18:55 | [diff] [blame] | 667 | FlagsState::GetInstance()->SetExperimentEnabled(prefs, internal_name, enable); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | void RemoveFlagsSwitches( |
| 671 | std::map<std::string, CommandLine::StringType>* switch_list) { |
[email protected] | 8e8bb6d | 2010-12-13 08:18:55 | [diff] [blame] | 672 | FlagsState::GetInstance()->RemoveFlagsSwitches(switch_list); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 673 | } |
| 674 | |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 675 | int GetCurrentPlatform() { |
| 676 | #if defined(OS_MACOSX) |
| 677 | return kOsMac; |
| 678 | #elif defined(OS_WIN) |
| 679 | return kOsWin; |
| 680 | #elif defined(OS_CHROMEOS) // Needs to be before the OS_LINUX check. |
| 681 | return kOsCrOS; |
[email protected] | c92f4ed | 2011-10-21 19:50:21 | [diff] [blame] | 682 | #elif defined(OS_LINUX) || defined(OS_OPENBSD) |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 683 | return kOsLinux; |
| 684 | #else |
| 685 | #error Unknown platform |
| 686 | #endif |
| 687 | } |
| 688 | |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 689 | void RecordUMAStatistics(const PrefService* prefs) { |
| 690 | std::set<std::string> flags; |
| 691 | GetEnabledFlags(prefs, &flags); |
| 692 | for (std::set<std::string>::iterator it = flags.begin(); it != flags.end(); |
| 693 | ++it) { |
| 694 | std::string action("AboutFlags_"); |
| 695 | action += *it; |
| 696 | UserMetrics::RecordComputedAction(action); |
| 697 | } |
| 698 | // Since flag metrics are recorded every startup, add a tick so that the |
| 699 | // stats can be made meaningful. |
| 700 | if (flags.size()) |
| 701 | UserMetrics::RecordAction(UserMetricsAction("AboutFlags_StartupTick")); |
[email protected] | 970b2fd | 2011-01-22 18:06:45 | [diff] [blame] | 702 | UserMetrics::RecordAction(UserMetricsAction("StartupTick")); |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 703 | } |
| 704 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 705 | ////////////////////////////////////////////////////////////////////////////// |
| 706 | // FlagsState implementation. |
| 707 | |
| 708 | namespace { |
| 709 | |
| 710 | void FlagsState::ConvertFlagsToSwitches( |
| 711 | PrefService* prefs, CommandLine* command_line) { |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 712 | if (command_line->HasSwitch(switches::kNoExperiments)) |
| 713 | return; |
| 714 | |
| 715 | std::set<std::string> enabled_experiments; |
[email protected] | ba816424 | 2010-11-16 21:31:00 | [diff] [blame] | 716 | |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 717 | GetSanitizedEnabledFlagsForCurrentPlatform(prefs, &enabled_experiments); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 718 | |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 719 | typedef std::map<std::string, std::pair<std::string, std::string> > |
| 720 | NameToSwitchAndValueMap; |
| 721 | NameToSwitchAndValueMap name_to_switch_map; |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 722 | for (size_t i = 0; i < num_experiments; ++i) { |
| 723 | const Experiment& e = experiments[i]; |
| 724 | if (e.type == Experiment::SINGLE_VALUE) { |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 725 | name_to_switch_map[e.internal_name] = |
| 726 | std::pair<std::string, std::string>(e.command_line_switch, |
| 727 | e.command_line_value); |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 728 | } else { |
| 729 | for (int j = 0; j < e.num_choices; ++j) |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 730 | name_to_switch_map[NameForChoice(e, j)] = |
| 731 | std::pair<std::string, std::string>( |
| 732 | e.choices[j].command_line_switch, |
| 733 | e.choices[j].command_line_value); |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 734 | } |
| 735 | } |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 736 | |
| 737 | command_line->AppendSwitch(switches::kFlagSwitchesBegin); |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 738 | flags_switches_.insert( |
| 739 | std::pair<std::string, std::string>(switches::kFlagSwitchesBegin, |
| 740 | std::string())); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 741 | for (std::set<std::string>::iterator it = enabled_experiments.begin(); |
| 742 | it != enabled_experiments.end(); |
| 743 | ++it) { |
| 744 | const std::string& experiment_name = *it; |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 745 | NameToSwitchAndValueMap::const_iterator name_to_switch_it = |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 746 | name_to_switch_map.find(experiment_name); |
| 747 | if (name_to_switch_it == name_to_switch_map.end()) { |
| 748 | NOTREACHED(); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 749 | continue; |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 750 | } |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 751 | |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 752 | const std::pair<std::string, std::string>& |
| 753 | switch_and_value_pair = name_to_switch_it->second; |
| 754 | |
| 755 | command_line->AppendSwitchASCII(switch_and_value_pair.first, |
| 756 | switch_and_value_pair.second); |
| 757 | flags_switches_[switch_and_value_pair.first] = switch_and_value_pair.second; |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 758 | } |
| 759 | command_line->AppendSwitch(switches::kFlagSwitchesEnd); |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 760 | flags_switches_.insert( |
| 761 | std::pair<std::string, std::string>(switches::kFlagSwitchesEnd, |
| 762 | std::string())); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | bool FlagsState::IsRestartNeededToCommitChanges() { |
| 766 | return needs_restart_; |
| 767 | } |
| 768 | |
| 769 | void FlagsState::SetExperimentEnabled( |
| 770 | PrefService* prefs, const std::string& internal_name, bool enable) { |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 771 | needs_restart_ = true; |
| 772 | |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 773 | size_t at_index = internal_name.find(about_flags::testing::kMultiSeparator); |
| 774 | if (at_index != std::string::npos) { |
| 775 | DCHECK(enable); |
| 776 | // We're being asked to enable a multi-choice experiment. Disable the |
| 777 | // currently selected choice. |
| 778 | DCHECK_NE(at_index, 0u); |
[email protected] | 28e35af | 2011-02-09 12:56:22 | [diff] [blame] | 779 | const std::string experiment_name = internal_name.substr(0, at_index); |
| 780 | SetExperimentEnabled(prefs, experiment_name, false); |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 781 | |
[email protected] | 28e35af | 2011-02-09 12:56:22 | [diff] [blame] | 782 | // And enable the new choice, if it is not the default first choice. |
| 783 | if (internal_name != experiment_name + "@0") { |
| 784 | std::set<std::string> enabled_experiments; |
| 785 | GetSanitizedEnabledFlags(prefs, &enabled_experiments); |
| 786 | enabled_experiments.insert(internal_name); |
| 787 | SetEnabledFlags(prefs, enabled_experiments); |
| 788 | } |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 789 | return; |
| 790 | } |
| 791 | |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 792 | std::set<std::string> enabled_experiments; |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 793 | GetSanitizedEnabledFlags(prefs, &enabled_experiments); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 794 | |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 795 | const Experiment* e = NULL; |
| 796 | for (size_t i = 0; i < num_experiments; ++i) { |
| 797 | if (experiments[i].internal_name == internal_name) { |
| 798 | e = experiments + i; |
| 799 | break; |
| 800 | } |
| 801 | } |
| 802 | DCHECK(e); |
| 803 | |
| 804 | if (e->type == Experiment::SINGLE_VALUE) { |
[email protected] | 8a271368 | 2011-08-19 10:36:59 | [diff] [blame] | 805 | if (enable) |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 806 | enabled_experiments.insert(internal_name); |
[email protected] | 8a271368 | 2011-08-19 10:36:59 | [diff] [blame] | 807 | else |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 808 | enabled_experiments.erase(internal_name); |
| 809 | } else { |
| 810 | if (enable) { |
| 811 | // Enable the first choice. |
| 812 | enabled_experiments.insert(NameForChoice(*e, 0)); |
| 813 | } else { |
| 814 | // Find the currently enabled choice and disable it. |
| 815 | for (int i = 0; i < e->num_choices; ++i) { |
| 816 | std::string choice_name = NameForChoice(*e, i); |
| 817 | if (enabled_experiments.find(choice_name) != |
| 818 | enabled_experiments.end()) { |
| 819 | enabled_experiments.erase(choice_name); |
| 820 | // Continue on just in case there's a bug and more than one |
| 821 | // experiment for this choice was enabled. |
| 822 | } |
| 823 | } |
| 824 | } |
| 825 | } |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 826 | |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 827 | SetEnabledFlags(prefs, enabled_experiments); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 828 | } |
| 829 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 830 | void FlagsState::RemoveFlagsSwitches( |
| 831 | std::map<std::string, CommandLine::StringType>* switch_list) { |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 832 | for (std::map<std::string, std::string>::const_iterator |
| 833 | it = flags_switches_.begin(); it != flags_switches_.end(); ++it) { |
| 834 | switch_list->erase(it->first); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 835 | } |
| 836 | } |
| 837 | |
| 838 | void FlagsState::reset() { |
| 839 | needs_restart_ = false; |
| 840 | flags_switches_.clear(); |
| 841 | } |
| 842 | |
[email protected] | 38e4681 | 2011-05-09 20:49:22 | [diff] [blame] | 843 | } // namespace |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 844 | |
| 845 | namespace testing { |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 846 | |
| 847 | // WARNING: '@' is also used in the html file. If you update this constant you |
| 848 | // also need to update the html file. |
| 849 | const char kMultiSeparator[] = "@"; |
| 850 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 851 | void ClearState() { |
[email protected] | 8e8bb6d | 2010-12-13 08:18:55 | [diff] [blame] | 852 | FlagsState::GetInstance()->reset(); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 853 | } |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 854 | |
| 855 | void SetExperiments(const Experiment* e, size_t count) { |
| 856 | if (!e) { |
| 857 | experiments = kExperiments; |
| 858 | num_experiments = arraysize(kExperiments); |
| 859 | } else { |
| 860 | experiments = e; |
| 861 | num_experiments = count; |
| 862 | } |
| 863 | } |
| 864 | |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 865 | const Experiment* GetExperiments(size_t* count) { |
| 866 | *count = num_experiments; |
| 867 | return experiments; |
| 868 | } |
| 869 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 870 | } // namespace testing |
| 871 | |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 872 | } // namespace about_flags |