blob: cf3196b4731f32b713c967cf9496795c7100ca47 [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]c9c73ad42012-04-18 03:35:5925#include "ui/base/ui_base_switches.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]dc04be7c2012-03-15 23:57:4928#if defined(USE_ASH)
[email protected]b65bdda2011-12-23 23:35:3129#include "ash/ash_switches.h"
[email protected]dc04be7c2012-03-15 23:57:4930#endif
31
32#if defined(USE_AURA)
[email protected]308aaa32012-03-12 13:14:5033#include "ui/aura/aura_switches.h"
[email protected]8cc10df2011-11-03 23:57:5034#endif
35
[email protected]7f6f44c2011-12-14 13:23:3836using content::UserMetricsAction;
37
[email protected]1a47d7e2010-10-15 00:37:2438namespace about_flags {
[email protected]ad2a3ded2010-08-27 13:19:0539
[email protected]8a6ff28d2010-12-02 16:35:1940// Macros to simplify specifying the type.
[email protected]a82744532011-02-11 16:15:5341#define SINGLE_VALUE_TYPE_AND_VALUE(command_line_switch, switch_value) \
42 Experiment::SINGLE_VALUE, command_line_switch, switch_value, NULL, 0
43#define SINGLE_VALUE_TYPE(command_line_switch) \
44 SINGLE_VALUE_TYPE_AND_VALUE(command_line_switch, "")
45#define MULTI_VALUE_TYPE(choices) \
[email protected]0e6f56d2011-02-12 23:45:1546 Experiment::MULTI_VALUE, "", "", choices, arraysize(choices)
[email protected]8a6ff28d2010-12-02 16:35:1947
[email protected]e2ddbc92010-10-15 20:02:0748namespace {
49
[email protected]9c7453d2012-01-21 00:45:4050const unsigned kOsAll = kOsMac | kOsWin | kOsLinux | kOsCrOS | kOsAndroid;
[email protected]ad2a3ded2010-08-27 13:19:0551
[email protected]cc3e2052011-12-20 01:01:4052// Adds a |StringValue| to |list| for each platform where |bitmask| indicates
53// whether the experiment is available on that platform.
54void AddOsStrings(unsigned bitmask, ListValue* list) {
55 struct {
56 unsigned bit;
57 const char* const name;
58 } kBitsToOs[] = {
59 {kOsMac, "Mac"},
60 {kOsWin, "Windows"},
61 {kOsLinux, "Linux"},
62 {kOsCrOS, "Chrome OS"},
63 };
64 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kBitsToOs); ++i)
65 if (bitmask & kBitsToOs[i].bit)
66 list->Append(new StringValue(kBitsToOs[i].name));
67}
68
[email protected]ba8164242010-11-16 21:31:0069// Names for former Chrome OS Labs experiments, shared with prefs migration
70// code.
71const char kMediaPlayerExperimentName[] = "media-player";
72const char kAdvancedFileSystemExperimentName[] = "advanced-file-system";
73const char kVerticalTabsExperimentName[] = "vertical-tabs";
74
[email protected]9b2c9f6a12012-01-27 21:00:0575const Experiment::Choice kOmniboxAggressiveHistoryURLChoices[] = {
76 { IDS_FLAGS_OMNIBOX_AGGRESSIVE_HISTORY_URL_SCORING_AUTOMATIC, "", "" },
77 { IDS_FLAGS_OMNIBOX_AGGRESSIVE_HISTORY_URL_SCORING_ENABLED,
78 switches::kOmniboxAggressiveHistoryURL,
79 switches::kOmniboxAggressiveHistoryURLEnabled },
80 { IDS_FLAGS_OMNIBOX_AGGRESSIVE_HISTORY_URL_SCORING_DISABLED,
81 switches::kOmniboxAggressiveHistoryURL,
82 switches::kOmniboxAggressiveHistoryURLDisabled }
83};
84
[email protected]032d5e6c2012-02-17 17:53:5585const Experiment::Choice kOmniboxInlineHistoryQuickProviderChoices[] = {
86 { IDS_FLAGS_OMNIBOX_INLINE_HISTORY_QUICK_PROVIDER_AUTOMATIC, "", "" },
87 { IDS_FLAGS_OMNIBOX_INLINE_HISTORY_QUICK_PROVIDER_ALLOWED,
88 switches::kOmniboxInlineHistoryQuickProvider,
89 switches::kOmniboxInlineHistoryQuickProviderAllowed },
90 { IDS_FLAGS_OMNIBOX_INLINE_HISTORY_QUICK_PROVIDER_PROHIBITED,
91 switches::kOmniboxInlineHistoryQuickProvider,
92 switches::kOmniboxInlineHistoryQuickProviderProhibited }
93};
94
[email protected]72787e392012-03-23 05:55:4395const Experiment::Choice kThreadedCompositingModeChoices[] = {
96 { IDS_FLAGS_THREADED_COMPOSITING_MODE_DEFAULT, "", "" },
97 { IDS_FLAGS_THREADED_COMPOSITING_MODE_DISABLED,
98 switches::kDisableThreadedCompositing, ""},
99 { IDS_FLAGS_THREADED_COMPOSITING_MODE_ENABLED,
100 switches::kEnableThreadedCompositing, ""}
101};
102
[email protected]4bc5050c2010-11-18 17:55:54103// RECORDING USER METRICS FOR FLAGS:
104// -----------------------------------------------------------------------------
105// The first line of the experiment is the internal name. If you'd like to
106// gather statistics about the usage of your flag, you should append a marker
107// comment to the end of the feature name, like so:
108// "my-special-feature", // FLAGS:RECORD_UMA
109//
110// After doing that, run //chrome/tools/extract_actions.py (see instructions at
111// the top of that file for details) to update the chromeactions.txt file, which
112// will enable UMA to record your feature flag.
113//
114// After your feature has shipped under a flag, you can locate the metrics
115// under the action name AboutFlags_internal-action-name. Actions are recorded
116// once per startup, so you should divide this number by AboutFlags_StartupTick
117// to get a sense of usage. Note that this will not be the same as number of
118// users with a given feature enabled because users can quit and relaunch
119// the application multiple times over a given time interval.
120// TODO(rsesek): See if there's a way to count per-user, rather than
121// per-startup.
122
[email protected]8a6ff28d2010-12-02 16:35:19123// To add a new experiment add to the end of kExperiments. There are two
124// distinct types of experiments:
125// . SINGLE_VALUE: experiment is either on or off. Use the SINGLE_VALUE_TYPE
126// macro for this type supplying the command line to the macro.
[email protected]28e35af2011-02-09 12:56:22127// . MULTI_VALUE: a list of choices, the first of which should correspond to a
128// deactivated state for this lab (i.e. no command line option). To specify
129// this type of experiment use the macro MULTI_VALUE_TYPE supplying it the
130// array of choices.
[email protected]8a6ff28d2010-12-02 16:35:19131// See the documentation of Experiment for details on the fields.
132//
133// When adding a new choice, add it to the end of the list.
[email protected]ad2a3ded2010-08-27 13:19:05134const Experiment kExperiments[] = {
135 {
[email protected]aac169d2011-03-18 19:53:03136 "expose-for-tabs", // FLAGS:RECORD_UMA
137 IDS_FLAGS_TABPOSE_NAME,
138 IDS_FLAGS_TABPOSE_DESCRIPTION,
139 kOsMac,
140#if defined(OS_MACOSX)
141 // The switch exists only on OS X.
142 SINGLE_VALUE_TYPE(switches::kEnableExposeForTabs)
143#else
144 SINGLE_VALUE_TYPE("")
145#endif
146 },
147 {
[email protected]4bc5050c2010-11-18 17:55:54148 "conflicting-modules-check", // FLAGS:RECORD_UMA
[email protected]c1bbaa82010-11-08 11:17:05149 IDS_FLAGS_CONFLICTS_CHECK_NAME,
150 IDS_FLAGS_CONFLICTS_CHECK_DESCRIPTION,
151 kOsWin,
[email protected]8a6ff28d2010-12-02 16:35:19152 SINGLE_VALUE_TYPE(switches::kConflictingModulesCheck)
[email protected]c1bbaa82010-11-08 11:17:05153 },
154 {
[email protected]4bc5050c2010-11-18 17:55:54155 "cloud-print-proxy", // FLAGS:RECORD_UMA
[email protected]dae7325b2011-12-21 20:56:54156 IDS_FLAGS_CLOUD_PRINT_CONNECTOR_NAME,
157 IDS_FLAGS_CLOUD_PRINT_CONNECTOR_DESCRIPTION,
[email protected]9f8872b32011-03-04 19:44:45158 // For a Chrome build, we know we have a PDF plug-in on Windows, so it's
[email protected]4fa24bf2011-08-20 02:15:22159 // fully enabled.
[email protected]5d10d57d2011-07-22 22:16:31160 // Otherwise, where we know Windows could be working if a viable PDF
[email protected]4fa24bf2011-08-20 02:15:22161 // plug-in could be supplied, we'll keep the lab enabled. Mac and Linux
162 // always have PDF rasterization available, so no flag needed there.
163#if !defined(GOOGLE_CHROME_BUILD)
164 kOsWin,
165#else
166 0,
[email protected]fa6d2a2f2010-11-30 21:47:19167#endif
[email protected]8a6ff28d2010-12-02 16:35:19168 SINGLE_VALUE_TYPE(switches::kEnableCloudPrintProxy)
[email protected]8b6588a2010-10-12 02:39:42169 },
[email protected]580939a2010-10-12 18:54:37170 {
[email protected]bb461532010-11-26 21:50:23171 "crxless-web-apps",
172 IDS_FLAGS_CRXLESS_WEB_APPS_NAME,
173 IDS_FLAGS_CRXLESS_WEB_APPS_DESCRIPTION,
174 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19175 SINGLE_VALUE_TYPE(switches::kEnableCrxlessWebApps)
[email protected]bb461532010-11-26 21:50:23176 },
177 {
[email protected]96c6f4c2011-05-18 19:36:22178 "ignore-gpu-blacklist",
179 IDS_FLAGS_IGNORE_GPU_BLACKLIST_NAME,
180 IDS_FLAGS_IGNORE_GPU_BLACKLIST_DESCRIPTION,
181 kOsAll,
182 SINGLE_VALUE_TYPE(switches::kIgnoreGpuBlacklist)
183 },
184 {
[email protected]0110cf112011-07-02 00:39:43185 "force-compositing-mode-2",
[email protected]96c6f4c2011-05-18 19:36:22186 IDS_FLAGS_FORCE_COMPOSITING_MODE_NAME,
187 IDS_FLAGS_FORCE_COMPOSITING_MODE_DESCRIPTION,
188 kOsAll,
189 SINGLE_VALUE_TYPE(switches::kForceCompositingMode)
190 },
191 {
[email protected]72787e392012-03-23 05:55:43192 "threaded-compositing-mode",
193 IDS_FLAGS_THREADED_COMPOSITING_MODE_NAME,
194 IDS_FLAGS_THREADED_COMPOSITING_MODE_DESCRIPTION,
[email protected]644a1072012-03-16 09:29:59195 kOsAll,
[email protected]72787e392012-03-23 05:55:43196 MULTI_VALUE_TYPE(kThreadedCompositingModeChoices)
[email protected]644a1072012-03-16 09:29:59197 },
198 {
[email protected]7d2e0532012-03-23 22:03:31199 "disable-threaded-animation",
200 IDS_FLAGS_DISABLE_THREADED_ANIMATION_NAME,
201 IDS_FLAGS_DISABLE_THREADED_ANIMATION_DESCRIPTION,
[email protected]644a1072012-03-16 09:29:59202 kOsAll,
[email protected]7d2e0532012-03-23 22:03:31203 SINGLE_VALUE_TYPE(switches::kDisableThreadedAnimation)
[email protected]644a1072012-03-16 09:29:59204 },
205 {
[email protected]5963b772011-02-09 22:55:38206 "composited-layer-borders",
207 IDS_FLAGS_COMPOSITED_LAYER_BORDERS,
208 IDS_FLAGS_COMPOSITED_LAYER_BORDERS_DESCRIPTION,
209 kOsAll,
210 SINGLE_VALUE_TYPE(switches::kShowCompositedLayerBorders)
211 },
212 {
[email protected]a8f1eaa2011-03-07 19:00:58213 "show-fps-counter",
214 IDS_FLAGS_SHOW_FPS_COUNTER,
215 IDS_FLAGS_SHOW_FPS_COUNTER_DESCRIPTION,
216 kOsAll,
217 SINGLE_VALUE_TYPE(switches::kShowFPSCounter)
218 },
[email protected]8ff7f342011-05-25 01:49:47219 {
[email protected]70c98a332011-12-21 20:51:52220 "accelerated-filters",
221 IDS_FLAGS_ACCELERATED_FILTERS,
222 IDS_FLAGS_ACCELERATED_FILTERS_DESCRIPTION,
223 kOsAll,
224 SINGLE_VALUE_TYPE(switches::kEnableAcceleratedFilters)
225 },
226 {
[email protected]8ff7f342011-05-25 01:49:47227 "disable-gpu-vsync",
228 IDS_FLAGS_DISABLE_GPU_VSYNC_NAME,
229 IDS_FLAGS_DISABLE_GPU_VSYNC_DESCRIPTION,
230 kOsAll,
231 SINGLE_VALUE_TYPE(switches::kDisableGpuVsync)
232 },
[email protected]deaba6d52011-09-23 14:47:12233 {
234 "disable-webgl",
235 IDS_FLAGS_DISABLE_WEBGL_NAME,
236 IDS_FLAGS_DISABLE_WEBGL_DESCRIPTION,
237 kOsAll,
238 SINGLE_VALUE_TYPE(switches::kDisableExperimentalWebGL)
239 },
[email protected]d208f4d82011-05-23 21:52:03240 // TODO(dspringer): When NaCl is on by default, remove this flag entry.
[email protected]2fe15fcb2010-10-21 20:39:53241 {
[email protected]e3791ce92011-08-09 01:03:32242 "enable-nacl", // FLAGS:RECORD_UMA
[email protected]4ff87d202010-11-06 01:28:40243 IDS_FLAGS_ENABLE_NACL_NAME,
244 IDS_FLAGS_ENABLE_NACL_DESCRIPTION,
245 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19246 SINGLE_VALUE_TYPE(switches::kEnableNaCl)
[email protected]4ff87d202010-11-06 01:28:40247 },
[email protected]b39c6d92012-01-31 16:38:41248 // TODO(halyavin): When exception handling is on by default, replace this
249 // flag with disable-nacl-exception-handling.
250 {
251 "enable-nacl-exception-handling", // FLAGS:RECORD_UMA
252 IDS_FLAGS_ENABLE_NACL_EXCEPTION_HANDLING_NAME,
253 IDS_FLAGS_ENABLE_NACL_EXCEPTION_HANDLING_DESCRIPTION,
254 kOsWin,
255 SINGLE_VALUE_TYPE(switches::kEnableNaClExceptionHandling)
256 },
[email protected]4ff87d202010-11-06 01:28:40257 {
[email protected]31a665e72012-03-11 12:37:46258 "nacl-gdb", // FLAGS:RECORD_UMA
259 IDS_FLAGS_NACL_GDB_NAME,
260 IDS_FLAGS_NACL_GDB_DESCRIPTION,
261 kOsWin,
262 SINGLE_VALUE_TYPE(switches::kNaClGdb)
263 },
264 {
[email protected]4bc5050c2010-11-18 17:55:54265 "extension-apis", // FLAGS:RECORD_UMA
[email protected]11dd68cd52010-11-12 01:15:32266 IDS_FLAGS_EXPERIMENTAL_EXTENSION_APIS_NAME,
267 IDS_FLAGS_EXPERIMENTAL_EXTENSION_APIS_DESCRIPTION,
268 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19269 SINGLE_VALUE_TYPE(switches::kEnableExperimentalExtensionApis)
[email protected]11dd68cd52010-11-12 01:15:32270 },
[email protected]3627b06d2010-11-12 16:36:16271 {
[email protected]f3c069622012-04-24 07:10:34272 "browser-actions-for-all",
273 IDS_FLAGS_BROWSER_ACTIONS_FOR_ALL_NAME,
274 IDS_FLAGS_BROWSER_ACTIONS_FOR_ALL_DESCRIPTION,
275 kOsAll,
276 SINGLE_VALUE_TYPE(switches::kEnableBrowserActionsForAll),
277 },
278 {
[email protected]cab18ef2012-04-27 07:22:03279 "action-box",
280 IDS_FLAGS_ACTION_BOX_NAME,
281 IDS_FLAGS_ACTION_BOX_DESCRIPTION,
282 kOsAll,
283 SINGLE_VALUE_TYPE(switches::kEnableActionBox),
284 },
285 {
[email protected]cbe224d2011-08-04 22:12:49286 "apps-new-install-bubble",
287 IDS_FLAGS_APPS_NEW_INSTALL_BUBBLE_NAME,
288 IDS_FLAGS_APPS_NEW_INSTALL_BUBBLE_DESCRIPTION,
289 kOsAll,
290 SINGLE_VALUE_TYPE(switches::kAppsNewInstallBubble)
291 },
292 {
[email protected]80bd24e2010-11-30 09:34:38293 "disable-hyperlink-auditing",
294 IDS_FLAGS_DISABLE_HYPERLINK_AUDITING_NAME,
295 IDS_FLAGS_DISABLE_HYPERLINK_AUDITING_DESCRIPTION,
296 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19297 SINGLE_VALUE_TYPE(switches::kNoPings)
[email protected]feb28fef2010-12-01 10:52:51298 },
299 {
300 "experimental-location-features", // FLAGS:RECORD_UMA
301 IDS_FLAGS_EXPERIMENTAL_LOCATION_FEATURES_NAME,
302 IDS_FLAGS_EXPERIMENTAL_LOCATION_FEATURES_DESCRIPTION,
303 kOsMac | kOsWin | kOsLinux, // Currently does nothing on CrOS.
[email protected]8a6ff28d2010-12-02 16:35:19304 SINGLE_VALUE_TYPE(switches::kExperimentalLocationFeatures)
305 },
306 {
[email protected]04227962011-01-20 02:03:09307 "disable-interactive-form-validation",
308 IDS_FLAGS_DISABLE_INTERACTIVE_FORM_VALIDATION_NAME,
309 IDS_FLAGS_DISABLE_INTERACTIVE_FORM_VALIDATION_DESCRIPTION,
310 kOsAll,
311 SINGLE_VALUE_TYPE(switches::kDisableInteractiveFormValidation)
312 },
[email protected]8df51192011-01-22 20:05:03313 {
[email protected]07d490bc2011-03-07 17:05:26314 "focus-existing-tab-on-open", // FLAGS:RECORD_UMA
315 IDS_FLAGS_FOCUS_EXISTING_TAB_ON_OPEN_NAME,
316 IDS_FLAGS_FOCUS_EXISTING_TAB_ON_OPEN_DESCRIPTION,
317 kOsAll,
318 SINGLE_VALUE_TYPE(switches::kFocusExistingTabOnOpen)
319 },
[email protected]d5dcfb32011-03-19 00:49:24320 {
[email protected]5aea1862011-03-23 23:55:39321 "tab-groups-context-menu",
322 IDS_FLAGS_TAB_GROUPS_CONTEXT_MENU_NAME,
323 IDS_FLAGS_TAB_GROUPS_CONTEXT_MENU_DESCRIPTION,
324 kOsWin,
325 SINGLE_VALUE_TYPE(switches::kEnableTabGroupsContextMenu)
326 },
[email protected]e9bf9d92011-03-31 20:57:15327 {
[email protected]f2557bd2011-06-01 02:33:07328 "preload-instant-search",
329 IDS_FLAGS_PRELOAD_INSTANT_SEARCH_NAME,
330 IDS_FLAGS_PRELOAD_INSTANT_SEARCH_DESCRIPTION,
331 kOsAll,
332 SINGLE_VALUE_TYPE(switches::kPreloadInstantSearch)
333 },
[email protected]354e33b2011-06-15 00:29:10334 {
335 "static-ip-config",
336 IDS_FLAGS_STATIC_IP_CONFIG_NAME,
337 IDS_FLAGS_STATIC_IP_CONFIG_DESCRIPTION,
338 kOsCrOS,
339#if defined(OS_CHROMEOS)
340 // This switch exists only on Chrome OS.
341 SINGLE_VALUE_TYPE(switches::kEnableStaticIPConfig)
342#else
343 SINGLE_VALUE_TYPE("")
344#endif
345 },
[email protected]3eb5728c2011-06-20 22:32:24346 {
347 "show-autofill-type-predictions",
348 IDS_FLAGS_SHOW_AUTOFILL_TYPE_PREDICTIONS_NAME,
349 IDS_FLAGS_SHOW_AUTOFILL_TYPE_PREDICTIONS_DESCRIPTION,
350 kOsAll,
351 SINGLE_VALUE_TYPE(switches::kShowAutofillTypePredictions)
352 },
[email protected]bff4d3e2011-06-21 23:58:52353 {
[email protected]9a6180d7d2011-09-07 01:40:33354 "sync-tabs",
355 IDS_FLAGS_SYNC_TABS_NAME,
356 IDS_FLAGS_SYNC_TABS_DESCRIPTION,
[email protected]5b0ec7f2011-08-11 02:17:17357 kOsAll,
[email protected]9a6180d7d2011-09-07 01:40:33358 SINGLE_VALUE_TYPE(switches::kEnableSyncTabs)
[email protected]5b0ec7f2011-08-11 02:17:17359 },
360 {
[email protected]fdf4e252012-04-27 00:26:55361 "sync-tab-favicons",
362 IDS_FLAGS_SYNC_TAB_FAVICONS_NAME,
363 IDS_FLAGS_SYNC_TAB_FAVICONS_DESCRIPTION,
364 kOsAll,
365 SINGLE_VALUE_TYPE(switches::kSyncTabFavicons)
366 },
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]9b2c9f6a12012-01-27 21:00:05384 "omnibox-aggressive-with-history-url",
[email protected]ed1e39502011-12-16 14:39:35385 IDS_FLAGS_OMNIBOX_AGGRESSIVE_HISTORY_URL_SCORING_NAME,
386 IDS_FLAGS_OMNIBOX_AGGRESSIVE_HISTORY_URL_SCORING_DESCRIPTION,
387 kOsAll,
[email protected]9b2c9f6a12012-01-27 21:00:05388 MULTI_VALUE_TYPE(kOmniboxAggressiveHistoryURLChoices)
[email protected]ed1e39502011-12-16 14:39:35389 },
390 {
[email protected]032d5e6c2012-02-17 17:53:55391 "omnibox-inline-history-quick-provider",
392 IDS_FLAGS_OMNIBOX_INLINE_HISTORY_QUICK_PROVIDER_NAME,
393 IDS_FLAGS_OMNIBOX_INLINE_HISTORY_QUICK_PROVIDER_DESCRIPTION,
394 kOsAll,
395 MULTI_VALUE_TYPE(kOmniboxInlineHistoryQuickProviderChoices)
396 },
397 {
[email protected]7e7a28092011-12-09 22:24:55398 "enable-panels",
399 IDS_FLAGS_ENABLE_PANELS_NAME,
400 IDS_FLAGS_ENABLE_PANELS_DESCRIPTION,
[email protected]73fb1fc52011-07-09 00:06:54401 kOsAll,
[email protected]7e7a28092011-12-09 22:24:55402 SINGLE_VALUE_TYPE(switches::kEnablePanels)
[email protected]73fb1fc52011-07-09 00:06:54403 },
[email protected]e3749d12011-07-25 22:22:12404 {
[email protected]9931875b2011-11-02 00:19:48405 "disable-shortcuts-provider",
406 IDS_FLAGS_DISABLE_SHORTCUTS_PROVIDER,
407 IDS_FLAGS_DISABLE_SHORTCUTS_PROVIDER_DESCRIPTION,
[email protected]e3749d12011-07-25 22:22:12408 kOsAll,
[email protected]9931875b2011-11-02 00:19:48409 SINGLE_VALUE_TYPE(switches::kDisableShortcutsProvider)
[email protected]e3749d12011-07-25 22:22:12410 },
[email protected]80eb4262011-08-03 16:10:41411 {
[email protected]a0e4b072011-08-17 01:47:07412 "downloads-new-ui", // FLAGS:RECORD_UMA
413 IDS_FLAGS_DOWNLOADS_NEW_UI_NAME,
414 IDS_FLAGS_DOWNLOADS_NEW_UI_DESCRIPTION,
415 kOsAll,
416 SINGLE_VALUE_TYPE(switches::kDownloadsNewUI)
417 },
[email protected]b7bb44f2011-09-01 05:17:03418 {
419 "enable-autologin",
420 IDS_FLAGS_ENABLE_AUTOLOGIN_NAME,
421 IDS_FLAGS_ENABLE_AUTOLOGIN_DESCRIPTION,
422 kOsMac | kOsWin | kOsLinux,
423 SINGLE_VALUE_TYPE(switches::kEnableAutologin)
424 },
[email protected]b9841172011-09-26 23:36:09425 {
[email protected]bbadb112011-12-12 16:55:28426 "enable-http-pipelining",
427 IDS_FLAGS_ENABLE_HTTP_PIPELINING_NAME,
428 IDS_FLAGS_ENABLE_HTTP_PIPELINING_DESCRIPTION,
429 kOsAll,
430 SINGLE_VALUE_TYPE(switches::kEnableHttpPipelining)
431 },
[email protected]d411c01d2011-10-18 16:00:27432 {
[email protected]3231b612012-03-23 05:57:54433 "enable-spdy3",
434 IDS_FLAGS_ENABLE_SPDY3_NAME,
435 IDS_FLAGS_ENABLE_SPDY3_DESCRIPTION,
436 kOsAll,
437 SINGLE_VALUE_TYPE(switches::kEnableSpdy3)
438 },
439 {
[email protected]27b3fe92012-03-21 05:35:06440 "enable-async-dns",
441 IDS_FLAGS_ENABLE_ASYNC_DNS_NAME,
442 IDS_FLAGS_ENABLE_ASYNC_DNS_DESCRIPTION,
[email protected]ec9d0532012-03-21 05:55:32443 kOsWin | kOsMac | kOsLinux | kOsCrOS,
[email protected]27b3fe92012-03-21 05:35:06444 SINGLE_VALUE_TYPE(switches::kEnableAsyncDns)
445 },
446 {
[email protected]f5da41d2011-10-08 17:40:07447 "enable-video-track",
448 IDS_FLAGS_ENABLE_VIDEO_TRACK_NAME,
449 IDS_FLAGS_ENABLE_VIDEO_TRACK_DESCRIPTION,
450 kOsAll,
451 SINGLE_VALUE_TYPE(switches::kEnableVideoTrack)
452 },
[email protected]08b83362011-10-19 05:23:17453 {
[email protected]6aa03b32011-10-27 21:44:44454 "enable-media-source",
455 IDS_FLAGS_ENABLE_MEDIA_SOURCE_NAME,
456 IDS_FLAGS_ENABLE_MEDIA_SOURCE_DESCRIPTION,
[email protected]ec9d0532012-03-21 05:55:32457 kOsAll,
[email protected]6aa03b32011-10-27 21:44:44458 SINGLE_VALUE_TYPE(switches::kEnableMediaSource)
459 },
[email protected]e4e68dbb2011-11-18 01:50:22460 {
[email protected]9f5b7822012-04-18 23:39:03461 "enable-encrypted-media",
462 IDS_FLAGS_ENABLE_ENCRYPTED_MEDIA_NAME,
463 IDS_FLAGS_ENABLE_ENCRYPTED_MEDIA_DESCRIPTION,
464 kOsAll,
465 SINGLE_VALUE_TYPE(switches::kEnableEncryptedMedia)
466 },
467 {
[email protected]e4e68dbb2011-11-18 01:50:22468 "enable-pointer-lock",
469 IDS_FLAGS_ENABLE_POINTER_LOCK_NAME,
470 IDS_FLAGS_ENABLE_POINTER_LOCK_DESCRIPTION,
471 kOsAll,
472 SINGLE_VALUE_TYPE(switches::kEnablePointerLock)
473 },
[email protected]dc04be7c2012-03-15 23:57:49474#if defined(USE_ASH)
[email protected]8cc10df2011-11-03 23:57:50475 {
[email protected]57b8bb352012-01-11 05:11:46476 "aura-google-dialog-frames",
477 IDS_FLAGS_AURA_GOOGLE_DIALOG_FRAMES_NAME,
478 IDS_FLAGS_AURA_GOOGLE_DIALOG_FRAMES_DESCRIPTION,
479 kOsWin | kOsLinux | kOsCrOS,
480 SINGLE_VALUE_TYPE(ash::switches::kAuraGoogleDialogFrames)
481 },
[email protected]dc04be7c2012-03-15 23:57:49482#endif
483#if defined(USE_AURA)
[email protected]308aaa32012-03-12 13:14:50484 {
485 "aura-disable-hold-mouse-moves",
486 IDS_FLAGS_AURA_DISABLE_HOLD_MOUSE_MOVES_NAME,
487 IDS_FLAGS_AURA_DISABLE_HOLD_MOUSE_MOVES_DESCRIPTION,
488 kOsWin | kOsLinux | kOsCrOS,
489 SINGLE_VALUE_TYPE(switches::kAuraDisableHoldMouseMoves)
490 },
[email protected]eaae8b462012-01-20 22:20:39491#endif // defined(USE_AURA)
492 {
493 "enable-gamepad",
494 IDS_FLAGS_ENABLE_GAMEPAD_NAME,
495 IDS_FLAGS_ENABLE_GAMEPAD_DESCRIPTION,
496 kOsAll,
497 SINGLE_VALUE_TYPE(switches::kEnableGamepad)
498 },
[email protected]db543d322011-12-15 20:40:15499 {
500 "per-tile-painting",
501 IDS_FLAGS_PER_TILE_PAINTING_NAME,
502 IDS_FLAGS_PER_TILE_PAINTING_DESCRIPTION,
503#if defined(USE_SKIA)
[email protected]a5b1b272012-01-06 20:44:37504 kOsMac | kOsLinux | kOsCrOS,
[email protected]db543d322011-12-15 20:40:15505#else
506 0,
507#endif
508 SINGLE_VALUE_TYPE(switches::kEnablePerTilePainting)
509 },
[email protected]bf88c032011-12-22 19:05:47510 {
511 "enable-javascript-harmony",
512 IDS_FLAGS_ENABLE_JAVASCRIPT_HARMONY_NAME,
513 IDS_FLAGS_ENABLE_JAVASCRIPT_HARMONY_DESCRIPTION,
514 kOsAll,
515 SINGLE_VALUE_TYPE_AND_VALUE(switches::kJavaScriptFlags, "--harmony")
516 },
[email protected]7e7f378a2012-01-05 14:35:37517 {
[email protected]85646172012-01-09 22:45:54518 "enable-tab-browser-dragging",
519 IDS_FLAGS_ENABLE_TAB_BROWSER_DRAGGING_NAME,
520 IDS_FLAGS_ENABLE_TAB_BROWSER_DRAGGING_DESCRIPTION,
521 kOsWin,
522 SINGLE_VALUE_TYPE(switches::kTabBrowserDragging)
523 },
524 {
[email protected]068b7b52012-02-27 12:41:44525 "disable-restore-session-state",
526 IDS_FLAGS_DISABLE_RESTORE_SESSION_STATE_NAME,
527 IDS_FLAGS_DISABLE_RESTORE_SESSION_STATE_DESCRIPTION,
[email protected]7e7f378a2012-01-05 14:35:37528 kOsAll,
[email protected]068b7b52012-02-27 12:41:44529 SINGLE_VALUE_TYPE(switches::kDisableRestoreSessionState)
[email protected]7e7f378a2012-01-05 14:35:37530 },
[email protected]88864db2012-01-18 20:56:35531 {
532 "disable-software-rasterizer",
533 IDS_FLAGS_DISABLE_SOFTWARE_RASTERIZER_NAME,
534 IDS_FLAGS_DISABLE_SOFTWARE_RASTERIZER_DESCRIPTION,
535#if defined(ENABLE_SWIFTSHADER)
536 kOsAll,
537#else
538 0,
539#endif
540 SINGLE_VALUE_TYPE(switches::kDisableSoftwareRasterizer)
541 },
[email protected]15a5d722012-01-23 09:11:14542 {
543 "enable-media-stream",
544 IDS_FLAGS_MEDIA_STREAM_NAME,
545 IDS_FLAGS_MEDIA_STREAM_DESCRIPTION,
[email protected]fa82b6772012-02-20 13:19:05546 kOsAll,
[email protected]15a5d722012-01-23 09:11:14547 SINGLE_VALUE_TYPE(switches::kEnableMediaStream)
548 },
[email protected]f5ec7242012-01-27 07:15:15549 {
[email protected]d2edc6702012-01-30 09:13:16550 "enable-shadow-dom",
551 IDS_FLAGS_SHADOW_DOM_NAME,
552 IDS_FLAGS_SHADOW_DOM_DESCRIPTION,
553 kOsAll,
554 SINGLE_VALUE_TYPE(switches::kEnableShadowDOM)
555 },
[email protected]9860c68b2012-02-02 01:58:09556 {
[email protected]4961218f2012-02-23 10:11:07557 "enable-style-scoped",
558 IDS_FLAGS_STYLE_SCOPED_NAME,
559 IDS_FLAGS_STYLE_SCOPED_DESCRIPTION,
560 kOsAll,
561 SINGLE_VALUE_TYPE(switches::kEnableStyleScoped)
562 },
563 {
[email protected]ca7a3d792012-03-02 15:55:49564 "enable-css-regions",
565 IDS_FLAGS_CSS_REGIONS_NAME,
566 IDS_FLAGS_CSS_REGIONS_DESCRIPTION,
567 kOsAll,
568 SINGLE_VALUE_TYPE(switches::kEnableCssRegions)
569 },
570 {
[email protected]8bed69d2012-02-02 06:46:00571 "ntp-app-install-hint",
572 IDS_FLAGS_APP_INSTALL_HINT_NAME,
573 IDS_FLAGS_APP_INSTALL_HINT_DESCRIPTION,
574 kOsAll,
575 SINGLE_VALUE_TYPE(switches::kNtpAppInstallHint)
576 },
577 {
[email protected]9860c68b2012-02-02 01:58:09578 "enable-extension-activity-ui",
579 IDS_FLAGS_ENABLE_EXTENSION_ACTIVITY_UI_NAME,
580 IDS_FLAGS_ENABLE_EXTENSION_ACTIVITY_UI_DESCRIPTION,
581 kOsAll,
582 SINGLE_VALUE_TYPE(switches::kEnableExtensionActivityUI)
[email protected]8bed69d2012-02-02 06:46:00583 },
[email protected]54ae4e92012-02-16 15:19:05584 {
585 "webui-task-manager",
586 IDS_FLAGS_WEBUI_TASK_MANAGER_NAME,
587 IDS_FLAGS_WEBUI_TASK_MANAGER_DESCRIPTION,
588 kOsAll,
589 SINGLE_VALUE_TYPE(switches::kWebUITaskManager)
590 },
[email protected]156f966332012-02-29 00:03:16591 {
[email protected]3e8befc2012-03-13 01:17:03592 "disable-ntp-other-sessions-menu",
[email protected]156f966332012-02-29 00:03:16593 IDS_FLAGS_NTP_OTHER_SESSIONS_MENU_NAME,
594 IDS_FLAGS_NTP_OTHER_SESSIONS_MENU_DESCRIPTION,
595 kOsAll,
[email protected]3e8befc2012-03-13 01:17:03596 SINGLE_VALUE_TYPE(switches::kDisableNTPOtherSessionsMenu)
[email protected]156f966332012-02-29 00:03:16597 },
[email protected]dc04be7c2012-03-15 23:57:49598#if defined(USE_ASH)
[email protected]31cf1c52012-02-29 20:55:01599 {
[email protected]3cd198a22012-03-12 20:38:01600 "enable-ash-oak",
601 IDS_FLAGS_ENABLE_ASH_OAK_NAME,
602 IDS_FLAGS_ENABLE_ASH_OAK_DESCRIPTION,
603 kOsAll,
604 SINGLE_VALUE_TYPE(ash::switches::kAshEnableOak),
605 },
[email protected]31cf1c52012-02-29 20:55:01606#endif
[email protected]184ec592012-03-01 11:54:28607 {
608 "enable-devtools-experiments",
609 IDS_FLAGS_ENABLE_DEVTOOLS_EXPERIMENTS_NAME,
610 IDS_FLAGS_ENABLE_DEVTOOLS_EXPERIMENTS_DESCRIPTION,
611 kOsAll,
612 SINGLE_VALUE_TYPE(switches::kEnableDevToolsExperiments)
613 },
[email protected]76d1854e2012-03-02 23:57:44614 {
615 "enable-suggestions-ntp",
616 IDS_FLAGS_NTP_SUGGESTIONS_PAGE_NAME,
617 IDS_FLAGS_NTP_SUGGESTIONS_PAGE_DESCRIPTION,
618 kOsAll,
619 SINGLE_VALUE_TYPE(switches::kEnableSuggestionsTabPage)
620 },
[email protected]a78ef9e2012-03-21 02:49:55621 {
[email protected]0b777be22012-04-03 04:42:24622 "disable-chrome-to-mobile", // FLAGS:RECORD_UMA
623 IDS_FLAGS_DISABLE_CHROME_TO_MOBILE_NAME,
624 IDS_FLAGS_DISABLE_CHROME_TO_MOBILE_DESCRIPTION,
[email protected]a78ef9e2012-03-21 02:49:55625 kOsAll,
[email protected]0b777be22012-04-03 04:42:24626 SINGLE_VALUE_TYPE(switches::kDisableChromeToMobile)
[email protected]a78ef9e2012-03-21 02:49:55627 },
[email protected]a3d54252012-04-05 20:04:13628#if defined(GOOGLE_CHROME_BUILD)
629 {
630 "enable-asynchronous-spellchecking",
631 IDS_FLAGS_ENABLE_ASYNCHRONOUS_SPELLCHECKING,
632 IDS_FLAGS_ENABLE_ASYNCHRONOUS_SPELLCHECKING_DESCRIPTION,
633 kOsAll,
634 SINGLE_VALUE_TYPE(switches::kEnableAsynchronousSpellChecking)
635 },
636#endif
[email protected]c9c73ad42012-04-18 03:35:59637 {
638 "touch-optimized-ui",
639 IDS_TOUCH_OPTIMIZED_UI_NAME,
640 IDS_TOUCH_OPTIMIZED_UI_DESCRIPTION,
641 kOsAll,
642 SINGLE_VALUE_TYPE(switches::kTouchOptimizedUI)
643 },
[email protected]8a6aaa72012-04-20 20:53:58644 {
645 "enable-touch-events",
646 IDS_ENABLE_TOUCH_EVENTS_NAME,
647 IDS_ENABLE_TOUCH_EVENTS_DESCRIPTION,
648 kOsAll,
649 SINGLE_VALUE_TYPE(switches::kEnableTouchEvents)
650 },
[email protected]0b60afa2012-04-19 17:36:39651#if defined(OS_CHROMEOS)
652 {
653 "no-discard-tabs",
654 IDS_FLAGS_NO_DISCARD_TABS_NAME,
655 IDS_FLAGS_NO_DISCARD_TABS_DESCRIPTION,
656 kOsCrOS,
657 SINGLE_VALUE_TYPE(switches::kNoDiscardTabs)
658 },
659#endif
[email protected]79be6d32012-04-24 20:47:44660 {
[email protected]f92fce5f2012-04-24 21:05:16661 "enable-sync-signin",
[email protected]79be6d32012-04-24 20:47:44662 IDS_ENABLE_SYNC_SIGNIN_NAME,
663 IDS_ENABLE_SYNC_SIGNIN_DESCRIPTION,
664 kOsAll,
665 SINGLE_VALUE_TYPE(switches::kEnableSyncSignin)
666 },
[email protected]6d947a602012-04-24 23:12:11667 {
668 "enable-platform-apps",
669 IDS_FLAGS_ENABLE_PLATFORM_APPS_NAME,
670 IDS_FLAGS_ENABLE_PLATFORM_APPS_DESCRIPTION,
671 kOsAll,
672 SINGLE_VALUE_TYPE(switches::kEnablePlatformApps)
[email protected]9a5940d2012-04-27 19:16:23673 },
674 {
675 "allow-nacl-socket-api",
676 IDS_FLAGS_ALLOW_NACL_SOCKET_API_NAME,
677 IDS_FLAGS_ALLOW_NACL_SOCKET_API_DESCRIPTION,
678 kOsAll,
679 SINGLE_VALUE_TYPE_AND_VALUE(switches::kAllowNaClSocketAPI, "*")
680 },
[email protected]85333732012-05-01 19:02:24681 {
682 "default-device-scale-factor",
683 IDS_FLAGS_FORCE_HIGH_DPI_NAME,
684 IDS_FLAGS_FORCE_HIGH_DPI_DESCRIPTION,
685 kOsCrOS,
686 SINGLE_VALUE_TYPE_AND_VALUE(switches::kDefaultDeviceScaleFactor, "2")
687 },
[email protected]190349fd2012-05-02 00:10:47688#if defined(OS_CHROMEOS)
689 {
690 "allow-touchpad-three-finger-click",
691 IDS_FLAGS_ALLOW_TOUCHPAD_THREE_FINGER_CLICK_NAME,
692 IDS_FLAGS_ALLOW_TOUCHPAD_THREE_FINGER_CLICK_DESCRIPTION,
693 kOsCrOS,
694 SINGLE_VALUE_TYPE(switches::kEnableTouchpadThreeFingerClick)
695 },
696#endif
[email protected]a0e4b072011-08-17 01:47:07697};
[email protected]ad2a3ded2010-08-27 13:19:05698
[email protected]a314ee5a2010-10-26 21:23:28699const Experiment* experiments = kExperiments;
700size_t num_experiments = arraysize(kExperiments);
701
[email protected]e2ddbc92010-10-15 20:02:07702// Stores and encapsulates the little state that about:flags has.
703class FlagsState {
704 public:
705 FlagsState() : needs_restart_(false) {}
706 void ConvertFlagsToSwitches(PrefService* prefs, CommandLine* command_line);
707 bool IsRestartNeededToCommitChanges();
708 void SetExperimentEnabled(
[email protected]a314ee5a2010-10-26 21:23:28709 PrefService* prefs, const std::string& internal_name, bool enable);
[email protected]e2ddbc92010-10-15 20:02:07710 void RemoveFlagsSwitches(
711 std::map<std::string, CommandLine::StringType>* switch_list);
712 void reset();
713
714 // Returns the singleton instance of this class
[email protected]8e8bb6d2010-12-13 08:18:55715 static FlagsState* GetInstance() {
[email protected]e2ddbc92010-10-15 20:02:07716 return Singleton<FlagsState>::get();
717 }
718
719 private:
720 bool needs_restart_;
[email protected]a82744532011-02-11 16:15:53721 std::map<std::string, std::string> flags_switches_;
[email protected]e2ddbc92010-10-15 20:02:07722
723 DISALLOW_COPY_AND_ASSIGN(FlagsState);
724};
725
[email protected]c7b7800a2010-10-07 18:51:35726// Extracts the list of enabled lab experiments from preferences and stores them
[email protected]ad2a3ded2010-08-27 13:19:05727// in a set.
[email protected]1a47d7e2010-10-15 00:37:24728void GetEnabledFlags(const PrefService* prefs, std::set<std::string>* result) {
[email protected]ad2a3ded2010-08-27 13:19:05729 const ListValue* enabled_experiments = prefs->GetList(
730 prefs::kEnabledLabsExperiments);
731 if (!enabled_experiments)
732 return;
733
734 for (ListValue::const_iterator it = enabled_experiments->begin();
735 it != enabled_experiments->end();
736 ++it) {
737 std::string experiment_name;
738 if (!(*it)->GetAsString(&experiment_name)) {
739 LOG(WARNING) << "Invalid entry in " << prefs::kEnabledLabsExperiments;
740 continue;
741 }
742 result->insert(experiment_name);
743 }
744}
745
746// Takes a set of enabled lab experiments
[email protected]1a47d7e2010-10-15 00:37:24747void SetEnabledFlags(
[email protected]ad2a3ded2010-08-27 13:19:05748 PrefService* prefs, const std::set<std::string>& enabled_experiments) {
[email protected]1bc78422011-03-31 08:41:38749 ListPrefUpdate update(prefs, prefs::kEnabledLabsExperiments);
750 ListValue* experiments_list = update.Get();
[email protected]ad2a3ded2010-08-27 13:19:05751
752 experiments_list->Clear();
753 for (std::set<std::string>::const_iterator it = enabled_experiments.begin();
754 it != enabled_experiments.end();
755 ++it) {
756 experiments_list->Append(new StringValue(*it));
757 }
758}
759
[email protected]8a6ff28d2010-12-02 16:35:19760// Returns the name used in prefs for the choice at the specified index.
761std::string NameForChoice(const Experiment& e, int index) {
[email protected]2ce9c89752011-02-25 18:24:34762 DCHECK_EQ(Experiment::MULTI_VALUE, e.type);
763 DCHECK_LT(index, e.num_choices);
[email protected]8a6ff28d2010-12-02 16:35:19764 return std::string(e.internal_name) + about_flags::testing::kMultiSeparator +
765 base::IntToString(index);
766}
767
768// Adds the internal names for the specified experiment to |names|.
769void AddInternalName(const Experiment& e, std::set<std::string>* names) {
770 if (e.type == Experiment::SINGLE_VALUE) {
771 names->insert(e.internal_name);
772 } else {
[email protected]2ce9c89752011-02-25 18:24:34773 DCHECK_EQ(Experiment::MULTI_VALUE, e.type);
[email protected]8a6ff28d2010-12-02 16:35:19774 for (int i = 0; i < e.num_choices; ++i)
775 names->insert(NameForChoice(e, i));
776 }
777}
778
[email protected]28e35af2011-02-09 12:56:22779// Confirms that an experiment is valid, used in a DCHECK in
780// SanitizeList below.
781bool ValidateExperiment(const Experiment& e) {
782 switch (e.type) {
783 case Experiment::SINGLE_VALUE:
784 DCHECK_EQ(0, e.num_choices);
785 DCHECK(!e.choices);
786 break;
787 case Experiment::MULTI_VALUE:
788 DCHECK_GT(e.num_choices, 0);
789 DCHECK(e.choices);
[email protected]a82744532011-02-11 16:15:53790 DCHECK(e.choices[0].command_line_switch);
791 DCHECK_EQ('\0', e.choices[0].command_line_switch[0]);
[email protected]28e35af2011-02-09 12:56:22792 break;
793 default:
794 NOTREACHED();
795 }
796 return true;
797}
798
[email protected]ad2a3ded2010-08-27 13:19:05799// Removes all experiments from prefs::kEnabledLabsExperiments that are
800// unknown, to prevent this list to become very long as experiments are added
801// and removed.
802void SanitizeList(PrefService* prefs) {
803 std::set<std::string> known_experiments;
[email protected]28e35af2011-02-09 12:56:22804 for (size_t i = 0; i < num_experiments; ++i) {
805 DCHECK(ValidateExperiment(experiments[i]));
[email protected]8a6ff28d2010-12-02 16:35:19806 AddInternalName(experiments[i], &known_experiments);
[email protected]28e35af2011-02-09 12:56:22807 }
[email protected]ad2a3ded2010-08-27 13:19:05808
809 std::set<std::string> enabled_experiments;
[email protected]1a47d7e2010-10-15 00:37:24810 GetEnabledFlags(prefs, &enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05811
812 std::set<std::string> new_enabled_experiments;
813 std::set_intersection(
814 known_experiments.begin(), known_experiments.end(),
815 enabled_experiments.begin(), enabled_experiments.end(),
816 std::inserter(new_enabled_experiments, new_enabled_experiments.begin()));
817
[email protected]1a47d7e2010-10-15 00:37:24818 SetEnabledFlags(prefs, new_enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05819}
820
[email protected]1a47d7e2010-10-15 00:37:24821void GetSanitizedEnabledFlags(
[email protected]ad2a3ded2010-08-27 13:19:05822 PrefService* prefs, std::set<std::string>* result) {
823 SanitizeList(prefs);
[email protected]1a47d7e2010-10-15 00:37:24824 GetEnabledFlags(prefs, result);
[email protected]ad2a3ded2010-08-27 13:19:05825}
826
[email protected]a314ee5a2010-10-26 21:23:28827// Variant of GetSanitizedEnabledFlags that also removes any flags that aren't
828// enabled on the current platform.
829void GetSanitizedEnabledFlagsForCurrentPlatform(
830 PrefService* prefs, std::set<std::string>* result) {
831 GetSanitizedEnabledFlags(prefs, result);
832
833 // Filter out any experiments that aren't enabled on the current platform. We
834 // don't remove these from prefs else syncing to a platform with a different
835 // set of experiments would be lossy.
836 std::set<std::string> platform_experiments;
837 int current_platform = GetCurrentPlatform();
838 for (size_t i = 0; i < num_experiments; ++i) {
839 if (experiments[i].supported_platforms & current_platform)
[email protected]8a6ff28d2010-12-02 16:35:19840 AddInternalName(experiments[i], &platform_experiments);
[email protected]a314ee5a2010-10-26 21:23:28841 }
842
843 std::set<std::string> new_enabled_experiments;
844 std::set_intersection(
845 platform_experiments.begin(), platform_experiments.end(),
846 result->begin(), result->end(),
847 std::inserter(new_enabled_experiments, new_enabled_experiments.begin()));
848
849 result->swap(new_enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05850}
851
[email protected]8a6ff28d2010-12-02 16:35:19852// Returns the Value representing the choice data in the specified experiment.
[email protected]8a6ff28d2010-12-02 16:35:19853Value* CreateChoiceData(const Experiment& experiment,
[email protected]28e35af2011-02-09 12:56:22854 const std::set<std::string>& enabled_experiments) {
[email protected]2ce9c89752011-02-25 18:24:34855 DCHECK_EQ(Experiment::MULTI_VALUE, experiment.type);
[email protected]8a6ff28d2010-12-02 16:35:19856 ListValue* result = new ListValue;
857 for (int i = 0; i < experiment.num_choices; ++i) {
858 const Experiment::Choice& choice = experiment.choices[i];
859 DictionaryValue* value = new DictionaryValue;
860 std::string name = NameForChoice(experiment, i);
861 value->SetString("description",
862 l10n_util::GetStringUTF16(choice.description_id));
863 value->SetString("internal_name", name);
[email protected]28e35af2011-02-09 12:56:22864 value->SetBoolean("selected", enabled_experiments.count(name) > 0);
[email protected]8a6ff28d2010-12-02 16:35:19865 result->Append(value);
866 }
867 return result;
868}
869
[email protected]e2ddbc92010-10-15 20:02:07870} // namespace
871
[email protected]1a47d7e2010-10-15 00:37:24872void ConvertFlagsToSwitches(PrefService* prefs, CommandLine* command_line) {
[email protected]8e8bb6d2010-12-13 08:18:55873 FlagsState::GetInstance()->ConvertFlagsToSwitches(prefs, command_line);
[email protected]ad2a3ded2010-08-27 13:19:05874}
875
[email protected]1a47d7e2010-10-15 00:37:24876ListValue* GetFlagsExperimentsData(PrefService* prefs) {
[email protected]ad2a3ded2010-08-27 13:19:05877 std::set<std::string> enabled_experiments;
[email protected]1a47d7e2010-10-15 00:37:24878 GetSanitizedEnabledFlags(prefs, &enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05879
880 int current_platform = GetCurrentPlatform();
881
882 ListValue* experiments_data = new ListValue();
[email protected]a314ee5a2010-10-26 21:23:28883 for (size_t i = 0; i < num_experiments; ++i) {
884 const Experiment& experiment = experiments[i];
[email protected]ad2a3ded2010-08-27 13:19:05885
886 DictionaryValue* data = new DictionaryValue();
887 data->SetString("internal_name", experiment.internal_name);
888 data->SetString("name",
889 l10n_util::GetStringUTF16(experiment.visible_name_id));
890 data->SetString("description",
891 l10n_util::GetStringUTF16(
892 experiment.visible_description_id));
[email protected]cc3e2052011-12-20 01:01:40893 bool supported = !!(experiment.supported_platforms & current_platform);
894 data->SetBoolean("supported", supported);
895
896 ListValue* supported_platforms = new ListValue();
897 AddOsStrings(experiment.supported_platforms, supported_platforms);
898 data->Set("supported_platforms", supported_platforms);
[email protected]ad2a3ded2010-08-27 13:19:05899
[email protected]28e35af2011-02-09 12:56:22900 switch (experiment.type) {
901 case Experiment::SINGLE_VALUE:
902 data->SetBoolean(
903 "enabled",
904 enabled_experiments.count(experiment.internal_name) > 0);
905 break;
906 case Experiment::MULTI_VALUE:
907 data->Set("choices", CreateChoiceData(experiment, enabled_experiments));
908 break;
909 default:
910 NOTREACHED();
[email protected]8a6ff28d2010-12-02 16:35:19911 }
912
[email protected]ad2a3ded2010-08-27 13:19:05913 experiments_data->Append(data);
914 }
915 return experiments_data;
916}
917
[email protected]ad2a3ded2010-08-27 13:19:05918bool IsRestartNeededToCommitChanges() {
[email protected]8e8bb6d2010-12-13 08:18:55919 return FlagsState::GetInstance()->IsRestartNeededToCommitChanges();
[email protected]ad2a3ded2010-08-27 13:19:05920}
921
922void SetExperimentEnabled(
[email protected]c7b7800a2010-10-07 18:51:35923 PrefService* prefs, const std::string& internal_name, bool enable) {
[email protected]8e8bb6d2010-12-13 08:18:55924 FlagsState::GetInstance()->SetExperimentEnabled(prefs, internal_name, enable);
[email protected]e2ddbc92010-10-15 20:02:07925}
926
927void RemoveFlagsSwitches(
928 std::map<std::string, CommandLine::StringType>* switch_list) {
[email protected]8e8bb6d2010-12-13 08:18:55929 FlagsState::GetInstance()->RemoveFlagsSwitches(switch_list);
[email protected]e2ddbc92010-10-15 20:02:07930}
931
[email protected]a314ee5a2010-10-26 21:23:28932int GetCurrentPlatform() {
933#if defined(OS_MACOSX)
934 return kOsMac;
935#elif defined(OS_WIN)
936 return kOsWin;
937#elif defined(OS_CHROMEOS) // Needs to be before the OS_LINUX check.
938 return kOsCrOS;
[email protected]c92f4ed2011-10-21 19:50:21939#elif defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]a314ee5a2010-10-26 21:23:28940 return kOsLinux;
[email protected]9c7453d2012-01-21 00:45:40941#elif defined(OS_ANDROID)
942 return kOsAndroid;
[email protected]a314ee5a2010-10-26 21:23:28943#else
944#error Unknown platform
945#endif
946}
947
[email protected]4bc5050c2010-11-18 17:55:54948void RecordUMAStatistics(const PrefService* prefs) {
949 std::set<std::string> flags;
950 GetEnabledFlags(prefs, &flags);
951 for (std::set<std::string>::iterator it = flags.begin(); it != flags.end();
952 ++it) {
953 std::string action("AboutFlags_");
954 action += *it;
[email protected]7f6f44c2011-12-14 13:23:38955 content::RecordComputedAction(action);
[email protected]4bc5050c2010-11-18 17:55:54956 }
957 // Since flag metrics are recorded every startup, add a tick so that the
958 // stats can be made meaningful.
959 if (flags.size())
[email protected]7f6f44c2011-12-14 13:23:38960 content::RecordAction(UserMetricsAction("AboutFlags_StartupTick"));
961 content::RecordAction(UserMetricsAction("StartupTick"));
[email protected]4bc5050c2010-11-18 17:55:54962}
963
[email protected]e2ddbc92010-10-15 20:02:07964//////////////////////////////////////////////////////////////////////////////
965// FlagsState implementation.
966
967namespace {
968
969void FlagsState::ConvertFlagsToSwitches(
970 PrefService* prefs, CommandLine* command_line) {
[email protected]e2ddbc92010-10-15 20:02:07971 if (command_line->HasSwitch(switches::kNoExperiments))
972 return;
973
974 std::set<std::string> enabled_experiments;
[email protected]ba8164242010-11-16 21:31:00975
[email protected]a314ee5a2010-10-26 21:23:28976 GetSanitizedEnabledFlagsForCurrentPlatform(prefs, &enabled_experiments);
[email protected]e2ddbc92010-10-15 20:02:07977
[email protected]a82744532011-02-11 16:15:53978 typedef std::map<std::string, std::pair<std::string, std::string> >
979 NameToSwitchAndValueMap;
980 NameToSwitchAndValueMap name_to_switch_map;
[email protected]8a6ff28d2010-12-02 16:35:19981 for (size_t i = 0; i < num_experiments; ++i) {
982 const Experiment& e = experiments[i];
983 if (e.type == Experiment::SINGLE_VALUE) {
[email protected]a82744532011-02-11 16:15:53984 name_to_switch_map[e.internal_name] =
985 std::pair<std::string, std::string>(e.command_line_switch,
986 e.command_line_value);
[email protected]8a6ff28d2010-12-02 16:35:19987 } else {
988 for (int j = 0; j < e.num_choices; ++j)
[email protected]a82744532011-02-11 16:15:53989 name_to_switch_map[NameForChoice(e, j)] =
990 std::pair<std::string, std::string>(
991 e.choices[j].command_line_switch,
992 e.choices[j].command_line_value);
[email protected]8a6ff28d2010-12-02 16:35:19993 }
994 }
[email protected]e2ddbc92010-10-15 20:02:07995
996 command_line->AppendSwitch(switches::kFlagSwitchesBegin);
[email protected]a82744532011-02-11 16:15:53997 flags_switches_.insert(
998 std::pair<std::string, std::string>(switches::kFlagSwitchesBegin,
999 std::string()));
[email protected]e2ddbc92010-10-15 20:02:071000 for (std::set<std::string>::iterator it = enabled_experiments.begin();
1001 it != enabled_experiments.end();
1002 ++it) {
1003 const std::string& experiment_name = *it;
[email protected]a82744532011-02-11 16:15:531004 NameToSwitchAndValueMap::const_iterator name_to_switch_it =
[email protected]8a6ff28d2010-12-02 16:35:191005 name_to_switch_map.find(experiment_name);
1006 if (name_to_switch_it == name_to_switch_map.end()) {
1007 NOTREACHED();
[email protected]e2ddbc92010-10-15 20:02:071008 continue;
[email protected]8a6ff28d2010-12-02 16:35:191009 }
[email protected]e2ddbc92010-10-15 20:02:071010
[email protected]a82744532011-02-11 16:15:531011 const std::pair<std::string, std::string>&
1012 switch_and_value_pair = name_to_switch_it->second;
1013
1014 command_line->AppendSwitchASCII(switch_and_value_pair.first,
1015 switch_and_value_pair.second);
1016 flags_switches_[switch_and_value_pair.first] = switch_and_value_pair.second;
[email protected]e2ddbc92010-10-15 20:02:071017 }
1018 command_line->AppendSwitch(switches::kFlagSwitchesEnd);
[email protected]a82744532011-02-11 16:15:531019 flags_switches_.insert(
1020 std::pair<std::string, std::string>(switches::kFlagSwitchesEnd,
1021 std::string()));
[email protected]e2ddbc92010-10-15 20:02:071022}
1023
1024bool FlagsState::IsRestartNeededToCommitChanges() {
1025 return needs_restart_;
1026}
1027
1028void FlagsState::SetExperimentEnabled(
1029 PrefService* prefs, const std::string& internal_name, bool enable) {
[email protected]ad2a3ded2010-08-27 13:19:051030 needs_restart_ = true;
1031
[email protected]8a6ff28d2010-12-02 16:35:191032 size_t at_index = internal_name.find(about_flags::testing::kMultiSeparator);
1033 if (at_index != std::string::npos) {
1034 DCHECK(enable);
1035 // We're being asked to enable a multi-choice experiment. Disable the
1036 // currently selected choice.
1037 DCHECK_NE(at_index, 0u);
[email protected]28e35af2011-02-09 12:56:221038 const std::string experiment_name = internal_name.substr(0, at_index);
1039 SetExperimentEnabled(prefs, experiment_name, false);
[email protected]8a6ff28d2010-12-02 16:35:191040
[email protected]28e35af2011-02-09 12:56:221041 // And enable the new choice, if it is not the default first choice.
1042 if (internal_name != experiment_name + "@0") {
1043 std::set<std::string> enabled_experiments;
1044 GetSanitizedEnabledFlags(prefs, &enabled_experiments);
1045 enabled_experiments.insert(internal_name);
1046 SetEnabledFlags(prefs, enabled_experiments);
1047 }
[email protected]8a6ff28d2010-12-02 16:35:191048 return;
1049 }
1050
[email protected]ad2a3ded2010-08-27 13:19:051051 std::set<std::string> enabled_experiments;
[email protected]1a47d7e2010-10-15 00:37:241052 GetSanitizedEnabledFlags(prefs, &enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:051053
[email protected]8a6ff28d2010-12-02 16:35:191054 const Experiment* e = NULL;
1055 for (size_t i = 0; i < num_experiments; ++i) {
1056 if (experiments[i].internal_name == internal_name) {
1057 e = experiments + i;
1058 break;
1059 }
1060 }
1061 DCHECK(e);
1062
1063 if (e->type == Experiment::SINGLE_VALUE) {
[email protected]8a2713682011-08-19 10:36:591064 if (enable)
[email protected]8a6ff28d2010-12-02 16:35:191065 enabled_experiments.insert(internal_name);
[email protected]8a2713682011-08-19 10:36:591066 else
[email protected]8a6ff28d2010-12-02 16:35:191067 enabled_experiments.erase(internal_name);
1068 } else {
1069 if (enable) {
1070 // Enable the first choice.
1071 enabled_experiments.insert(NameForChoice(*e, 0));
1072 } else {
1073 // Find the currently enabled choice and disable it.
1074 for (int i = 0; i < e->num_choices; ++i) {
1075 std::string choice_name = NameForChoice(*e, i);
1076 if (enabled_experiments.find(choice_name) !=
1077 enabled_experiments.end()) {
1078 enabled_experiments.erase(choice_name);
1079 // Continue on just in case there's a bug and more than one
1080 // experiment for this choice was enabled.
1081 }
1082 }
1083 }
1084 }
[email protected]ad2a3ded2010-08-27 13:19:051085
[email protected]1a47d7e2010-10-15 00:37:241086 SetEnabledFlags(prefs, enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:051087}
1088
[email protected]e2ddbc92010-10-15 20:02:071089void FlagsState::RemoveFlagsSwitches(
1090 std::map<std::string, CommandLine::StringType>* switch_list) {
[email protected]a82744532011-02-11 16:15:531091 for (std::map<std::string, std::string>::const_iterator
1092 it = flags_switches_.begin(); it != flags_switches_.end(); ++it) {
1093 switch_list->erase(it->first);
[email protected]e2ddbc92010-10-15 20:02:071094 }
1095}
1096
1097void FlagsState::reset() {
1098 needs_restart_ = false;
1099 flags_switches_.clear();
1100}
1101
[email protected]38e46812011-05-09 20:49:221102} // namespace
[email protected]e2ddbc92010-10-15 20:02:071103
1104namespace testing {
[email protected]8a6ff28d2010-12-02 16:35:191105
1106// WARNING: '@' is also used in the html file. If you update this constant you
1107// also need to update the html file.
1108const char kMultiSeparator[] = "@";
1109
[email protected]e2ddbc92010-10-15 20:02:071110void ClearState() {
[email protected]8e8bb6d2010-12-13 08:18:551111 FlagsState::GetInstance()->reset();
[email protected]e2ddbc92010-10-15 20:02:071112}
[email protected]a314ee5a2010-10-26 21:23:281113
1114void SetExperiments(const Experiment* e, size_t count) {
1115 if (!e) {
1116 experiments = kExperiments;
1117 num_experiments = arraysize(kExperiments);
1118 } else {
1119 experiments = e;
1120 num_experiments = count;
1121 }
1122}
1123
[email protected]8a6ff28d2010-12-02 16:35:191124const Experiment* GetExperiments(size_t* count) {
1125 *count = num_experiments;
1126 return experiments;
1127}
1128
[email protected]e2ddbc92010-10-15 20:02:071129} // namespace testing
1130
[email protected]1a47d7e2010-10-15 00:37:241131} // namespace about_flags