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