blob: f0ec9ddd0e87adb2abe1aa9fb208dd7ba49311c7 [file] [log] [blame]
[email protected]9c66adc2012-01-05 02:10:161// Copyright (c) 2012 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]ad2a3ded2010-08-27 13:19:0517#include "chrome/browser/prefs/pref_service.h"
[email protected]1bc78422011-03-31 08:41:3818#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]d208f4d82011-05-23 21:52:0319#include "chrome/common/chrome_content_client.h"
[email protected]ad2a3ded2010-08-27 13:19:0520#include "chrome/common/chrome_switches.h"
21#include "chrome/common/pref_names.h"
[email protected]7f6f44c2011-12-14 13:23:3822#include "content/public/browser/user_metrics.h"
[email protected]ad2a3ded2010-08-27 13:19:0523#include "grit/generated_resources.h"
[email protected]c051a1b2011-01-21 23:30:1724#include "ui/base/l10n/l10n_util.h"
[email protected]8ff7f342011-05-25 01:49:4725#include "ui/gfx/gl/gl_switches.h"
[email protected]ad2a3ded2010-08-27 13:19:0526
[email protected]8cc10df2011-11-03 23:57:5027#if defined(USE_AURA)
[email protected]b65bdda2011-12-23 23:35:3128#include "ash/ash_switches.h"
[email protected]8cc10df2011-11-03 23:57:5029#endif
30
[email protected]7f6f44c2011-12-14 13:23:3831using content::UserMetricsAction;
32
[email protected]1a47d7e2010-10-15 00:37:2433namespace about_flags {
[email protected]ad2a3ded2010-08-27 13:19:0534
[email protected]8a6ff28d2010-12-02 16:35:1935// Macros to simplify specifying the type.
[email protected]a82744532011-02-11 16:15:5336#define SINGLE_VALUE_TYPE_AND_VALUE(command_line_switch, switch_value) \
37 Experiment::SINGLE_VALUE, command_line_switch, switch_value, NULL, 0
38#define SINGLE_VALUE_TYPE(command_line_switch) \
39 SINGLE_VALUE_TYPE_AND_VALUE(command_line_switch, "")
40#define MULTI_VALUE_TYPE(choices) \
[email protected]0e6f56d2011-02-12 23:45:1541 Experiment::MULTI_VALUE, "", "", choices, arraysize(choices)
[email protected]8a6ff28d2010-12-02 16:35:1942
[email protected]e2ddbc92010-10-15 20:02:0743namespace {
44
[email protected]9c7453d2012-01-21 00:45:4045const unsigned kOsAll = kOsMac | kOsWin | kOsLinux | kOsCrOS | kOsAndroid;
[email protected]ad2a3ded2010-08-27 13:19:0546
[email protected]cc3e2052011-12-20 01:01:4047// Adds a |StringValue| to |list| for each platform where |bitmask| indicates
48// whether the experiment is available on that platform.
49void AddOsStrings(unsigned bitmask, ListValue* list) {
50 struct {
51 unsigned bit;
52 const char* const name;
53 } kBitsToOs[] = {
54 {kOsMac, "Mac"},
55 {kOsWin, "Windows"},
56 {kOsLinux, "Linux"},
57 {kOsCrOS, "Chrome OS"},
58 };
59 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kBitsToOs); ++i)
60 if (bitmask & kBitsToOs[i].bit)
61 list->Append(new StringValue(kBitsToOs[i].name));
62}
63
[email protected]ba8164242010-11-16 21:31:0064// Names for former Chrome OS Labs experiments, shared with prefs migration
65// code.
66const char kMediaPlayerExperimentName[] = "media-player";
67const char kAdvancedFileSystemExperimentName[] = "advanced-file-system";
68const char kVerticalTabsExperimentName[] = "vertical-tabs";
69
[email protected]778ef7c2011-10-11 15:37:0570const Experiment::Choice kPrerenderFromOmniboxChoices[] = {
71 { IDS_FLAGS_PRERENDER_FROM_OMNIBOX_AUTOMATIC, "", "" },
72 { IDS_FLAGS_PRERENDER_FROM_OMNIBOX_ENABLED, switches::kPrerenderFromOmnibox,
73 switches::kPrerenderFromOmniboxSwitchValueEnabled },
74 { IDS_FLAGS_PRERENDER_FROM_OMNIBOX_DISABLED, switches::kPrerenderFromOmnibox,
75 switches::kPrerenderFromOmniboxSwitchValueDisabled }
76};
77
[email protected]9b2c9f6a12012-01-27 21:00:0578const Experiment::Choice kOmniboxAggressiveHistoryURLChoices[] = {
79 { IDS_FLAGS_OMNIBOX_AGGRESSIVE_HISTORY_URL_SCORING_AUTOMATIC, "", "" },
80 { IDS_FLAGS_OMNIBOX_AGGRESSIVE_HISTORY_URL_SCORING_ENABLED,
81 switches::kOmniboxAggressiveHistoryURL,
82 switches::kOmniboxAggressiveHistoryURLEnabled },
83 { IDS_FLAGS_OMNIBOX_AGGRESSIVE_HISTORY_URL_SCORING_DISABLED,
84 switches::kOmniboxAggressiveHistoryURL,
85 switches::kOmniboxAggressiveHistoryURLDisabled }
86};
87
[email protected]032d5e6c2012-02-17 17:53:5588const Experiment::Choice kOmniboxInlineHistoryQuickProviderChoices[] = {
89 { IDS_FLAGS_OMNIBOX_INLINE_HISTORY_QUICK_PROVIDER_AUTOMATIC, "", "" },
90 { IDS_FLAGS_OMNIBOX_INLINE_HISTORY_QUICK_PROVIDER_ALLOWED,
91 switches::kOmniboxInlineHistoryQuickProvider,
92 switches::kOmniboxInlineHistoryQuickProviderAllowed },
93 { IDS_FLAGS_OMNIBOX_INLINE_HISTORY_QUICK_PROVIDER_PROHIBITED,
94 switches::kOmniboxInlineHistoryQuickProvider,
95 switches::kOmniboxInlineHistoryQuickProviderProhibited }
96};
97
[email protected]3fbd9c12011-12-16 21:35:1198#if defined(USE_AURA)
99const Experiment::Choice kAuraWindowModeChoices[] = {
[email protected]9c66adc2012-01-05 02:10:16100 { IDS_FLAGS_AURA_WINDOW_MODE_AUTOMATIC, "", "" },
[email protected]3fbd9c12011-12-16 21:35:11101 { IDS_FLAGS_AURA_WINDOW_MODE_COMPACT,
[email protected]d2840ef2012-02-01 05:10:36102 ash::switches::kAuraWindowMode,
103 ash::switches::kAuraWindowModeCompact },
104 { IDS_FLAGS_AURA_WINDOW_MODE_MANAGED,
105 ash::switches::kAuraWindowMode,
106 ash::switches::kAuraWindowModeManaged },
107 { IDS_FLAGS_AURA_WINDOW_MODE_OVERLAPPING,
108 ash::switches::kAuraWindowMode,
109 ash::switches::kAuraWindowModeOverlapping },
[email protected]3fbd9c12011-12-16 21:35:11110};
111#endif
112
[email protected]4bc5050c2010-11-18 17:55:54113// RECORDING USER METRICS FOR FLAGS:
114// -----------------------------------------------------------------------------
115// The first line of the experiment is the internal name. If you'd like to
116// gather statistics about the usage of your flag, you should append a marker
117// comment to the end of the feature name, like so:
118// "my-special-feature", // FLAGS:RECORD_UMA
119//
120// After doing that, run //chrome/tools/extract_actions.py (see instructions at
121// the top of that file for details) to update the chromeactions.txt file, which
122// will enable UMA to record your feature flag.
123//
124// After your feature has shipped under a flag, you can locate the metrics
125// under the action name AboutFlags_internal-action-name. Actions are recorded
126// once per startup, so you should divide this number by AboutFlags_StartupTick
127// to get a sense of usage. Note that this will not be the same as number of
128// users with a given feature enabled because users can quit and relaunch
129// the application multiple times over a given time interval.
130// TODO(rsesek): See if there's a way to count per-user, rather than
131// per-startup.
132
[email protected]8a6ff28d2010-12-02 16:35:19133// To add a new experiment add to the end of kExperiments. There are two
134// distinct types of experiments:
135// . SINGLE_VALUE: experiment is either on or off. Use the SINGLE_VALUE_TYPE
136// macro for this type supplying the command line to the macro.
[email protected]28e35af2011-02-09 12:56:22137// . MULTI_VALUE: a list of choices, the first of which should correspond to a
138// deactivated state for this lab (i.e. no command line option). To specify
139// this type of experiment use the macro MULTI_VALUE_TYPE supplying it the
140// array of choices.
[email protected]8a6ff28d2010-12-02 16:35:19141// See the documentation of Experiment for details on the fields.
142//
143// When adding a new choice, add it to the end of the list.
[email protected]ad2a3ded2010-08-27 13:19:05144const Experiment kExperiments[] = {
145 {
[email protected]aac169d2011-03-18 19:53:03146 "expose-for-tabs", // FLAGS:RECORD_UMA
147 IDS_FLAGS_TABPOSE_NAME,
148 IDS_FLAGS_TABPOSE_DESCRIPTION,
149 kOsMac,
150#if defined(OS_MACOSX)
151 // The switch exists only on OS X.
152 SINGLE_VALUE_TYPE(switches::kEnableExposeForTabs)
153#else
154 SINGLE_VALUE_TYPE("")
155#endif
156 },
157 {
[email protected]4bc5050c2010-11-18 17:55:54158 "conflicting-modules-check", // FLAGS:RECORD_UMA
[email protected]c1bbaa82010-11-08 11:17:05159 IDS_FLAGS_CONFLICTS_CHECK_NAME,
160 IDS_FLAGS_CONFLICTS_CHECK_DESCRIPTION,
161 kOsWin,
[email protected]8a6ff28d2010-12-02 16:35:19162 SINGLE_VALUE_TYPE(switches::kConflictingModulesCheck)
[email protected]c1bbaa82010-11-08 11:17:05163 },
164 {
[email protected]4bc5050c2010-11-18 17:55:54165 "cloud-print-proxy", // FLAGS:RECORD_UMA
[email protected]dae7325b2011-12-21 20:56:54166 IDS_FLAGS_CLOUD_PRINT_CONNECTOR_NAME,
167 IDS_FLAGS_CLOUD_PRINT_CONNECTOR_DESCRIPTION,
[email protected]9f8872b32011-03-04 19:44:45168 // For a Chrome build, we know we have a PDF plug-in on Windows, so it's
[email protected]4fa24bf2011-08-20 02:15:22169 // fully enabled.
[email protected]5d10d57d2011-07-22 22:16:31170 // Otherwise, where we know Windows could be working if a viable PDF
[email protected]4fa24bf2011-08-20 02:15:22171 // plug-in could be supplied, we'll keep the lab enabled. Mac and Linux
172 // always have PDF rasterization available, so no flag needed there.
173#if !defined(GOOGLE_CHROME_BUILD)
174 kOsWin,
175#else
176 0,
[email protected]fa6d2a2f2010-11-30 21:47:19177#endif
[email protected]8a6ff28d2010-12-02 16:35:19178 SINGLE_VALUE_TYPE(switches::kEnableCloudPrintProxy)
[email protected]8b6588a2010-10-12 02:39:42179 },
[email protected]580939a2010-10-12 18:54:37180 {
[email protected]bb461532010-11-26 21:50:23181 "crxless-web-apps",
182 IDS_FLAGS_CRXLESS_WEB_APPS_NAME,
183 IDS_FLAGS_CRXLESS_WEB_APPS_DESCRIPTION,
184 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19185 SINGLE_VALUE_TYPE(switches::kEnableCrxlessWebApps)
[email protected]bb461532010-11-26 21:50:23186 },
187 {
[email protected]96c6f4c2011-05-18 19:36:22188 "ignore-gpu-blacklist",
189 IDS_FLAGS_IGNORE_GPU_BLACKLIST_NAME,
190 IDS_FLAGS_IGNORE_GPU_BLACKLIST_DESCRIPTION,
191 kOsAll,
192 SINGLE_VALUE_TYPE(switches::kIgnoreGpuBlacklist)
193 },
194 {
[email protected]0110cf112011-07-02 00:39:43195 "force-compositing-mode-2",
[email protected]96c6f4c2011-05-18 19:36:22196 IDS_FLAGS_FORCE_COMPOSITING_MODE_NAME,
197 IDS_FLAGS_FORCE_COMPOSITING_MODE_DESCRIPTION,
198 kOsAll,
199 SINGLE_VALUE_TYPE(switches::kForceCompositingMode)
200 },
201 {
[email protected]5963b772011-02-09 22:55:38202 "composited-layer-borders",
203 IDS_FLAGS_COMPOSITED_LAYER_BORDERS,
204 IDS_FLAGS_COMPOSITED_LAYER_BORDERS_DESCRIPTION,
205 kOsAll,
206 SINGLE_VALUE_TYPE(switches::kShowCompositedLayerBorders)
207 },
208 {
[email protected]db543d322011-12-15 20:40:15209 "accelerated-painting",
210 IDS_FLAGS_ACCELERATED_PAINTING_NAME,
211 IDS_FLAGS_ACCELERATED_PAINTING_DESCRIPTION,
[email protected]60dea122011-12-06 00:32:45212#if defined(USE_SKIA)
213 kOsAll,
214#else
215 0,
216#endif
[email protected]db543d322011-12-15 20:40:15217 SINGLE_VALUE_TYPE(switches::kEnableAcceleratedPainting)
[email protected]60dea122011-12-06 00:32:45218 },
219 {
[email protected]a8f1eaa2011-03-07 19:00:58220 "show-fps-counter",
221 IDS_FLAGS_SHOW_FPS_COUNTER,
222 IDS_FLAGS_SHOW_FPS_COUNTER_DESCRIPTION,
223 kOsAll,
224 SINGLE_VALUE_TYPE(switches::kShowFPSCounter)
225 },
[email protected]8ff7f342011-05-25 01:49:47226 {
[email protected]70c98a332011-12-21 20:51:52227 "accelerated-filters",
228 IDS_FLAGS_ACCELERATED_FILTERS,
229 IDS_FLAGS_ACCELERATED_FILTERS_DESCRIPTION,
230 kOsAll,
231 SINGLE_VALUE_TYPE(switches::kEnableAcceleratedFilters)
232 },
233 {
[email protected]8ff7f342011-05-25 01:49:47234 "disable-gpu-vsync",
235 IDS_FLAGS_DISABLE_GPU_VSYNC_NAME,
236 IDS_FLAGS_DISABLE_GPU_VSYNC_DESCRIPTION,
237 kOsAll,
238 SINGLE_VALUE_TYPE(switches::kDisableGpuVsync)
239 },
[email protected]deaba6d52011-09-23 14:47:12240 {
241 "disable-webgl",
242 IDS_FLAGS_DISABLE_WEBGL_NAME,
243 IDS_FLAGS_DISABLE_WEBGL_DESCRIPTION,
244 kOsAll,
245 SINGLE_VALUE_TYPE(switches::kDisableExperimentalWebGL)
246 },
[email protected]eb00a762012-01-18 07:29:28247
248#if defined(GOOGLE_CHROME_BUILD)
249 // TODO(thestig) Remove this for bug 107600.
250 {
251 "disable-print-preview", // FLAGS:RECORD_UMA
252 IDS_FLAGS_DISABLE_PRINT_PREVIEW_NAME,
253 IDS_FLAGS_DISABLE_PRINT_PREVIEW_DESCRIPTION,
254 kOsAll,
255 SINGLE_VALUE_TYPE(switches::kDisablePrintPreview)
256 },
257#else
258 // For Chromium builds where users may not have the PDF plugin.
[email protected]8d260e52010-10-13 01:03:05259 {
[email protected]4bc5050c2010-11-18 17:55:54260 "print-preview", // FLAGS:RECORD_UMA
[email protected]9486c1f2010-10-14 19:52:12261 IDS_FLAGS_PRINT_PREVIEW_NAME,
262 IDS_FLAGS_PRINT_PREVIEW_DESCRIPTION,
[email protected]b579afd2011-07-13 00:01:27263 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19264 SINGLE_VALUE_TYPE(switches::kEnablePrintPreview)
[email protected]2fe15fcb2010-10-21 20:39:53265 },
[email protected]eb00a762012-01-18 07:29:28266#endif
267
[email protected]d208f4d82011-05-23 21:52:03268 // TODO(dspringer): When NaCl is on by default, remove this flag entry.
[email protected]2fe15fcb2010-10-21 20:39:53269 {
[email protected]e3791ce92011-08-09 01:03:32270 "enable-nacl", // FLAGS:RECORD_UMA
[email protected]4ff87d202010-11-06 01:28:40271 IDS_FLAGS_ENABLE_NACL_NAME,
272 IDS_FLAGS_ENABLE_NACL_DESCRIPTION,
273 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19274 SINGLE_VALUE_TYPE(switches::kEnableNaCl)
[email protected]4ff87d202010-11-06 01:28:40275 },
[email protected]b39c6d92012-01-31 16:38:41276 // TODO(halyavin): When exception handling is on by default, replace this
277 // flag with disable-nacl-exception-handling.
278 {
279 "enable-nacl-exception-handling", // FLAGS:RECORD_UMA
280 IDS_FLAGS_ENABLE_NACL_EXCEPTION_HANDLING_NAME,
281 IDS_FLAGS_ENABLE_NACL_EXCEPTION_HANDLING_DESCRIPTION,
282 kOsWin,
283 SINGLE_VALUE_TYPE(switches::kEnableNaClExceptionHandling)
284 },
[email protected]4ff87d202010-11-06 01:28:40285 {
[email protected]4bc5050c2010-11-18 17:55:54286 "extension-apis", // FLAGS:RECORD_UMA
[email protected]11dd68cd52010-11-12 01:15:32287 IDS_FLAGS_EXPERIMENTAL_EXTENSION_APIS_NAME,
288 IDS_FLAGS_EXPERIMENTAL_EXTENSION_APIS_DESCRIPTION,
289 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19290 SINGLE_VALUE_TYPE(switches::kEnableExperimentalExtensionApis)
[email protected]11dd68cd52010-11-12 01:15:32291 },
[email protected]3627b06d2010-11-12 16:36:16292 {
[email protected]cbe224d2011-08-04 22:12:49293 "apps-new-install-bubble",
294 IDS_FLAGS_APPS_NEW_INSTALL_BUBBLE_NAME,
295 IDS_FLAGS_APPS_NEW_INSTALL_BUBBLE_DESCRIPTION,
296 kOsAll,
297 SINGLE_VALUE_TYPE(switches::kAppsNewInstallBubble)
298 },
299 {
[email protected]80bd24e2010-11-30 09:34:38300 "disable-hyperlink-auditing",
301 IDS_FLAGS_DISABLE_HYPERLINK_AUDITING_NAME,
302 IDS_FLAGS_DISABLE_HYPERLINK_AUDITING_DESCRIPTION,
303 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19304 SINGLE_VALUE_TYPE(switches::kNoPings)
[email protected]feb28fef2010-12-01 10:52:51305 },
306 {
307 "experimental-location-features", // FLAGS:RECORD_UMA
308 IDS_FLAGS_EXPERIMENTAL_LOCATION_FEATURES_NAME,
309 IDS_FLAGS_EXPERIMENTAL_LOCATION_FEATURES_DESCRIPTION,
310 kOsMac | kOsWin | kOsLinux, // Currently does nothing on CrOS.
[email protected]8a6ff28d2010-12-02 16:35:19311 SINGLE_VALUE_TYPE(switches::kExperimentalLocationFeatures)
312 },
313 {
[email protected]04227962011-01-20 02:03:09314 "disable-interactive-form-validation",
315 IDS_FLAGS_DISABLE_INTERACTIVE_FORM_VALIDATION_NAME,
316 IDS_FLAGS_DISABLE_INTERACTIVE_FORM_VALIDATION_DESCRIPTION,
317 kOsAll,
318 SINGLE_VALUE_TYPE(switches::kDisableInteractiveFormValidation)
319 },
[email protected]8df51192011-01-22 20:05:03320 {
[email protected]07d490bc2011-03-07 17:05:26321 "focus-existing-tab-on-open", // FLAGS:RECORD_UMA
322 IDS_FLAGS_FOCUS_EXISTING_TAB_ON_OPEN_NAME,
323 IDS_FLAGS_FOCUS_EXISTING_TAB_ON_OPEN_DESCRIPTION,
324 kOsAll,
325 SINGLE_VALUE_TYPE(switches::kFocusExistingTabOnOpen)
326 },
[email protected]d5dcfb32011-03-19 00:49:24327 {
[email protected]5aea1862011-03-23 23:55:39328 "tab-groups-context-menu",
329 IDS_FLAGS_TAB_GROUPS_CONTEXT_MENU_NAME,
330 IDS_FLAGS_TAB_GROUPS_CONTEXT_MENU_DESCRIPTION,
331 kOsWin,
332 SINGLE_VALUE_TYPE(switches::kEnableTabGroupsContextMenu)
333 },
[email protected]e9bf9d92011-03-31 20:57:15334 {
[email protected]f2557bd2011-06-01 02:33:07335 "preload-instant-search",
336 IDS_FLAGS_PRELOAD_INSTANT_SEARCH_NAME,
337 IDS_FLAGS_PRELOAD_INSTANT_SEARCH_DESCRIPTION,
338 kOsAll,
339 SINGLE_VALUE_TYPE(switches::kPreloadInstantSearch)
340 },
[email protected]354e33b2011-06-15 00:29:10341 {
342 "static-ip-config",
343 IDS_FLAGS_STATIC_IP_CONFIG_NAME,
344 IDS_FLAGS_STATIC_IP_CONFIG_DESCRIPTION,
345 kOsCrOS,
346#if defined(OS_CHROMEOS)
347 // This switch exists only on Chrome OS.
348 SINGLE_VALUE_TYPE(switches::kEnableStaticIPConfig)
349#else
350 SINGLE_VALUE_TYPE("")
351#endif
352 },
[email protected]3eb5728c2011-06-20 22:32:24353 {
354 "show-autofill-type-predictions",
355 IDS_FLAGS_SHOW_AUTOFILL_TYPE_PREDICTIONS_NAME,
356 IDS_FLAGS_SHOW_AUTOFILL_TYPE_PREDICTIONS_DESCRIPTION,
357 kOsAll,
358 SINGLE_VALUE_TYPE(switches::kShowAutofillTypePredictions)
359 },
[email protected]bff4d3e2011-06-21 23:58:52360 {
[email protected]9a6180d7d2011-09-07 01:40:33361 "sync-tabs",
362 IDS_FLAGS_SYNC_TABS_NAME,
363 IDS_FLAGS_SYNC_TABS_DESCRIPTION,
[email protected]5b0ec7f2011-08-11 02:17:17364 kOsAll,
[email protected]9a6180d7d2011-09-07 01:40:33365 SINGLE_VALUE_TYPE(switches::kEnableSyncTabs)
[email protected]5b0ec7f2011-08-11 02:17:17366 },
367 {
[email protected]aae9eeb12011-10-21 21:59:26368 "sync-app-notifications",
369 IDS_FLAGS_SYNC_APP_NOTIFICATIONS_NAME,
370 IDS_FLAGS_SYNC_APP_NOTIFICATIONS_DESCRIPTION,
371 kOsAll,
[email protected]0b6fba82011-11-18 01:31:11372 SINGLE_VALUE_TYPE(switches::kDisableSyncAppNotifications)
[email protected]aae9eeb12011-10-21 21:59:26373 },
374 {
[email protected]a22ebd812011-06-23 00:05:39375 "enable-smooth-scrolling", // FLAGS:RECORD_UMA
376 IDS_FLAGS_ENABLE_SMOOTH_SCROLLING_NAME,
377 IDS_FLAGS_ENABLE_SMOOTH_SCROLLING_DESCRIPTION,
378 // Can't expose the switch unless the code is compiled in.
[email protected]554b7062011-09-03 03:09:40379 // On by default for the Mac (different implementation in WebKit).
[email protected]554b7062011-09-03 03:09:40380 kOsWin | kOsLinux | kOsCrOS,
[email protected]a22ebd812011-06-23 00:05:39381 SINGLE_VALUE_TYPE(switches::kEnableSmoothScrolling)
382 },
[email protected]81a6b0b2011-06-24 17:55:40383 {
[email protected]ae1eb29a2011-08-17 17:50:57384 "prerender-from-omnibox", // FLAGS:RECORD_UMA
[email protected]81a6b0b2011-06-24 17:55:40385 IDS_FLAGS_PRERENDER_FROM_OMNIBOX_NAME,
386 IDS_FLAGS_PRERENDER_FROM_OMNIBOX_DESCRIPTION,
387 kOsAll,
[email protected]778ef7c2011-10-11 15:37:05388 MULTI_VALUE_TYPE(kPrerenderFromOmniboxChoices)
[email protected]81a6b0b2011-06-24 17:55:40389 },
[email protected]40916632011-07-02 01:11:01390 {
[email protected]9b2c9f6a12012-01-27 21:00:05391 "omnibox-aggressive-with-history-url",
[email protected]ed1e39502011-12-16 14:39:35392 IDS_FLAGS_OMNIBOX_AGGRESSIVE_HISTORY_URL_SCORING_NAME,
393 IDS_FLAGS_OMNIBOX_AGGRESSIVE_HISTORY_URL_SCORING_DESCRIPTION,
394 kOsAll,
[email protected]9b2c9f6a12012-01-27 21:00:05395 MULTI_VALUE_TYPE(kOmniboxAggressiveHistoryURLChoices)
[email protected]ed1e39502011-12-16 14:39:35396 },
397 {
[email protected]032d5e6c2012-02-17 17:53:55398 "omnibox-inline-history-quick-provider",
399 IDS_FLAGS_OMNIBOX_INLINE_HISTORY_QUICK_PROVIDER_NAME,
400 IDS_FLAGS_OMNIBOX_INLINE_HISTORY_QUICK_PROVIDER_DESCRIPTION,
401 kOsAll,
402 MULTI_VALUE_TYPE(kOmniboxInlineHistoryQuickProviderChoices)
403 },
404 {
[email protected]7e7a28092011-12-09 22:24:55405 "enable-panels",
406 IDS_FLAGS_ENABLE_PANELS_NAME,
407 IDS_FLAGS_ENABLE_PANELS_DESCRIPTION,
[email protected]73fb1fc52011-07-09 00:06:54408 kOsAll,
[email protected]7e7a28092011-12-09 22:24:55409 SINGLE_VALUE_TYPE(switches::kEnablePanels)
[email protected]73fb1fc52011-07-09 00:06:54410 },
[email protected]e3749d12011-07-25 22:22:12411 {
[email protected]9931875b2011-11-02 00:19:48412 "disable-shortcuts-provider",
413 IDS_FLAGS_DISABLE_SHORTCUTS_PROVIDER,
414 IDS_FLAGS_DISABLE_SHORTCUTS_PROVIDER_DESCRIPTION,
[email protected]e3749d12011-07-25 22:22:12415 kOsAll,
[email protected]9931875b2011-11-02 00:19:48416 SINGLE_VALUE_TYPE(switches::kDisableShortcutsProvider)
[email protected]e3749d12011-07-25 22:22:12417 },
[email protected]1a2966b92011-08-09 06:50:19418#if defined(OS_CHROMEOS)
419 {
[email protected]cd681c42011-09-29 02:49:44420 "enable-bluetooth",
421 IDS_FLAGS_ENABLE_BLUETOOTH_NAME,
422 IDS_FLAGS_ENABLE_BLUETOOTH_DESCRIPTION,
423 kOsCrOS,
424 SINGLE_VALUE_TYPE(switches::kEnableBluetooth)
425 },
[email protected]1a2966b92011-08-09 06:50:19426#endif
[email protected]80eb4262011-08-03 16:10:41427 {
428 "memory-widget",
429 IDS_FLAGS_MEMORY_WIDGET_NAME,
430 IDS_FLAGS_MEMORY_WIDGET_DESCRIPTION,
431 kOsCrOS,
432#if defined(OS_CHROMEOS)
433 // This switch exists only on Chrome OS.
434 SINGLE_VALUE_TYPE(switches::kMemoryWidget)
435#else
436 SINGLE_VALUE_TYPE("")
437#endif
[email protected]a0e4b072011-08-17 01:47:07438 },
439 {
440 "downloads-new-ui", // FLAGS:RECORD_UMA
441 IDS_FLAGS_DOWNLOADS_NEW_UI_NAME,
442 IDS_FLAGS_DOWNLOADS_NEW_UI_DESCRIPTION,
443 kOsAll,
444 SINGLE_VALUE_TYPE(switches::kDownloadsNewUI)
445 },
[email protected]b7bb44f2011-09-01 05:17:03446 {
447 "enable-autologin",
448 IDS_FLAGS_ENABLE_AUTOLOGIN_NAME,
449 IDS_FLAGS_ENABLE_AUTOLOGIN_DESCRIPTION,
450 kOsMac | kOsWin | kOsLinux,
451 SINGLE_VALUE_TYPE(switches::kEnableAutologin)
452 },
[email protected]b9841172011-09-26 23:36:09453 {
[email protected]bbadb112011-12-12 16:55:28454 "enable-http-pipelining",
455 IDS_FLAGS_ENABLE_HTTP_PIPELINING_NAME,
456 IDS_FLAGS_ENABLE_HTTP_PIPELINING_DESCRIPTION,
457 kOsAll,
458 SINGLE_VALUE_TYPE(switches::kEnableHttpPipelining)
459 },
[email protected]d411c01d2011-10-18 16:00:27460 {
[email protected]f5da41d2011-10-08 17:40:07461 "enable-video-track",
462 IDS_FLAGS_ENABLE_VIDEO_TRACK_NAME,
463 IDS_FLAGS_ENABLE_VIDEO_TRACK_DESCRIPTION,
464 kOsAll,
465 SINGLE_VALUE_TYPE(switches::kEnableVideoTrack)
466 },
[email protected]08b83362011-10-19 05:23:17467 {
[email protected]6aa03b32011-10-27 21:44:44468 "enable-media-source",
469 IDS_FLAGS_ENABLE_MEDIA_SOURCE_NAME,
470 IDS_FLAGS_ENABLE_MEDIA_SOURCE_DESCRIPTION,
471 kOsAll,
472 SINGLE_VALUE_TYPE(switches::kEnableMediaSource)
473 },
[email protected]e4e68dbb2011-11-18 01:50:22474 {
475 "enable-pointer-lock",
476 IDS_FLAGS_ENABLE_POINTER_LOCK_NAME,
477 IDS_FLAGS_ENABLE_POINTER_LOCK_DESCRIPTION,
478 kOsAll,
479 SINGLE_VALUE_TYPE(switches::kEnablePointerLock)
480 },
[email protected]8cc10df2011-11-03 23:57:50481#if defined(USE_AURA)
482 {
[email protected]20cea592011-12-10 01:55:30483 "aura-translucent-frames",
484 IDS_FLAGS_AURA_TRANSLUCENT_FRAMES_NAME,
485 IDS_FLAGS_AURA_TRANSLUCENT_FRAMES_DESCRIPTION,
486 kOsWin | kOsLinux | kOsCrOS,
[email protected]55f593352011-12-24 05:42:46487 SINGLE_VALUE_TYPE(ash::switches::kAuraTranslucentFrames)
[email protected]20cea592011-12-10 01:55:30488 },
[email protected]57b8bb352012-01-11 05:11:46489 {
490 "aura-google-dialog-frames",
491 IDS_FLAGS_AURA_GOOGLE_DIALOG_FRAMES_NAME,
492 IDS_FLAGS_AURA_GOOGLE_DIALOG_FRAMES_DESCRIPTION,
493 kOsWin | kOsLinux | kOsCrOS,
494 SINGLE_VALUE_TYPE(ash::switches::kAuraGoogleDialogFrames)
495 },
[email protected]35304ce2011-12-14 23:21:01496 {
[email protected]3fbd9c12011-12-16 21:35:11497 "aura-window-mode",
498 IDS_FLAGS_AURA_WINDOW_MODE_NAME,
499 IDS_FLAGS_AURA_WINDOW_MODE_DESCRIPTION,
[email protected]35304ce2011-12-14 23:21:01500 kOsWin | kOsLinux | kOsCrOS,
[email protected]3fbd9c12011-12-16 21:35:11501 MULTI_VALUE_TYPE(kAuraWindowModeChoices)
[email protected]35304ce2011-12-14 23:21:01502 },
[email protected]eaae8b462012-01-20 22:20:39503#endif // defined(USE_AURA)
504 {
505 "enable-gamepad",
506 IDS_FLAGS_ENABLE_GAMEPAD_NAME,
507 IDS_FLAGS_ENABLE_GAMEPAD_DESCRIPTION,
508 kOsAll,
509 SINGLE_VALUE_TYPE(switches::kEnableGamepad)
510 },
[email protected]db543d322011-12-15 20:40:15511 {
512 "per-tile-painting",
513 IDS_FLAGS_PER_TILE_PAINTING_NAME,
514 IDS_FLAGS_PER_TILE_PAINTING_DESCRIPTION,
515#if defined(USE_SKIA)
[email protected]a5b1b272012-01-06 20:44:37516 kOsMac | kOsLinux | kOsCrOS,
[email protected]db543d322011-12-15 20:40:15517#else
518 0,
519#endif
520 SINGLE_VALUE_TYPE(switches::kEnablePerTilePainting)
521 },
[email protected]bf88c032011-12-22 19:05:47522 {
523 "enable-javascript-harmony",
524 IDS_FLAGS_ENABLE_JAVASCRIPT_HARMONY_NAME,
525 IDS_FLAGS_ENABLE_JAVASCRIPT_HARMONY_DESCRIPTION,
526 kOsAll,
527 SINGLE_VALUE_TYPE_AND_VALUE(switches::kJavaScriptFlags, "--harmony")
528 },
[email protected]7e7f378a2012-01-05 14:35:37529 {
[email protected]85646172012-01-09 22:45:54530 "enable-tab-browser-dragging",
531 IDS_FLAGS_ENABLE_TAB_BROWSER_DRAGGING_NAME,
532 IDS_FLAGS_ENABLE_TAB_BROWSER_DRAGGING_DESCRIPTION,
533 kOsWin,
534 SINGLE_VALUE_TYPE(switches::kTabBrowserDragging)
535 },
536 {
[email protected]7e7f378a2012-01-05 14:35:37537 "enable-restore-session-state",
538 IDS_FLAGS_ENABLE_RESTORE_SESSION_STATE_NAME,
539 IDS_FLAGS_ENABLE_RESTORE_SESSION_STATE_DESCRIPTION,
540 kOsAll,
541 SINGLE_VALUE_TYPE(switches::kEnableRestoreSessionState)
542 },
[email protected]88864db2012-01-18 20:56:35543 {
544 "disable-software-rasterizer",
545 IDS_FLAGS_DISABLE_SOFTWARE_RASTERIZER_NAME,
546 IDS_FLAGS_DISABLE_SOFTWARE_RASTERIZER_DESCRIPTION,
547#if defined(ENABLE_SWIFTSHADER)
548 kOsAll,
549#else
550 0,
551#endif
552 SINGLE_VALUE_TYPE(switches::kDisableSoftwareRasterizer)
553 },
[email protected]15a5d722012-01-23 09:11:14554 {
555 "enable-media-stream",
556 IDS_FLAGS_MEDIA_STREAM_NAME,
557 IDS_FLAGS_MEDIA_STREAM_DESCRIPTION,
[email protected]fa82b6772012-02-20 13:19:05558 kOsAll,
[email protected]15a5d722012-01-23 09:11:14559 SINGLE_VALUE_TYPE(switches::kEnableMediaStream)
560 },
[email protected]f5ec7242012-01-27 07:15:15561 {
[email protected]fa12e2d2012-02-06 21:03:10562 "disable-uber-page",
563 IDS_FLAGS_DISABLE_UBER_PAGE_NAME,
564 IDS_FLAGS_DISABLE_UBER_PAGE_DESCRIPTION,
[email protected]f5ec7242012-01-27 07:15:15565 kOsAll,
[email protected]fa12e2d2012-02-06 21:03:10566 SINGLE_VALUE_TYPE(switches::kDisableUberPage)
[email protected]f5ec7242012-01-27 07:15:15567 },
[email protected]d2edc6702012-01-30 09:13:16568 {
569 "enable-shadow-dom",
570 IDS_FLAGS_SHADOW_DOM_NAME,
571 IDS_FLAGS_SHADOW_DOM_DESCRIPTION,
572 kOsAll,
573 SINGLE_VALUE_TYPE(switches::kEnableShadowDOM)
574 },
[email protected]9860c68b2012-02-02 01:58:09575 {
[email protected]4961218f2012-02-23 10:11:07576 "enable-style-scoped",
577 IDS_FLAGS_STYLE_SCOPED_NAME,
578 IDS_FLAGS_STYLE_SCOPED_DESCRIPTION,
579 kOsAll,
580 SINGLE_VALUE_TYPE(switches::kEnableStyleScoped)
581 },
582 {
[email protected]8bed69d2012-02-02 06:46:00583 "ntp-app-install-hint",
584 IDS_FLAGS_APP_INSTALL_HINT_NAME,
585 IDS_FLAGS_APP_INSTALL_HINT_DESCRIPTION,
586 kOsAll,
587 SINGLE_VALUE_TYPE(switches::kNtpAppInstallHint)
588 },
589 {
[email protected]9860c68b2012-02-02 01:58:09590 "enable-extension-activity-ui",
591 IDS_FLAGS_ENABLE_EXTENSION_ACTIVITY_UI_NAME,
592 IDS_FLAGS_ENABLE_EXTENSION_ACTIVITY_UI_DESCRIPTION,
593 kOsAll,
594 SINGLE_VALUE_TYPE(switches::kEnableExtensionActivityUI)
[email protected]8bed69d2012-02-02 06:46:00595 },
[email protected]54ae4e92012-02-16 15:19:05596 {
597 "webui-task-manager",
598 IDS_FLAGS_WEBUI_TASK_MANAGER_NAME,
599 IDS_FLAGS_WEBUI_TASK_MANAGER_DESCRIPTION,
600 kOsAll,
601 SINGLE_VALUE_TYPE(switches::kWebUITaskManager)
602 },
[email protected]a0e4b072011-08-17 01:47:07603};
[email protected]ad2a3ded2010-08-27 13:19:05604
[email protected]a314ee5a2010-10-26 21:23:28605const Experiment* experiments = kExperiments;
606size_t num_experiments = arraysize(kExperiments);
607
[email protected]e2ddbc92010-10-15 20:02:07608// Stores and encapsulates the little state that about:flags has.
609class FlagsState {
610 public:
611 FlagsState() : needs_restart_(false) {}
612 void ConvertFlagsToSwitches(PrefService* prefs, CommandLine* command_line);
613 bool IsRestartNeededToCommitChanges();
614 void SetExperimentEnabled(
[email protected]a314ee5a2010-10-26 21:23:28615 PrefService* prefs, const std::string& internal_name, bool enable);
[email protected]e2ddbc92010-10-15 20:02:07616 void RemoveFlagsSwitches(
617 std::map<std::string, CommandLine::StringType>* switch_list);
618 void reset();
619
620 // Returns the singleton instance of this class
[email protected]8e8bb6d2010-12-13 08:18:55621 static FlagsState* GetInstance() {
[email protected]e2ddbc92010-10-15 20:02:07622 return Singleton<FlagsState>::get();
623 }
624
625 private:
626 bool needs_restart_;
[email protected]a82744532011-02-11 16:15:53627 std::map<std::string, std::string> flags_switches_;
[email protected]e2ddbc92010-10-15 20:02:07628
629 DISALLOW_COPY_AND_ASSIGN(FlagsState);
630};
631
[email protected]c7b7800a2010-10-07 18:51:35632// Extracts the list of enabled lab experiments from preferences and stores them
[email protected]ad2a3ded2010-08-27 13:19:05633// in a set.
[email protected]1a47d7e2010-10-15 00:37:24634void GetEnabledFlags(const PrefService* prefs, std::set<std::string>* result) {
[email protected]ad2a3ded2010-08-27 13:19:05635 const ListValue* enabled_experiments = prefs->GetList(
636 prefs::kEnabledLabsExperiments);
637 if (!enabled_experiments)
638 return;
639
640 for (ListValue::const_iterator it = enabled_experiments->begin();
641 it != enabled_experiments->end();
642 ++it) {
643 std::string experiment_name;
644 if (!(*it)->GetAsString(&experiment_name)) {
645 LOG(WARNING) << "Invalid entry in " << prefs::kEnabledLabsExperiments;
646 continue;
647 }
648 result->insert(experiment_name);
649 }
650}
651
652// Takes a set of enabled lab experiments
[email protected]1a47d7e2010-10-15 00:37:24653void SetEnabledFlags(
[email protected]ad2a3ded2010-08-27 13:19:05654 PrefService* prefs, const std::set<std::string>& enabled_experiments) {
[email protected]1bc78422011-03-31 08:41:38655 ListPrefUpdate update(prefs, prefs::kEnabledLabsExperiments);
656 ListValue* experiments_list = update.Get();
[email protected]ad2a3ded2010-08-27 13:19:05657
658 experiments_list->Clear();
659 for (std::set<std::string>::const_iterator it = enabled_experiments.begin();
660 it != enabled_experiments.end();
661 ++it) {
662 experiments_list->Append(new StringValue(*it));
663 }
664}
665
[email protected]8a6ff28d2010-12-02 16:35:19666// Returns the name used in prefs for the choice at the specified index.
667std::string NameForChoice(const Experiment& e, int index) {
[email protected]2ce9c89752011-02-25 18:24:34668 DCHECK_EQ(Experiment::MULTI_VALUE, e.type);
669 DCHECK_LT(index, e.num_choices);
[email protected]8a6ff28d2010-12-02 16:35:19670 return std::string(e.internal_name) + about_flags::testing::kMultiSeparator +
671 base::IntToString(index);
672}
673
674// Adds the internal names for the specified experiment to |names|.
675void AddInternalName(const Experiment& e, std::set<std::string>* names) {
676 if (e.type == Experiment::SINGLE_VALUE) {
677 names->insert(e.internal_name);
678 } else {
[email protected]2ce9c89752011-02-25 18:24:34679 DCHECK_EQ(Experiment::MULTI_VALUE, e.type);
[email protected]8a6ff28d2010-12-02 16:35:19680 for (int i = 0; i < e.num_choices; ++i)
681 names->insert(NameForChoice(e, i));
682 }
683}
684
[email protected]28e35af2011-02-09 12:56:22685// Confirms that an experiment is valid, used in a DCHECK in
686// SanitizeList below.
687bool ValidateExperiment(const Experiment& e) {
688 switch (e.type) {
689 case Experiment::SINGLE_VALUE:
690 DCHECK_EQ(0, e.num_choices);
691 DCHECK(!e.choices);
692 break;
693 case Experiment::MULTI_VALUE:
694 DCHECK_GT(e.num_choices, 0);
695 DCHECK(e.choices);
[email protected]a82744532011-02-11 16:15:53696 DCHECK(e.choices[0].command_line_switch);
697 DCHECK_EQ('\0', e.choices[0].command_line_switch[0]);
[email protected]28e35af2011-02-09 12:56:22698 break;
699 default:
700 NOTREACHED();
701 }
702 return true;
703}
704
[email protected]ad2a3ded2010-08-27 13:19:05705// Removes all experiments from prefs::kEnabledLabsExperiments that are
706// unknown, to prevent this list to become very long as experiments are added
707// and removed.
708void SanitizeList(PrefService* prefs) {
709 std::set<std::string> known_experiments;
[email protected]28e35af2011-02-09 12:56:22710 for (size_t i = 0; i < num_experiments; ++i) {
711 DCHECK(ValidateExperiment(experiments[i]));
[email protected]8a6ff28d2010-12-02 16:35:19712 AddInternalName(experiments[i], &known_experiments);
[email protected]28e35af2011-02-09 12:56:22713 }
[email protected]ad2a3ded2010-08-27 13:19:05714
715 std::set<std::string> enabled_experiments;
[email protected]1a47d7e2010-10-15 00:37:24716 GetEnabledFlags(prefs, &enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05717
718 std::set<std::string> new_enabled_experiments;
719 std::set_intersection(
720 known_experiments.begin(), known_experiments.end(),
721 enabled_experiments.begin(), enabled_experiments.end(),
722 std::inserter(new_enabled_experiments, new_enabled_experiments.begin()));
723
[email protected]1a47d7e2010-10-15 00:37:24724 SetEnabledFlags(prefs, new_enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05725}
726
[email protected]1a47d7e2010-10-15 00:37:24727void GetSanitizedEnabledFlags(
[email protected]ad2a3ded2010-08-27 13:19:05728 PrefService* prefs, std::set<std::string>* result) {
729 SanitizeList(prefs);
[email protected]1a47d7e2010-10-15 00:37:24730 GetEnabledFlags(prefs, result);
[email protected]ad2a3ded2010-08-27 13:19:05731}
732
[email protected]a314ee5a2010-10-26 21:23:28733// Variant of GetSanitizedEnabledFlags that also removes any flags that aren't
734// enabled on the current platform.
735void GetSanitizedEnabledFlagsForCurrentPlatform(
736 PrefService* prefs, std::set<std::string>* result) {
737 GetSanitizedEnabledFlags(prefs, result);
738
739 // Filter out any experiments that aren't enabled on the current platform. We
740 // don't remove these from prefs else syncing to a platform with a different
741 // set of experiments would be lossy.
742 std::set<std::string> platform_experiments;
743 int current_platform = GetCurrentPlatform();
744 for (size_t i = 0; i < num_experiments; ++i) {
745 if (experiments[i].supported_platforms & current_platform)
[email protected]8a6ff28d2010-12-02 16:35:19746 AddInternalName(experiments[i], &platform_experiments);
[email protected]a314ee5a2010-10-26 21:23:28747 }
748
749 std::set<std::string> new_enabled_experiments;
750 std::set_intersection(
751 platform_experiments.begin(), platform_experiments.end(),
752 result->begin(), result->end(),
753 std::inserter(new_enabled_experiments, new_enabled_experiments.begin()));
754
755 result->swap(new_enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05756}
757
[email protected]8a6ff28d2010-12-02 16:35:19758// Returns the Value representing the choice data in the specified experiment.
[email protected]8a6ff28d2010-12-02 16:35:19759Value* CreateChoiceData(const Experiment& experiment,
[email protected]28e35af2011-02-09 12:56:22760 const std::set<std::string>& enabled_experiments) {
[email protected]2ce9c89752011-02-25 18:24:34761 DCHECK_EQ(Experiment::MULTI_VALUE, experiment.type);
[email protected]8a6ff28d2010-12-02 16:35:19762 ListValue* result = new ListValue;
763 for (int i = 0; i < experiment.num_choices; ++i) {
764 const Experiment::Choice& choice = experiment.choices[i];
765 DictionaryValue* value = new DictionaryValue;
766 std::string name = NameForChoice(experiment, i);
767 value->SetString("description",
768 l10n_util::GetStringUTF16(choice.description_id));
769 value->SetString("internal_name", name);
[email protected]28e35af2011-02-09 12:56:22770 value->SetBoolean("selected", enabled_experiments.count(name) > 0);
[email protected]8a6ff28d2010-12-02 16:35:19771 result->Append(value);
772 }
773 return result;
774}
775
[email protected]e2ddbc92010-10-15 20:02:07776} // namespace
777
[email protected]1a47d7e2010-10-15 00:37:24778void ConvertFlagsToSwitches(PrefService* prefs, CommandLine* command_line) {
[email protected]8e8bb6d2010-12-13 08:18:55779 FlagsState::GetInstance()->ConvertFlagsToSwitches(prefs, command_line);
[email protected]ad2a3ded2010-08-27 13:19:05780}
781
[email protected]1a47d7e2010-10-15 00:37:24782ListValue* GetFlagsExperimentsData(PrefService* prefs) {
[email protected]ad2a3ded2010-08-27 13:19:05783 std::set<std::string> enabled_experiments;
[email protected]1a47d7e2010-10-15 00:37:24784 GetSanitizedEnabledFlags(prefs, &enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05785
786 int current_platform = GetCurrentPlatform();
787
788 ListValue* experiments_data = new ListValue();
[email protected]a314ee5a2010-10-26 21:23:28789 for (size_t i = 0; i < num_experiments; ++i) {
790 const Experiment& experiment = experiments[i];
[email protected]ad2a3ded2010-08-27 13:19:05791
792 DictionaryValue* data = new DictionaryValue();
793 data->SetString("internal_name", experiment.internal_name);
794 data->SetString("name",
795 l10n_util::GetStringUTF16(experiment.visible_name_id));
796 data->SetString("description",
797 l10n_util::GetStringUTF16(
798 experiment.visible_description_id));
[email protected]cc3e2052011-12-20 01:01:40799 bool supported = !!(experiment.supported_platforms & current_platform);
[email protected]c54ad562012-01-23 22:21:59800#if defined(USE_AURA) && defined(OS_CHROMEOS)
801 // Some Chrome OS devices currently require Aura compact window mode, so
802 // don't offer a choice of mode.
803 // TODO(jamescook): Remove after Aura supports normal mode on all devices,
804 // likely around M19.
805 if (experiment.visible_name_id == IDS_FLAGS_AURA_WINDOW_MODE_NAME &&
806 CommandLine::ForCurrentProcess()->
807 HasSwitch(ash::switches::kAuraForceCompactWindowMode))
808 supported = false;
809#endif
[email protected]cc3e2052011-12-20 01:01:40810 data->SetBoolean("supported", supported);
811
812 ListValue* supported_platforms = new ListValue();
813 AddOsStrings(experiment.supported_platforms, supported_platforms);
814 data->Set("supported_platforms", supported_platforms);
[email protected]ad2a3ded2010-08-27 13:19:05815
[email protected]28e35af2011-02-09 12:56:22816 switch (experiment.type) {
817 case Experiment::SINGLE_VALUE:
818 data->SetBoolean(
819 "enabled",
820 enabled_experiments.count(experiment.internal_name) > 0);
821 break;
822 case Experiment::MULTI_VALUE:
823 data->Set("choices", CreateChoiceData(experiment, enabled_experiments));
824 break;
825 default:
826 NOTREACHED();
[email protected]8a6ff28d2010-12-02 16:35:19827 }
828
[email protected]ad2a3ded2010-08-27 13:19:05829 experiments_data->Append(data);
830 }
831 return experiments_data;
832}
833
[email protected]ad2a3ded2010-08-27 13:19:05834bool IsRestartNeededToCommitChanges() {
[email protected]8e8bb6d2010-12-13 08:18:55835 return FlagsState::GetInstance()->IsRestartNeededToCommitChanges();
[email protected]ad2a3ded2010-08-27 13:19:05836}
837
838void SetExperimentEnabled(
[email protected]c7b7800a2010-10-07 18:51:35839 PrefService* prefs, const std::string& internal_name, bool enable) {
[email protected]8e8bb6d2010-12-13 08:18:55840 FlagsState::GetInstance()->SetExperimentEnabled(prefs, internal_name, enable);
[email protected]e2ddbc92010-10-15 20:02:07841}
842
843void RemoveFlagsSwitches(
844 std::map<std::string, CommandLine::StringType>* switch_list) {
[email protected]8e8bb6d2010-12-13 08:18:55845 FlagsState::GetInstance()->RemoveFlagsSwitches(switch_list);
[email protected]e2ddbc92010-10-15 20:02:07846}
847
[email protected]a314ee5a2010-10-26 21:23:28848int GetCurrentPlatform() {
849#if defined(OS_MACOSX)
850 return kOsMac;
851#elif defined(OS_WIN)
852 return kOsWin;
853#elif defined(OS_CHROMEOS) // Needs to be before the OS_LINUX check.
854 return kOsCrOS;
[email protected]c92f4ed2011-10-21 19:50:21855#elif defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]a314ee5a2010-10-26 21:23:28856 return kOsLinux;
[email protected]9c7453d2012-01-21 00:45:40857#elif defined(OS_ANDROID)
858 return kOsAndroid;
[email protected]a314ee5a2010-10-26 21:23:28859#else
860#error Unknown platform
861#endif
862}
863
[email protected]4bc5050c2010-11-18 17:55:54864void RecordUMAStatistics(const PrefService* prefs) {
865 std::set<std::string> flags;
866 GetEnabledFlags(prefs, &flags);
867 for (std::set<std::string>::iterator it = flags.begin(); it != flags.end();
868 ++it) {
869 std::string action("AboutFlags_");
870 action += *it;
[email protected]7f6f44c2011-12-14 13:23:38871 content::RecordComputedAction(action);
[email protected]4bc5050c2010-11-18 17:55:54872 }
873 // Since flag metrics are recorded every startup, add a tick so that the
874 // stats can be made meaningful.
875 if (flags.size())
[email protected]7f6f44c2011-12-14 13:23:38876 content::RecordAction(UserMetricsAction("AboutFlags_StartupTick"));
877 content::RecordAction(UserMetricsAction("StartupTick"));
[email protected]4bc5050c2010-11-18 17:55:54878}
879
[email protected]e2ddbc92010-10-15 20:02:07880//////////////////////////////////////////////////////////////////////////////
881// FlagsState implementation.
882
883namespace {
884
885void FlagsState::ConvertFlagsToSwitches(
886 PrefService* prefs, CommandLine* command_line) {
[email protected]e2ddbc92010-10-15 20:02:07887 if (command_line->HasSwitch(switches::kNoExperiments))
888 return;
889
890 std::set<std::string> enabled_experiments;
[email protected]ba8164242010-11-16 21:31:00891
[email protected]a314ee5a2010-10-26 21:23:28892 GetSanitizedEnabledFlagsForCurrentPlatform(prefs, &enabled_experiments);
[email protected]e2ddbc92010-10-15 20:02:07893
[email protected]a82744532011-02-11 16:15:53894 typedef std::map<std::string, std::pair<std::string, std::string> >
895 NameToSwitchAndValueMap;
896 NameToSwitchAndValueMap name_to_switch_map;
[email protected]8a6ff28d2010-12-02 16:35:19897 for (size_t i = 0; i < num_experiments; ++i) {
898 const Experiment& e = experiments[i];
899 if (e.type == Experiment::SINGLE_VALUE) {
[email protected]a82744532011-02-11 16:15:53900 name_to_switch_map[e.internal_name] =
901 std::pair<std::string, std::string>(e.command_line_switch,
902 e.command_line_value);
[email protected]8a6ff28d2010-12-02 16:35:19903 } else {
904 for (int j = 0; j < e.num_choices; ++j)
[email protected]a82744532011-02-11 16:15:53905 name_to_switch_map[NameForChoice(e, j)] =
906 std::pair<std::string, std::string>(
907 e.choices[j].command_line_switch,
908 e.choices[j].command_line_value);
[email protected]8a6ff28d2010-12-02 16:35:19909 }
910 }
[email protected]e2ddbc92010-10-15 20:02:07911
912 command_line->AppendSwitch(switches::kFlagSwitchesBegin);
[email protected]a82744532011-02-11 16:15:53913 flags_switches_.insert(
914 std::pair<std::string, std::string>(switches::kFlagSwitchesBegin,
915 std::string()));
[email protected]e2ddbc92010-10-15 20:02:07916 for (std::set<std::string>::iterator it = enabled_experiments.begin();
917 it != enabled_experiments.end();
918 ++it) {
919 const std::string& experiment_name = *it;
[email protected]a82744532011-02-11 16:15:53920 NameToSwitchAndValueMap::const_iterator name_to_switch_it =
[email protected]8a6ff28d2010-12-02 16:35:19921 name_to_switch_map.find(experiment_name);
922 if (name_to_switch_it == name_to_switch_map.end()) {
923 NOTREACHED();
[email protected]e2ddbc92010-10-15 20:02:07924 continue;
[email protected]8a6ff28d2010-12-02 16:35:19925 }
[email protected]e2ddbc92010-10-15 20:02:07926
[email protected]a82744532011-02-11 16:15:53927 const std::pair<std::string, std::string>&
928 switch_and_value_pair = name_to_switch_it->second;
929
930 command_line->AppendSwitchASCII(switch_and_value_pair.first,
931 switch_and_value_pair.second);
932 flags_switches_[switch_and_value_pair.first] = switch_and_value_pair.second;
[email protected]e2ddbc92010-10-15 20:02:07933 }
934 command_line->AppendSwitch(switches::kFlagSwitchesEnd);
[email protected]a82744532011-02-11 16:15:53935 flags_switches_.insert(
936 std::pair<std::string, std::string>(switches::kFlagSwitchesEnd,
937 std::string()));
[email protected]e2ddbc92010-10-15 20:02:07938}
939
940bool FlagsState::IsRestartNeededToCommitChanges() {
941 return needs_restart_;
942}
943
944void FlagsState::SetExperimentEnabled(
945 PrefService* prefs, const std::string& internal_name, bool enable) {
[email protected]ad2a3ded2010-08-27 13:19:05946 needs_restart_ = true;
947
[email protected]8a6ff28d2010-12-02 16:35:19948 size_t at_index = internal_name.find(about_flags::testing::kMultiSeparator);
949 if (at_index != std::string::npos) {
950 DCHECK(enable);
951 // We're being asked to enable a multi-choice experiment. Disable the
952 // currently selected choice.
953 DCHECK_NE(at_index, 0u);
[email protected]28e35af2011-02-09 12:56:22954 const std::string experiment_name = internal_name.substr(0, at_index);
955 SetExperimentEnabled(prefs, experiment_name, false);
[email protected]8a6ff28d2010-12-02 16:35:19956
[email protected]28e35af2011-02-09 12:56:22957 // And enable the new choice, if it is not the default first choice.
958 if (internal_name != experiment_name + "@0") {
959 std::set<std::string> enabled_experiments;
960 GetSanitizedEnabledFlags(prefs, &enabled_experiments);
961 enabled_experiments.insert(internal_name);
962 SetEnabledFlags(prefs, enabled_experiments);
963 }
[email protected]8a6ff28d2010-12-02 16:35:19964 return;
965 }
966
[email protected]ad2a3ded2010-08-27 13:19:05967 std::set<std::string> enabled_experiments;
[email protected]1a47d7e2010-10-15 00:37:24968 GetSanitizedEnabledFlags(prefs, &enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05969
[email protected]8a6ff28d2010-12-02 16:35:19970 const Experiment* e = NULL;
971 for (size_t i = 0; i < num_experiments; ++i) {
972 if (experiments[i].internal_name == internal_name) {
973 e = experiments + i;
974 break;
975 }
976 }
977 DCHECK(e);
978
979 if (e->type == Experiment::SINGLE_VALUE) {
[email protected]8a2713682011-08-19 10:36:59980 if (enable)
[email protected]8a6ff28d2010-12-02 16:35:19981 enabled_experiments.insert(internal_name);
[email protected]8a2713682011-08-19 10:36:59982 else
[email protected]8a6ff28d2010-12-02 16:35:19983 enabled_experiments.erase(internal_name);
984 } else {
985 if (enable) {
986 // Enable the first choice.
987 enabled_experiments.insert(NameForChoice(*e, 0));
988 } else {
989 // Find the currently enabled choice and disable it.
990 for (int i = 0; i < e->num_choices; ++i) {
991 std::string choice_name = NameForChoice(*e, i);
992 if (enabled_experiments.find(choice_name) !=
993 enabled_experiments.end()) {
994 enabled_experiments.erase(choice_name);
995 // Continue on just in case there's a bug and more than one
996 // experiment for this choice was enabled.
997 }
998 }
999 }
1000 }
[email protected]ad2a3ded2010-08-27 13:19:051001
[email protected]1a47d7e2010-10-15 00:37:241002 SetEnabledFlags(prefs, enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:051003}
1004
[email protected]e2ddbc92010-10-15 20:02:071005void FlagsState::RemoveFlagsSwitches(
1006 std::map<std::string, CommandLine::StringType>* switch_list) {
[email protected]a82744532011-02-11 16:15:531007 for (std::map<std::string, std::string>::const_iterator
1008 it = flags_switches_.begin(); it != flags_switches_.end(); ++it) {
1009 switch_list->erase(it->first);
[email protected]e2ddbc92010-10-15 20:02:071010 }
1011}
1012
1013void FlagsState::reset() {
1014 needs_restart_ = false;
1015 flags_switches_.clear();
1016}
1017
[email protected]38e46812011-05-09 20:49:221018} // namespace
[email protected]e2ddbc92010-10-15 20:02:071019
1020namespace testing {
[email protected]8a6ff28d2010-12-02 16:35:191021
1022// WARNING: '@' is also used in the html file. If you update this constant you
1023// also need to update the html file.
1024const char kMultiSeparator[] = "@";
1025
[email protected]e2ddbc92010-10-15 20:02:071026void ClearState() {
[email protected]8e8bb6d2010-12-13 08:18:551027 FlagsState::GetInstance()->reset();
[email protected]e2ddbc92010-10-15 20:02:071028}
[email protected]a314ee5a2010-10-26 21:23:281029
1030void SetExperiments(const Experiment* e, size_t count) {
1031 if (!e) {
1032 experiments = kExperiments;
1033 num_experiments = arraysize(kExperiments);
1034 } else {
1035 experiments = e;
1036 num_experiments = count;
1037 }
1038}
1039
[email protected]8a6ff28d2010-12-02 16:35:191040const Experiment* GetExperiments(size_t* count) {
1041 *count = num_experiments;
1042 return experiments;
1043}
1044
[email protected]e2ddbc92010-10-15 20:02:071045} // namespace testing
1046
[email protected]1a47d7e2010-10-15 00:37:241047} // namespace about_flags