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