[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 | |
| 12 | #include "app/l10n_util.h" |
| 13 | #include "base/command_line.h" |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 14 | #include "base/singleton.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" |
| 21 | |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 22 | namespace about_flags { |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 23 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 24 | namespace { |
| 25 | |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 26 | const unsigned kOsAll = kOsMac | kOsWin | kOsLinux | kOsCrOS; |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 27 | |
[email protected] | ba816424 | 2010-11-16 21:31:00 | [diff] [blame] | 28 | // Names for former Chrome OS Labs experiments, shared with prefs migration |
| 29 | // code. |
| 30 | const char kMediaPlayerExperimentName[] = "media-player"; |
| 31 | const char kAdvancedFileSystemExperimentName[] = "advanced-file-system"; |
| 32 | const char kVerticalTabsExperimentName[] = "vertical-tabs"; |
| 33 | |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 34 | // RECORDING USER METRICS FOR FLAGS: |
| 35 | // ----------------------------------------------------------------------------- |
| 36 | // The first line of the experiment is the internal name. If you'd like to |
| 37 | // gather statistics about the usage of your flag, you should append a marker |
| 38 | // comment to the end of the feature name, like so: |
| 39 | // "my-special-feature", // FLAGS:RECORD_UMA |
| 40 | // |
| 41 | // After doing that, run //chrome/tools/extract_actions.py (see instructions at |
| 42 | // the top of that file for details) to update the chromeactions.txt file, which |
| 43 | // will enable UMA to record your feature flag. |
| 44 | // |
| 45 | // After your feature has shipped under a flag, you can locate the metrics |
| 46 | // under the action name AboutFlags_internal-action-name. Actions are recorded |
| 47 | // once per startup, so you should divide this number by AboutFlags_StartupTick |
| 48 | // to get a sense of usage. Note that this will not be the same as number of |
| 49 | // users with a given feature enabled because users can quit and relaunch |
| 50 | // the application multiple times over a given time interval. |
| 51 | // TODO(rsesek): See if there's a way to count per-user, rather than |
| 52 | // per-startup. |
| 53 | |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 54 | const Experiment kExperiments[] = { |
| 55 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 56 | "expose-for-tabs", // FLAGS:RECORD_UMA |
[email protected] | 9486c1f | 2010-10-14 19:52:12 | [diff] [blame] | 57 | IDS_FLAGS_TABPOSE_NAME, |
| 58 | IDS_FLAGS_TABPOSE_DESCRIPTION, |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 59 | kOsMac, |
| 60 | #if defined(OS_MACOSX) |
| 61 | // The switch exists only on OS X. |
| 62 | switches::kEnableExposeForTabs |
| 63 | #else |
| 64 | "" |
| 65 | #endif |
| 66 | }, |
| 67 | { |
[email protected] | ba816424 | 2010-11-16 21:31:00 | [diff] [blame] | 68 | kMediaPlayerExperimentName, |
| 69 | IDS_FLAGS_MEDIA_PLAYER_NAME, |
| 70 | IDS_FLAGS_MEDIA_PLAYER_DESCRIPTION, |
| 71 | kOsCrOS, |
| 72 | #if defined(OS_CHROMEOS) |
| 73 | // The switch exists only on Chrome OS. |
| 74 | switches::kEnableMediaPlayer |
| 75 | #else |
| 76 | "" |
| 77 | #endif |
| 78 | }, |
| 79 | { |
| 80 | kAdvancedFileSystemExperimentName, |
| 81 | IDS_FLAGS_ADVANCED_FS_NAME, |
| 82 | IDS_FLAGS_ADVANCED_FS_DESCRIPTION, |
| 83 | kOsCrOS, |
| 84 | #if defined(OS_CHROMEOS) |
| 85 | // The switch exists only on Chrome OS. |
| 86 | switches::kEnableAdvancedFileSystem |
| 87 | #else |
| 88 | "" |
| 89 | #endif |
| 90 | }, |
| 91 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 92 | "vertical-tabs", // FLAGS:RECORD_UMA |
[email protected] | 9486c1f | 2010-10-14 19:52:12 | [diff] [blame] | 93 | IDS_FLAGS_SIDE_TABS_NAME, |
| 94 | IDS_FLAGS_SIDE_TABS_DESCRIPTION, |
[email protected] | ba816424 | 2010-11-16 21:31:00 | [diff] [blame] | 95 | kOsWin | kOsCrOS, |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 96 | switches::kEnableVerticalTabs |
[email protected] | 65415187 | 2010-09-13 22:43:05 | [diff] [blame] | 97 | }, |
| 98 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 99 | "tabbed-options", // FLAGS:RECORD_UMA |
[email protected] | 9486c1f | 2010-10-14 19:52:12 | [diff] [blame] | 100 | IDS_FLAGS_TABBED_OPTIONS_NAME, |
| 101 | IDS_FLAGS_TABBED_OPTIONS_DESCRIPTION, |
[email protected] | 1af1dfe | 2010-10-19 23:49:14 | [diff] [blame] | 102 | kOsWin | kOsLinux | kOsMac, // Enabled by default on CrOS. |
[email protected] | 65415187 | 2010-09-13 22:43:05 | [diff] [blame] | 103 | switches::kEnableTabbedOptions |
| 104 | }, |
[email protected] | bcf9167 | 2010-09-16 15:40:21 | [diff] [blame] | 105 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 106 | "remoting", // FLAGS:RECORD_UMA |
[email protected] | 9486c1f | 2010-10-14 19:52:12 | [diff] [blame] | 107 | IDS_FLAGS_REMOTING_NAME, |
[email protected] | 4fb2f119 | 2010-09-25 14:56:31 | [diff] [blame] | 108 | #if defined(OS_WIN) |
[email protected] | 52fa2d5 | 2010-09-25 14:08:56 | [diff] [blame] | 109 | // Windows only supports host functionality at the moment. |
[email protected] | 9486c1f | 2010-10-14 19:52:12 | [diff] [blame] | 110 | IDS_FLAGS_REMOTING_HOST_DESCRIPTION, |
[email protected] | 1af1dfe | 2010-10-19 23:49:14 | [diff] [blame] | 111 | #elif defined(OS_LINUX) // Also true for CrOS. |
[email protected] | 52fa2d5 | 2010-09-25 14:08:56 | [diff] [blame] | 112 | // Linux only supports client functionality at the moment. |
[email protected] | 9486c1f | 2010-10-14 19:52:12 | [diff] [blame] | 113 | IDS_FLAGS_REMOTING_CLIENT_DESCRIPTION, |
[email protected] | 52fa2d5 | 2010-09-25 14:08:56 | [diff] [blame] | 114 | #else |
[email protected] | a694085 | 2010-09-25 14:25:32 | [diff] [blame] | 115 | // On other platforms, this lab isn't available at all. |
| 116 | 0, |
[email protected] | 52fa2d5 | 2010-09-25 14:08:56 | [diff] [blame] | 117 | #endif |
[email protected] | 1af1dfe | 2010-10-19 23:49:14 | [diff] [blame] | 118 | kOsWin | kOsLinux | kOsCrOS, |
[email protected] | 52fa2d5 | 2010-09-25 14:08:56 | [diff] [blame] | 119 | switches::kEnableRemoting |
| 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 | "disable-outdated-plugins", // FLAGS:RECORD_UMA |
[email protected] | 9486c1f | 2010-10-14 19:52:12 | [diff] [blame] | 123 | IDS_FLAGS_DISABLE_OUTDATED_PLUGINS_NAME, |
| 124 | IDS_FLAGS_DISABLE_OUTDATED_PLUGINS_DESCRIPTION, |
[email protected] | 57b66d0 | 2010-09-30 11:24:51 | [diff] [blame] | 125 | kOsAll, |
| 126 | switches::kDisableOutdatedPlugins |
| 127 | }, |
[email protected] | b3ce30ea | 2010-10-01 09:33:53 | [diff] [blame] | 128 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 129 | "xss-auditor", // FLAGS:RECORD_UMA |
[email protected] | 9486c1f | 2010-10-14 19:52:12 | [diff] [blame] | 130 | IDS_FLAGS_XSS_AUDITOR_NAME, |
| 131 | IDS_FLAGS_XSS_AUDITOR_DESCRIPTION, |
[email protected] | b3ce30ea | 2010-10-01 09:33:53 | [diff] [blame] | 132 | kOsAll, |
| 133 | switches::kEnableXSSAuditor |
| 134 | }, |
[email protected] | aea2ff4 | 2010-10-04 18:04:19 | [diff] [blame] | 135 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 136 | "background-webapps", // FLAGS:RECORD_UMA |
[email protected] | 9486c1f | 2010-10-14 19:52:12 | [diff] [blame] | 137 | IDS_FLAGS_BACKGROUND_WEBAPPS_NAME, |
| 138 | IDS_FLAGS_BACKGROUND_WEBAPPS_DESCRIPTION, |
[email protected] | 186c8af | 2010-11-24 07:01:10 | [diff] [blame] | 139 | kOsMac | kOsLinux | kOsCrOS, // Enabled by default on windows |
[email protected] | aea2ff4 | 2010-10-04 18:04:19 | [diff] [blame] | 140 | switches::kEnableBackgroundMode |
[email protected] | 7bee0b2 | 2010-10-05 17:00:47 | [diff] [blame] | 141 | }, |
| 142 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 143 | "conflicting-modules-check", // FLAGS:RECORD_UMA |
[email protected] | c1bbaa8 | 2010-11-08 11:17:05 | [diff] [blame] | 144 | IDS_FLAGS_CONFLICTS_CHECK_NAME, |
| 145 | IDS_FLAGS_CONFLICTS_CHECK_DESCRIPTION, |
| 146 | kOsWin, |
| 147 | switches::kConflictingModulesCheck |
| 148 | }, |
| 149 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 150 | "cloud-print-proxy", // FLAGS:RECORD_UMA |
[email protected] | 9486c1f | 2010-10-14 19:52:12 | [diff] [blame] | 151 | IDS_FLAGS_CLOUD_PRINT_PROXY_NAME, |
| 152 | IDS_FLAGS_CLOUD_PRINT_PROXY_DESCRIPTION, |
[email protected] | fa6d2a2f | 2010-11-30 21:47:19 | [diff] [blame] | 153 | #if defined(GOOGLE_CHROME_BUILD) |
| 154 | // For a Chrome build, we know we have a PDF plug-in, and so we'll |
| 155 | // enable by platform as we get things working. |
| 156 | 0, |
| 157 | #else |
| 158 | // Otherwise, where we know it could be working if a viable PDF |
| 159 | // plug-in could be supplied, we'll keep the lab enabled. |
[email protected] | 7bee0b2 | 2010-10-05 17:00:47 | [diff] [blame] | 160 | kOsWin, |
[email protected] | fa6d2a2f | 2010-11-30 21:47:19 | [diff] [blame] | 161 | #endif |
[email protected] | 7bee0b2 | 2010-10-05 17:00:47 | [diff] [blame] | 162 | switches::kEnableCloudPrintProxy |
[email protected] | 8b6588a | 2010-10-12 02:39:42 | [diff] [blame] | 163 | }, |
[email protected] | 580939a | 2010-10-12 18:54:37 | [diff] [blame] | 164 | { |
[email protected] | bb46153 | 2010-11-26 21:50:23 | [diff] [blame] | 165 | "crxless-web-apps", |
| 166 | IDS_FLAGS_CRXLESS_WEB_APPS_NAME, |
| 167 | IDS_FLAGS_CRXLESS_WEB_APPS_DESCRIPTION, |
| 168 | kOsAll, |
| 169 | switches::kEnableCrxlessWebApps |
| 170 | }, |
| 171 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 172 | "match-preview", // FLAGS:RECORD_UMA |
[email protected] | fdf773c5 | 2010-11-01 20:58:19 | [diff] [blame] | 173 | IDS_FLAGS_PREDICTIVE_INSTANT_NAME, |
| 174 | IDS_FLAGS_PREDICTIVE_INSTANT_DESCRIPTION, |
[email protected] | cab03077 | 2010-11-03 21:37:36 | [diff] [blame] | 175 | kOsMac, |
[email protected] | fdf773c5 | 2010-11-01 20:58:19 | [diff] [blame] | 176 | switches::kEnablePredictiveInstant |
| 177 | }, |
[email protected] | 11c4c81 | 2010-10-22 19:50:12 | [diff] [blame] | 178 | // FIXME(scheib): Add Flags entry for accelerated Compositing, |
| 179 | // or pull it and the strings in generated_resources.grd by Dec 2010 |
| 180 | // { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 181 | // "gpu-compositing", |
[email protected] | 11c4c81 | 2010-10-22 19:50:12 | [diff] [blame] | 182 | // IDS_FLAGS_ACCELERATED_COMPOSITING_NAME, |
| 183 | // IDS_FLAGS_ACCELERATED_COMPOSITING_DESCRIPTION, |
| 184 | // kOsAll, |
| 185 | // switches::kDisableAcceleratedCompositing |
| 186 | // }, |
[email protected] | 8b6588a | 2010-10-12 02:39:42 | [diff] [blame] | 187 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 188 | "gpu-canvas-2d", // FLAGS:RECORD_UMA |
[email protected] | 9486c1f | 2010-10-14 19:52:12 | [diff] [blame] | 189 | IDS_FLAGS_ACCELERATED_CANVAS_2D_NAME, |
| 190 | IDS_FLAGS_ACCELERATED_CANVAS_2D_DESCRIPTION, |
[email protected] | 1af1dfe | 2010-10-19 23:49:14 | [diff] [blame] | 191 | kOsWin | kOsLinux | kOsCrOS, |
[email protected] | 8b6588a | 2010-10-12 02:39:42 | [diff] [blame] | 192 | switches::kEnableAccelerated2dCanvas |
[email protected] | 8d260e5 | 2010-10-13 01:03:05 | [diff] [blame] | 193 | }, |
[email protected] | 11c4c81 | 2010-10-22 19:50:12 | [diff] [blame] | 194 | // FIXME(scheib): Add Flags entry for WebGL, |
| 195 | // or pull it and the strings in generated_resources.grd by Dec 2010 |
| 196 | // { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 197 | // "webgl", |
[email protected] | 11c4c81 | 2010-10-22 19:50:12 | [diff] [blame] | 198 | // IDS_FLAGS_WEBGL_NAME, |
| 199 | // IDS_FLAGS_WEBGL_DESCRIPTION, |
| 200 | // kOsAll, |
| 201 | // switches::kDisableExperimentalWebGL |
| 202 | // } |
[email protected] | 8d260e5 | 2010-10-13 01:03:05 | [diff] [blame] | 203 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 204 | "print-preview", // FLAGS:RECORD_UMA |
[email protected] | 9486c1f | 2010-10-14 19:52:12 | [diff] [blame] | 205 | IDS_FLAGS_PRINT_PREVIEW_NAME, |
| 206 | IDS_FLAGS_PRINT_PREVIEW_DESCRIPTION, |
[email protected] | 8d260e5 | 2010-10-13 01:03:05 | [diff] [blame] | 207 | kOsAll, |
| 208 | switches::kEnablePrintPreview |
[email protected] | 2fe15fcb | 2010-10-21 20:39:53 | [diff] [blame] | 209 | }, |
| 210 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 211 | "enable-nacl", // FLAGS:RECORD_UMA |
[email protected] | 4ff87d20 | 2010-11-06 01:28:40 | [diff] [blame] | 212 | IDS_FLAGS_ENABLE_NACL_NAME, |
| 213 | IDS_FLAGS_ENABLE_NACL_DESCRIPTION, |
| 214 | kOsAll, |
| 215 | switches::kEnableNaCl |
| 216 | }, |
| 217 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 218 | "dns-server", // FLAGS:RECORD_UMA |
[email protected] | 2fe15fcb | 2010-10-21 20:39:53 | [diff] [blame] | 219 | IDS_FLAGS_DNS_SERVER_NAME, |
| 220 | IDS_FLAGS_DNS_SERVER_DESCRIPTION, |
| 221 | kOsLinux, |
| 222 | switches::kDnsServer |
| 223 | }, |
[email protected] | 177aceb | 2010-11-03 16:17:41 | [diff] [blame] | 224 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 225 | "page-prerender", // FLAGS:RECORD_UMA |
[email protected] | 83d00d9 | 2010-11-04 19:20:21 | [diff] [blame] | 226 | IDS_FLAGS_PAGE_PRERENDER_NAME, |
| 227 | IDS_FLAGS_PAGE_PRERENDER_DESCRIPTION, |
| 228 | kOsAll, |
| 229 | switches::kEnablePagePrerender |
| 230 | }, |
| 231 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 232 | "confirm-to-quit", // FLAGS:RECORD_UMA |
[email protected] | 177aceb | 2010-11-03 16:17:41 | [diff] [blame] | 233 | IDS_FLAGS_CONFIRM_TO_QUIT_NAME, |
| 234 | IDS_FLAGS_CONFIRM_TO_QUIT_DESCRIPTION, |
| 235 | kOsMac, |
| 236 | switches::kEnableConfirmToQuit |
| 237 | }, |
[email protected] | 9a40ebef | 2010-11-10 17:49:13 | [diff] [blame] | 238 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 239 | "extension-apis", // FLAGS:RECORD_UMA |
[email protected] | 11dd68cd5 | 2010-11-12 01:15:32 | [diff] [blame] | 240 | IDS_FLAGS_EXPERIMENTAL_EXTENSION_APIS_NAME, |
| 241 | IDS_FLAGS_EXPERIMENTAL_EXTENSION_APIS_DESCRIPTION, |
| 242 | kOsAll, |
| 243 | switches::kEnableExperimentalExtensionApis |
| 244 | }, |
[email protected] | 3627b06d | 2010-11-12 16:36:16 | [diff] [blame] | 245 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 246 | "click-to-play", // FLAGS:RECORD_UMA |
[email protected] | 3627b06d | 2010-11-12 16:36:16 | [diff] [blame] | 247 | IDS_FLAGS_CLICK_TO_PLAY_NAME, |
| 248 | IDS_FLAGS_CLICK_TO_PLAY_DESCRIPTION, |
| 249 | kOsAll, |
| 250 | switches::kEnableClickToPlay |
| 251 | }, |
[email protected] | 80bd24e | 2010-11-30 09:34:38 | [diff] [blame] | 252 | { |
| 253 | "disable-hyperlink-auditing", |
| 254 | IDS_FLAGS_DISABLE_HYPERLINK_AUDITING_NAME, |
| 255 | IDS_FLAGS_DISABLE_HYPERLINK_AUDITING_DESCRIPTION, |
| 256 | kOsAll, |
| 257 | switches::kNoPings |
[email protected] | feb28fef | 2010-12-01 10:52:51 | [diff] [blame] | 258 | }, |
| 259 | { |
| 260 | "experimental-location-features", // FLAGS:RECORD_UMA |
| 261 | IDS_FLAGS_EXPERIMENTAL_LOCATION_FEATURES_NAME, |
| 262 | IDS_FLAGS_EXPERIMENTAL_LOCATION_FEATURES_DESCRIPTION, |
| 263 | kOsMac | kOsWin | kOsLinux, // Currently does nothing on CrOS. |
| 264 | switches::kExperimentalLocationFeatures |
[email protected] | 80bd24e | 2010-11-30 09:34:38 | [diff] [blame] | 265 | } |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 266 | }; |
| 267 | |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 268 | const Experiment* experiments = kExperiments; |
| 269 | size_t num_experiments = arraysize(kExperiments); |
| 270 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 271 | // Stores and encapsulates the little state that about:flags has. |
| 272 | class FlagsState { |
| 273 | public: |
| 274 | FlagsState() : needs_restart_(false) {} |
| 275 | void ConvertFlagsToSwitches(PrefService* prefs, CommandLine* command_line); |
| 276 | bool IsRestartNeededToCommitChanges(); |
| 277 | void SetExperimentEnabled( |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 278 | PrefService* prefs, const std::string& internal_name, bool enable); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 279 | void RemoveFlagsSwitches( |
| 280 | std::map<std::string, CommandLine::StringType>* switch_list); |
| 281 | void reset(); |
| 282 | |
| 283 | // Returns the singleton instance of this class |
| 284 | static FlagsState* instance() { |
| 285 | return Singleton<FlagsState>::get(); |
| 286 | } |
| 287 | |
| 288 | private: |
| 289 | bool needs_restart_; |
| 290 | std::set<std::string> flags_switches_; |
| 291 | |
| 292 | DISALLOW_COPY_AND_ASSIGN(FlagsState); |
| 293 | }; |
| 294 | |
[email protected] | ba816424 | 2010-11-16 21:31:00 | [diff] [blame] | 295 | #if defined(OS_CHROMEOS) |
| 296 | // Migrates Chrome OS Labs settings to experiments adding flags to enabled |
| 297 | // experiment list if the corresponding pref is on. |
| 298 | void MigrateChromeOSLabsPrefs(PrefService* prefs, |
| 299 | std::set<std::string>* result) { |
| 300 | DCHECK(prefs); |
| 301 | DCHECK(result); |
| 302 | if (prefs->GetBoolean(prefs::kLabsMediaplayerEnabled)) |
| 303 | result->insert(kMediaPlayerExperimentName); |
| 304 | if (prefs->GetBoolean(prefs::kLabsAdvancedFilesystemEnabled)) |
| 305 | result->insert(kAdvancedFileSystemExperimentName); |
| 306 | if (prefs->GetBoolean(prefs::kUseVerticalTabs)) |
| 307 | result->insert(kVerticalTabsExperimentName); |
| 308 | prefs->SetBoolean(prefs::kLabsMediaplayerEnabled, false); |
| 309 | prefs->SetBoolean(prefs::kLabsAdvancedFilesystemEnabled, false); |
| 310 | prefs->SetBoolean(prefs::kUseVerticalTabs, false); |
| 311 | } |
| 312 | #endif |
| 313 | |
[email protected] | c7b7800a | 2010-10-07 18:51:35 | [diff] [blame] | 314 | // Extracts the list of enabled lab experiments from preferences and stores them |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 315 | // in a set. |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 316 | void GetEnabledFlags(const PrefService* prefs, std::set<std::string>* result) { |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 317 | const ListValue* enabled_experiments = prefs->GetList( |
| 318 | prefs::kEnabledLabsExperiments); |
| 319 | if (!enabled_experiments) |
| 320 | return; |
| 321 | |
| 322 | for (ListValue::const_iterator it = enabled_experiments->begin(); |
| 323 | it != enabled_experiments->end(); |
| 324 | ++it) { |
| 325 | std::string experiment_name; |
| 326 | if (!(*it)->GetAsString(&experiment_name)) { |
| 327 | LOG(WARNING) << "Invalid entry in " << prefs::kEnabledLabsExperiments; |
| 328 | continue; |
| 329 | } |
| 330 | result->insert(experiment_name); |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | // Takes a set of enabled lab experiments |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 335 | void SetEnabledFlags( |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 336 | PrefService* prefs, const std::set<std::string>& enabled_experiments) { |
| 337 | ListValue* experiments_list = prefs->GetMutableList( |
| 338 | prefs::kEnabledLabsExperiments); |
| 339 | if (!experiments_list) |
| 340 | return; |
| 341 | |
| 342 | experiments_list->Clear(); |
| 343 | for (std::set<std::string>::const_iterator it = enabled_experiments.begin(); |
| 344 | it != enabled_experiments.end(); |
| 345 | ++it) { |
| 346 | experiments_list->Append(new StringValue(*it)); |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | // Removes all experiments from prefs::kEnabledLabsExperiments that are |
| 351 | // unknown, to prevent this list to become very long as experiments are added |
| 352 | // and removed. |
| 353 | void SanitizeList(PrefService* prefs) { |
| 354 | std::set<std::string> known_experiments; |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 355 | for (size_t i = 0; i < num_experiments; ++i) |
| 356 | known_experiments.insert(experiments[i].internal_name); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 357 | |
| 358 | std::set<std::string> enabled_experiments; |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 359 | GetEnabledFlags(prefs, &enabled_experiments); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 360 | |
| 361 | std::set<std::string> new_enabled_experiments; |
| 362 | std::set_intersection( |
| 363 | known_experiments.begin(), known_experiments.end(), |
| 364 | enabled_experiments.begin(), enabled_experiments.end(), |
| 365 | std::inserter(new_enabled_experiments, new_enabled_experiments.begin())); |
| 366 | |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 367 | SetEnabledFlags(prefs, new_enabled_experiments); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 368 | } |
| 369 | |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 370 | void GetSanitizedEnabledFlags( |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 371 | PrefService* prefs, std::set<std::string>* result) { |
| 372 | SanitizeList(prefs); |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 373 | GetEnabledFlags(prefs, result); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 374 | } |
| 375 | |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 376 | // Variant of GetSanitizedEnabledFlags that also removes any flags that aren't |
| 377 | // enabled on the current platform. |
| 378 | void GetSanitizedEnabledFlagsForCurrentPlatform( |
| 379 | PrefService* prefs, std::set<std::string>* result) { |
| 380 | GetSanitizedEnabledFlags(prefs, result); |
| 381 | |
| 382 | // Filter out any experiments that aren't enabled on the current platform. We |
| 383 | // don't remove these from prefs else syncing to a platform with a different |
| 384 | // set of experiments would be lossy. |
| 385 | std::set<std::string> platform_experiments; |
| 386 | int current_platform = GetCurrentPlatform(); |
| 387 | for (size_t i = 0; i < num_experiments; ++i) { |
| 388 | if (experiments[i].supported_platforms & current_platform) |
| 389 | platform_experiments.insert(experiments[i].internal_name); |
| 390 | } |
| 391 | |
| 392 | std::set<std::string> new_enabled_experiments; |
| 393 | std::set_intersection( |
| 394 | platform_experiments.begin(), platform_experiments.end(), |
| 395 | result->begin(), result->end(), |
| 396 | std::inserter(new_enabled_experiments, new_enabled_experiments.begin())); |
| 397 | |
| 398 | result->swap(new_enabled_experiments); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 399 | } |
| 400 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 401 | } // namespace |
| 402 | |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 403 | void ConvertFlagsToSwitches(PrefService* prefs, CommandLine* command_line) { |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 404 | FlagsState::instance()->ConvertFlagsToSwitches(prefs, command_line); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 405 | } |
| 406 | |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 407 | ListValue* GetFlagsExperimentsData(PrefService* prefs) { |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 408 | std::set<std::string> enabled_experiments; |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 409 | GetSanitizedEnabledFlags(prefs, &enabled_experiments); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 410 | |
| 411 | int current_platform = GetCurrentPlatform(); |
| 412 | |
| 413 | ListValue* experiments_data = new ListValue(); |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 414 | for (size_t i = 0; i < num_experiments; ++i) { |
| 415 | const Experiment& experiment = experiments[i]; |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 416 | if (!(experiment.supported_platforms & current_platform)) |
| 417 | continue; |
| 418 | |
| 419 | DictionaryValue* data = new DictionaryValue(); |
| 420 | data->SetString("internal_name", experiment.internal_name); |
| 421 | data->SetString("name", |
| 422 | l10n_util::GetStringUTF16(experiment.visible_name_id)); |
| 423 | data->SetString("description", |
| 424 | l10n_util::GetStringUTF16( |
| 425 | experiment.visible_description_id)); |
| 426 | data->SetBoolean("enabled", |
| 427 | enabled_experiments.count(experiment.internal_name) > 0); |
| 428 | |
| 429 | experiments_data->Append(data); |
| 430 | } |
| 431 | return experiments_data; |
| 432 | } |
| 433 | |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 434 | bool IsRestartNeededToCommitChanges() { |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 435 | return FlagsState::instance()->IsRestartNeededToCommitChanges(); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | void SetExperimentEnabled( |
[email protected] | c7b7800a | 2010-10-07 18:51:35 | [diff] [blame] | 439 | PrefService* prefs, const std::string& internal_name, bool enable) { |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 440 | FlagsState::instance()->SetExperimentEnabled(prefs, internal_name, enable); |
| 441 | } |
| 442 | |
| 443 | void RemoveFlagsSwitches( |
| 444 | std::map<std::string, CommandLine::StringType>* switch_list) { |
| 445 | FlagsState::instance()->RemoveFlagsSwitches(switch_list); |
| 446 | } |
| 447 | |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 448 | int GetCurrentPlatform() { |
| 449 | #if defined(OS_MACOSX) |
| 450 | return kOsMac; |
| 451 | #elif defined(OS_WIN) |
| 452 | return kOsWin; |
| 453 | #elif defined(OS_CHROMEOS) // Needs to be before the OS_LINUX check. |
| 454 | return kOsCrOS; |
| 455 | #elif defined(OS_LINUX) |
| 456 | return kOsLinux; |
| 457 | #else |
| 458 | #error Unknown platform |
| 459 | #endif |
| 460 | } |
| 461 | |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 462 | void RecordUMAStatistics(const PrefService* prefs) { |
| 463 | std::set<std::string> flags; |
| 464 | GetEnabledFlags(prefs, &flags); |
| 465 | for (std::set<std::string>::iterator it = flags.begin(); it != flags.end(); |
| 466 | ++it) { |
| 467 | std::string action("AboutFlags_"); |
| 468 | action += *it; |
| 469 | UserMetrics::RecordComputedAction(action); |
| 470 | } |
| 471 | // Since flag metrics are recorded every startup, add a tick so that the |
| 472 | // stats can be made meaningful. |
| 473 | if (flags.size()) |
| 474 | UserMetrics::RecordAction(UserMetricsAction("AboutFlags_StartupTick")); |
| 475 | } |
| 476 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 477 | ////////////////////////////////////////////////////////////////////////////// |
| 478 | // FlagsState implementation. |
| 479 | |
| 480 | namespace { |
| 481 | |
| 482 | void FlagsState::ConvertFlagsToSwitches( |
| 483 | PrefService* prefs, CommandLine* command_line) { |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 484 | if (command_line->HasSwitch(switches::kNoExperiments)) |
| 485 | return; |
| 486 | |
| 487 | std::set<std::string> enabled_experiments; |
[email protected] | ba816424 | 2010-11-16 21:31:00 | [diff] [blame] | 488 | |
| 489 | #if defined(OS_CHROMEOS) |
| 490 | // Some experiments were implemented via prefs on Chrome OS and we want to |
| 491 | // seamlessly migrate these prefs to about:flags for updated users. |
| 492 | MigrateChromeOSLabsPrefs(prefs, &enabled_experiments); |
| 493 | #endif |
| 494 | |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 495 | GetSanitizedEnabledFlagsForCurrentPlatform(prefs, &enabled_experiments); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 496 | |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 497 | std::map<std::string, const Experiment*> experiment_map; |
| 498 | for (size_t i = 0; i < num_experiments; ++i) |
| 499 | experiment_map[experiments[i].internal_name] = &experiments[i]; |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 500 | |
| 501 | command_line->AppendSwitch(switches::kFlagSwitchesBegin); |
| 502 | flags_switches_.insert(switches::kFlagSwitchesBegin); |
| 503 | for (std::set<std::string>::iterator it = enabled_experiments.begin(); |
| 504 | it != enabled_experiments.end(); |
| 505 | ++it) { |
| 506 | const std::string& experiment_name = *it; |
| 507 | std::map<std::string, const Experiment*>::iterator experiment = |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 508 | experiment_map.find(experiment_name); |
| 509 | DCHECK(experiment != experiment_map.end()); |
| 510 | if (experiment == experiment_map.end()) |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 511 | continue; |
| 512 | |
| 513 | command_line->AppendSwitch(experiment->second->command_line); |
| 514 | flags_switches_.insert(experiment->second->command_line); |
| 515 | } |
| 516 | command_line->AppendSwitch(switches::kFlagSwitchesEnd); |
| 517 | flags_switches_.insert(switches::kFlagSwitchesEnd); |
| 518 | } |
| 519 | |
| 520 | bool FlagsState::IsRestartNeededToCommitChanges() { |
| 521 | return needs_restart_; |
| 522 | } |
| 523 | |
| 524 | void FlagsState::SetExperimentEnabled( |
| 525 | PrefService* prefs, const std::string& internal_name, bool enable) { |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 526 | needs_restart_ = true; |
| 527 | |
| 528 | std::set<std::string> enabled_experiments; |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 529 | GetSanitizedEnabledFlags(prefs, &enabled_experiments); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 530 | |
| 531 | if (enable) |
| 532 | enabled_experiments.insert(internal_name); |
| 533 | else |
| 534 | enabled_experiments.erase(internal_name); |
| 535 | |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 536 | SetEnabledFlags(prefs, enabled_experiments); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 537 | } |
| 538 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 539 | void FlagsState::RemoveFlagsSwitches( |
| 540 | std::map<std::string, CommandLine::StringType>* switch_list) { |
| 541 | for (std::set<std::string>::const_iterator it = flags_switches_.begin(); |
| 542 | it != flags_switches_.end(); |
| 543 | ++it) { |
| 544 | switch_list->erase(*it); |
| 545 | } |
| 546 | } |
| 547 | |
| 548 | void FlagsState::reset() { |
| 549 | needs_restart_ = false; |
| 550 | flags_switches_.clear(); |
| 551 | } |
| 552 | |
| 553 | } // namespace |
| 554 | |
| 555 | namespace testing { |
| 556 | void ClearState() { |
| 557 | FlagsState::instance()->reset(); |
| 558 | } |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 559 | |
| 560 | void SetExperiments(const Experiment* e, size_t count) { |
| 561 | if (!e) { |
| 562 | experiments = kExperiments; |
| 563 | num_experiments = arraysize(kExperiments); |
| 564 | } else { |
| 565 | experiments = e; |
| 566 | num_experiments = count; |
| 567 | } |
| 568 | } |
| 569 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 570 | } // namespace testing |
| 571 | |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 572 | } // namespace about_flags |