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