[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] | a8f1eaa | 2011-03-07 19:00:58 | [diff] [blame] | 158 | "show-fps-counter", |
| 159 | IDS_FLAGS_SHOW_FPS_COUNTER, |
| 160 | IDS_FLAGS_SHOW_FPS_COUNTER_DESCRIPTION, |
| 161 | kOsAll, |
| 162 | SINGLE_VALUE_TYPE(switches::kShowFPSCounter) |
| 163 | }, |
[email protected] | 8ff7f34 | 2011-05-25 01:49:47 | [diff] [blame] | 164 | { |
| 165 | "disable-gpu-vsync", |
| 166 | IDS_FLAGS_DISABLE_GPU_VSYNC_NAME, |
| 167 | IDS_FLAGS_DISABLE_GPU_VSYNC_DESCRIPTION, |
| 168 | kOsAll, |
| 169 | SINGLE_VALUE_TYPE(switches::kDisableGpuVsync) |
| 170 | }, |
[email protected] | 38e4681 | 2011-05-09 20:49:22 | [diff] [blame] | 171 | #if !defined(GOOGLE_CHROME_BUILD) |
| 172 | // Only expose this for Chromium builds where users may not have the PDF |
| 173 | // plugin. Do not give Google Chrome users the option to disable it here. |
[email protected] | 8d260e5 | 2010-10-13 01:03:05 | [diff] [blame] | 174 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 175 | "print-preview", // FLAGS:RECORD_UMA |
[email protected] | 9486c1f | 2010-10-14 19:52:12 | [diff] [blame] | 176 | IDS_FLAGS_PRINT_PREVIEW_NAME, |
| 177 | IDS_FLAGS_PRINT_PREVIEW_DESCRIPTION, |
[email protected] | 38e4681 | 2011-05-09 20:49:22 | [diff] [blame] | 178 | kOsMac | kOsWin | kOsLinux, // This switch is not available in CrOS. |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 179 | SINGLE_VALUE_TYPE(switches::kEnablePrintPreview) |
[email protected] | 2fe15fcb | 2010-10-21 20:39:53 | [diff] [blame] | 180 | }, |
[email protected] | 38e4681 | 2011-05-09 20:49:22 | [diff] [blame] | 181 | #endif |
[email protected] | d208f4d8 | 2011-05-23 21:52:03 | [diff] [blame] | 182 | // TODO(dspringer): When NaCl is on by default, remove this flag entry. |
[email protected] | 2fe15fcb | 2010-10-21 20:39:53 | [diff] [blame] | 183 | { |
[email protected] | d208f4d8 | 2011-05-23 21:52:03 | [diff] [blame] | 184 | switches::kEnableNaCl, // FLAGS:RECORD_UMA |
[email protected] | 4ff87d20 | 2010-11-06 01:28:40 | [diff] [blame] | 185 | IDS_FLAGS_ENABLE_NACL_NAME, |
| 186 | IDS_FLAGS_ENABLE_NACL_DESCRIPTION, |
| 187 | kOsAll, |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 188 | SINGLE_VALUE_TYPE(switches::kEnableNaCl) |
[email protected] | 4ff87d20 | 2010-11-06 01:28:40 | [diff] [blame] | 189 | }, |
| 190 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 191 | "dns-server", // FLAGS:RECORD_UMA |
[email protected] | 2fe15fcb | 2010-10-21 20:39:53 | [diff] [blame] | 192 | IDS_FLAGS_DNS_SERVER_NAME, |
| 193 | IDS_FLAGS_DNS_SERVER_DESCRIPTION, |
| 194 | kOsLinux, |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 195 | SINGLE_VALUE_TYPE(switches::kDnsServer) |
[email protected] | 2fe15fcb | 2010-10-21 20:39:53 | [diff] [blame] | 196 | }, |
[email protected] | 177aceb | 2010-11-03 16:17:41 | [diff] [blame] | 197 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 198 | "extension-apis", // FLAGS:RECORD_UMA |
[email protected] | 11dd68cd5 | 2010-11-12 01:15:32 | [diff] [blame] | 199 | IDS_FLAGS_EXPERIMENTAL_EXTENSION_APIS_NAME, |
| 200 | IDS_FLAGS_EXPERIMENTAL_EXTENSION_APIS_DESCRIPTION, |
| 201 | kOsAll, |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 202 | SINGLE_VALUE_TYPE(switches::kEnableExperimentalExtensionApis) |
[email protected] | 11dd68cd5 | 2010-11-12 01:15:32 | [diff] [blame] | 203 | }, |
[email protected] | 3627b06d | 2010-11-12 16:36:16 | [diff] [blame] | 204 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 205 | "click-to-play", // FLAGS:RECORD_UMA |
[email protected] | 3627b06d | 2010-11-12 16:36:16 | [diff] [blame] | 206 | IDS_FLAGS_CLICK_TO_PLAY_NAME, |
| 207 | IDS_FLAGS_CLICK_TO_PLAY_DESCRIPTION, |
| 208 | kOsAll, |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 209 | SINGLE_VALUE_TYPE(switches::kEnableClickToPlay) |
[email protected] | 3627b06d | 2010-11-12 16:36:16 | [diff] [blame] | 210 | }, |
[email protected] | 80bd24e | 2010-11-30 09:34:38 | [diff] [blame] | 211 | { |
| 212 | "disable-hyperlink-auditing", |
| 213 | IDS_FLAGS_DISABLE_HYPERLINK_AUDITING_NAME, |
| 214 | IDS_FLAGS_DISABLE_HYPERLINK_AUDITING_DESCRIPTION, |
| 215 | kOsAll, |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 216 | SINGLE_VALUE_TYPE(switches::kNoPings) |
[email protected] | feb28fef | 2010-12-01 10:52:51 | [diff] [blame] | 217 | }, |
| 218 | { |
| 219 | "experimental-location-features", // FLAGS:RECORD_UMA |
| 220 | IDS_FLAGS_EXPERIMENTAL_LOCATION_FEATURES_NAME, |
| 221 | IDS_FLAGS_EXPERIMENTAL_LOCATION_FEATURES_DESCRIPTION, |
| 222 | kOsMac | kOsWin | kOsLinux, // Currently does nothing on CrOS. |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 223 | SINGLE_VALUE_TYPE(switches::kExperimentalLocationFeatures) |
| 224 | }, |
| 225 | { |
[email protected] | 4c6452d | 2011-01-12 08:47:57 | [diff] [blame] | 226 | "block-reading-third-party-cookies", |
| 227 | IDS_FLAGS_BLOCK_ALL_THIRD_PARTY_COOKIES_NAME, |
| 228 | IDS_FLAGS_BLOCK_ALL_THIRD_PARTY_COOKIES_DESCRIPTION, |
| 229 | kOsAll, |
| 230 | SINGLE_VALUE_TYPE(switches::kBlockReadingThirdPartyCookies) |
| 231 | }, |
[email protected] | 0422796 | 2011-01-20 02:03:09 | [diff] [blame] | 232 | { |
| 233 | "disable-interactive-form-validation", |
| 234 | IDS_FLAGS_DISABLE_INTERACTIVE_FORM_VALIDATION_NAME, |
| 235 | IDS_FLAGS_DISABLE_INTERACTIVE_FORM_VALIDATION_DESCRIPTION, |
| 236 | kOsAll, |
| 237 | SINGLE_VALUE_TYPE(switches::kDisableInteractiveFormValidation) |
| 238 | }, |
[email protected] | 8df5119 | 2011-01-22 20:05:03 | [diff] [blame] | 239 | { |
| 240 | "webaudio", |
| 241 | IDS_FLAGS_WEBAUDIO_NAME, |
| 242 | IDS_FLAGS_WEBAUDIO_DESCRIPTION, |
[email protected] | 54afa74 | 2011-04-29 21:21:34 | [diff] [blame] | 243 | // This switch is currently not available in CrOS. |
| 244 | // TODO(crogers): FFmpeg Windows DLLs need to be rebuilt for chromium. |
| 245 | #if defined(GOOGLE_CHROME_BUILD) |
| 246 | kOsMac | kOsWin | kOsLinux, |
| 247 | #else |
| 248 | kOsMac | kOsLinux, |
| 249 | #endif |
[email protected] | 8df5119 | 2011-01-22 20:05:03 | [diff] [blame] | 250 | SINGLE_VALUE_TYPE(switches::kEnableWebAudio) |
| 251 | }, |
[email protected] | 3828d6f | 2011-02-24 18:32:21 | [diff] [blame] | 252 | { |
[email protected] | 6c54e7e4 | 2011-03-02 20:52:34 | [diff] [blame] | 253 | "p2papi", |
| 254 | IDS_FLAGS_P2P_API_NAME, |
| 255 | IDS_FLAGS_P2P_API_DESCRIPTION, |
| 256 | kOsAll, |
[email protected] | a026daa | 2011-04-20 15:49:51 | [diff] [blame] | 257 | #if defined(ENABLE_P2P_APIS) |
[email protected] | 6c54e7e4 | 2011-03-02 20:52:34 | [diff] [blame] | 258 | SINGLE_VALUE_TYPE(switches::kEnableP2PApi) |
[email protected] | a026daa | 2011-04-20 15:49:51 | [diff] [blame] | 259 | #else |
| 260 | SINGLE_VALUE_TYPE("") |
| 261 | #endif |
[email protected] | 6c54e7e4 | 2011-03-02 20:52:34 | [diff] [blame] | 262 | }, |
[email protected] | 07d490bc | 2011-03-07 17:05:26 | [diff] [blame] | 263 | { |
| 264 | "focus-existing-tab-on-open", // FLAGS:RECORD_UMA |
| 265 | IDS_FLAGS_FOCUS_EXISTING_TAB_ON_OPEN_NAME, |
| 266 | IDS_FLAGS_FOCUS_EXISTING_TAB_ON_OPEN_DESCRIPTION, |
| 267 | kOsAll, |
| 268 | SINGLE_VALUE_TYPE(switches::kFocusExistingTabOnOpen) |
| 269 | }, |
[email protected] | d5dcfb3 | 2011-03-19 00:49:24 | [diff] [blame] | 270 | { |
[email protected] | ac86c98 | 2011-05-11 13:26:05 | [diff] [blame] | 271 | "compact-navigation", |
| 272 | IDS_FLAGS_ENABLE_COMPACT_NAVIGATION, |
| 273 | IDS_FLAGS_ENABLE_COMPACT_NAVIGATION_DESCRIPTION, |
| 274 | kOsWin, // TODO(stevet): Add other platforms when ready. |
| 275 | SINGLE_VALUE_TYPE(switches::kEnableCompactNavigation) |
| 276 | }, |
| 277 | { |
[email protected] | d5dcfb3 | 2011-03-19 00:49:24 | [diff] [blame] | 278 | "new-tab-page-4", |
| 279 | IDS_FLAGS_NEW_TAB_PAGE_4_NAME, |
| 280 | IDS_FLAGS_NEW_TAB_PAGE_4_DESCRIPTION, |
| 281 | kOsAll, |
| 282 | SINGLE_VALUE_TYPE(switches::kNewTabPage4) |
| 283 | }, |
[email protected] | 5aea186 | 2011-03-23 23:55:39 | [diff] [blame] | 284 | { |
| 285 | "tab-groups-context-menu", |
| 286 | IDS_FLAGS_TAB_GROUPS_CONTEXT_MENU_NAME, |
| 287 | IDS_FLAGS_TAB_GROUPS_CONTEXT_MENU_DESCRIPTION, |
| 288 | kOsWin, |
| 289 | SINGLE_VALUE_TYPE(switches::kEnableTabGroupsContextMenu) |
| 290 | }, |
[email protected] | e9bf9d9 | 2011-03-31 20:57:15 | [diff] [blame] | 291 | { |
| 292 | "ppapi-flash-in-process", |
| 293 | IDS_FLAGS_PPAPI_FLASH_IN_PROCESS_NAME, |
| 294 | IDS_FLAGS_PPAPI_FLASH_IN_PROCESS_DESCRIPTION, |
[email protected] | f2d3ce0d | 2011-04-01 18:19:30 | [diff] [blame] | 295 | kOsAll, |
[email protected] | e9bf9d9 | 2011-03-31 20:57:15 | [diff] [blame] | 296 | SINGLE_VALUE_TYPE(switches::kPpapiFlashInProcess) |
| 297 | }, |
[email protected] | ce573714 | 2011-04-14 23:35:09 | [diff] [blame] | 298 | { |
[email protected] | 20b5df96 | 2011-04-18 22:07:43 | [diff] [blame] | 299 | "multi-profiles", |
| 300 | IDS_FLAGS_MULTI_PROFILES_NAME, |
| 301 | IDS_FLAGS_MULTI_PROFILES_DESCRIPTION, |
| 302 | kOsAll, |
| 303 | SINGLE_VALUE_TYPE(switches::kMultiProfiles) |
| 304 | }, |
[email protected] | cc057b0 | 2011-04-21 17:19:04 | [diff] [blame] | 305 | { |
[email protected] | 08338b86 | 2011-05-05 20:22:23 | [diff] [blame] | 306 | "restrict-instant-to-search", |
| 307 | IDS_FLAGS_RESTRICT_INSTANT_TO_SEARCH_NAME, |
| 308 | IDS_FLAGS_RESTRICT_INSTANT_TO_SEARCH_DESCRIPTION, |
| 309 | kOsAll, |
| 310 | SINGLE_VALUE_TYPE(switches::kRestrictInstantToSearch) |
| 311 | }, |
[email protected] | b652fc8 | 2011-05-23 07:53:05 | [diff] [blame] | 312 | { |
| 313 | "indexeddb-use-leveldb", // FLAGS:RECORD_UMA |
| 314 | IDS_FLAGS_INDEXEDDB_USE_LEVELDB_NAME, |
| 315 | IDS_FLAGS_INDEXEDDB_USE_LEVELDB_DESCRIPTION, |
| 316 | kOsAll, |
| 317 | SINGLE_VALUE_TYPE(switches::kLevelDBIndexedDatabase) |
| 318 | }, |
[email protected] | f2557bd | 2011-06-01 02:33:07 | [diff] [blame^] | 319 | { |
| 320 | "preload-instant-search", |
| 321 | IDS_FLAGS_PRELOAD_INSTANT_SEARCH_NAME, |
| 322 | IDS_FLAGS_PRELOAD_INSTANT_SEARCH_DESCRIPTION, |
| 323 | kOsAll, |
| 324 | SINGLE_VALUE_TYPE(switches::kPreloadInstantSearch) |
| 325 | }, |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 326 | }; |
| 327 | |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 328 | const Experiment* experiments = kExperiments; |
| 329 | size_t num_experiments = arraysize(kExperiments); |
| 330 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 331 | // Stores and encapsulates the little state that about:flags has. |
| 332 | class FlagsState { |
| 333 | public: |
| 334 | FlagsState() : needs_restart_(false) {} |
| 335 | void ConvertFlagsToSwitches(PrefService* prefs, CommandLine* command_line); |
| 336 | bool IsRestartNeededToCommitChanges(); |
| 337 | void SetExperimentEnabled( |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 338 | PrefService* prefs, const std::string& internal_name, bool enable); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 339 | void RemoveFlagsSwitches( |
| 340 | std::map<std::string, CommandLine::StringType>* switch_list); |
| 341 | void reset(); |
| 342 | |
| 343 | // Returns the singleton instance of this class |
[email protected] | 8e8bb6d | 2010-12-13 08:18:55 | [diff] [blame] | 344 | static FlagsState* GetInstance() { |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 345 | return Singleton<FlagsState>::get(); |
| 346 | } |
| 347 | |
| 348 | private: |
| 349 | bool needs_restart_; |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 350 | std::map<std::string, std::string> flags_switches_; |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 351 | |
| 352 | DISALLOW_COPY_AND_ASSIGN(FlagsState); |
| 353 | }; |
| 354 | |
[email protected] | c7b7800a | 2010-10-07 18:51:35 | [diff] [blame] | 355 | // Extracts the list of enabled lab experiments from preferences and stores them |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 356 | // in a set. |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 357 | void GetEnabledFlags(const PrefService* prefs, std::set<std::string>* result) { |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 358 | const ListValue* enabled_experiments = prefs->GetList( |
| 359 | prefs::kEnabledLabsExperiments); |
| 360 | if (!enabled_experiments) |
| 361 | return; |
| 362 | |
| 363 | for (ListValue::const_iterator it = enabled_experiments->begin(); |
| 364 | it != enabled_experiments->end(); |
| 365 | ++it) { |
| 366 | std::string experiment_name; |
| 367 | if (!(*it)->GetAsString(&experiment_name)) { |
| 368 | LOG(WARNING) << "Invalid entry in " << prefs::kEnabledLabsExperiments; |
| 369 | continue; |
| 370 | } |
| 371 | result->insert(experiment_name); |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | // Takes a set of enabled lab experiments |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 376 | void SetEnabledFlags( |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 377 | PrefService* prefs, const std::set<std::string>& enabled_experiments) { |
[email protected] | 1bc7842 | 2011-03-31 08:41:38 | [diff] [blame] | 378 | ListPrefUpdate update(prefs, prefs::kEnabledLabsExperiments); |
| 379 | ListValue* experiments_list = update.Get(); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 380 | |
| 381 | experiments_list->Clear(); |
| 382 | for (std::set<std::string>::const_iterator it = enabled_experiments.begin(); |
| 383 | it != enabled_experiments.end(); |
| 384 | ++it) { |
| 385 | experiments_list->Append(new StringValue(*it)); |
| 386 | } |
| 387 | } |
| 388 | |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 389 | // Returns the name used in prefs for the choice at the specified index. |
| 390 | std::string NameForChoice(const Experiment& e, int index) { |
[email protected] | 2ce9c8975 | 2011-02-25 18:24:34 | [diff] [blame] | 391 | DCHECK_EQ(Experiment::MULTI_VALUE, e.type); |
| 392 | DCHECK_LT(index, e.num_choices); |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 393 | return std::string(e.internal_name) + about_flags::testing::kMultiSeparator + |
| 394 | base::IntToString(index); |
| 395 | } |
| 396 | |
| 397 | // Adds the internal names for the specified experiment to |names|. |
| 398 | void AddInternalName(const Experiment& e, std::set<std::string>* names) { |
| 399 | if (e.type == Experiment::SINGLE_VALUE) { |
| 400 | names->insert(e.internal_name); |
| 401 | } else { |
[email protected] | 2ce9c8975 | 2011-02-25 18:24:34 | [diff] [blame] | 402 | DCHECK_EQ(Experiment::MULTI_VALUE, e.type); |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 403 | for (int i = 0; i < e.num_choices; ++i) |
| 404 | names->insert(NameForChoice(e, i)); |
| 405 | } |
| 406 | } |
| 407 | |
[email protected] | 28e35af | 2011-02-09 12:56:22 | [diff] [blame] | 408 | // Confirms that an experiment is valid, used in a DCHECK in |
| 409 | // SanitizeList below. |
| 410 | bool ValidateExperiment(const Experiment& e) { |
| 411 | switch (e.type) { |
| 412 | case Experiment::SINGLE_VALUE: |
| 413 | DCHECK_EQ(0, e.num_choices); |
| 414 | DCHECK(!e.choices); |
| 415 | break; |
| 416 | case Experiment::MULTI_VALUE: |
| 417 | DCHECK_GT(e.num_choices, 0); |
| 418 | DCHECK(e.choices); |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 419 | DCHECK(e.choices[0].command_line_switch); |
| 420 | DCHECK_EQ('\0', e.choices[0].command_line_switch[0]); |
[email protected] | 28e35af | 2011-02-09 12:56:22 | [diff] [blame] | 421 | break; |
| 422 | default: |
| 423 | NOTREACHED(); |
| 424 | } |
| 425 | return true; |
| 426 | } |
| 427 | |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 428 | // Removes all experiments from prefs::kEnabledLabsExperiments that are |
| 429 | // unknown, to prevent this list to become very long as experiments are added |
| 430 | // and removed. |
| 431 | void SanitizeList(PrefService* prefs) { |
| 432 | std::set<std::string> known_experiments; |
[email protected] | 28e35af | 2011-02-09 12:56:22 | [diff] [blame] | 433 | for (size_t i = 0; i < num_experiments; ++i) { |
| 434 | DCHECK(ValidateExperiment(experiments[i])); |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 435 | AddInternalName(experiments[i], &known_experiments); |
[email protected] | 28e35af | 2011-02-09 12:56:22 | [diff] [blame] | 436 | } |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 437 | |
| 438 | std::set<std::string> enabled_experiments; |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 439 | GetEnabledFlags(prefs, &enabled_experiments); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 440 | |
| 441 | std::set<std::string> new_enabled_experiments; |
| 442 | std::set_intersection( |
| 443 | known_experiments.begin(), known_experiments.end(), |
| 444 | enabled_experiments.begin(), enabled_experiments.end(), |
| 445 | std::inserter(new_enabled_experiments, new_enabled_experiments.begin())); |
| 446 | |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 447 | SetEnabledFlags(prefs, new_enabled_experiments); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 448 | } |
| 449 | |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 450 | void GetSanitizedEnabledFlags( |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 451 | PrefService* prefs, std::set<std::string>* result) { |
| 452 | SanitizeList(prefs); |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 453 | GetEnabledFlags(prefs, result); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 454 | } |
| 455 | |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 456 | // Variant of GetSanitizedEnabledFlags that also removes any flags that aren't |
| 457 | // enabled on the current platform. |
| 458 | void GetSanitizedEnabledFlagsForCurrentPlatform( |
| 459 | PrefService* prefs, std::set<std::string>* result) { |
| 460 | GetSanitizedEnabledFlags(prefs, result); |
| 461 | |
| 462 | // Filter out any experiments that aren't enabled on the current platform. We |
| 463 | // don't remove these from prefs else syncing to a platform with a different |
| 464 | // set of experiments would be lossy. |
| 465 | std::set<std::string> platform_experiments; |
| 466 | int current_platform = GetCurrentPlatform(); |
| 467 | for (size_t i = 0; i < num_experiments; ++i) { |
| 468 | if (experiments[i].supported_platforms & current_platform) |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 469 | AddInternalName(experiments[i], &platform_experiments); |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | std::set<std::string> new_enabled_experiments; |
| 473 | std::set_intersection( |
| 474 | platform_experiments.begin(), platform_experiments.end(), |
| 475 | result->begin(), result->end(), |
| 476 | std::inserter(new_enabled_experiments, new_enabled_experiments.begin())); |
| 477 | |
| 478 | result->swap(new_enabled_experiments); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 479 | } |
| 480 | |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 481 | // Returns the Value representing the choice data in the specified experiment. |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 482 | Value* CreateChoiceData(const Experiment& experiment, |
[email protected] | 28e35af | 2011-02-09 12:56:22 | [diff] [blame] | 483 | const std::set<std::string>& enabled_experiments) { |
[email protected] | 2ce9c8975 | 2011-02-25 18:24:34 | [diff] [blame] | 484 | DCHECK_EQ(Experiment::MULTI_VALUE, experiment.type); |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 485 | ListValue* result = new ListValue; |
| 486 | for (int i = 0; i < experiment.num_choices; ++i) { |
| 487 | const Experiment::Choice& choice = experiment.choices[i]; |
| 488 | DictionaryValue* value = new DictionaryValue; |
| 489 | std::string name = NameForChoice(experiment, i); |
| 490 | value->SetString("description", |
| 491 | l10n_util::GetStringUTF16(choice.description_id)); |
| 492 | value->SetString("internal_name", name); |
[email protected] | 28e35af | 2011-02-09 12:56:22 | [diff] [blame] | 493 | value->SetBoolean("selected", enabled_experiments.count(name) > 0); |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 494 | result->Append(value); |
| 495 | } |
| 496 | return result; |
| 497 | } |
| 498 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 499 | } // namespace |
| 500 | |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 501 | void ConvertFlagsToSwitches(PrefService* prefs, CommandLine* command_line) { |
[email protected] | 8e8bb6d | 2010-12-13 08:18:55 | [diff] [blame] | 502 | FlagsState::GetInstance()->ConvertFlagsToSwitches(prefs, command_line); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 503 | } |
| 504 | |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 505 | ListValue* GetFlagsExperimentsData(PrefService* prefs) { |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 506 | std::set<std::string> enabled_experiments; |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 507 | GetSanitizedEnabledFlags(prefs, &enabled_experiments); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 508 | |
| 509 | int current_platform = GetCurrentPlatform(); |
| 510 | |
| 511 | ListValue* experiments_data = new ListValue(); |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 512 | for (size_t i = 0; i < num_experiments; ++i) { |
| 513 | const Experiment& experiment = experiments[i]; |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 514 | if (!(experiment.supported_platforms & current_platform)) |
| 515 | continue; |
| 516 | |
| 517 | DictionaryValue* data = new DictionaryValue(); |
| 518 | data->SetString("internal_name", experiment.internal_name); |
| 519 | data->SetString("name", |
| 520 | l10n_util::GetStringUTF16(experiment.visible_name_id)); |
| 521 | data->SetString("description", |
| 522 | l10n_util::GetStringUTF16( |
| 523 | experiment.visible_description_id)); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 524 | |
[email protected] | 28e35af | 2011-02-09 12:56:22 | [diff] [blame] | 525 | switch (experiment.type) { |
| 526 | case Experiment::SINGLE_VALUE: |
| 527 | data->SetBoolean( |
| 528 | "enabled", |
| 529 | enabled_experiments.count(experiment.internal_name) > 0); |
| 530 | break; |
| 531 | case Experiment::MULTI_VALUE: |
| 532 | data->Set("choices", CreateChoiceData(experiment, enabled_experiments)); |
| 533 | break; |
| 534 | default: |
| 535 | NOTREACHED(); |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 536 | } |
| 537 | |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 538 | experiments_data->Append(data); |
| 539 | } |
| 540 | return experiments_data; |
| 541 | } |
| 542 | |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 543 | bool IsRestartNeededToCommitChanges() { |
[email protected] | 8e8bb6d | 2010-12-13 08:18:55 | [diff] [blame] | 544 | return FlagsState::GetInstance()->IsRestartNeededToCommitChanges(); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | void SetExperimentEnabled( |
[email protected] | c7b7800a | 2010-10-07 18:51:35 | [diff] [blame] | 548 | PrefService* prefs, const std::string& internal_name, bool enable) { |
[email protected] | 8e8bb6d | 2010-12-13 08:18:55 | [diff] [blame] | 549 | FlagsState::GetInstance()->SetExperimentEnabled(prefs, internal_name, enable); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | void RemoveFlagsSwitches( |
| 553 | std::map<std::string, CommandLine::StringType>* switch_list) { |
[email protected] | 8e8bb6d | 2010-12-13 08:18:55 | [diff] [blame] | 554 | FlagsState::GetInstance()->RemoveFlagsSwitches(switch_list); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 555 | } |
| 556 | |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 557 | int GetCurrentPlatform() { |
| 558 | #if defined(OS_MACOSX) |
| 559 | return kOsMac; |
| 560 | #elif defined(OS_WIN) |
| 561 | return kOsWin; |
| 562 | #elif defined(OS_CHROMEOS) // Needs to be before the OS_LINUX check. |
| 563 | return kOsCrOS; |
| 564 | #elif defined(OS_LINUX) |
| 565 | return kOsLinux; |
| 566 | #else |
| 567 | #error Unknown platform |
| 568 | #endif |
| 569 | } |
| 570 | |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 571 | void RecordUMAStatistics(const PrefService* prefs) { |
| 572 | std::set<std::string> flags; |
| 573 | GetEnabledFlags(prefs, &flags); |
| 574 | for (std::set<std::string>::iterator it = flags.begin(); it != flags.end(); |
| 575 | ++it) { |
| 576 | std::string action("AboutFlags_"); |
| 577 | action += *it; |
| 578 | UserMetrics::RecordComputedAction(action); |
| 579 | } |
| 580 | // Since flag metrics are recorded every startup, add a tick so that the |
| 581 | // stats can be made meaningful. |
| 582 | if (flags.size()) |
| 583 | UserMetrics::RecordAction(UserMetricsAction("AboutFlags_StartupTick")); |
[email protected] | 970b2fd | 2011-01-22 18:06:45 | [diff] [blame] | 584 | UserMetrics::RecordAction(UserMetricsAction("StartupTick")); |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 585 | } |
| 586 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 587 | ////////////////////////////////////////////////////////////////////////////// |
| 588 | // FlagsState implementation. |
| 589 | |
| 590 | namespace { |
| 591 | |
| 592 | void FlagsState::ConvertFlagsToSwitches( |
| 593 | PrefService* prefs, CommandLine* command_line) { |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 594 | if (command_line->HasSwitch(switches::kNoExperiments)) |
| 595 | return; |
| 596 | |
| 597 | std::set<std::string> enabled_experiments; |
[email protected] | ba816424 | 2010-11-16 21:31:00 | [diff] [blame] | 598 | |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 599 | GetSanitizedEnabledFlagsForCurrentPlatform(prefs, &enabled_experiments); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 600 | |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 601 | typedef std::map<std::string, std::pair<std::string, std::string> > |
| 602 | NameToSwitchAndValueMap; |
| 603 | NameToSwitchAndValueMap name_to_switch_map; |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 604 | for (size_t i = 0; i < num_experiments; ++i) { |
| 605 | const Experiment& e = experiments[i]; |
| 606 | if (e.type == Experiment::SINGLE_VALUE) { |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 607 | name_to_switch_map[e.internal_name] = |
| 608 | std::pair<std::string, std::string>(e.command_line_switch, |
| 609 | e.command_line_value); |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 610 | } else { |
| 611 | for (int j = 0; j < e.num_choices; ++j) |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 612 | name_to_switch_map[NameForChoice(e, j)] = |
| 613 | std::pair<std::string, std::string>( |
| 614 | e.choices[j].command_line_switch, |
| 615 | e.choices[j].command_line_value); |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 616 | } |
| 617 | } |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 618 | |
| 619 | command_line->AppendSwitch(switches::kFlagSwitchesBegin); |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 620 | flags_switches_.insert( |
| 621 | std::pair<std::string, std::string>(switches::kFlagSwitchesBegin, |
| 622 | std::string())); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 623 | for (std::set<std::string>::iterator it = enabled_experiments.begin(); |
| 624 | it != enabled_experiments.end(); |
| 625 | ++it) { |
| 626 | const std::string& experiment_name = *it; |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 627 | NameToSwitchAndValueMap::const_iterator name_to_switch_it = |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 628 | name_to_switch_map.find(experiment_name); |
| 629 | if (name_to_switch_it == name_to_switch_map.end()) { |
| 630 | NOTREACHED(); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 631 | continue; |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 632 | } |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 633 | |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 634 | const std::pair<std::string, std::string>& |
| 635 | switch_and_value_pair = name_to_switch_it->second; |
| 636 | |
| 637 | command_line->AppendSwitchASCII(switch_and_value_pair.first, |
| 638 | switch_and_value_pair.second); |
| 639 | flags_switches_[switch_and_value_pair.first] = switch_and_value_pair.second; |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 640 | } |
| 641 | command_line->AppendSwitch(switches::kFlagSwitchesEnd); |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 642 | flags_switches_.insert( |
| 643 | std::pair<std::string, std::string>(switches::kFlagSwitchesEnd, |
| 644 | std::string())); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | bool FlagsState::IsRestartNeededToCommitChanges() { |
| 648 | return needs_restart_; |
| 649 | } |
| 650 | |
| 651 | void FlagsState::SetExperimentEnabled( |
| 652 | PrefService* prefs, const std::string& internal_name, bool enable) { |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 653 | needs_restart_ = true; |
| 654 | |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 655 | size_t at_index = internal_name.find(about_flags::testing::kMultiSeparator); |
| 656 | if (at_index != std::string::npos) { |
| 657 | DCHECK(enable); |
| 658 | // We're being asked to enable a multi-choice experiment. Disable the |
| 659 | // currently selected choice. |
| 660 | DCHECK_NE(at_index, 0u); |
[email protected] | 28e35af | 2011-02-09 12:56:22 | [diff] [blame] | 661 | const std::string experiment_name = internal_name.substr(0, at_index); |
| 662 | SetExperimentEnabled(prefs, experiment_name, false); |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 663 | |
[email protected] | 28e35af | 2011-02-09 12:56:22 | [diff] [blame] | 664 | // And enable the new choice, if it is not the default first choice. |
| 665 | if (internal_name != experiment_name + "@0") { |
| 666 | std::set<std::string> enabled_experiments; |
| 667 | GetSanitizedEnabledFlags(prefs, &enabled_experiments); |
| 668 | enabled_experiments.insert(internal_name); |
| 669 | SetEnabledFlags(prefs, enabled_experiments); |
| 670 | } |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 671 | return; |
| 672 | } |
| 673 | |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 674 | std::set<std::string> enabled_experiments; |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 675 | GetSanitizedEnabledFlags(prefs, &enabled_experiments); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 676 | |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 677 | const Experiment* e = NULL; |
| 678 | for (size_t i = 0; i < num_experiments; ++i) { |
| 679 | if (experiments[i].internal_name == internal_name) { |
| 680 | e = experiments + i; |
| 681 | break; |
| 682 | } |
| 683 | } |
| 684 | DCHECK(e); |
| 685 | |
| 686 | if (e->type == Experiment::SINGLE_VALUE) { |
[email protected] | d208f4d8 | 2011-05-23 21:52:03 | [diff] [blame] | 687 | if (enable) { |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 688 | enabled_experiments.insert(internal_name); |
[email protected] | d208f4d8 | 2011-05-23 21:52:03 | [diff] [blame] | 689 | // If enabling NaCl, make sure the plugin is also enabled. See bug |
| 690 | // http://code.google.com/p/chromium/issues/detail?id=81010 for more |
| 691 | // information. |
| 692 | // TODO(dspringer): When NaCl is on by default, remove this code. |
| 693 | if (internal_name == switches::kEnableNaCl) { |
| 694 | PluginUpdater* plugin_updater = PluginUpdater::GetInstance(); |
| 695 | string16 nacl_plugin_name = |
| 696 | ASCIIToUTF16(chrome::ChromeContentClient::kNaClPluginName); |
| 697 | plugin_updater->EnablePluginGroup(true, nacl_plugin_name); |
| 698 | } |
| 699 | } else { |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 700 | enabled_experiments.erase(internal_name); |
[email protected] | d208f4d8 | 2011-05-23 21:52:03 | [diff] [blame] | 701 | } |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 702 | } else { |
| 703 | if (enable) { |
| 704 | // Enable the first choice. |
| 705 | enabled_experiments.insert(NameForChoice(*e, 0)); |
| 706 | } else { |
| 707 | // Find the currently enabled choice and disable it. |
| 708 | for (int i = 0; i < e->num_choices; ++i) { |
| 709 | std::string choice_name = NameForChoice(*e, i); |
| 710 | if (enabled_experiments.find(choice_name) != |
| 711 | enabled_experiments.end()) { |
| 712 | enabled_experiments.erase(choice_name); |
| 713 | // Continue on just in case there's a bug and more than one |
| 714 | // experiment for this choice was enabled. |
| 715 | } |
| 716 | } |
| 717 | } |
| 718 | } |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 719 | |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 720 | SetEnabledFlags(prefs, enabled_experiments); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 721 | } |
| 722 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 723 | void FlagsState::RemoveFlagsSwitches( |
| 724 | std::map<std::string, CommandLine::StringType>* switch_list) { |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 725 | for (std::map<std::string, std::string>::const_iterator |
| 726 | it = flags_switches_.begin(); it != flags_switches_.end(); ++it) { |
| 727 | switch_list->erase(it->first); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 728 | } |
| 729 | } |
| 730 | |
| 731 | void FlagsState::reset() { |
| 732 | needs_restart_ = false; |
| 733 | flags_switches_.clear(); |
| 734 | } |
| 735 | |
[email protected] | 38e4681 | 2011-05-09 20:49:22 | [diff] [blame] | 736 | } // namespace |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 737 | |
| 738 | namespace testing { |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 739 | |
| 740 | // WARNING: '@' is also used in the html file. If you update this constant you |
| 741 | // also need to update the html file. |
| 742 | const char kMultiSeparator[] = "@"; |
| 743 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 744 | void ClearState() { |
[email protected] | 8e8bb6d | 2010-12-13 08:18:55 | [diff] [blame] | 745 | FlagsState::GetInstance()->reset(); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 746 | } |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 747 | |
| 748 | void SetExperiments(const Experiment* e, size_t count) { |
| 749 | if (!e) { |
| 750 | experiments = kExperiments; |
| 751 | num_experiments = arraysize(kExperiments); |
| 752 | } else { |
| 753 | experiments = e; |
| 754 | num_experiments = count; |
| 755 | } |
| 756 | } |
| 757 | |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 758 | const Experiment* GetExperiments(size_t* count) { |
| 759 | *count = num_experiments; |
| 760 | return experiments; |
| 761 | } |
| 762 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 763 | } // namespace testing |
| 764 | |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 765 | } // namespace about_flags |