blob: ebec71a4d72a29ab51c54e42aeb54a69fd34d9d2 [file] [log] [blame]
[email protected]3828d6f2011-02-24 18:32:211// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]ad2a3ded2010-08-27 13:19:052// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]1a47d7e2010-10-15 00:37:245#include "chrome/browser/about_flags.h"
[email protected]ad2a3ded2010-08-27 13:19:056
7#include <algorithm>
8#include <iterator>
9#include <map>
10#include <set>
11
[email protected]ad2a3ded2010-08-27 13:19:0512#include "base/command_line.h"
[email protected]3b63f8f42011-03-28 01:54:1513#include "base/memory/singleton.h"
[email protected]8a6ff28d2010-12-02 16:35:1914#include "base/string_number_conversions.h"
[email protected]d208f4d82011-05-23 21:52:0315#include "base/utf_string_conversions.h"
[email protected]ad2a3ded2010-08-27 13:19:0516#include "base/values.h"
[email protected]d208f4d82011-05-23 21:52:0317#include "chrome/browser/plugin_updater.h"
[email protected]ad2a3ded2010-08-27 13:19:0518#include "chrome/browser/prefs/pref_service.h"
[email protected]1bc78422011-03-31 08:41:3819#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]d208f4d82011-05-23 21:52:0320#include "chrome/common/chrome_content_client.h"
[email protected]ad2a3ded2010-08-27 13:19:0521#include "chrome/common/chrome_switches.h"
22#include "chrome/common/pref_names.h"
[email protected]afd1e522011-04-27 23:29:5923#include "content/browser/user_metrics.h"
[email protected]ad2a3ded2010-08-27 13:19:0524#include "grit/generated_resources.h"
[email protected]c051a1b2011-01-21 23:30:1725#include "ui/base/l10n/l10n_util.h"
[email protected]8ff7f342011-05-25 01:49:4726#include "ui/gfx/gl/gl_switches.h"
[email protected]ad2a3ded2010-08-27 13:19:0527
[email protected]1a47d7e2010-10-15 00:37:2428namespace about_flags {
[email protected]ad2a3ded2010-08-27 13:19:0529
[email protected]8a6ff28d2010-12-02 16:35:1930// Macros to simplify specifying the type.
[email protected]a82744532011-02-11 16:15:5331#define SINGLE_VALUE_TYPE_AND_VALUE(command_line_switch, switch_value) \
32 Experiment::SINGLE_VALUE, command_line_switch, switch_value, NULL, 0
33#define SINGLE_VALUE_TYPE(command_line_switch) \
34 SINGLE_VALUE_TYPE_AND_VALUE(command_line_switch, "")
35#define MULTI_VALUE_TYPE(choices) \
[email protected]0e6f56d2011-02-12 23:45:1536 Experiment::MULTI_VALUE, "", "", choices, arraysize(choices)
[email protected]8a6ff28d2010-12-02 16:35:1937
[email protected]e2ddbc92010-10-15 20:02:0738namespace {
39
[email protected]a314ee5a2010-10-26 21:23:2840const unsigned kOsAll = kOsMac | kOsWin | kOsLinux | kOsCrOS;
[email protected]ad2a3ded2010-08-27 13:19:0541
[email protected]ba8164242010-11-16 21:31:0042// Names for former Chrome OS Labs experiments, shared with prefs migration
43// code.
44const char kMediaPlayerExperimentName[] = "media-player";
45const char kAdvancedFileSystemExperimentName[] = "advanced-file-system";
46const char kVerticalTabsExperimentName[] = "vertical-tabs";
47
[email protected]4bc5050c2010-11-18 17:55:5448// RECORDING USER METRICS FOR FLAGS:
49// -----------------------------------------------------------------------------
50// The first line of the experiment is the internal name. If you'd like to
51// gather statistics about the usage of your flag, you should append a marker
52// comment to the end of the feature name, like so:
53// "my-special-feature", // FLAGS:RECORD_UMA
54//
55// After doing that, run //chrome/tools/extract_actions.py (see instructions at
56// the top of that file for details) to update the chromeactions.txt file, which
57// will enable UMA to record your feature flag.
58//
59// After your feature has shipped under a flag, you can locate the metrics
60// under the action name AboutFlags_internal-action-name. Actions are recorded
61// once per startup, so you should divide this number by AboutFlags_StartupTick
62// to get a sense of usage. Note that this will not be the same as number of
63// users with a given feature enabled because users can quit and relaunch
64// the application multiple times over a given time interval.
65// TODO(rsesek): See if there's a way to count per-user, rather than
66// per-startup.
67
[email protected]8a6ff28d2010-12-02 16:35:1968// To add a new experiment add to the end of kExperiments. There are two
69// distinct types of experiments:
70// . SINGLE_VALUE: experiment is either on or off. Use the SINGLE_VALUE_TYPE
71// macro for this type supplying the command line to the macro.
[email protected]28e35af2011-02-09 12:56:2272// . MULTI_VALUE: a list of choices, the first of which should correspond to a
73// deactivated state for this lab (i.e. no command line option). To specify
74// this type of experiment use the macro MULTI_VALUE_TYPE supplying it the
75// array of choices.
[email protected]8a6ff28d2010-12-02 16:35:1976// See the documentation of Experiment for details on the fields.
77//
78// When adding a new choice, add it to the end of the list.
[email protected]ad2a3ded2010-08-27 13:19:0579const Experiment kExperiments[] = {
80 {
[email protected]aac169d2011-03-18 19:53:0381 "expose-for-tabs", // FLAGS:RECORD_UMA
82 IDS_FLAGS_TABPOSE_NAME,
83 IDS_FLAGS_TABPOSE_DESCRIPTION,
84 kOsMac,
85#if defined(OS_MACOSX)
86 // The switch exists only on OS X.
87 SINGLE_VALUE_TYPE(switches::kEnableExposeForTabs)
88#else
89 SINGLE_VALUE_TYPE("")
90#endif
91 },
92 {
[email protected]4bc5050c2010-11-18 17:55:5493 "vertical-tabs", // FLAGS:RECORD_UMA
[email protected]9486c1f2010-10-14 19:52:1294 IDS_FLAGS_SIDE_TABS_NAME,
95 IDS_FLAGS_SIDE_TABS_DESCRIPTION,
[email protected]ba8164242010-11-16 21:31:0096 kOsWin | kOsCrOS,
[email protected]8a6ff28d2010-12-02 16:35:1997 SINGLE_VALUE_TYPE(switches::kEnableVerticalTabs)
[email protected]654151872010-09-13 22:43:0598 },
99 {
[email protected]4bc5050c2010-11-18 17:55:54100 "remoting", // FLAGS:RECORD_UMA
[email protected]9486c1f2010-10-14 19:52:12101 IDS_FLAGS_REMOTING_NAME,
[email protected]d99599862011-01-20 22:43:59102 IDS_FLAGS_REMOTING_DESCRIPTION,
103 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19104 SINGLE_VALUE_TYPE(switches::kEnableRemoting)
[email protected]52fa2d52010-09-25 14:08:56105 },
[email protected]a6f03652010-09-28 15:59:07106 {
[email protected]4bc5050c2010-11-18 17:55:54107 "conflicting-modules-check", // FLAGS:RECORD_UMA
[email protected]c1bbaa82010-11-08 11:17:05108 IDS_FLAGS_CONFLICTS_CHECK_NAME,
109 IDS_FLAGS_CONFLICTS_CHECK_DESCRIPTION,
110 kOsWin,
[email protected]8a6ff28d2010-12-02 16:35:19111 SINGLE_VALUE_TYPE(switches::kConflictingModulesCheck)
[email protected]c1bbaa82010-11-08 11:17:05112 },
113 {
[email protected]4bc5050c2010-11-18 17:55:54114 "cloud-print-proxy", // FLAGS:RECORD_UMA
[email protected]9486c1f2010-10-14 19:52:12115 IDS_FLAGS_CLOUD_PRINT_PROXY_NAME,
116 IDS_FLAGS_CLOUD_PRINT_PROXY_DESCRIPTION,
[email protected]6a18e2b2011-07-01 01:02:53117#if defined(GOOGLE_CHROME_BUILD)
[email protected]9f8872b32011-03-04 19:44:45118 // For a Chrome build, we know we have a PDF plug-in on Windows, so it's
[email protected]6a18e2b2011-07-01 01:02:53119 // fully enabled. Linux still need some final polish.
120 kOsLinux,
121#else
[email protected]be51dd252011-03-05 00:23:44122 // Otherwise, where we know Windows could be working if a viable PDF
[email protected]6a18e2b2011-07-01 01:02:53123 // plug-in could be supplied, we'll keep the lab enabled. Mac always has
124 // PDF rasterization available, so no flag needed there.
125 kOsWin | kOsLinux,
[email protected]fa6d2a2f2010-11-30 21:47:19126#endif
[email protected]8a6ff28d2010-12-02 16:35:19127 SINGLE_VALUE_TYPE(switches::kEnableCloudPrintProxy)
[email protected]8b6588a2010-10-12 02:39:42128 },
[email protected]580939a2010-10-12 18:54:37129 {
[email protected]bb461532010-11-26 21:50:23130 "crxless-web-apps",
131 IDS_FLAGS_CRXLESS_WEB_APPS_NAME,
132 IDS_FLAGS_CRXLESS_WEB_APPS_DESCRIPTION,
133 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19134 SINGLE_VALUE_TYPE(switches::kEnableCrxlessWebApps)
[email protected]bb461532010-11-26 21:50:23135 },
136 {
[email protected]96c6f4c2011-05-18 19:36:22137 "ignore-gpu-blacklist",
138 IDS_FLAGS_IGNORE_GPU_BLACKLIST_NAME,
139 IDS_FLAGS_IGNORE_GPU_BLACKLIST_DESCRIPTION,
140 kOsAll,
141 SINGLE_VALUE_TYPE(switches::kIgnoreGpuBlacklist)
142 },
143 {
[email protected]0110cf112011-07-02 00:39:43144 "force-compositing-mode-2",
[email protected]96c6f4c2011-05-18 19:36:22145 IDS_FLAGS_FORCE_COMPOSITING_MODE_NAME,
146 IDS_FLAGS_FORCE_COMPOSITING_MODE_DESCRIPTION,
147 kOsAll,
148 SINGLE_VALUE_TYPE(switches::kForceCompositingMode)
149 },
150 {
[email protected]5963b772011-02-09 22:55:38151 "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]ff385132011-06-21 16:19:36158 "accelerated-drawing",
159 IDS_FLAGS_ACCELERATED_DRAWING_NAME,
160 IDS_FLAGS_ACCELERATED_DRAWING_DESCRIPTION,
161 kOsWin | kOsLinux | kOsCrOS, // Not available on Mac until it uses Skia.
162 SINGLE_VALUE_TYPE(switches::kEnableAcceleratedDrawing)
163 },
164 {
[email protected]a8f1eaa2011-03-07 19:00:58165 "show-fps-counter",
166 IDS_FLAGS_SHOW_FPS_COUNTER,
167 IDS_FLAGS_SHOW_FPS_COUNTER_DESCRIPTION,
168 kOsAll,
169 SINGLE_VALUE_TYPE(switches::kShowFPSCounter)
170 },
[email protected]8ff7f342011-05-25 01:49:47171 {
172 "disable-gpu-vsync",
173 IDS_FLAGS_DISABLE_GPU_VSYNC_NAME,
174 IDS_FLAGS_DISABLE_GPU_VSYNC_DESCRIPTION,
175 kOsAll,
176 SINGLE_VALUE_TYPE(switches::kDisableGpuVsync)
177 },
[email protected]64b33432011-06-01 05:17:59178#if !defined(GOOGLE_CHROME_BUILD) || defined(OS_MACOSX)
[email protected]38e46812011-05-09 20:49:22179 // Only expose this for Chromium builds where users may not have the PDF
[email protected]64b33432011-06-01 05:17:59180 // plugin. Do not give Google Chrome users the option to disable it here,
181 // except on Mac, where it is disabled.
[email protected]8d260e52010-10-13 01:03:05182 {
[email protected]4bc5050c2010-11-18 17:55:54183 "print-preview", // FLAGS:RECORD_UMA
[email protected]9486c1f2010-10-14 19:52:12184 IDS_FLAGS_PRINT_PREVIEW_NAME,
185 IDS_FLAGS_PRINT_PREVIEW_DESCRIPTION,
[email protected]b579afd2011-07-13 00:01:27186 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19187 SINGLE_VALUE_TYPE(switches::kEnablePrintPreview)
[email protected]2fe15fcb2010-10-21 20:39:53188 },
[email protected]38e46812011-05-09 20:49:22189#endif
[email protected]d208f4d82011-05-23 21:52:03190 // TODO(dspringer): When NaCl is on by default, remove this flag entry.
[email protected]2fe15fcb2010-10-21 20:39:53191 {
[email protected]d208f4d82011-05-23 21:52:03192 switches::kEnableNaCl, // FLAGS:RECORD_UMA
[email protected]4ff87d202010-11-06 01:28:40193 IDS_FLAGS_ENABLE_NACL_NAME,
194 IDS_FLAGS_ENABLE_NACL_DESCRIPTION,
195 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19196 SINGLE_VALUE_TYPE(switches::kEnableNaCl)
[email protected]4ff87d202010-11-06 01:28:40197 },
198 {
[email protected]4bc5050c2010-11-18 17:55:54199 "dns-server", // FLAGS:RECORD_UMA
[email protected]2fe15fcb2010-10-21 20:39:53200 IDS_FLAGS_DNS_SERVER_NAME,
201 IDS_FLAGS_DNS_SERVER_DESCRIPTION,
202 kOsLinux,
[email protected]8a6ff28d2010-12-02 16:35:19203 SINGLE_VALUE_TYPE(switches::kDnsServer)
[email protected]2fe15fcb2010-10-21 20:39:53204 },
[email protected]177aceb2010-11-03 16:17:41205 {
[email protected]4bc5050c2010-11-18 17:55:54206 "extension-apis", // FLAGS:RECORD_UMA
[email protected]11dd68cd52010-11-12 01:15:32207 IDS_FLAGS_EXPERIMENTAL_EXTENSION_APIS_NAME,
208 IDS_FLAGS_EXPERIMENTAL_EXTENSION_APIS_DESCRIPTION,
209 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19210 SINGLE_VALUE_TYPE(switches::kEnableExperimentalExtensionApis)
[email protected]11dd68cd52010-11-12 01:15:32211 },
[email protected]3627b06d2010-11-12 16:36:16212 {
[email protected]4bc5050c2010-11-18 17:55:54213 "click-to-play", // FLAGS:RECORD_UMA
[email protected]3627b06d2010-11-12 16:36:16214 IDS_FLAGS_CLICK_TO_PLAY_NAME,
215 IDS_FLAGS_CLICK_TO_PLAY_DESCRIPTION,
216 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19217 SINGLE_VALUE_TYPE(switches::kEnableClickToPlay)
[email protected]3627b06d2010-11-12 16:36:16218 },
[email protected]80bd24e2010-11-30 09:34:38219 {
220 "disable-hyperlink-auditing",
221 IDS_FLAGS_DISABLE_HYPERLINK_AUDITING_NAME,
222 IDS_FLAGS_DISABLE_HYPERLINK_AUDITING_DESCRIPTION,
223 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19224 SINGLE_VALUE_TYPE(switches::kNoPings)
[email protected]feb28fef2010-12-01 10:52:51225 },
226 {
227 "experimental-location-features", // FLAGS:RECORD_UMA
228 IDS_FLAGS_EXPERIMENTAL_LOCATION_FEATURES_NAME,
229 IDS_FLAGS_EXPERIMENTAL_LOCATION_FEATURES_DESCRIPTION,
230 kOsMac | kOsWin | kOsLinux, // Currently does nothing on CrOS.
[email protected]8a6ff28d2010-12-02 16:35:19231 SINGLE_VALUE_TYPE(switches::kExperimentalLocationFeatures)
232 },
233 {
[email protected]4c6452d2011-01-12 08:47:57234 "block-reading-third-party-cookies",
235 IDS_FLAGS_BLOCK_ALL_THIRD_PARTY_COOKIES_NAME,
236 IDS_FLAGS_BLOCK_ALL_THIRD_PARTY_COOKIES_DESCRIPTION,
237 kOsAll,
238 SINGLE_VALUE_TYPE(switches::kBlockReadingThirdPartyCookies)
239 },
[email protected]04227962011-01-20 02:03:09240 {
241 "disable-interactive-form-validation",
242 IDS_FLAGS_DISABLE_INTERACTIVE_FORM_VALIDATION_NAME,
243 IDS_FLAGS_DISABLE_INTERACTIVE_FORM_VALIDATION_DESCRIPTION,
244 kOsAll,
245 SINGLE_VALUE_TYPE(switches::kDisableInteractiveFormValidation)
246 },
[email protected]8df51192011-01-22 20:05:03247 {
[email protected]6c54e7e42011-03-02 20:52:34248 "p2papi",
249 IDS_FLAGS_P2P_API_NAME,
250 IDS_FLAGS_P2P_API_DESCRIPTION,
251 kOsAll,
[email protected]a026daa2011-04-20 15:49:51252#if defined(ENABLE_P2P_APIS)
[email protected]6c54e7e42011-03-02 20:52:34253 SINGLE_VALUE_TYPE(switches::kEnableP2PApi)
[email protected]a026daa2011-04-20 15:49:51254#else
255 SINGLE_VALUE_TYPE("")
256#endif
[email protected]6c54e7e42011-03-02 20:52:34257 },
[email protected]07d490bc2011-03-07 17:05:26258 {
259 "focus-existing-tab-on-open", // FLAGS:RECORD_UMA
260 IDS_FLAGS_FOCUS_EXISTING_TAB_ON_OPEN_NAME,
261 IDS_FLAGS_FOCUS_EXISTING_TAB_ON_OPEN_DESCRIPTION,
262 kOsAll,
263 SINGLE_VALUE_TYPE(switches::kFocusExistingTabOnOpen)
264 },
[email protected]d5dcfb32011-03-19 00:49:24265 {
[email protected]ac86c982011-05-11 13:26:05266 "compact-navigation",
267 IDS_FLAGS_ENABLE_COMPACT_NAVIGATION,
268 IDS_FLAGS_ENABLE_COMPACT_NAVIGATION_DESCRIPTION,
269 kOsWin, // TODO(stevet): Add other platforms when ready.
270 SINGLE_VALUE_TYPE(switches::kEnableCompactNavigation)
271 },
272 {
[email protected]d5dcfb32011-03-19 00:49:24273 "new-tab-page-4",
274 IDS_FLAGS_NEW_TAB_PAGE_4_NAME,
275 IDS_FLAGS_NEW_TAB_PAGE_4_DESCRIPTION,
276 kOsAll,
277 SINGLE_VALUE_TYPE(switches::kNewTabPage4)
278 },
[email protected]5aea1862011-03-23 23:55:39279 {
280 "tab-groups-context-menu",
281 IDS_FLAGS_TAB_GROUPS_CONTEXT_MENU_NAME,
282 IDS_FLAGS_TAB_GROUPS_CONTEXT_MENU_DESCRIPTION,
283 kOsWin,
284 SINGLE_VALUE_TYPE(switches::kEnableTabGroupsContextMenu)
285 },
[email protected]e9bf9d92011-03-31 20:57:15286 {
287 "ppapi-flash-in-process",
288 IDS_FLAGS_PPAPI_FLASH_IN_PROCESS_NAME,
289 IDS_FLAGS_PPAPI_FLASH_IN_PROCESS_DESCRIPTION,
[email protected]f2d3ce0d2011-04-01 18:19:30290 kOsAll,
[email protected]e9bf9d92011-03-31 20:57:15291 SINGLE_VALUE_TYPE(switches::kPpapiFlashInProcess)
292 },
[email protected]ce5737142011-04-14 23:35:09293 {
[email protected]20b5df962011-04-18 22:07:43294 "multi-profiles",
295 IDS_FLAGS_MULTI_PROFILES_NAME,
296 IDS_FLAGS_MULTI_PROFILES_DESCRIPTION,
[email protected]7237bfc2011-07-10 03:44:28297 kOsMac | kOsLinux, // This switch is not available in CrOS.
[email protected]20b5df962011-04-18 22:07:43298 SINGLE_VALUE_TYPE(switches::kMultiProfiles)
299 },
[email protected]cc057b02011-04-21 17:19:04300 {
[email protected]08338b862011-05-05 20:22:23301 "restrict-instant-to-search",
302 IDS_FLAGS_RESTRICT_INSTANT_TO_SEARCH_NAME,
303 IDS_FLAGS_RESTRICT_INSTANT_TO_SEARCH_DESCRIPTION,
304 kOsAll,
305 SINGLE_VALUE_TYPE(switches::kRestrictInstantToSearch)
306 },
[email protected]b652fc82011-05-23 07:53:05307 {
[email protected]f2557bd2011-06-01 02:33:07308 "preload-instant-search",
309 IDS_FLAGS_PRELOAD_INSTANT_SEARCH_NAME,
310 IDS_FLAGS_PRELOAD_INSTANT_SEARCH_DESCRIPTION,
311 kOsAll,
312 SINGLE_VALUE_TYPE(switches::kPreloadInstantSearch)
313 },
[email protected]354e33b2011-06-15 00:29:10314 {
[email protected]7d155e92011-06-21 16:39:21315 "disable-auto-login",
316 IDS_FLAGS_AUTO_LOGIN_NAME,
317 IDS_FLAGS_AUTO_LOGIN_DESCRIPTION,
318 kOsMac | kOsWin | kOsLinux,
319 SINGLE_VALUE_TYPE(switches::kDisableAutoLogin)
320 },
321 {
[email protected]354e33b2011-06-15 00:29:10322 "static-ip-config",
323 IDS_FLAGS_STATIC_IP_CONFIG_NAME,
324 IDS_FLAGS_STATIC_IP_CONFIG_DESCRIPTION,
325 kOsCrOS,
326#if defined(OS_CHROMEOS)
327 // This switch exists only on Chrome OS.
328 SINGLE_VALUE_TYPE(switches::kEnableStaticIPConfig)
329#else
330 SINGLE_VALUE_TYPE("")
331#endif
332 },
[email protected]3eb5728c2011-06-20 22:32:24333 {
334 "show-autofill-type-predictions",
335 IDS_FLAGS_SHOW_AUTOFILL_TYPE_PREDICTIONS_NAME,
336 IDS_FLAGS_SHOW_AUTOFILL_TYPE_PREDICTIONS_DESCRIPTION,
337 kOsAll,
338 SINGLE_VALUE_TYPE(switches::kShowAutofillTypePredictions)
339 },
[email protected]bff4d3e2011-06-21 23:58:52340 {
341 "sync-typed-urls",
342 IDS_FLAGS_SYNC_TYPED_URLS_NAME,
343 IDS_FLAGS_SYNC_TYPED_URLS_DESCRIPTION,
344 kOsAll,
345 SINGLE_VALUE_TYPE(switches::kEnableSyncTypedUrls)
346 },
[email protected]a22ebd812011-06-23 00:05:39347 {
348 "enable-smooth-scrolling", // FLAGS:RECORD_UMA
349 IDS_FLAGS_ENABLE_SMOOTH_SCROLLING_NAME,
350 IDS_FLAGS_ENABLE_SMOOTH_SCROLLING_DESCRIPTION,
351 // Can't expose the switch unless the code is compiled in.
352#if defined(ENABLE_SMOOTH_SCROLLING)
353 kOsAll,
354#else
355 0,
356#endif
357 SINGLE_VALUE_TYPE(switches::kEnableSmoothScrolling)
358 },
[email protected]81a6b0b2011-06-24 17:55:40359 {
360 "prerender-from-omnibox",
361 IDS_FLAGS_PRERENDER_FROM_OMNIBOX_NAME,
362 IDS_FLAGS_PRERENDER_FROM_OMNIBOX_DESCRIPTION,
363 kOsAll,
364 SINGLE_VALUE_TYPE(switches::kPrerenderFromOmnibox)
365 },
[email protected]40916632011-07-02 01:11:01366 {
367 "enable-autofill-feedback",
368 IDS_FLAGS_ENABLE_ADDITIONAL_AUTOFILL_FEEDBACK_NAME,
369 IDS_FLAGS_ENABLE_ADDITIONAL_AUTOFILL_FEEDBACK_DESCRIPTION,
370 kOsAll,
371 SINGLE_VALUE_TYPE(switches::kEnableAutofillFeedback)
372 },
[email protected]73fb1fc52011-07-09 00:06:54373 {
374 "panels",
375 IDS_FLAGS_ENABLE_PANELS_NAME,
376 IDS_FLAGS_ENABLE_PANELS_DESCRIPTION,
377 kOsAll,
378 SINGLE_VALUE_TYPE(switches::kEnablePanels)
379 },
[email protected]ad2a3ded2010-08-27 13:19:05380};
381
[email protected]a314ee5a2010-10-26 21:23:28382const Experiment* experiments = kExperiments;
383size_t num_experiments = arraysize(kExperiments);
384
[email protected]e2ddbc92010-10-15 20:02:07385// Stores and encapsulates the little state that about:flags has.
386class FlagsState {
387 public:
388 FlagsState() : needs_restart_(false) {}
389 void ConvertFlagsToSwitches(PrefService* prefs, CommandLine* command_line);
390 bool IsRestartNeededToCommitChanges();
391 void SetExperimentEnabled(
[email protected]a314ee5a2010-10-26 21:23:28392 PrefService* prefs, const std::string& internal_name, bool enable);
[email protected]e2ddbc92010-10-15 20:02:07393 void RemoveFlagsSwitches(
394 std::map<std::string, CommandLine::StringType>* switch_list);
395 void reset();
396
397 // Returns the singleton instance of this class
[email protected]8e8bb6d2010-12-13 08:18:55398 static FlagsState* GetInstance() {
[email protected]e2ddbc92010-10-15 20:02:07399 return Singleton<FlagsState>::get();
400 }
401
402 private:
403 bool needs_restart_;
[email protected]a82744532011-02-11 16:15:53404 std::map<std::string, std::string> flags_switches_;
[email protected]e2ddbc92010-10-15 20:02:07405
406 DISALLOW_COPY_AND_ASSIGN(FlagsState);
407};
408
[email protected]c7b7800a2010-10-07 18:51:35409// Extracts the list of enabled lab experiments from preferences and stores them
[email protected]ad2a3ded2010-08-27 13:19:05410// in a set.
[email protected]1a47d7e2010-10-15 00:37:24411void GetEnabledFlags(const PrefService* prefs, std::set<std::string>* result) {
[email protected]ad2a3ded2010-08-27 13:19:05412 const ListValue* enabled_experiments = prefs->GetList(
413 prefs::kEnabledLabsExperiments);
414 if (!enabled_experiments)
415 return;
416
417 for (ListValue::const_iterator it = enabled_experiments->begin();
418 it != enabled_experiments->end();
419 ++it) {
420 std::string experiment_name;
421 if (!(*it)->GetAsString(&experiment_name)) {
422 LOG(WARNING) << "Invalid entry in " << prefs::kEnabledLabsExperiments;
423 continue;
424 }
425 result->insert(experiment_name);
426 }
427}
428
429// Takes a set of enabled lab experiments
[email protected]1a47d7e2010-10-15 00:37:24430void SetEnabledFlags(
[email protected]ad2a3ded2010-08-27 13:19:05431 PrefService* prefs, const std::set<std::string>& enabled_experiments) {
[email protected]1bc78422011-03-31 08:41:38432 ListPrefUpdate update(prefs, prefs::kEnabledLabsExperiments);
433 ListValue* experiments_list = update.Get();
[email protected]ad2a3ded2010-08-27 13:19:05434
435 experiments_list->Clear();
436 for (std::set<std::string>::const_iterator it = enabled_experiments.begin();
437 it != enabled_experiments.end();
438 ++it) {
439 experiments_list->Append(new StringValue(*it));
440 }
441}
442
[email protected]8a6ff28d2010-12-02 16:35:19443// Returns the name used in prefs for the choice at the specified index.
444std::string NameForChoice(const Experiment& e, int index) {
[email protected]2ce9c89752011-02-25 18:24:34445 DCHECK_EQ(Experiment::MULTI_VALUE, e.type);
446 DCHECK_LT(index, e.num_choices);
[email protected]8a6ff28d2010-12-02 16:35:19447 return std::string(e.internal_name) + about_flags::testing::kMultiSeparator +
448 base::IntToString(index);
449}
450
451// Adds the internal names for the specified experiment to |names|.
452void AddInternalName(const Experiment& e, std::set<std::string>* names) {
453 if (e.type == Experiment::SINGLE_VALUE) {
454 names->insert(e.internal_name);
455 } else {
[email protected]2ce9c89752011-02-25 18:24:34456 DCHECK_EQ(Experiment::MULTI_VALUE, e.type);
[email protected]8a6ff28d2010-12-02 16:35:19457 for (int i = 0; i < e.num_choices; ++i)
458 names->insert(NameForChoice(e, i));
459 }
460}
461
[email protected]28e35af2011-02-09 12:56:22462// Confirms that an experiment is valid, used in a DCHECK in
463// SanitizeList below.
464bool ValidateExperiment(const Experiment& e) {
465 switch (e.type) {
466 case Experiment::SINGLE_VALUE:
467 DCHECK_EQ(0, e.num_choices);
468 DCHECK(!e.choices);
469 break;
470 case Experiment::MULTI_VALUE:
471 DCHECK_GT(e.num_choices, 0);
472 DCHECK(e.choices);
[email protected]a82744532011-02-11 16:15:53473 DCHECK(e.choices[0].command_line_switch);
474 DCHECK_EQ('\0', e.choices[0].command_line_switch[0]);
[email protected]28e35af2011-02-09 12:56:22475 break;
476 default:
477 NOTREACHED();
478 }
479 return true;
480}
481
[email protected]ad2a3ded2010-08-27 13:19:05482// Removes all experiments from prefs::kEnabledLabsExperiments that are
483// unknown, to prevent this list to become very long as experiments are added
484// and removed.
485void SanitizeList(PrefService* prefs) {
486 std::set<std::string> known_experiments;
[email protected]28e35af2011-02-09 12:56:22487 for (size_t i = 0; i < num_experiments; ++i) {
488 DCHECK(ValidateExperiment(experiments[i]));
[email protected]8a6ff28d2010-12-02 16:35:19489 AddInternalName(experiments[i], &known_experiments);
[email protected]28e35af2011-02-09 12:56:22490 }
[email protected]ad2a3ded2010-08-27 13:19:05491
492 std::set<std::string> enabled_experiments;
[email protected]1a47d7e2010-10-15 00:37:24493 GetEnabledFlags(prefs, &enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05494
495 std::set<std::string> new_enabled_experiments;
496 std::set_intersection(
497 known_experiments.begin(), known_experiments.end(),
498 enabled_experiments.begin(), enabled_experiments.end(),
499 std::inserter(new_enabled_experiments, new_enabled_experiments.begin()));
500
[email protected]1a47d7e2010-10-15 00:37:24501 SetEnabledFlags(prefs, new_enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05502}
503
[email protected]1a47d7e2010-10-15 00:37:24504void GetSanitizedEnabledFlags(
[email protected]ad2a3ded2010-08-27 13:19:05505 PrefService* prefs, std::set<std::string>* result) {
506 SanitizeList(prefs);
[email protected]1a47d7e2010-10-15 00:37:24507 GetEnabledFlags(prefs, result);
[email protected]ad2a3ded2010-08-27 13:19:05508}
509
[email protected]a314ee5a2010-10-26 21:23:28510// Variant of GetSanitizedEnabledFlags that also removes any flags that aren't
511// enabled on the current platform.
512void GetSanitizedEnabledFlagsForCurrentPlatform(
513 PrefService* prefs, std::set<std::string>* result) {
514 GetSanitizedEnabledFlags(prefs, result);
515
516 // Filter out any experiments that aren't enabled on the current platform. We
517 // don't remove these from prefs else syncing to a platform with a different
518 // set of experiments would be lossy.
519 std::set<std::string> platform_experiments;
520 int current_platform = GetCurrentPlatform();
521 for (size_t i = 0; i < num_experiments; ++i) {
522 if (experiments[i].supported_platforms & current_platform)
[email protected]8a6ff28d2010-12-02 16:35:19523 AddInternalName(experiments[i], &platform_experiments);
[email protected]a314ee5a2010-10-26 21:23:28524 }
525
526 std::set<std::string> new_enabled_experiments;
527 std::set_intersection(
528 platform_experiments.begin(), platform_experiments.end(),
529 result->begin(), result->end(),
530 std::inserter(new_enabled_experiments, new_enabled_experiments.begin()));
531
532 result->swap(new_enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05533}
534
[email protected]8a6ff28d2010-12-02 16:35:19535// Returns the Value representing the choice data in the specified experiment.
[email protected]8a6ff28d2010-12-02 16:35:19536Value* CreateChoiceData(const Experiment& experiment,
[email protected]28e35af2011-02-09 12:56:22537 const std::set<std::string>& enabled_experiments) {
[email protected]2ce9c89752011-02-25 18:24:34538 DCHECK_EQ(Experiment::MULTI_VALUE, experiment.type);
[email protected]8a6ff28d2010-12-02 16:35:19539 ListValue* result = new ListValue;
540 for (int i = 0; i < experiment.num_choices; ++i) {
541 const Experiment::Choice& choice = experiment.choices[i];
542 DictionaryValue* value = new DictionaryValue;
543 std::string name = NameForChoice(experiment, i);
544 value->SetString("description",
545 l10n_util::GetStringUTF16(choice.description_id));
546 value->SetString("internal_name", name);
[email protected]28e35af2011-02-09 12:56:22547 value->SetBoolean("selected", enabled_experiments.count(name) > 0);
[email protected]8a6ff28d2010-12-02 16:35:19548 result->Append(value);
549 }
550 return result;
551}
552
[email protected]e2ddbc92010-10-15 20:02:07553} // namespace
554
[email protected]1a47d7e2010-10-15 00:37:24555void ConvertFlagsToSwitches(PrefService* prefs, CommandLine* command_line) {
[email protected]8e8bb6d2010-12-13 08:18:55556 FlagsState::GetInstance()->ConvertFlagsToSwitches(prefs, command_line);
[email protected]ad2a3ded2010-08-27 13:19:05557}
558
[email protected]1a47d7e2010-10-15 00:37:24559ListValue* GetFlagsExperimentsData(PrefService* prefs) {
[email protected]ad2a3ded2010-08-27 13:19:05560 std::set<std::string> enabled_experiments;
[email protected]1a47d7e2010-10-15 00:37:24561 GetSanitizedEnabledFlags(prefs, &enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05562
563 int current_platform = GetCurrentPlatform();
564
565 ListValue* experiments_data = new ListValue();
[email protected]a314ee5a2010-10-26 21:23:28566 for (size_t i = 0; i < num_experiments; ++i) {
567 const Experiment& experiment = experiments[i];
[email protected]ad2a3ded2010-08-27 13:19:05568 if (!(experiment.supported_platforms & current_platform))
569 continue;
570
571 DictionaryValue* data = new DictionaryValue();
572 data->SetString("internal_name", experiment.internal_name);
573 data->SetString("name",
574 l10n_util::GetStringUTF16(experiment.visible_name_id));
575 data->SetString("description",
576 l10n_util::GetStringUTF16(
577 experiment.visible_description_id));
[email protected]ad2a3ded2010-08-27 13:19:05578
[email protected]28e35af2011-02-09 12:56:22579 switch (experiment.type) {
580 case Experiment::SINGLE_VALUE:
581 data->SetBoolean(
582 "enabled",
583 enabled_experiments.count(experiment.internal_name) > 0);
584 break;
585 case Experiment::MULTI_VALUE:
586 data->Set("choices", CreateChoiceData(experiment, enabled_experiments));
587 break;
588 default:
589 NOTREACHED();
[email protected]8a6ff28d2010-12-02 16:35:19590 }
591
[email protected]ad2a3ded2010-08-27 13:19:05592 experiments_data->Append(data);
593 }
594 return experiments_data;
595}
596
[email protected]ad2a3ded2010-08-27 13:19:05597bool IsRestartNeededToCommitChanges() {
[email protected]8e8bb6d2010-12-13 08:18:55598 return FlagsState::GetInstance()->IsRestartNeededToCommitChanges();
[email protected]ad2a3ded2010-08-27 13:19:05599}
600
601void SetExperimentEnabled(
[email protected]c7b7800a2010-10-07 18:51:35602 PrefService* prefs, const std::string& internal_name, bool enable) {
[email protected]8e8bb6d2010-12-13 08:18:55603 FlagsState::GetInstance()->SetExperimentEnabled(prefs, internal_name, enable);
[email protected]e2ddbc92010-10-15 20:02:07604}
605
606void RemoveFlagsSwitches(
607 std::map<std::string, CommandLine::StringType>* switch_list) {
[email protected]8e8bb6d2010-12-13 08:18:55608 FlagsState::GetInstance()->RemoveFlagsSwitches(switch_list);
[email protected]e2ddbc92010-10-15 20:02:07609}
610
[email protected]a314ee5a2010-10-26 21:23:28611int GetCurrentPlatform() {
612#if defined(OS_MACOSX)
613 return kOsMac;
614#elif defined(OS_WIN)
615 return kOsWin;
616#elif defined(OS_CHROMEOS) // Needs to be before the OS_LINUX check.
617 return kOsCrOS;
618#elif defined(OS_LINUX)
619 return kOsLinux;
620#else
621#error Unknown platform
622#endif
623}
624
[email protected]4bc5050c2010-11-18 17:55:54625void RecordUMAStatistics(const PrefService* prefs) {
626 std::set<std::string> flags;
627 GetEnabledFlags(prefs, &flags);
628 for (std::set<std::string>::iterator it = flags.begin(); it != flags.end();
629 ++it) {
630 std::string action("AboutFlags_");
631 action += *it;
632 UserMetrics::RecordComputedAction(action);
633 }
634 // Since flag metrics are recorded every startup, add a tick so that the
635 // stats can be made meaningful.
636 if (flags.size())
637 UserMetrics::RecordAction(UserMetricsAction("AboutFlags_StartupTick"));
[email protected]970b2fd2011-01-22 18:06:45638 UserMetrics::RecordAction(UserMetricsAction("StartupTick"));
[email protected]4bc5050c2010-11-18 17:55:54639}
640
[email protected]e2ddbc92010-10-15 20:02:07641//////////////////////////////////////////////////////////////////////////////
642// FlagsState implementation.
643
644namespace {
645
646void FlagsState::ConvertFlagsToSwitches(
647 PrefService* prefs, CommandLine* command_line) {
[email protected]e2ddbc92010-10-15 20:02:07648 if (command_line->HasSwitch(switches::kNoExperiments))
649 return;
650
651 std::set<std::string> enabled_experiments;
[email protected]ba8164242010-11-16 21:31:00652
[email protected]a314ee5a2010-10-26 21:23:28653 GetSanitizedEnabledFlagsForCurrentPlatform(prefs, &enabled_experiments);
[email protected]e2ddbc92010-10-15 20:02:07654
[email protected]a82744532011-02-11 16:15:53655 typedef std::map<std::string, std::pair<std::string, std::string> >
656 NameToSwitchAndValueMap;
657 NameToSwitchAndValueMap name_to_switch_map;
[email protected]8a6ff28d2010-12-02 16:35:19658 for (size_t i = 0; i < num_experiments; ++i) {
659 const Experiment& e = experiments[i];
660 if (e.type == Experiment::SINGLE_VALUE) {
[email protected]a82744532011-02-11 16:15:53661 name_to_switch_map[e.internal_name] =
662 std::pair<std::string, std::string>(e.command_line_switch,
663 e.command_line_value);
[email protected]8a6ff28d2010-12-02 16:35:19664 } else {
665 for (int j = 0; j < e.num_choices; ++j)
[email protected]a82744532011-02-11 16:15:53666 name_to_switch_map[NameForChoice(e, j)] =
667 std::pair<std::string, std::string>(
668 e.choices[j].command_line_switch,
669 e.choices[j].command_line_value);
[email protected]8a6ff28d2010-12-02 16:35:19670 }
671 }
[email protected]e2ddbc92010-10-15 20:02:07672
673 command_line->AppendSwitch(switches::kFlagSwitchesBegin);
[email protected]a82744532011-02-11 16:15:53674 flags_switches_.insert(
675 std::pair<std::string, std::string>(switches::kFlagSwitchesBegin,
676 std::string()));
[email protected]e2ddbc92010-10-15 20:02:07677 for (std::set<std::string>::iterator it = enabled_experiments.begin();
678 it != enabled_experiments.end();
679 ++it) {
680 const std::string& experiment_name = *it;
[email protected]a82744532011-02-11 16:15:53681 NameToSwitchAndValueMap::const_iterator name_to_switch_it =
[email protected]8a6ff28d2010-12-02 16:35:19682 name_to_switch_map.find(experiment_name);
683 if (name_to_switch_it == name_to_switch_map.end()) {
684 NOTREACHED();
[email protected]e2ddbc92010-10-15 20:02:07685 continue;
[email protected]8a6ff28d2010-12-02 16:35:19686 }
[email protected]e2ddbc92010-10-15 20:02:07687
[email protected]a82744532011-02-11 16:15:53688 const std::pair<std::string, std::string>&
689 switch_and_value_pair = name_to_switch_it->second;
690
691 command_line->AppendSwitchASCII(switch_and_value_pair.first,
692 switch_and_value_pair.second);
693 flags_switches_[switch_and_value_pair.first] = switch_and_value_pair.second;
[email protected]e2ddbc92010-10-15 20:02:07694 }
695 command_line->AppendSwitch(switches::kFlagSwitchesEnd);
[email protected]a82744532011-02-11 16:15:53696 flags_switches_.insert(
697 std::pair<std::string, std::string>(switches::kFlagSwitchesEnd,
698 std::string()));
[email protected]e2ddbc92010-10-15 20:02:07699}
700
701bool FlagsState::IsRestartNeededToCommitChanges() {
702 return needs_restart_;
703}
704
705void FlagsState::SetExperimentEnabled(
706 PrefService* prefs, const std::string& internal_name, bool enable) {
[email protected]ad2a3ded2010-08-27 13:19:05707 needs_restart_ = true;
708
[email protected]8a6ff28d2010-12-02 16:35:19709 size_t at_index = internal_name.find(about_flags::testing::kMultiSeparator);
710 if (at_index != std::string::npos) {
711 DCHECK(enable);
712 // We're being asked to enable a multi-choice experiment. Disable the
713 // currently selected choice.
714 DCHECK_NE(at_index, 0u);
[email protected]28e35af2011-02-09 12:56:22715 const std::string experiment_name = internal_name.substr(0, at_index);
716 SetExperimentEnabled(prefs, experiment_name, false);
[email protected]8a6ff28d2010-12-02 16:35:19717
[email protected]28e35af2011-02-09 12:56:22718 // And enable the new choice, if it is not the default first choice.
719 if (internal_name != experiment_name + "@0") {
720 std::set<std::string> enabled_experiments;
721 GetSanitizedEnabledFlags(prefs, &enabled_experiments);
722 enabled_experiments.insert(internal_name);
723 SetEnabledFlags(prefs, enabled_experiments);
724 }
[email protected]8a6ff28d2010-12-02 16:35:19725 return;
726 }
727
[email protected]ad2a3ded2010-08-27 13:19:05728 std::set<std::string> enabled_experiments;
[email protected]1a47d7e2010-10-15 00:37:24729 GetSanitizedEnabledFlags(prefs, &enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05730
[email protected]8a6ff28d2010-12-02 16:35:19731 const Experiment* e = NULL;
732 for (size_t i = 0; i < num_experiments; ++i) {
733 if (experiments[i].internal_name == internal_name) {
734 e = experiments + i;
735 break;
736 }
737 }
738 DCHECK(e);
739
740 if (e->type == Experiment::SINGLE_VALUE) {
[email protected]d208f4d82011-05-23 21:52:03741 if (enable) {
[email protected]8a6ff28d2010-12-02 16:35:19742 enabled_experiments.insert(internal_name);
[email protected]d208f4d82011-05-23 21:52:03743 // If enabling NaCl, make sure the plugin is also enabled. See bug
744 // http://code.google.com/p/chromium/issues/detail?id=81010 for more
745 // information.
746 // TODO(dspringer): When NaCl is on by default, remove this code.
747 if (internal_name == switches::kEnableNaCl) {
748 PluginUpdater* plugin_updater = PluginUpdater::GetInstance();
749 string16 nacl_plugin_name =
750 ASCIIToUTF16(chrome::ChromeContentClient::kNaClPluginName);
751 plugin_updater->EnablePluginGroup(true, nacl_plugin_name);
752 }
753 } else {
[email protected]8a6ff28d2010-12-02 16:35:19754 enabled_experiments.erase(internal_name);
[email protected]d208f4d82011-05-23 21:52:03755 }
[email protected]8a6ff28d2010-12-02 16:35:19756 } else {
757 if (enable) {
758 // Enable the first choice.
759 enabled_experiments.insert(NameForChoice(*e, 0));
760 } else {
761 // Find the currently enabled choice and disable it.
762 for (int i = 0; i < e->num_choices; ++i) {
763 std::string choice_name = NameForChoice(*e, i);
764 if (enabled_experiments.find(choice_name) !=
765 enabled_experiments.end()) {
766 enabled_experiments.erase(choice_name);
767 // Continue on just in case there's a bug and more than one
768 // experiment for this choice was enabled.
769 }
770 }
771 }
772 }
[email protected]ad2a3ded2010-08-27 13:19:05773
[email protected]1a47d7e2010-10-15 00:37:24774 SetEnabledFlags(prefs, enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05775}
776
[email protected]e2ddbc92010-10-15 20:02:07777void FlagsState::RemoveFlagsSwitches(
778 std::map<std::string, CommandLine::StringType>* switch_list) {
[email protected]a82744532011-02-11 16:15:53779 for (std::map<std::string, std::string>::const_iterator
780 it = flags_switches_.begin(); it != flags_switches_.end(); ++it) {
781 switch_list->erase(it->first);
[email protected]e2ddbc92010-10-15 20:02:07782 }
783}
784
785void FlagsState::reset() {
786 needs_restart_ = false;
787 flags_switches_.clear();
788}
789
[email protected]38e46812011-05-09 20:49:22790} // namespace
[email protected]e2ddbc92010-10-15 20:02:07791
792namespace testing {
[email protected]8a6ff28d2010-12-02 16:35:19793
794// WARNING: '@' is also used in the html file. If you update this constant you
795// also need to update the html file.
796const char kMultiSeparator[] = "@";
797
[email protected]e2ddbc92010-10-15 20:02:07798void ClearState() {
[email protected]8e8bb6d2010-12-13 08:18:55799 FlagsState::GetInstance()->reset();
[email protected]e2ddbc92010-10-15 20:02:07800}
[email protected]a314ee5a2010-10-26 21:23:28801
802void SetExperiments(const Experiment* e, size_t count) {
803 if (!e) {
804 experiments = kExperiments;
805 num_experiments = arraysize(kExperiments);
806 } else {
807 experiments = e;
808 num_experiments = count;
809 }
810}
811
[email protected]8a6ff28d2010-12-02 16:35:19812const Experiment* GetExperiments(size_t* count) {
813 *count = num_experiments;
814 return experiments;
815}
816
[email protected]e2ddbc92010-10-15 20:02:07817} // namespace testing
818
[email protected]1a47d7e2010-10-15 00:37:24819} // namespace about_flags