blob: 256f80938378abc527599610b94b21045d4cb375 [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]cbe224d2011-08-04 22:12:49272 "apps-new-install-bubble",
273 IDS_FLAGS_APPS_NEW_INSTALL_BUBBLE_NAME,
274 IDS_FLAGS_APPS_NEW_INSTALL_BUBBLE_DESCRIPTION,
275 kOsAll,
276 SINGLE_VALUE_TYPE(switches::kAppsNewInstallBubble)
277 },
278 {
[email protected]80bd24e2010-11-30 09:34:38279 "disable-hyperlink-auditing",
280 IDS_FLAGS_DISABLE_HYPERLINK_AUDITING_NAME,
281 IDS_FLAGS_DISABLE_HYPERLINK_AUDITING_DESCRIPTION,
282 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19283 SINGLE_VALUE_TYPE(switches::kNoPings)
[email protected]feb28fef2010-12-01 10:52:51284 },
285 {
286 "experimental-location-features", // FLAGS:RECORD_UMA
287 IDS_FLAGS_EXPERIMENTAL_LOCATION_FEATURES_NAME,
288 IDS_FLAGS_EXPERIMENTAL_LOCATION_FEATURES_DESCRIPTION,
289 kOsMac | kOsWin | kOsLinux, // Currently does nothing on CrOS.
[email protected]8a6ff28d2010-12-02 16:35:19290 SINGLE_VALUE_TYPE(switches::kExperimentalLocationFeatures)
291 },
292 {
[email protected]04227962011-01-20 02:03:09293 "disable-interactive-form-validation",
294 IDS_FLAGS_DISABLE_INTERACTIVE_FORM_VALIDATION_NAME,
295 IDS_FLAGS_DISABLE_INTERACTIVE_FORM_VALIDATION_DESCRIPTION,
296 kOsAll,
297 SINGLE_VALUE_TYPE(switches::kDisableInteractiveFormValidation)
298 },
[email protected]8df51192011-01-22 20:05:03299 {
[email protected]07d490bc2011-03-07 17:05:26300 "focus-existing-tab-on-open", // FLAGS:RECORD_UMA
301 IDS_FLAGS_FOCUS_EXISTING_TAB_ON_OPEN_NAME,
302 IDS_FLAGS_FOCUS_EXISTING_TAB_ON_OPEN_DESCRIPTION,
303 kOsAll,
304 SINGLE_VALUE_TYPE(switches::kFocusExistingTabOnOpen)
305 },
[email protected]d5dcfb32011-03-19 00:49:24306 {
[email protected]5aea1862011-03-23 23:55:39307 "tab-groups-context-menu",
308 IDS_FLAGS_TAB_GROUPS_CONTEXT_MENU_NAME,
309 IDS_FLAGS_TAB_GROUPS_CONTEXT_MENU_DESCRIPTION,
310 kOsWin,
311 SINGLE_VALUE_TYPE(switches::kEnableTabGroupsContextMenu)
312 },
[email protected]e9bf9d92011-03-31 20:57:15313 {
[email protected]f2557bd2011-06-01 02:33:07314 "preload-instant-search",
315 IDS_FLAGS_PRELOAD_INSTANT_SEARCH_NAME,
316 IDS_FLAGS_PRELOAD_INSTANT_SEARCH_DESCRIPTION,
317 kOsAll,
318 SINGLE_VALUE_TYPE(switches::kPreloadInstantSearch)
319 },
[email protected]354e33b2011-06-15 00:29:10320 {
321 "static-ip-config",
322 IDS_FLAGS_STATIC_IP_CONFIG_NAME,
323 IDS_FLAGS_STATIC_IP_CONFIG_DESCRIPTION,
324 kOsCrOS,
325#if defined(OS_CHROMEOS)
326 // This switch exists only on Chrome OS.
327 SINGLE_VALUE_TYPE(switches::kEnableStaticIPConfig)
328#else
329 SINGLE_VALUE_TYPE("")
330#endif
331 },
[email protected]3eb5728c2011-06-20 22:32:24332 {
333 "show-autofill-type-predictions",
334 IDS_FLAGS_SHOW_AUTOFILL_TYPE_PREDICTIONS_NAME,
335 IDS_FLAGS_SHOW_AUTOFILL_TYPE_PREDICTIONS_DESCRIPTION,
336 kOsAll,
337 SINGLE_VALUE_TYPE(switches::kShowAutofillTypePredictions)
338 },
[email protected]bff4d3e2011-06-21 23:58:52339 {
[email protected]9a6180d7d2011-09-07 01:40:33340 "sync-tabs",
341 IDS_FLAGS_SYNC_TABS_NAME,
342 IDS_FLAGS_SYNC_TABS_DESCRIPTION,
[email protected]5b0ec7f2011-08-11 02:17:17343 kOsAll,
[email protected]9a6180d7d2011-09-07 01:40:33344 SINGLE_VALUE_TYPE(switches::kEnableSyncTabs)
[email protected]5b0ec7f2011-08-11 02:17:17345 },
346 {
[email protected]aae9eeb12011-10-21 21:59:26347 "sync-app-notifications",
348 IDS_FLAGS_SYNC_APP_NOTIFICATIONS_NAME,
349 IDS_FLAGS_SYNC_APP_NOTIFICATIONS_DESCRIPTION,
350 kOsAll,
[email protected]0b6fba82011-11-18 01:31:11351 SINGLE_VALUE_TYPE(switches::kDisableSyncAppNotifications)
[email protected]aae9eeb12011-10-21 21:59:26352 },
353 {
[email protected]a22ebd812011-06-23 00:05:39354 "enable-smooth-scrolling", // FLAGS:RECORD_UMA
355 IDS_FLAGS_ENABLE_SMOOTH_SCROLLING_NAME,
356 IDS_FLAGS_ENABLE_SMOOTH_SCROLLING_DESCRIPTION,
357 // Can't expose the switch unless the code is compiled in.
[email protected]554b7062011-09-03 03:09:40358 // On by default for the Mac (different implementation in WebKit).
[email protected]554b7062011-09-03 03:09:40359 kOsWin | kOsLinux | kOsCrOS,
[email protected]a22ebd812011-06-23 00:05:39360 SINGLE_VALUE_TYPE(switches::kEnableSmoothScrolling)
361 },
[email protected]81a6b0b2011-06-24 17:55:40362 {
[email protected]9b2c9f6a12012-01-27 21:00:05363 "omnibox-aggressive-with-history-url",
[email protected]ed1e39502011-12-16 14:39:35364 IDS_FLAGS_OMNIBOX_AGGRESSIVE_HISTORY_URL_SCORING_NAME,
365 IDS_FLAGS_OMNIBOX_AGGRESSIVE_HISTORY_URL_SCORING_DESCRIPTION,
366 kOsAll,
[email protected]9b2c9f6a12012-01-27 21:00:05367 MULTI_VALUE_TYPE(kOmniboxAggressiveHistoryURLChoices)
[email protected]ed1e39502011-12-16 14:39:35368 },
369 {
[email protected]032d5e6c2012-02-17 17:53:55370 "omnibox-inline-history-quick-provider",
371 IDS_FLAGS_OMNIBOX_INLINE_HISTORY_QUICK_PROVIDER_NAME,
372 IDS_FLAGS_OMNIBOX_INLINE_HISTORY_QUICK_PROVIDER_DESCRIPTION,
373 kOsAll,
374 MULTI_VALUE_TYPE(kOmniboxInlineHistoryQuickProviderChoices)
375 },
376 {
[email protected]7e7a28092011-12-09 22:24:55377 "enable-panels",
378 IDS_FLAGS_ENABLE_PANELS_NAME,
379 IDS_FLAGS_ENABLE_PANELS_DESCRIPTION,
[email protected]73fb1fc52011-07-09 00:06:54380 kOsAll,
[email protected]7e7a28092011-12-09 22:24:55381 SINGLE_VALUE_TYPE(switches::kEnablePanels)
[email protected]73fb1fc52011-07-09 00:06:54382 },
[email protected]e3749d12011-07-25 22:22:12383 {
[email protected]9931875b2011-11-02 00:19:48384 "disable-shortcuts-provider",
385 IDS_FLAGS_DISABLE_SHORTCUTS_PROVIDER,
386 IDS_FLAGS_DISABLE_SHORTCUTS_PROVIDER_DESCRIPTION,
[email protected]e3749d12011-07-25 22:22:12387 kOsAll,
[email protected]9931875b2011-11-02 00:19:48388 SINGLE_VALUE_TYPE(switches::kDisableShortcutsProvider)
[email protected]e3749d12011-07-25 22:22:12389 },
[email protected]80eb4262011-08-03 16:10:41390 {
[email protected]a0e4b072011-08-17 01:47:07391 "downloads-new-ui", // FLAGS:RECORD_UMA
392 IDS_FLAGS_DOWNLOADS_NEW_UI_NAME,
393 IDS_FLAGS_DOWNLOADS_NEW_UI_DESCRIPTION,
394 kOsAll,
395 SINGLE_VALUE_TYPE(switches::kDownloadsNewUI)
396 },
[email protected]b7bb44f2011-09-01 05:17:03397 {
398 "enable-autologin",
399 IDS_FLAGS_ENABLE_AUTOLOGIN_NAME,
400 IDS_FLAGS_ENABLE_AUTOLOGIN_DESCRIPTION,
401 kOsMac | kOsWin | kOsLinux,
402 SINGLE_VALUE_TYPE(switches::kEnableAutologin)
403 },
[email protected]b9841172011-09-26 23:36:09404 {
[email protected]bbadb112011-12-12 16:55:28405 "enable-http-pipelining",
406 IDS_FLAGS_ENABLE_HTTP_PIPELINING_NAME,
407 IDS_FLAGS_ENABLE_HTTP_PIPELINING_DESCRIPTION,
408 kOsAll,
409 SINGLE_VALUE_TYPE(switches::kEnableHttpPipelining)
410 },
[email protected]d411c01d2011-10-18 16:00:27411 {
[email protected]3231b612012-03-23 05:57:54412 "enable-spdy3",
413 IDS_FLAGS_ENABLE_SPDY3_NAME,
414 IDS_FLAGS_ENABLE_SPDY3_DESCRIPTION,
415 kOsAll,
416 SINGLE_VALUE_TYPE(switches::kEnableSpdy3)
417 },
418 {
[email protected]27b3fe92012-03-21 05:35:06419 "enable-async-dns",
420 IDS_FLAGS_ENABLE_ASYNC_DNS_NAME,
421 IDS_FLAGS_ENABLE_ASYNC_DNS_DESCRIPTION,
[email protected]ec9d0532012-03-21 05:55:32422 kOsWin | kOsMac | kOsLinux | kOsCrOS,
[email protected]27b3fe92012-03-21 05:35:06423 SINGLE_VALUE_TYPE(switches::kEnableAsyncDns)
424 },
425 {
[email protected]f5da41d2011-10-08 17:40:07426 "enable-video-track",
427 IDS_FLAGS_ENABLE_VIDEO_TRACK_NAME,
428 IDS_FLAGS_ENABLE_VIDEO_TRACK_DESCRIPTION,
429 kOsAll,
430 SINGLE_VALUE_TYPE(switches::kEnableVideoTrack)
431 },
[email protected]08b83362011-10-19 05:23:17432 {
[email protected]6aa03b32011-10-27 21:44:44433 "enable-media-source",
434 IDS_FLAGS_ENABLE_MEDIA_SOURCE_NAME,
435 IDS_FLAGS_ENABLE_MEDIA_SOURCE_DESCRIPTION,
[email protected]ec9d0532012-03-21 05:55:32436 kOsAll,
[email protected]6aa03b32011-10-27 21:44:44437 SINGLE_VALUE_TYPE(switches::kEnableMediaSource)
438 },
[email protected]e4e68dbb2011-11-18 01:50:22439 {
[email protected]9f5b7822012-04-18 23:39:03440 "enable-encrypted-media",
441 IDS_FLAGS_ENABLE_ENCRYPTED_MEDIA_NAME,
442 IDS_FLAGS_ENABLE_ENCRYPTED_MEDIA_DESCRIPTION,
443 kOsAll,
444 SINGLE_VALUE_TYPE(switches::kEnableEncryptedMedia)
445 },
446 {
[email protected]e4e68dbb2011-11-18 01:50:22447 "enable-pointer-lock",
448 IDS_FLAGS_ENABLE_POINTER_LOCK_NAME,
449 IDS_FLAGS_ENABLE_POINTER_LOCK_DESCRIPTION,
450 kOsAll,
451 SINGLE_VALUE_TYPE(switches::kEnablePointerLock)
452 },
[email protected]dc04be7c2012-03-15 23:57:49453#if defined(USE_ASH)
[email protected]8cc10df2011-11-03 23:57:50454 {
[email protected]57b8bb352012-01-11 05:11:46455 "aura-google-dialog-frames",
456 IDS_FLAGS_AURA_GOOGLE_DIALOG_FRAMES_NAME,
457 IDS_FLAGS_AURA_GOOGLE_DIALOG_FRAMES_DESCRIPTION,
458 kOsWin | kOsLinux | kOsCrOS,
459 SINGLE_VALUE_TYPE(ash::switches::kAuraGoogleDialogFrames)
460 },
[email protected]dc04be7c2012-03-15 23:57:49461#endif
462#if defined(USE_AURA)
[email protected]308aaa32012-03-12 13:14:50463 {
464 "aura-disable-hold-mouse-moves",
465 IDS_FLAGS_AURA_DISABLE_HOLD_MOUSE_MOVES_NAME,
466 IDS_FLAGS_AURA_DISABLE_HOLD_MOUSE_MOVES_DESCRIPTION,
467 kOsWin | kOsLinux | kOsCrOS,
468 SINGLE_VALUE_TYPE(switches::kAuraDisableHoldMouseMoves)
469 },
[email protected]eaae8b462012-01-20 22:20:39470#endif // defined(USE_AURA)
471 {
472 "enable-gamepad",
473 IDS_FLAGS_ENABLE_GAMEPAD_NAME,
474 IDS_FLAGS_ENABLE_GAMEPAD_DESCRIPTION,
475 kOsAll,
476 SINGLE_VALUE_TYPE(switches::kEnableGamepad)
477 },
[email protected]db543d322011-12-15 20:40:15478 {
479 "per-tile-painting",
480 IDS_FLAGS_PER_TILE_PAINTING_NAME,
481 IDS_FLAGS_PER_TILE_PAINTING_DESCRIPTION,
482#if defined(USE_SKIA)
[email protected]a5b1b272012-01-06 20:44:37483 kOsMac | kOsLinux | kOsCrOS,
[email protected]db543d322011-12-15 20:40:15484#else
485 0,
486#endif
487 SINGLE_VALUE_TYPE(switches::kEnablePerTilePainting)
488 },
[email protected]bf88c032011-12-22 19:05:47489 {
490 "enable-javascript-harmony",
491 IDS_FLAGS_ENABLE_JAVASCRIPT_HARMONY_NAME,
492 IDS_FLAGS_ENABLE_JAVASCRIPT_HARMONY_DESCRIPTION,
493 kOsAll,
494 SINGLE_VALUE_TYPE_AND_VALUE(switches::kJavaScriptFlags, "--harmony")
495 },
[email protected]7e7f378a2012-01-05 14:35:37496 {
[email protected]85646172012-01-09 22:45:54497 "enable-tab-browser-dragging",
498 IDS_FLAGS_ENABLE_TAB_BROWSER_DRAGGING_NAME,
499 IDS_FLAGS_ENABLE_TAB_BROWSER_DRAGGING_DESCRIPTION,
500 kOsWin,
501 SINGLE_VALUE_TYPE(switches::kTabBrowserDragging)
502 },
503 {
[email protected]068b7b52012-02-27 12:41:44504 "disable-restore-session-state",
505 IDS_FLAGS_DISABLE_RESTORE_SESSION_STATE_NAME,
506 IDS_FLAGS_DISABLE_RESTORE_SESSION_STATE_DESCRIPTION,
[email protected]7e7f378a2012-01-05 14:35:37507 kOsAll,
[email protected]068b7b52012-02-27 12:41:44508 SINGLE_VALUE_TYPE(switches::kDisableRestoreSessionState)
[email protected]7e7f378a2012-01-05 14:35:37509 },
[email protected]88864db2012-01-18 20:56:35510 {
511 "disable-software-rasterizer",
512 IDS_FLAGS_DISABLE_SOFTWARE_RASTERIZER_NAME,
513 IDS_FLAGS_DISABLE_SOFTWARE_RASTERIZER_DESCRIPTION,
514#if defined(ENABLE_SWIFTSHADER)
515 kOsAll,
516#else
517 0,
518#endif
519 SINGLE_VALUE_TYPE(switches::kDisableSoftwareRasterizer)
520 },
[email protected]15a5d722012-01-23 09:11:14521 {
522 "enable-media-stream",
523 IDS_FLAGS_MEDIA_STREAM_NAME,
524 IDS_FLAGS_MEDIA_STREAM_DESCRIPTION,
[email protected]fa82b6772012-02-20 13:19:05525 kOsAll,
[email protected]15a5d722012-01-23 09:11:14526 SINGLE_VALUE_TYPE(switches::kEnableMediaStream)
527 },
[email protected]f5ec7242012-01-27 07:15:15528 {
[email protected]d2edc6702012-01-30 09:13:16529 "enable-shadow-dom",
530 IDS_FLAGS_SHADOW_DOM_NAME,
531 IDS_FLAGS_SHADOW_DOM_DESCRIPTION,
532 kOsAll,
533 SINGLE_VALUE_TYPE(switches::kEnableShadowDOM)
534 },
[email protected]9860c68b2012-02-02 01:58:09535 {
[email protected]4961218f2012-02-23 10:11:07536 "enable-style-scoped",
537 IDS_FLAGS_STYLE_SCOPED_NAME,
538 IDS_FLAGS_STYLE_SCOPED_DESCRIPTION,
539 kOsAll,
540 SINGLE_VALUE_TYPE(switches::kEnableStyleScoped)
541 },
542 {
[email protected]ca7a3d792012-03-02 15:55:49543 "enable-css-regions",
544 IDS_FLAGS_CSS_REGIONS_NAME,
545 IDS_FLAGS_CSS_REGIONS_DESCRIPTION,
546 kOsAll,
547 SINGLE_VALUE_TYPE(switches::kEnableCssRegions)
548 },
549 {
[email protected]8bed69d2012-02-02 06:46:00550 "ntp-app-install-hint",
551 IDS_FLAGS_APP_INSTALL_HINT_NAME,
552 IDS_FLAGS_APP_INSTALL_HINT_DESCRIPTION,
553 kOsAll,
554 SINGLE_VALUE_TYPE(switches::kNtpAppInstallHint)
555 },
556 {
[email protected]9860c68b2012-02-02 01:58:09557 "enable-extension-activity-ui",
558 IDS_FLAGS_ENABLE_EXTENSION_ACTIVITY_UI_NAME,
559 IDS_FLAGS_ENABLE_EXTENSION_ACTIVITY_UI_DESCRIPTION,
560 kOsAll,
561 SINGLE_VALUE_TYPE(switches::kEnableExtensionActivityUI)
[email protected]8bed69d2012-02-02 06:46:00562 },
[email protected]54ae4e92012-02-16 15:19:05563 {
564 "webui-task-manager",
565 IDS_FLAGS_WEBUI_TASK_MANAGER_NAME,
566 IDS_FLAGS_WEBUI_TASK_MANAGER_DESCRIPTION,
567 kOsAll,
568 SINGLE_VALUE_TYPE(switches::kWebUITaskManager)
569 },
[email protected]156f966332012-02-29 00:03:16570 {
[email protected]3e8befc2012-03-13 01:17:03571 "disable-ntp-other-sessions-menu",
[email protected]156f966332012-02-29 00:03:16572 IDS_FLAGS_NTP_OTHER_SESSIONS_MENU_NAME,
573 IDS_FLAGS_NTP_OTHER_SESSIONS_MENU_DESCRIPTION,
574 kOsAll,
[email protected]3e8befc2012-03-13 01:17:03575 SINGLE_VALUE_TYPE(switches::kDisableNTPOtherSessionsMenu)
[email protected]156f966332012-02-29 00:03:16576 },
[email protected]dc04be7c2012-03-15 23:57:49577#if defined(USE_ASH)
[email protected]31cf1c52012-02-29 20:55:01578 {
[email protected]3cd198a22012-03-12 20:38:01579 "enable-ash-oak",
580 IDS_FLAGS_ENABLE_ASH_OAK_NAME,
581 IDS_FLAGS_ENABLE_ASH_OAK_DESCRIPTION,
582 kOsAll,
583 SINGLE_VALUE_TYPE(ash::switches::kAshEnableOak),
584 },
[email protected]31cf1c52012-02-29 20:55:01585#endif
[email protected]184ec592012-03-01 11:54:28586 {
587 "enable-devtools-experiments",
588 IDS_FLAGS_ENABLE_DEVTOOLS_EXPERIMENTS_NAME,
589 IDS_FLAGS_ENABLE_DEVTOOLS_EXPERIMENTS_DESCRIPTION,
590 kOsAll,
591 SINGLE_VALUE_TYPE(switches::kEnableDevToolsExperiments)
592 },
[email protected]76d1854e2012-03-02 23:57:44593 {
594 "enable-suggestions-ntp",
595 IDS_FLAGS_NTP_SUGGESTIONS_PAGE_NAME,
596 IDS_FLAGS_NTP_SUGGESTIONS_PAGE_DESCRIPTION,
597 kOsAll,
598 SINGLE_VALUE_TYPE(switches::kEnableSuggestionsTabPage)
599 },
[email protected]a78ef9e2012-03-21 02:49:55600 {
[email protected]0b777be22012-04-03 04:42:24601 "disable-chrome-to-mobile", // FLAGS:RECORD_UMA
602 IDS_FLAGS_DISABLE_CHROME_TO_MOBILE_NAME,
603 IDS_FLAGS_DISABLE_CHROME_TO_MOBILE_DESCRIPTION,
[email protected]a78ef9e2012-03-21 02:49:55604 kOsAll,
[email protected]0b777be22012-04-03 04:42:24605 SINGLE_VALUE_TYPE(switches::kDisableChromeToMobile)
[email protected]a78ef9e2012-03-21 02:49:55606 },
[email protected]a3d54252012-04-05 20:04:13607#if defined(GOOGLE_CHROME_BUILD)
608 {
609 "enable-asynchronous-spellchecking",
610 IDS_FLAGS_ENABLE_ASYNCHRONOUS_SPELLCHECKING,
611 IDS_FLAGS_ENABLE_ASYNCHRONOUS_SPELLCHECKING_DESCRIPTION,
612 kOsAll,
613 SINGLE_VALUE_TYPE(switches::kEnableAsynchronousSpellChecking)
614 },
615#endif
[email protected]c9c73ad42012-04-18 03:35:59616 {
617 "touch-optimized-ui",
618 IDS_TOUCH_OPTIMIZED_UI_NAME,
619 IDS_TOUCH_OPTIMIZED_UI_DESCRIPTION,
620 kOsAll,
621 SINGLE_VALUE_TYPE(switches::kTouchOptimizedUI)
622 },
[email protected]0b60afa2012-04-19 17:36:39623#if defined(OS_CHROMEOS)
624 {
625 "no-discard-tabs",
626 IDS_FLAGS_NO_DISCARD_TABS_NAME,
627 IDS_FLAGS_NO_DISCARD_TABS_DESCRIPTION,
628 kOsCrOS,
629 SINGLE_VALUE_TYPE(switches::kNoDiscardTabs)
630 },
631#endif
[email protected]a0e4b072011-08-17 01:47:07632};
[email protected]ad2a3ded2010-08-27 13:19:05633
[email protected]a314ee5a2010-10-26 21:23:28634const Experiment* experiments = kExperiments;
635size_t num_experiments = arraysize(kExperiments);
636
[email protected]e2ddbc92010-10-15 20:02:07637// Stores and encapsulates the little state that about:flags has.
638class FlagsState {
639 public:
640 FlagsState() : needs_restart_(false) {}
641 void ConvertFlagsToSwitches(PrefService* prefs, CommandLine* command_line);
642 bool IsRestartNeededToCommitChanges();
643 void SetExperimentEnabled(
[email protected]a314ee5a2010-10-26 21:23:28644 PrefService* prefs, const std::string& internal_name, bool enable);
[email protected]e2ddbc92010-10-15 20:02:07645 void RemoveFlagsSwitches(
646 std::map<std::string, CommandLine::StringType>* switch_list);
647 void reset();
648
649 // Returns the singleton instance of this class
[email protected]8e8bb6d2010-12-13 08:18:55650 static FlagsState* GetInstance() {
[email protected]e2ddbc92010-10-15 20:02:07651 return Singleton<FlagsState>::get();
652 }
653
654 private:
655 bool needs_restart_;
[email protected]a82744532011-02-11 16:15:53656 std::map<std::string, std::string> flags_switches_;
[email protected]e2ddbc92010-10-15 20:02:07657
658 DISALLOW_COPY_AND_ASSIGN(FlagsState);
659};
660
[email protected]c7b7800a2010-10-07 18:51:35661// Extracts the list of enabled lab experiments from preferences and stores them
[email protected]ad2a3ded2010-08-27 13:19:05662// in a set.
[email protected]1a47d7e2010-10-15 00:37:24663void GetEnabledFlags(const PrefService* prefs, std::set<std::string>* result) {
[email protected]ad2a3ded2010-08-27 13:19:05664 const ListValue* enabled_experiments = prefs->GetList(
665 prefs::kEnabledLabsExperiments);
666 if (!enabled_experiments)
667 return;
668
669 for (ListValue::const_iterator it = enabled_experiments->begin();
670 it != enabled_experiments->end();
671 ++it) {
672 std::string experiment_name;
673 if (!(*it)->GetAsString(&experiment_name)) {
674 LOG(WARNING) << "Invalid entry in " << prefs::kEnabledLabsExperiments;
675 continue;
676 }
677 result->insert(experiment_name);
678 }
679}
680
681// Takes a set of enabled lab experiments
[email protected]1a47d7e2010-10-15 00:37:24682void SetEnabledFlags(
[email protected]ad2a3ded2010-08-27 13:19:05683 PrefService* prefs, const std::set<std::string>& enabled_experiments) {
[email protected]1bc78422011-03-31 08:41:38684 ListPrefUpdate update(prefs, prefs::kEnabledLabsExperiments);
685 ListValue* experiments_list = update.Get();
[email protected]ad2a3ded2010-08-27 13:19:05686
687 experiments_list->Clear();
688 for (std::set<std::string>::const_iterator it = enabled_experiments.begin();
689 it != enabled_experiments.end();
690 ++it) {
691 experiments_list->Append(new StringValue(*it));
692 }
693}
694
[email protected]8a6ff28d2010-12-02 16:35:19695// Returns the name used in prefs for the choice at the specified index.
696std::string NameForChoice(const Experiment& e, int index) {
[email protected]2ce9c89752011-02-25 18:24:34697 DCHECK_EQ(Experiment::MULTI_VALUE, e.type);
698 DCHECK_LT(index, e.num_choices);
[email protected]8a6ff28d2010-12-02 16:35:19699 return std::string(e.internal_name) + about_flags::testing::kMultiSeparator +
700 base::IntToString(index);
701}
702
703// Adds the internal names for the specified experiment to |names|.
704void AddInternalName(const Experiment& e, std::set<std::string>* names) {
705 if (e.type == Experiment::SINGLE_VALUE) {
706 names->insert(e.internal_name);
707 } else {
[email protected]2ce9c89752011-02-25 18:24:34708 DCHECK_EQ(Experiment::MULTI_VALUE, e.type);
[email protected]8a6ff28d2010-12-02 16:35:19709 for (int i = 0; i < e.num_choices; ++i)
710 names->insert(NameForChoice(e, i));
711 }
712}
713
[email protected]28e35af2011-02-09 12:56:22714// Confirms that an experiment is valid, used in a DCHECK in
715// SanitizeList below.
716bool ValidateExperiment(const Experiment& e) {
717 switch (e.type) {
718 case Experiment::SINGLE_VALUE:
719 DCHECK_EQ(0, e.num_choices);
720 DCHECK(!e.choices);
721 break;
722 case Experiment::MULTI_VALUE:
723 DCHECK_GT(e.num_choices, 0);
724 DCHECK(e.choices);
[email protected]a82744532011-02-11 16:15:53725 DCHECK(e.choices[0].command_line_switch);
726 DCHECK_EQ('\0', e.choices[0].command_line_switch[0]);
[email protected]28e35af2011-02-09 12:56:22727 break;
728 default:
729 NOTREACHED();
730 }
731 return true;
732}
733
[email protected]ad2a3ded2010-08-27 13:19:05734// Removes all experiments from prefs::kEnabledLabsExperiments that are
735// unknown, to prevent this list to become very long as experiments are added
736// and removed.
737void SanitizeList(PrefService* prefs) {
738 std::set<std::string> known_experiments;
[email protected]28e35af2011-02-09 12:56:22739 for (size_t i = 0; i < num_experiments; ++i) {
740 DCHECK(ValidateExperiment(experiments[i]));
[email protected]8a6ff28d2010-12-02 16:35:19741 AddInternalName(experiments[i], &known_experiments);
[email protected]28e35af2011-02-09 12:56:22742 }
[email protected]ad2a3ded2010-08-27 13:19:05743
744 std::set<std::string> enabled_experiments;
[email protected]1a47d7e2010-10-15 00:37:24745 GetEnabledFlags(prefs, &enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05746
747 std::set<std::string> new_enabled_experiments;
748 std::set_intersection(
749 known_experiments.begin(), known_experiments.end(),
750 enabled_experiments.begin(), enabled_experiments.end(),
751 std::inserter(new_enabled_experiments, new_enabled_experiments.begin()));
752
[email protected]1a47d7e2010-10-15 00:37:24753 SetEnabledFlags(prefs, new_enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05754}
755
[email protected]1a47d7e2010-10-15 00:37:24756void GetSanitizedEnabledFlags(
[email protected]ad2a3ded2010-08-27 13:19:05757 PrefService* prefs, std::set<std::string>* result) {
758 SanitizeList(prefs);
[email protected]1a47d7e2010-10-15 00:37:24759 GetEnabledFlags(prefs, result);
[email protected]ad2a3ded2010-08-27 13:19:05760}
761
[email protected]a314ee5a2010-10-26 21:23:28762// Variant of GetSanitizedEnabledFlags that also removes any flags that aren't
763// enabled on the current platform.
764void GetSanitizedEnabledFlagsForCurrentPlatform(
765 PrefService* prefs, std::set<std::string>* result) {
766 GetSanitizedEnabledFlags(prefs, result);
767
768 // Filter out any experiments that aren't enabled on the current platform. We
769 // don't remove these from prefs else syncing to a platform with a different
770 // set of experiments would be lossy.
771 std::set<std::string> platform_experiments;
772 int current_platform = GetCurrentPlatform();
773 for (size_t i = 0; i < num_experiments; ++i) {
774 if (experiments[i].supported_platforms & current_platform)
[email protected]8a6ff28d2010-12-02 16:35:19775 AddInternalName(experiments[i], &platform_experiments);
[email protected]a314ee5a2010-10-26 21:23:28776 }
777
778 std::set<std::string> new_enabled_experiments;
779 std::set_intersection(
780 platform_experiments.begin(), platform_experiments.end(),
781 result->begin(), result->end(),
782 std::inserter(new_enabled_experiments, new_enabled_experiments.begin()));
783
784 result->swap(new_enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05785}
786
[email protected]8a6ff28d2010-12-02 16:35:19787// Returns the Value representing the choice data in the specified experiment.
[email protected]8a6ff28d2010-12-02 16:35:19788Value* CreateChoiceData(const Experiment& experiment,
[email protected]28e35af2011-02-09 12:56:22789 const std::set<std::string>& enabled_experiments) {
[email protected]2ce9c89752011-02-25 18:24:34790 DCHECK_EQ(Experiment::MULTI_VALUE, experiment.type);
[email protected]8a6ff28d2010-12-02 16:35:19791 ListValue* result = new ListValue;
792 for (int i = 0; i < experiment.num_choices; ++i) {
793 const Experiment::Choice& choice = experiment.choices[i];
794 DictionaryValue* value = new DictionaryValue;
795 std::string name = NameForChoice(experiment, i);
796 value->SetString("description",
797 l10n_util::GetStringUTF16(choice.description_id));
798 value->SetString("internal_name", name);
[email protected]28e35af2011-02-09 12:56:22799 value->SetBoolean("selected", enabled_experiments.count(name) > 0);
[email protected]8a6ff28d2010-12-02 16:35:19800 result->Append(value);
801 }
802 return result;
803}
804
[email protected]e2ddbc92010-10-15 20:02:07805} // namespace
806
[email protected]1a47d7e2010-10-15 00:37:24807void ConvertFlagsToSwitches(PrefService* prefs, CommandLine* command_line) {
[email protected]8e8bb6d2010-12-13 08:18:55808 FlagsState::GetInstance()->ConvertFlagsToSwitches(prefs, command_line);
[email protected]ad2a3ded2010-08-27 13:19:05809}
810
[email protected]1a47d7e2010-10-15 00:37:24811ListValue* GetFlagsExperimentsData(PrefService* prefs) {
[email protected]ad2a3ded2010-08-27 13:19:05812 std::set<std::string> enabled_experiments;
[email protected]1a47d7e2010-10-15 00:37:24813 GetSanitizedEnabledFlags(prefs, &enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05814
815 int current_platform = GetCurrentPlatform();
816
817 ListValue* experiments_data = new ListValue();
[email protected]a314ee5a2010-10-26 21:23:28818 for (size_t i = 0; i < num_experiments; ++i) {
819 const Experiment& experiment = experiments[i];
[email protected]ad2a3ded2010-08-27 13:19:05820
821 DictionaryValue* data = new DictionaryValue();
822 data->SetString("internal_name", experiment.internal_name);
823 data->SetString("name",
824 l10n_util::GetStringUTF16(experiment.visible_name_id));
825 data->SetString("description",
826 l10n_util::GetStringUTF16(
827 experiment.visible_description_id));
[email protected]cc3e2052011-12-20 01:01:40828 bool supported = !!(experiment.supported_platforms & current_platform);
829 data->SetBoolean("supported", supported);
830
831 ListValue* supported_platforms = new ListValue();
832 AddOsStrings(experiment.supported_platforms, supported_platforms);
833 data->Set("supported_platforms", supported_platforms);
[email protected]ad2a3ded2010-08-27 13:19:05834
[email protected]28e35af2011-02-09 12:56:22835 switch (experiment.type) {
836 case Experiment::SINGLE_VALUE:
837 data->SetBoolean(
838 "enabled",
839 enabled_experiments.count(experiment.internal_name) > 0);
840 break;
841 case Experiment::MULTI_VALUE:
842 data->Set("choices", CreateChoiceData(experiment, enabled_experiments));
843 break;
844 default:
845 NOTREACHED();
[email protected]8a6ff28d2010-12-02 16:35:19846 }
847
[email protected]ad2a3ded2010-08-27 13:19:05848 experiments_data->Append(data);
849 }
850 return experiments_data;
851}
852
[email protected]ad2a3ded2010-08-27 13:19:05853bool IsRestartNeededToCommitChanges() {
[email protected]8e8bb6d2010-12-13 08:18:55854 return FlagsState::GetInstance()->IsRestartNeededToCommitChanges();
[email protected]ad2a3ded2010-08-27 13:19:05855}
856
857void SetExperimentEnabled(
[email protected]c7b7800a2010-10-07 18:51:35858 PrefService* prefs, const std::string& internal_name, bool enable) {
[email protected]8e8bb6d2010-12-13 08:18:55859 FlagsState::GetInstance()->SetExperimentEnabled(prefs, internal_name, enable);
[email protected]e2ddbc92010-10-15 20:02:07860}
861
862void RemoveFlagsSwitches(
863 std::map<std::string, CommandLine::StringType>* switch_list) {
[email protected]8e8bb6d2010-12-13 08:18:55864 FlagsState::GetInstance()->RemoveFlagsSwitches(switch_list);
[email protected]e2ddbc92010-10-15 20:02:07865}
866
[email protected]a314ee5a2010-10-26 21:23:28867int GetCurrentPlatform() {
868#if defined(OS_MACOSX)
869 return kOsMac;
870#elif defined(OS_WIN)
871 return kOsWin;
872#elif defined(OS_CHROMEOS) // Needs to be before the OS_LINUX check.
873 return kOsCrOS;
[email protected]c92f4ed2011-10-21 19:50:21874#elif defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]a314ee5a2010-10-26 21:23:28875 return kOsLinux;
[email protected]9c7453d2012-01-21 00:45:40876#elif defined(OS_ANDROID)
877 return kOsAndroid;
[email protected]a314ee5a2010-10-26 21:23:28878#else
879#error Unknown platform
880#endif
881}
882
[email protected]4bc5050c2010-11-18 17:55:54883void RecordUMAStatistics(const PrefService* prefs) {
884 std::set<std::string> flags;
885 GetEnabledFlags(prefs, &flags);
886 for (std::set<std::string>::iterator it = flags.begin(); it != flags.end();
887 ++it) {
888 std::string action("AboutFlags_");
889 action += *it;
[email protected]7f6f44c2011-12-14 13:23:38890 content::RecordComputedAction(action);
[email protected]4bc5050c2010-11-18 17:55:54891 }
892 // Since flag metrics are recorded every startup, add a tick so that the
893 // stats can be made meaningful.
894 if (flags.size())
[email protected]7f6f44c2011-12-14 13:23:38895 content::RecordAction(UserMetricsAction("AboutFlags_StartupTick"));
896 content::RecordAction(UserMetricsAction("StartupTick"));
[email protected]4bc5050c2010-11-18 17:55:54897}
898
[email protected]e2ddbc92010-10-15 20:02:07899//////////////////////////////////////////////////////////////////////////////
900// FlagsState implementation.
901
902namespace {
903
904void FlagsState::ConvertFlagsToSwitches(
905 PrefService* prefs, CommandLine* command_line) {
[email protected]e2ddbc92010-10-15 20:02:07906 if (command_line->HasSwitch(switches::kNoExperiments))
907 return;
908
909 std::set<std::string> enabled_experiments;
[email protected]ba8164242010-11-16 21:31:00910
[email protected]a314ee5a2010-10-26 21:23:28911 GetSanitizedEnabledFlagsForCurrentPlatform(prefs, &enabled_experiments);
[email protected]e2ddbc92010-10-15 20:02:07912
[email protected]a82744532011-02-11 16:15:53913 typedef std::map<std::string, std::pair<std::string, std::string> >
914 NameToSwitchAndValueMap;
915 NameToSwitchAndValueMap name_to_switch_map;
[email protected]8a6ff28d2010-12-02 16:35:19916 for (size_t i = 0; i < num_experiments; ++i) {
917 const Experiment& e = experiments[i];
918 if (e.type == Experiment::SINGLE_VALUE) {
[email protected]a82744532011-02-11 16:15:53919 name_to_switch_map[e.internal_name] =
920 std::pair<std::string, std::string>(e.command_line_switch,
921 e.command_line_value);
[email protected]8a6ff28d2010-12-02 16:35:19922 } else {
923 for (int j = 0; j < e.num_choices; ++j)
[email protected]a82744532011-02-11 16:15:53924 name_to_switch_map[NameForChoice(e, j)] =
925 std::pair<std::string, std::string>(
926 e.choices[j].command_line_switch,
927 e.choices[j].command_line_value);
[email protected]8a6ff28d2010-12-02 16:35:19928 }
929 }
[email protected]e2ddbc92010-10-15 20:02:07930
931 command_line->AppendSwitch(switches::kFlagSwitchesBegin);
[email protected]a82744532011-02-11 16:15:53932 flags_switches_.insert(
933 std::pair<std::string, std::string>(switches::kFlagSwitchesBegin,
934 std::string()));
[email protected]e2ddbc92010-10-15 20:02:07935 for (std::set<std::string>::iterator it = enabled_experiments.begin();
936 it != enabled_experiments.end();
937 ++it) {
938 const std::string& experiment_name = *it;
[email protected]a82744532011-02-11 16:15:53939 NameToSwitchAndValueMap::const_iterator name_to_switch_it =
[email protected]8a6ff28d2010-12-02 16:35:19940 name_to_switch_map.find(experiment_name);
941 if (name_to_switch_it == name_to_switch_map.end()) {
942 NOTREACHED();
[email protected]e2ddbc92010-10-15 20:02:07943 continue;
[email protected]8a6ff28d2010-12-02 16:35:19944 }
[email protected]e2ddbc92010-10-15 20:02:07945
[email protected]a82744532011-02-11 16:15:53946 const std::pair<std::string, std::string>&
947 switch_and_value_pair = name_to_switch_it->second;
948
949 command_line->AppendSwitchASCII(switch_and_value_pair.first,
950 switch_and_value_pair.second);
951 flags_switches_[switch_and_value_pair.first] = switch_and_value_pair.second;
[email protected]e2ddbc92010-10-15 20:02:07952 }
953 command_line->AppendSwitch(switches::kFlagSwitchesEnd);
[email protected]a82744532011-02-11 16:15:53954 flags_switches_.insert(
955 std::pair<std::string, std::string>(switches::kFlagSwitchesEnd,
956 std::string()));
[email protected]e2ddbc92010-10-15 20:02:07957}
958
959bool FlagsState::IsRestartNeededToCommitChanges() {
960 return needs_restart_;
961}
962
963void FlagsState::SetExperimentEnabled(
964 PrefService* prefs, const std::string& internal_name, bool enable) {
[email protected]ad2a3ded2010-08-27 13:19:05965 needs_restart_ = true;
966
[email protected]8a6ff28d2010-12-02 16:35:19967 size_t at_index = internal_name.find(about_flags::testing::kMultiSeparator);
968 if (at_index != std::string::npos) {
969 DCHECK(enable);
970 // We're being asked to enable a multi-choice experiment. Disable the
971 // currently selected choice.
972 DCHECK_NE(at_index, 0u);
[email protected]28e35af2011-02-09 12:56:22973 const std::string experiment_name = internal_name.substr(0, at_index);
974 SetExperimentEnabled(prefs, experiment_name, false);
[email protected]8a6ff28d2010-12-02 16:35:19975
[email protected]28e35af2011-02-09 12:56:22976 // And enable the new choice, if it is not the default first choice.
977 if (internal_name != experiment_name + "@0") {
978 std::set<std::string> enabled_experiments;
979 GetSanitizedEnabledFlags(prefs, &enabled_experiments);
980 enabled_experiments.insert(internal_name);
981 SetEnabledFlags(prefs, enabled_experiments);
982 }
[email protected]8a6ff28d2010-12-02 16:35:19983 return;
984 }
985
[email protected]ad2a3ded2010-08-27 13:19:05986 std::set<std::string> enabled_experiments;
[email protected]1a47d7e2010-10-15 00:37:24987 GetSanitizedEnabledFlags(prefs, &enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05988
[email protected]8a6ff28d2010-12-02 16:35:19989 const Experiment* e = NULL;
990 for (size_t i = 0; i < num_experiments; ++i) {
991 if (experiments[i].internal_name == internal_name) {
992 e = experiments + i;
993 break;
994 }
995 }
996 DCHECK(e);
997
998 if (e->type == Experiment::SINGLE_VALUE) {
[email protected]8a2713682011-08-19 10:36:59999 if (enable)
[email protected]8a6ff28d2010-12-02 16:35:191000 enabled_experiments.insert(internal_name);
[email protected]8a2713682011-08-19 10:36:591001 else
[email protected]8a6ff28d2010-12-02 16:35:191002 enabled_experiments.erase(internal_name);
1003 } else {
1004 if (enable) {
1005 // Enable the first choice.
1006 enabled_experiments.insert(NameForChoice(*e, 0));
1007 } else {
1008 // Find the currently enabled choice and disable it.
1009 for (int i = 0; i < e->num_choices; ++i) {
1010 std::string choice_name = NameForChoice(*e, i);
1011 if (enabled_experiments.find(choice_name) !=
1012 enabled_experiments.end()) {
1013 enabled_experiments.erase(choice_name);
1014 // Continue on just in case there's a bug and more than one
1015 // experiment for this choice was enabled.
1016 }
1017 }
1018 }
1019 }
[email protected]ad2a3ded2010-08-27 13:19:051020
[email protected]1a47d7e2010-10-15 00:37:241021 SetEnabledFlags(prefs, enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:051022}
1023
[email protected]e2ddbc92010-10-15 20:02:071024void FlagsState::RemoveFlagsSwitches(
1025 std::map<std::string, CommandLine::StringType>* switch_list) {
[email protected]a82744532011-02-11 16:15:531026 for (std::map<std::string, std::string>::const_iterator
1027 it = flags_switches_.begin(); it != flags_switches_.end(); ++it) {
1028 switch_list->erase(it->first);
[email protected]e2ddbc92010-10-15 20:02:071029 }
1030}
1031
1032void FlagsState::reset() {
1033 needs_restart_ = false;
1034 flags_switches_.clear();
1035}
1036
[email protected]38e46812011-05-09 20:49:221037} // namespace
[email protected]e2ddbc92010-10-15 20:02:071038
1039namespace testing {
[email protected]8a6ff28d2010-12-02 16:35:191040
1041// WARNING: '@' is also used in the html file. If you update this constant you
1042// also need to update the html file.
1043const char kMultiSeparator[] = "@";
1044
[email protected]e2ddbc92010-10-15 20:02:071045void ClearState() {
[email protected]8e8bb6d2010-12-13 08:18:551046 FlagsState::GetInstance()->reset();
[email protected]e2ddbc92010-10-15 20:02:071047}
[email protected]a314ee5a2010-10-26 21:23:281048
1049void SetExperiments(const Experiment* e, size_t count) {
1050 if (!e) {
1051 experiments = kExperiments;
1052 num_experiments = arraysize(kExperiments);
1053 } else {
1054 experiments = e;
1055 num_experiments = count;
1056 }
1057}
1058
[email protected]8a6ff28d2010-12-02 16:35:191059const Experiment* GetExperiments(size_t* count) {
1060 *count = num_experiments;
1061 return experiments;
1062}
1063
[email protected]e2ddbc92010-10-15 20:02:071064} // namespace testing
1065
[email protected]1a47d7e2010-10-15 00:37:241066} // namespace about_flags