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