blob: fb9d002fa7cfd58021b2a1e46342fe2f65eb3ec1 [file] [log] [blame]
[email protected]9c66adc2012-01-05 02:10:161// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]ad2a3ded2010-08-27 13:19:052// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]1a47d7e2010-10-15 00:37:245#include "chrome/browser/about_flags.h"
[email protected]ad2a3ded2010-08-27 13:19:056
7#include <algorithm>
8#include <iterator>
9#include <map>
10#include <set>
11
[email protected]ad2a3ded2010-08-27 13:19:0512#include "base/command_line.h"
[email protected]3b63f8f42011-03-28 01:54:1513#include "base/memory/singleton.h"
[email protected]8a6ff28d2010-12-02 16:35:1914#include "base/string_number_conversions.h"
[email protected]d208f4d82011-05-23 21:52:0315#include "base/utf_string_conversions.h"
[email protected]ad2a3ded2010-08-27 13:19:0516#include "base/values.h"
[email protected]ad2a3ded2010-08-27 13:19:0517#include "chrome/browser/prefs/pref_service.h"
[email protected]1bc78422011-03-31 08:41:3818#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]d208f4d82011-05-23 21:52:0319#include "chrome/common/chrome_content_client.h"
[email protected]ad2a3ded2010-08-27 13:19:0520#include "chrome/common/chrome_switches.h"
21#include "chrome/common/pref_names.h"
[email protected]7f6f44c2011-12-14 13:23:3822#include "content/public/browser/user_metrics.h"
[email protected]ad2a3ded2010-08-27 13:19:0523#include "grit/generated_resources.h"
[email protected]c051a1b2011-01-21 23:30:1724#include "ui/base/l10n/l10n_util.h"
[email protected]8ff7f342011-05-25 01:49:4725#include "ui/gfx/gl/gl_switches.h"
[email protected]ad2a3ded2010-08-27 13:19:0526
[email protected]8cc10df2011-11-03 23:57:5027#if defined(USE_AURA)
[email protected]b65bdda2011-12-23 23:35:3128#include "ash/ash_switches.h"
[email protected]8cc10df2011-11-03 23:57:5029#endif
30
[email protected]7f6f44c2011-12-14 13:23:3831using content::UserMetricsAction;
32
[email protected]1a47d7e2010-10-15 00:37:2433namespace about_flags {
[email protected]ad2a3ded2010-08-27 13:19:0534
[email protected]8a6ff28d2010-12-02 16:35:1935// Macros to simplify specifying the type.
[email protected]a82744532011-02-11 16:15:5336#define SINGLE_VALUE_TYPE_AND_VALUE(command_line_switch, switch_value) \
37 Experiment::SINGLE_VALUE, command_line_switch, switch_value, NULL, 0
38#define SINGLE_VALUE_TYPE(command_line_switch) \
39 SINGLE_VALUE_TYPE_AND_VALUE(command_line_switch, "")
40#define MULTI_VALUE_TYPE(choices) \
[email protected]0e6f56d2011-02-12 23:45:1541 Experiment::MULTI_VALUE, "", "", choices, arraysize(choices)
[email protected]8a6ff28d2010-12-02 16:35:1942
[email protected]e2ddbc92010-10-15 20:02:0743namespace {
44
[email protected]9c7453d2012-01-21 00:45:4045const unsigned kOsAll = kOsMac | kOsWin | kOsLinux | kOsCrOS | kOsAndroid;
[email protected]ad2a3ded2010-08-27 13:19:0546
[email protected]cc3e2052011-12-20 01:01:4047// Adds a |StringValue| to |list| for each platform where |bitmask| indicates
48// whether the experiment is available on that platform.
49void AddOsStrings(unsigned bitmask, ListValue* list) {
50 struct {
51 unsigned bit;
52 const char* const name;
53 } kBitsToOs[] = {
54 {kOsMac, "Mac"},
55 {kOsWin, "Windows"},
56 {kOsLinux, "Linux"},
57 {kOsCrOS, "Chrome OS"},
58 };
59 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kBitsToOs); ++i)
60 if (bitmask & kBitsToOs[i].bit)
61 list->Append(new StringValue(kBitsToOs[i].name));
62}
63
[email protected]ba8164242010-11-16 21:31:0064// Names for former Chrome OS Labs experiments, shared with prefs migration
65// code.
66const char kMediaPlayerExperimentName[] = "media-player";
67const char kAdvancedFileSystemExperimentName[] = "advanced-file-system";
68const char kVerticalTabsExperimentName[] = "vertical-tabs";
69
[email protected]9b2c9f6a12012-01-27 21:00:0570const Experiment::Choice kOmniboxAggressiveHistoryURLChoices[] = {
71 { IDS_FLAGS_OMNIBOX_AGGRESSIVE_HISTORY_URL_SCORING_AUTOMATIC, "", "" },
72 { IDS_FLAGS_OMNIBOX_AGGRESSIVE_HISTORY_URL_SCORING_ENABLED,
73 switches::kOmniboxAggressiveHistoryURL,
74 switches::kOmniboxAggressiveHistoryURLEnabled },
75 { IDS_FLAGS_OMNIBOX_AGGRESSIVE_HISTORY_URL_SCORING_DISABLED,
76 switches::kOmniboxAggressiveHistoryURL,
77 switches::kOmniboxAggressiveHistoryURLDisabled }
78};
79
[email protected]032d5e6c2012-02-17 17:53:5580const Experiment::Choice kOmniboxInlineHistoryQuickProviderChoices[] = {
81 { IDS_FLAGS_OMNIBOX_INLINE_HISTORY_QUICK_PROVIDER_AUTOMATIC, "", "" },
82 { IDS_FLAGS_OMNIBOX_INLINE_HISTORY_QUICK_PROVIDER_ALLOWED,
83 switches::kOmniboxInlineHistoryQuickProvider,
84 switches::kOmniboxInlineHistoryQuickProviderAllowed },
85 { IDS_FLAGS_OMNIBOX_INLINE_HISTORY_QUICK_PROVIDER_PROHIBITED,
86 switches::kOmniboxInlineHistoryQuickProvider,
87 switches::kOmniboxInlineHistoryQuickProviderProhibited }
88};
89
[email protected]3fbd9c12011-12-16 21:35:1190#if defined(USE_AURA)
91const Experiment::Choice kAuraWindowModeChoices[] = {
[email protected]9c66adc2012-01-05 02:10:1692 { IDS_FLAGS_AURA_WINDOW_MODE_AUTOMATIC, "", "" },
[email protected]3fbd9c12011-12-16 21:35:1193 { IDS_FLAGS_AURA_WINDOW_MODE_COMPACT,
[email protected]d2840ef2012-02-01 05:10:3694 ash::switches::kAuraWindowMode,
95 ash::switches::kAuraWindowModeCompact },
96 { IDS_FLAGS_AURA_WINDOW_MODE_MANAGED,
97 ash::switches::kAuraWindowMode,
98 ash::switches::kAuraWindowModeManaged },
99 { IDS_FLAGS_AURA_WINDOW_MODE_OVERLAPPING,
100 ash::switches::kAuraWindowMode,
101 ash::switches::kAuraWindowModeOverlapping },
[email protected]3fbd9c12011-12-16 21:35:11102};
103#endif
104
[email protected]4bc5050c2010-11-18 17:55:54105// RECORDING USER METRICS FOR FLAGS:
106// -----------------------------------------------------------------------------
107// The first line of the experiment is the internal name. If you'd like to
108// gather statistics about the usage of your flag, you should append a marker
109// comment to the end of the feature name, like so:
110// "my-special-feature", // FLAGS:RECORD_UMA
111//
112// After doing that, run //chrome/tools/extract_actions.py (see instructions at
113// the top of that file for details) to update the chromeactions.txt file, which
114// will enable UMA to record your feature flag.
115//
116// After your feature has shipped under a flag, you can locate the metrics
117// under the action name AboutFlags_internal-action-name. Actions are recorded
118// once per startup, so you should divide this number by AboutFlags_StartupTick
119// to get a sense of usage. Note that this will not be the same as number of
120// users with a given feature enabled because users can quit and relaunch
121// the application multiple times over a given time interval.
122// TODO(rsesek): See if there's a way to count per-user, rather than
123// per-startup.
124
[email protected]8a6ff28d2010-12-02 16:35:19125// To add a new experiment add to the end of kExperiments. There are two
126// distinct types of experiments:
127// . SINGLE_VALUE: experiment is either on or off. Use the SINGLE_VALUE_TYPE
128// macro for this type supplying the command line to the macro.
[email protected]28e35af2011-02-09 12:56:22129// . MULTI_VALUE: a list of choices, the first of which should correspond to a
130// deactivated state for this lab (i.e. no command line option). To specify
131// this type of experiment use the macro MULTI_VALUE_TYPE supplying it the
132// array of choices.
[email protected]8a6ff28d2010-12-02 16:35:19133// See the documentation of Experiment for details on the fields.
134//
135// When adding a new choice, add it to the end of the list.
[email protected]ad2a3ded2010-08-27 13:19:05136const Experiment kExperiments[] = {
137 {
[email protected]aac169d2011-03-18 19:53:03138 "expose-for-tabs", // FLAGS:RECORD_UMA
139 IDS_FLAGS_TABPOSE_NAME,
140 IDS_FLAGS_TABPOSE_DESCRIPTION,
141 kOsMac,
142#if defined(OS_MACOSX)
143 // The switch exists only on OS X.
144 SINGLE_VALUE_TYPE(switches::kEnableExposeForTabs)
145#else
146 SINGLE_VALUE_TYPE("")
147#endif
148 },
149 {
[email protected]4bc5050c2010-11-18 17:55:54150 "conflicting-modules-check", // FLAGS:RECORD_UMA
[email protected]c1bbaa82010-11-08 11:17:05151 IDS_FLAGS_CONFLICTS_CHECK_NAME,
152 IDS_FLAGS_CONFLICTS_CHECK_DESCRIPTION,
153 kOsWin,
[email protected]8a6ff28d2010-12-02 16:35:19154 SINGLE_VALUE_TYPE(switches::kConflictingModulesCheck)
[email protected]c1bbaa82010-11-08 11:17:05155 },
156 {
[email protected]4bc5050c2010-11-18 17:55:54157 "cloud-print-proxy", // FLAGS:RECORD_UMA
[email protected]dae7325b2011-12-21 20:56:54158 IDS_FLAGS_CLOUD_PRINT_CONNECTOR_NAME,
159 IDS_FLAGS_CLOUD_PRINT_CONNECTOR_DESCRIPTION,
[email protected]9f8872b32011-03-04 19:44:45160 // For a Chrome build, we know we have a PDF plug-in on Windows, so it's
[email protected]4fa24bf2011-08-20 02:15:22161 // fully enabled.
[email protected]5d10d57d2011-07-22 22:16:31162 // Otherwise, where we know Windows could be working if a viable PDF
[email protected]4fa24bf2011-08-20 02:15:22163 // plug-in could be supplied, we'll keep the lab enabled. Mac and Linux
164 // always have PDF rasterization available, so no flag needed there.
165#if !defined(GOOGLE_CHROME_BUILD)
166 kOsWin,
167#else
168 0,
[email protected]fa6d2a2f2010-11-30 21:47:19169#endif
[email protected]8a6ff28d2010-12-02 16:35:19170 SINGLE_VALUE_TYPE(switches::kEnableCloudPrintProxy)
[email protected]8b6588a2010-10-12 02:39:42171 },
[email protected]580939a2010-10-12 18:54:37172 {
[email protected]bb461532010-11-26 21:50:23173 "crxless-web-apps",
174 IDS_FLAGS_CRXLESS_WEB_APPS_NAME,
175 IDS_FLAGS_CRXLESS_WEB_APPS_DESCRIPTION,
176 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19177 SINGLE_VALUE_TYPE(switches::kEnableCrxlessWebApps)
[email protected]bb461532010-11-26 21:50:23178 },
179 {
[email protected]96c6f4c2011-05-18 19:36:22180 "ignore-gpu-blacklist",
181 IDS_FLAGS_IGNORE_GPU_BLACKLIST_NAME,
182 IDS_FLAGS_IGNORE_GPU_BLACKLIST_DESCRIPTION,
183 kOsAll,
184 SINGLE_VALUE_TYPE(switches::kIgnoreGpuBlacklist)
185 },
186 {
[email protected]0110cf112011-07-02 00:39:43187 "force-compositing-mode-2",
[email protected]96c6f4c2011-05-18 19:36:22188 IDS_FLAGS_FORCE_COMPOSITING_MODE_NAME,
189 IDS_FLAGS_FORCE_COMPOSITING_MODE_DESCRIPTION,
190 kOsAll,
191 SINGLE_VALUE_TYPE(switches::kForceCompositingMode)
192 },
193 {
[email protected]5963b772011-02-09 22:55:38194 "composited-layer-borders",
195 IDS_FLAGS_COMPOSITED_LAYER_BORDERS,
196 IDS_FLAGS_COMPOSITED_LAYER_BORDERS_DESCRIPTION,
197 kOsAll,
198 SINGLE_VALUE_TYPE(switches::kShowCompositedLayerBorders)
199 },
200 {
[email protected]a8f1eaa2011-03-07 19:00:58201 "show-fps-counter",
202 IDS_FLAGS_SHOW_FPS_COUNTER,
203 IDS_FLAGS_SHOW_FPS_COUNTER_DESCRIPTION,
204 kOsAll,
205 SINGLE_VALUE_TYPE(switches::kShowFPSCounter)
206 },
[email protected]8ff7f342011-05-25 01:49:47207 {
[email protected]70c98a332011-12-21 20:51:52208 "accelerated-filters",
209 IDS_FLAGS_ACCELERATED_FILTERS,
210 IDS_FLAGS_ACCELERATED_FILTERS_DESCRIPTION,
211 kOsAll,
212 SINGLE_VALUE_TYPE(switches::kEnableAcceleratedFilters)
213 },
214 {
[email protected]8ff7f342011-05-25 01:49:47215 "disable-gpu-vsync",
216 IDS_FLAGS_DISABLE_GPU_VSYNC_NAME,
217 IDS_FLAGS_DISABLE_GPU_VSYNC_DESCRIPTION,
218 kOsAll,
219 SINGLE_VALUE_TYPE(switches::kDisableGpuVsync)
220 },
[email protected]deaba6d52011-09-23 14:47:12221 {
222 "disable-webgl",
223 IDS_FLAGS_DISABLE_WEBGL_NAME,
224 IDS_FLAGS_DISABLE_WEBGL_DESCRIPTION,
225 kOsAll,
226 SINGLE_VALUE_TYPE(switches::kDisableExperimentalWebGL)
227 },
[email protected]eb00a762012-01-18 07:29:28228
229#if defined(GOOGLE_CHROME_BUILD)
230 // TODO(thestig) Remove this for bug 107600.
231 {
232 "disable-print-preview", // FLAGS:RECORD_UMA
233 IDS_FLAGS_DISABLE_PRINT_PREVIEW_NAME,
234 IDS_FLAGS_DISABLE_PRINT_PREVIEW_DESCRIPTION,
235 kOsAll,
236 SINGLE_VALUE_TYPE(switches::kDisablePrintPreview)
237 },
238#else
239 // For Chromium builds where users may not have the PDF plugin.
[email protected]8d260e52010-10-13 01:03:05240 {
[email protected]4bc5050c2010-11-18 17:55:54241 "print-preview", // FLAGS:RECORD_UMA
[email protected]9486c1f2010-10-14 19:52:12242 IDS_FLAGS_PRINT_PREVIEW_NAME,
243 IDS_FLAGS_PRINT_PREVIEW_DESCRIPTION,
[email protected]b579afd2011-07-13 00:01:27244 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19245 SINGLE_VALUE_TYPE(switches::kEnablePrintPreview)
[email protected]2fe15fcb2010-10-21 20:39:53246 },
[email protected]eb00a762012-01-18 07:29:28247#endif
248
[email protected]d208f4d82011-05-23 21:52:03249 // TODO(dspringer): When NaCl is on by default, remove this flag entry.
[email protected]2fe15fcb2010-10-21 20:39:53250 {
[email protected]e3791ce92011-08-09 01:03:32251 "enable-nacl", // FLAGS:RECORD_UMA
[email protected]4ff87d202010-11-06 01:28:40252 IDS_FLAGS_ENABLE_NACL_NAME,
253 IDS_FLAGS_ENABLE_NACL_DESCRIPTION,
254 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19255 SINGLE_VALUE_TYPE(switches::kEnableNaCl)
[email protected]4ff87d202010-11-06 01:28:40256 },
[email protected]b39c6d92012-01-31 16:38:41257 // TODO(halyavin): When exception handling is on by default, replace this
258 // flag with disable-nacl-exception-handling.
259 {
260 "enable-nacl-exception-handling", // FLAGS:RECORD_UMA
261 IDS_FLAGS_ENABLE_NACL_EXCEPTION_HANDLING_NAME,
262 IDS_FLAGS_ENABLE_NACL_EXCEPTION_HANDLING_DESCRIPTION,
263 kOsWin,
264 SINGLE_VALUE_TYPE(switches::kEnableNaClExceptionHandling)
265 },
[email protected]4ff87d202010-11-06 01:28:40266 {
[email protected]4bc5050c2010-11-18 17:55:54267 "extension-apis", // FLAGS:RECORD_UMA
[email protected]11dd68cd52010-11-12 01:15:32268 IDS_FLAGS_EXPERIMENTAL_EXTENSION_APIS_NAME,
269 IDS_FLAGS_EXPERIMENTAL_EXTENSION_APIS_DESCRIPTION,
270 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19271 SINGLE_VALUE_TYPE(switches::kEnableExperimentalExtensionApis)
[email protected]11dd68cd52010-11-12 01:15:32272 },
[email protected]3627b06d2010-11-12 16:36:16273 {
[email protected]cbe224d2011-08-04 22:12:49274 "apps-new-install-bubble",
275 IDS_FLAGS_APPS_NEW_INSTALL_BUBBLE_NAME,
276 IDS_FLAGS_APPS_NEW_INSTALL_BUBBLE_DESCRIPTION,
277 kOsAll,
278 SINGLE_VALUE_TYPE(switches::kAppsNewInstallBubble)
279 },
280 {
[email protected]80bd24e2010-11-30 09:34:38281 "disable-hyperlink-auditing",
282 IDS_FLAGS_DISABLE_HYPERLINK_AUDITING_NAME,
283 IDS_FLAGS_DISABLE_HYPERLINK_AUDITING_DESCRIPTION,
284 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19285 SINGLE_VALUE_TYPE(switches::kNoPings)
[email protected]feb28fef2010-12-01 10:52:51286 },
287 {
288 "experimental-location-features", // FLAGS:RECORD_UMA
289 IDS_FLAGS_EXPERIMENTAL_LOCATION_FEATURES_NAME,
290 IDS_FLAGS_EXPERIMENTAL_LOCATION_FEATURES_DESCRIPTION,
291 kOsMac | kOsWin | kOsLinux, // Currently does nothing on CrOS.
[email protected]8a6ff28d2010-12-02 16:35:19292 SINGLE_VALUE_TYPE(switches::kExperimentalLocationFeatures)
293 },
294 {
[email protected]04227962011-01-20 02:03:09295 "disable-interactive-form-validation",
296 IDS_FLAGS_DISABLE_INTERACTIVE_FORM_VALIDATION_NAME,
297 IDS_FLAGS_DISABLE_INTERACTIVE_FORM_VALIDATION_DESCRIPTION,
298 kOsAll,
299 SINGLE_VALUE_TYPE(switches::kDisableInteractiveFormValidation)
300 },
[email protected]8df51192011-01-22 20:05:03301 {
[email protected]07d490bc2011-03-07 17:05:26302 "focus-existing-tab-on-open", // FLAGS:RECORD_UMA
303 IDS_FLAGS_FOCUS_EXISTING_TAB_ON_OPEN_NAME,
304 IDS_FLAGS_FOCUS_EXISTING_TAB_ON_OPEN_DESCRIPTION,
305 kOsAll,
306 SINGLE_VALUE_TYPE(switches::kFocusExistingTabOnOpen)
307 },
[email protected]d5dcfb32011-03-19 00:49:24308 {
[email protected]5aea1862011-03-23 23:55:39309 "tab-groups-context-menu",
310 IDS_FLAGS_TAB_GROUPS_CONTEXT_MENU_NAME,
311 IDS_FLAGS_TAB_GROUPS_CONTEXT_MENU_DESCRIPTION,
312 kOsWin,
313 SINGLE_VALUE_TYPE(switches::kEnableTabGroupsContextMenu)
314 },
[email protected]e9bf9d92011-03-31 20:57:15315 {
[email protected]f2557bd2011-06-01 02:33:07316 "preload-instant-search",
317 IDS_FLAGS_PRELOAD_INSTANT_SEARCH_NAME,
318 IDS_FLAGS_PRELOAD_INSTANT_SEARCH_DESCRIPTION,
319 kOsAll,
320 SINGLE_VALUE_TYPE(switches::kPreloadInstantSearch)
321 },
[email protected]354e33b2011-06-15 00:29:10322 {
323 "static-ip-config",
324 IDS_FLAGS_STATIC_IP_CONFIG_NAME,
325 IDS_FLAGS_STATIC_IP_CONFIG_DESCRIPTION,
326 kOsCrOS,
327#if defined(OS_CHROMEOS)
328 // This switch exists only on Chrome OS.
329 SINGLE_VALUE_TYPE(switches::kEnableStaticIPConfig)
330#else
331 SINGLE_VALUE_TYPE("")
332#endif
333 },
[email protected]3eb5728c2011-06-20 22:32:24334 {
335 "show-autofill-type-predictions",
336 IDS_FLAGS_SHOW_AUTOFILL_TYPE_PREDICTIONS_NAME,
337 IDS_FLAGS_SHOW_AUTOFILL_TYPE_PREDICTIONS_DESCRIPTION,
338 kOsAll,
339 SINGLE_VALUE_TYPE(switches::kShowAutofillTypePredictions)
340 },
[email protected]bff4d3e2011-06-21 23:58:52341 {
[email protected]9a6180d7d2011-09-07 01:40:33342 "sync-tabs",
343 IDS_FLAGS_SYNC_TABS_NAME,
344 IDS_FLAGS_SYNC_TABS_DESCRIPTION,
[email protected]5b0ec7f2011-08-11 02:17:17345 kOsAll,
[email protected]9a6180d7d2011-09-07 01:40:33346 SINGLE_VALUE_TYPE(switches::kEnableSyncTabs)
[email protected]5b0ec7f2011-08-11 02:17:17347 },
348 {
[email protected]aae9eeb12011-10-21 21:59:26349 "sync-app-notifications",
350 IDS_FLAGS_SYNC_APP_NOTIFICATIONS_NAME,
351 IDS_FLAGS_SYNC_APP_NOTIFICATIONS_DESCRIPTION,
352 kOsAll,
[email protected]0b6fba82011-11-18 01:31:11353 SINGLE_VALUE_TYPE(switches::kDisableSyncAppNotifications)
[email protected]aae9eeb12011-10-21 21:59:26354 },
355 {
[email protected]a22ebd812011-06-23 00:05:39356 "enable-smooth-scrolling", // FLAGS:RECORD_UMA
357 IDS_FLAGS_ENABLE_SMOOTH_SCROLLING_NAME,
358 IDS_FLAGS_ENABLE_SMOOTH_SCROLLING_DESCRIPTION,
359 // Can't expose the switch unless the code is compiled in.
[email protected]554b7062011-09-03 03:09:40360 // On by default for the Mac (different implementation in WebKit).
[email protected]554b7062011-09-03 03:09:40361 kOsWin | kOsLinux | kOsCrOS,
[email protected]a22ebd812011-06-23 00:05:39362 SINGLE_VALUE_TYPE(switches::kEnableSmoothScrolling)
363 },
[email protected]81a6b0b2011-06-24 17:55:40364 {
[email protected]9b2c9f6a12012-01-27 21:00:05365 "omnibox-aggressive-with-history-url",
[email protected]ed1e39502011-12-16 14:39:35366 IDS_FLAGS_OMNIBOX_AGGRESSIVE_HISTORY_URL_SCORING_NAME,
367 IDS_FLAGS_OMNIBOX_AGGRESSIVE_HISTORY_URL_SCORING_DESCRIPTION,
368 kOsAll,
[email protected]9b2c9f6a12012-01-27 21:00:05369 MULTI_VALUE_TYPE(kOmniboxAggressiveHistoryURLChoices)
[email protected]ed1e39502011-12-16 14:39:35370 },
371 {
[email protected]032d5e6c2012-02-17 17:53:55372 "omnibox-inline-history-quick-provider",
373 IDS_FLAGS_OMNIBOX_INLINE_HISTORY_QUICK_PROVIDER_NAME,
374 IDS_FLAGS_OMNIBOX_INLINE_HISTORY_QUICK_PROVIDER_DESCRIPTION,
375 kOsAll,
376 MULTI_VALUE_TYPE(kOmniboxInlineHistoryQuickProviderChoices)
377 },
378 {
[email protected]7e7a28092011-12-09 22:24:55379 "enable-panels",
380 IDS_FLAGS_ENABLE_PANELS_NAME,
381 IDS_FLAGS_ENABLE_PANELS_DESCRIPTION,
[email protected]73fb1fc52011-07-09 00:06:54382 kOsAll,
[email protected]7e7a28092011-12-09 22:24:55383 SINGLE_VALUE_TYPE(switches::kEnablePanels)
[email protected]73fb1fc52011-07-09 00:06:54384 },
[email protected]e3749d12011-07-25 22:22:12385 {
[email protected]9931875b2011-11-02 00:19:48386 "disable-shortcuts-provider",
387 IDS_FLAGS_DISABLE_SHORTCUTS_PROVIDER,
388 IDS_FLAGS_DISABLE_SHORTCUTS_PROVIDER_DESCRIPTION,
[email protected]e3749d12011-07-25 22:22:12389 kOsAll,
[email protected]9931875b2011-11-02 00:19:48390 SINGLE_VALUE_TYPE(switches::kDisableShortcutsProvider)
[email protected]e3749d12011-07-25 22:22:12391 },
[email protected]1a2966b92011-08-09 06:50:19392#if defined(OS_CHROMEOS)
393 {
[email protected]cd681c42011-09-29 02:49:44394 "enable-bluetooth",
395 IDS_FLAGS_ENABLE_BLUETOOTH_NAME,
396 IDS_FLAGS_ENABLE_BLUETOOTH_DESCRIPTION,
397 kOsCrOS,
398 SINGLE_VALUE_TYPE(switches::kEnableBluetooth)
399 },
[email protected]1a2966b92011-08-09 06:50:19400#endif
[email protected]80eb4262011-08-03 16:10:41401 {
402 "memory-widget",
403 IDS_FLAGS_MEMORY_WIDGET_NAME,
404 IDS_FLAGS_MEMORY_WIDGET_DESCRIPTION,
405 kOsCrOS,
406#if defined(OS_CHROMEOS)
407 // This switch exists only on Chrome OS.
408 SINGLE_VALUE_TYPE(switches::kMemoryWidget)
409#else
410 SINGLE_VALUE_TYPE("")
411#endif
[email protected]a0e4b072011-08-17 01:47:07412 },
413 {
414 "downloads-new-ui", // FLAGS:RECORD_UMA
415 IDS_FLAGS_DOWNLOADS_NEW_UI_NAME,
416 IDS_FLAGS_DOWNLOADS_NEW_UI_DESCRIPTION,
417 kOsAll,
418 SINGLE_VALUE_TYPE(switches::kDownloadsNewUI)
419 },
[email protected]b7bb44f2011-09-01 05:17:03420 {
421 "enable-autologin",
422 IDS_FLAGS_ENABLE_AUTOLOGIN_NAME,
423 IDS_FLAGS_ENABLE_AUTOLOGIN_DESCRIPTION,
424 kOsMac | kOsWin | kOsLinux,
425 SINGLE_VALUE_TYPE(switches::kEnableAutologin)
426 },
[email protected]b9841172011-09-26 23:36:09427 {
[email protected]bbadb112011-12-12 16:55:28428 "enable-http-pipelining",
429 IDS_FLAGS_ENABLE_HTTP_PIPELINING_NAME,
430 IDS_FLAGS_ENABLE_HTTP_PIPELINING_DESCRIPTION,
431 kOsAll,
432 SINGLE_VALUE_TYPE(switches::kEnableHttpPipelining)
433 },
[email protected]d411c01d2011-10-18 16:00:27434 {
[email protected]f5da41d2011-10-08 17:40:07435 "enable-video-track",
436 IDS_FLAGS_ENABLE_VIDEO_TRACK_NAME,
437 IDS_FLAGS_ENABLE_VIDEO_TRACK_DESCRIPTION,
438 kOsAll,
439 SINGLE_VALUE_TYPE(switches::kEnableVideoTrack)
440 },
[email protected]08b83362011-10-19 05:23:17441 {
[email protected]6aa03b32011-10-27 21:44:44442 "enable-media-source",
443 IDS_FLAGS_ENABLE_MEDIA_SOURCE_NAME,
444 IDS_FLAGS_ENABLE_MEDIA_SOURCE_DESCRIPTION,
445 kOsAll,
446 SINGLE_VALUE_TYPE(switches::kEnableMediaSource)
447 },
[email protected]e4e68dbb2011-11-18 01:50:22448 {
449 "enable-pointer-lock",
450 IDS_FLAGS_ENABLE_POINTER_LOCK_NAME,
451 IDS_FLAGS_ENABLE_POINTER_LOCK_DESCRIPTION,
452 kOsAll,
453 SINGLE_VALUE_TYPE(switches::kEnablePointerLock)
454 },
[email protected]8cc10df2011-11-03 23:57:50455#if defined(USE_AURA)
456 {
[email protected]20cea592011-12-10 01:55:30457 "aura-translucent-frames",
458 IDS_FLAGS_AURA_TRANSLUCENT_FRAMES_NAME,
459 IDS_FLAGS_AURA_TRANSLUCENT_FRAMES_DESCRIPTION,
460 kOsWin | kOsLinux | kOsCrOS,
[email protected]55f593352011-12-24 05:42:46461 SINGLE_VALUE_TYPE(ash::switches::kAuraTranslucentFrames)
[email protected]20cea592011-12-10 01:55:30462 },
[email protected]57b8bb352012-01-11 05:11:46463 {
464 "aura-google-dialog-frames",
465 IDS_FLAGS_AURA_GOOGLE_DIALOG_FRAMES_NAME,
466 IDS_FLAGS_AURA_GOOGLE_DIALOG_FRAMES_DESCRIPTION,
467 kOsWin | kOsLinux | kOsCrOS,
468 SINGLE_VALUE_TYPE(ash::switches::kAuraGoogleDialogFrames)
469 },
[email protected]35304ce2011-12-14 23:21:01470 {
[email protected]3fbd9c12011-12-16 21:35:11471 "aura-window-mode",
472 IDS_FLAGS_AURA_WINDOW_MODE_NAME,
473 IDS_FLAGS_AURA_WINDOW_MODE_DESCRIPTION,
[email protected]35304ce2011-12-14 23:21:01474 kOsWin | kOsLinux | kOsCrOS,
[email protected]3fbd9c12011-12-16 21:35:11475 MULTI_VALUE_TYPE(kAuraWindowModeChoices)
[email protected]35304ce2011-12-14 23:21:01476 },
[email protected]eaae8b462012-01-20 22:20:39477#endif // defined(USE_AURA)
478 {
479 "enable-gamepad",
480 IDS_FLAGS_ENABLE_GAMEPAD_NAME,
481 IDS_FLAGS_ENABLE_GAMEPAD_DESCRIPTION,
482 kOsAll,
483 SINGLE_VALUE_TYPE(switches::kEnableGamepad)
484 },
[email protected]db543d322011-12-15 20:40:15485 {
486 "per-tile-painting",
487 IDS_FLAGS_PER_TILE_PAINTING_NAME,
488 IDS_FLAGS_PER_TILE_PAINTING_DESCRIPTION,
489#if defined(USE_SKIA)
[email protected]a5b1b272012-01-06 20:44:37490 kOsMac | kOsLinux | kOsCrOS,
[email protected]db543d322011-12-15 20:40:15491#else
492 0,
493#endif
494 SINGLE_VALUE_TYPE(switches::kEnablePerTilePainting)
495 },
[email protected]bf88c032011-12-22 19:05:47496 {
497 "enable-javascript-harmony",
498 IDS_FLAGS_ENABLE_JAVASCRIPT_HARMONY_NAME,
499 IDS_FLAGS_ENABLE_JAVASCRIPT_HARMONY_DESCRIPTION,
500 kOsAll,
501 SINGLE_VALUE_TYPE_AND_VALUE(switches::kJavaScriptFlags, "--harmony")
502 },
[email protected]7e7f378a2012-01-05 14:35:37503 {
[email protected]85646172012-01-09 22:45:54504 "enable-tab-browser-dragging",
505 IDS_FLAGS_ENABLE_TAB_BROWSER_DRAGGING_NAME,
506 IDS_FLAGS_ENABLE_TAB_BROWSER_DRAGGING_DESCRIPTION,
507 kOsWin,
508 SINGLE_VALUE_TYPE(switches::kTabBrowserDragging)
509 },
510 {
[email protected]068b7b52012-02-27 12:41:44511 "disable-restore-session-state",
512 IDS_FLAGS_DISABLE_RESTORE_SESSION_STATE_NAME,
513 IDS_FLAGS_DISABLE_RESTORE_SESSION_STATE_DESCRIPTION,
[email protected]7e7f378a2012-01-05 14:35:37514 kOsAll,
[email protected]068b7b52012-02-27 12:41:44515 SINGLE_VALUE_TYPE(switches::kDisableRestoreSessionState)
[email protected]7e7f378a2012-01-05 14:35:37516 },
[email protected]88864db2012-01-18 20:56:35517 {
518 "disable-software-rasterizer",
519 IDS_FLAGS_DISABLE_SOFTWARE_RASTERIZER_NAME,
520 IDS_FLAGS_DISABLE_SOFTWARE_RASTERIZER_DESCRIPTION,
521#if defined(ENABLE_SWIFTSHADER)
522 kOsAll,
523#else
524 0,
525#endif
526 SINGLE_VALUE_TYPE(switches::kDisableSoftwareRasterizer)
527 },
[email protected]15a5d722012-01-23 09:11:14528 {
529 "enable-media-stream",
530 IDS_FLAGS_MEDIA_STREAM_NAME,
531 IDS_FLAGS_MEDIA_STREAM_DESCRIPTION,
[email protected]fa82b6772012-02-20 13:19:05532 kOsAll,
[email protected]15a5d722012-01-23 09:11:14533 SINGLE_VALUE_TYPE(switches::kEnableMediaStream)
534 },
[email protected]f5ec7242012-01-27 07:15:15535 {
[email protected]fa12e2d2012-02-06 21:03:10536 "disable-uber-page",
537 IDS_FLAGS_DISABLE_UBER_PAGE_NAME,
538 IDS_FLAGS_DISABLE_UBER_PAGE_DESCRIPTION,
[email protected]f5ec7242012-01-27 07:15:15539 kOsAll,
[email protected]fa12e2d2012-02-06 21:03:10540 SINGLE_VALUE_TYPE(switches::kDisableUberPage)
[email protected]f5ec7242012-01-27 07:15:15541 },
[email protected]d2edc6702012-01-30 09:13:16542 {
543 "enable-shadow-dom",
544 IDS_FLAGS_SHADOW_DOM_NAME,
545 IDS_FLAGS_SHADOW_DOM_DESCRIPTION,
546 kOsAll,
547 SINGLE_VALUE_TYPE(switches::kEnableShadowDOM)
548 },
[email protected]9860c68b2012-02-02 01:58:09549 {
[email protected]4961218f2012-02-23 10:11:07550 "enable-style-scoped",
551 IDS_FLAGS_STYLE_SCOPED_NAME,
552 IDS_FLAGS_STYLE_SCOPED_DESCRIPTION,
553 kOsAll,
554 SINGLE_VALUE_TYPE(switches::kEnableStyleScoped)
555 },
556 {
[email protected]ca7a3d792012-03-02 15:55:49557 "enable-css-regions",
558 IDS_FLAGS_CSS_REGIONS_NAME,
559 IDS_FLAGS_CSS_REGIONS_DESCRIPTION,
560 kOsAll,
561 SINGLE_VALUE_TYPE(switches::kEnableCssRegions)
562 },
563 {
[email protected]8bed69d2012-02-02 06:46:00564 "ntp-app-install-hint",
565 IDS_FLAGS_APP_INSTALL_HINT_NAME,
566 IDS_FLAGS_APP_INSTALL_HINT_DESCRIPTION,
567 kOsAll,
568 SINGLE_VALUE_TYPE(switches::kNtpAppInstallHint)
569 },
570 {
[email protected]9860c68b2012-02-02 01:58:09571 "enable-extension-activity-ui",
572 IDS_FLAGS_ENABLE_EXTENSION_ACTIVITY_UI_NAME,
573 IDS_FLAGS_ENABLE_EXTENSION_ACTIVITY_UI_DESCRIPTION,
574 kOsAll,
575 SINGLE_VALUE_TYPE(switches::kEnableExtensionActivityUI)
[email protected]8bed69d2012-02-02 06:46:00576 },
[email protected]54ae4e92012-02-16 15:19:05577 {
578 "webui-task-manager",
579 IDS_FLAGS_WEBUI_TASK_MANAGER_NAME,
580 IDS_FLAGS_WEBUI_TASK_MANAGER_DESCRIPTION,
581 kOsAll,
582 SINGLE_VALUE_TYPE(switches::kWebUITaskManager)
583 },
[email protected]156f966332012-02-29 00:03:16584 {
585 "disable-ntp-other-sessions-menu",
586 IDS_FLAGS_NTP_OTHER_SESSIONS_MENU_NAME,
587 IDS_FLAGS_NTP_OTHER_SESSIONS_MENU_DESCRIPTION,
588 kOsAll,
589 SINGLE_VALUE_TYPE(switches::kDisableNTPOtherSessionsMenu)
590 },
[email protected]31cf1c52012-02-29 20:55:01591#if defined(USE_AURA)
592 {
593 "enable-ash-uber-tray",
594 IDS_FLAGS_ENABLE_ASH_UBER_TRAY_NAME,
595 IDS_FLAGS_ENABLE_ASH_UBER_TRAY_DESCRIPTION,
596 kOsAll,
597 SINGLE_VALUE_TYPE(ash::switches::kAshUberTray),
598 },
599#endif
[email protected]184ec592012-03-01 11:54:28600 {
601 "enable-devtools-experiments",
602 IDS_FLAGS_ENABLE_DEVTOOLS_EXPERIMENTS_NAME,
603 IDS_FLAGS_ENABLE_DEVTOOLS_EXPERIMENTS_DESCRIPTION,
604 kOsAll,
605 SINGLE_VALUE_TYPE(switches::kEnableDevToolsExperiments)
606 },
[email protected]a0e4b072011-08-17 01:47:07607};
[email protected]ad2a3ded2010-08-27 13:19:05608
[email protected]a314ee5a2010-10-26 21:23:28609const Experiment* experiments = kExperiments;
610size_t num_experiments = arraysize(kExperiments);
611
[email protected]e2ddbc92010-10-15 20:02:07612// Stores and encapsulates the little state that about:flags has.
613class FlagsState {
614 public:
615 FlagsState() : needs_restart_(false) {}
616 void ConvertFlagsToSwitches(PrefService* prefs, CommandLine* command_line);
617 bool IsRestartNeededToCommitChanges();
618 void SetExperimentEnabled(
[email protected]a314ee5a2010-10-26 21:23:28619 PrefService* prefs, const std::string& internal_name, bool enable);
[email protected]e2ddbc92010-10-15 20:02:07620 void RemoveFlagsSwitches(
621 std::map<std::string, CommandLine::StringType>* switch_list);
622 void reset();
623
624 // Returns the singleton instance of this class
[email protected]8e8bb6d2010-12-13 08:18:55625 static FlagsState* GetInstance() {
[email protected]e2ddbc92010-10-15 20:02:07626 return Singleton<FlagsState>::get();
627 }
628
629 private:
630 bool needs_restart_;
[email protected]a82744532011-02-11 16:15:53631 std::map<std::string, std::string> flags_switches_;
[email protected]e2ddbc92010-10-15 20:02:07632
633 DISALLOW_COPY_AND_ASSIGN(FlagsState);
634};
635
[email protected]c7b7800a2010-10-07 18:51:35636// Extracts the list of enabled lab experiments from preferences and stores them
[email protected]ad2a3ded2010-08-27 13:19:05637// in a set.
[email protected]1a47d7e2010-10-15 00:37:24638void GetEnabledFlags(const PrefService* prefs, std::set<std::string>* result) {
[email protected]ad2a3ded2010-08-27 13:19:05639 const ListValue* enabled_experiments = prefs->GetList(
640 prefs::kEnabledLabsExperiments);
641 if (!enabled_experiments)
642 return;
643
644 for (ListValue::const_iterator it = enabled_experiments->begin();
645 it != enabled_experiments->end();
646 ++it) {
647 std::string experiment_name;
648 if (!(*it)->GetAsString(&experiment_name)) {
649 LOG(WARNING) << "Invalid entry in " << prefs::kEnabledLabsExperiments;
650 continue;
651 }
652 result->insert(experiment_name);
653 }
654}
655
656// Takes a set of enabled lab experiments
[email protected]1a47d7e2010-10-15 00:37:24657void SetEnabledFlags(
[email protected]ad2a3ded2010-08-27 13:19:05658 PrefService* prefs, const std::set<std::string>& enabled_experiments) {
[email protected]1bc78422011-03-31 08:41:38659 ListPrefUpdate update(prefs, prefs::kEnabledLabsExperiments);
660 ListValue* experiments_list = update.Get();
[email protected]ad2a3ded2010-08-27 13:19:05661
662 experiments_list->Clear();
663 for (std::set<std::string>::const_iterator it = enabled_experiments.begin();
664 it != enabled_experiments.end();
665 ++it) {
666 experiments_list->Append(new StringValue(*it));
667 }
668}
669
[email protected]8a6ff28d2010-12-02 16:35:19670// Returns the name used in prefs for the choice at the specified index.
671std::string NameForChoice(const Experiment& e, int index) {
[email protected]2ce9c89752011-02-25 18:24:34672 DCHECK_EQ(Experiment::MULTI_VALUE, e.type);
673 DCHECK_LT(index, e.num_choices);
[email protected]8a6ff28d2010-12-02 16:35:19674 return std::string(e.internal_name) + about_flags::testing::kMultiSeparator +
675 base::IntToString(index);
676}
677
678// Adds the internal names for the specified experiment to |names|.
679void AddInternalName(const Experiment& e, std::set<std::string>* names) {
680 if (e.type == Experiment::SINGLE_VALUE) {
681 names->insert(e.internal_name);
682 } else {
[email protected]2ce9c89752011-02-25 18:24:34683 DCHECK_EQ(Experiment::MULTI_VALUE, e.type);
[email protected]8a6ff28d2010-12-02 16:35:19684 for (int i = 0; i < e.num_choices; ++i)
685 names->insert(NameForChoice(e, i));
686 }
687}
688
[email protected]28e35af2011-02-09 12:56:22689// Confirms that an experiment is valid, used in a DCHECK in
690// SanitizeList below.
691bool ValidateExperiment(const Experiment& e) {
692 switch (e.type) {
693 case Experiment::SINGLE_VALUE:
694 DCHECK_EQ(0, e.num_choices);
695 DCHECK(!e.choices);
696 break;
697 case Experiment::MULTI_VALUE:
698 DCHECK_GT(e.num_choices, 0);
699 DCHECK(e.choices);
[email protected]a82744532011-02-11 16:15:53700 DCHECK(e.choices[0].command_line_switch);
701 DCHECK_EQ('\0', e.choices[0].command_line_switch[0]);
[email protected]28e35af2011-02-09 12:56:22702 break;
703 default:
704 NOTREACHED();
705 }
706 return true;
707}
708
[email protected]ad2a3ded2010-08-27 13:19:05709// Removes all experiments from prefs::kEnabledLabsExperiments that are
710// unknown, to prevent this list to become very long as experiments are added
711// and removed.
712void SanitizeList(PrefService* prefs) {
713 std::set<std::string> known_experiments;
[email protected]28e35af2011-02-09 12:56:22714 for (size_t i = 0; i < num_experiments; ++i) {
715 DCHECK(ValidateExperiment(experiments[i]));
[email protected]8a6ff28d2010-12-02 16:35:19716 AddInternalName(experiments[i], &known_experiments);
[email protected]28e35af2011-02-09 12:56:22717 }
[email protected]ad2a3ded2010-08-27 13:19:05718
719 std::set<std::string> enabled_experiments;
[email protected]1a47d7e2010-10-15 00:37:24720 GetEnabledFlags(prefs, &enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05721
722 std::set<std::string> new_enabled_experiments;
723 std::set_intersection(
724 known_experiments.begin(), known_experiments.end(),
725 enabled_experiments.begin(), enabled_experiments.end(),
726 std::inserter(new_enabled_experiments, new_enabled_experiments.begin()));
727
[email protected]1a47d7e2010-10-15 00:37:24728 SetEnabledFlags(prefs, new_enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05729}
730
[email protected]1a47d7e2010-10-15 00:37:24731void GetSanitizedEnabledFlags(
[email protected]ad2a3ded2010-08-27 13:19:05732 PrefService* prefs, std::set<std::string>* result) {
733 SanitizeList(prefs);
[email protected]1a47d7e2010-10-15 00:37:24734 GetEnabledFlags(prefs, result);
[email protected]ad2a3ded2010-08-27 13:19:05735}
736
[email protected]a314ee5a2010-10-26 21:23:28737// Variant of GetSanitizedEnabledFlags that also removes any flags that aren't
738// enabled on the current platform.
739void GetSanitizedEnabledFlagsForCurrentPlatform(
740 PrefService* prefs, std::set<std::string>* result) {
741 GetSanitizedEnabledFlags(prefs, result);
742
743 // Filter out any experiments that aren't enabled on the current platform. We
744 // don't remove these from prefs else syncing to a platform with a different
745 // set of experiments would be lossy.
746 std::set<std::string> platform_experiments;
747 int current_platform = GetCurrentPlatform();
748 for (size_t i = 0; i < num_experiments; ++i) {
749 if (experiments[i].supported_platforms & current_platform)
[email protected]8a6ff28d2010-12-02 16:35:19750 AddInternalName(experiments[i], &platform_experiments);
[email protected]a314ee5a2010-10-26 21:23:28751 }
752
753 std::set<std::string> new_enabled_experiments;
754 std::set_intersection(
755 platform_experiments.begin(), platform_experiments.end(),
756 result->begin(), result->end(),
757 std::inserter(new_enabled_experiments, new_enabled_experiments.begin()));
758
759 result->swap(new_enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05760}
761
[email protected]8a6ff28d2010-12-02 16:35:19762// Returns the Value representing the choice data in the specified experiment.
[email protected]8a6ff28d2010-12-02 16:35:19763Value* CreateChoiceData(const Experiment& experiment,
[email protected]28e35af2011-02-09 12:56:22764 const std::set<std::string>& enabled_experiments) {
[email protected]2ce9c89752011-02-25 18:24:34765 DCHECK_EQ(Experiment::MULTI_VALUE, experiment.type);
[email protected]8a6ff28d2010-12-02 16:35:19766 ListValue* result = new ListValue;
767 for (int i = 0; i < experiment.num_choices; ++i) {
768 const Experiment::Choice& choice = experiment.choices[i];
769 DictionaryValue* value = new DictionaryValue;
770 std::string name = NameForChoice(experiment, i);
771 value->SetString("description",
772 l10n_util::GetStringUTF16(choice.description_id));
773 value->SetString("internal_name", name);
[email protected]28e35af2011-02-09 12:56:22774 value->SetBoolean("selected", enabled_experiments.count(name) > 0);
[email protected]8a6ff28d2010-12-02 16:35:19775 result->Append(value);
776 }
777 return result;
778}
779
[email protected]e2ddbc92010-10-15 20:02:07780} // namespace
781
[email protected]1a47d7e2010-10-15 00:37:24782void ConvertFlagsToSwitches(PrefService* prefs, CommandLine* command_line) {
[email protected]8e8bb6d2010-12-13 08:18:55783 FlagsState::GetInstance()->ConvertFlagsToSwitches(prefs, command_line);
[email protected]ad2a3ded2010-08-27 13:19:05784}
785
[email protected]1a47d7e2010-10-15 00:37:24786ListValue* GetFlagsExperimentsData(PrefService* prefs) {
[email protected]ad2a3ded2010-08-27 13:19:05787 std::set<std::string> enabled_experiments;
[email protected]1a47d7e2010-10-15 00:37:24788 GetSanitizedEnabledFlags(prefs, &enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05789
790 int current_platform = GetCurrentPlatform();
791
792 ListValue* experiments_data = new ListValue();
[email protected]a314ee5a2010-10-26 21:23:28793 for (size_t i = 0; i < num_experiments; ++i) {
794 const Experiment& experiment = experiments[i];
[email protected]ad2a3ded2010-08-27 13:19:05795
796 DictionaryValue* data = new DictionaryValue();
797 data->SetString("internal_name", experiment.internal_name);
798 data->SetString("name",
799 l10n_util::GetStringUTF16(experiment.visible_name_id));
800 data->SetString("description",
801 l10n_util::GetStringUTF16(
802 experiment.visible_description_id));
[email protected]cc3e2052011-12-20 01:01:40803 bool supported = !!(experiment.supported_platforms & current_platform);
[email protected]c54ad562012-01-23 22:21:59804#if defined(USE_AURA) && defined(OS_CHROMEOS)
805 // Some Chrome OS devices currently require Aura compact window mode, so
806 // don't offer a choice of mode.
807 // TODO(jamescook): Remove after Aura supports normal mode on all devices,
808 // likely around M19.
809 if (experiment.visible_name_id == IDS_FLAGS_AURA_WINDOW_MODE_NAME &&
810 CommandLine::ForCurrentProcess()->
811 HasSwitch(ash::switches::kAuraForceCompactWindowMode))
812 supported = false;
813#endif
[email protected]cc3e2052011-12-20 01:01:40814 data->SetBoolean("supported", supported);
815
816 ListValue* supported_platforms = new ListValue();
817 AddOsStrings(experiment.supported_platforms, supported_platforms);
818 data->Set("supported_platforms", supported_platforms);
[email protected]ad2a3ded2010-08-27 13:19:05819
[email protected]28e35af2011-02-09 12:56:22820 switch (experiment.type) {
821 case Experiment::SINGLE_VALUE:
822 data->SetBoolean(
823 "enabled",
824 enabled_experiments.count(experiment.internal_name) > 0);
825 break;
826 case Experiment::MULTI_VALUE:
827 data->Set("choices", CreateChoiceData(experiment, enabled_experiments));
828 break;
829 default:
830 NOTREACHED();
[email protected]8a6ff28d2010-12-02 16:35:19831 }
832
[email protected]ad2a3ded2010-08-27 13:19:05833 experiments_data->Append(data);
834 }
835 return experiments_data;
836}
837
[email protected]ad2a3ded2010-08-27 13:19:05838bool IsRestartNeededToCommitChanges() {
[email protected]8e8bb6d2010-12-13 08:18:55839 return FlagsState::GetInstance()->IsRestartNeededToCommitChanges();
[email protected]ad2a3ded2010-08-27 13:19:05840}
841
842void SetExperimentEnabled(
[email protected]c7b7800a2010-10-07 18:51:35843 PrefService* prefs, const std::string& internal_name, bool enable) {
[email protected]8e8bb6d2010-12-13 08:18:55844 FlagsState::GetInstance()->SetExperimentEnabled(prefs, internal_name, enable);
[email protected]e2ddbc92010-10-15 20:02:07845}
846
847void RemoveFlagsSwitches(
848 std::map<std::string, CommandLine::StringType>* switch_list) {
[email protected]8e8bb6d2010-12-13 08:18:55849 FlagsState::GetInstance()->RemoveFlagsSwitches(switch_list);
[email protected]e2ddbc92010-10-15 20:02:07850}
851
[email protected]a314ee5a2010-10-26 21:23:28852int GetCurrentPlatform() {
853#if defined(OS_MACOSX)
854 return kOsMac;
855#elif defined(OS_WIN)
856 return kOsWin;
857#elif defined(OS_CHROMEOS) // Needs to be before the OS_LINUX check.
858 return kOsCrOS;
[email protected]c92f4ed2011-10-21 19:50:21859#elif defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]a314ee5a2010-10-26 21:23:28860 return kOsLinux;
[email protected]9c7453d2012-01-21 00:45:40861#elif defined(OS_ANDROID)
862 return kOsAndroid;
[email protected]a314ee5a2010-10-26 21:23:28863#else
864#error Unknown platform
865#endif
866}
867
[email protected]4bc5050c2010-11-18 17:55:54868void RecordUMAStatistics(const PrefService* prefs) {
869 std::set<std::string> flags;
870 GetEnabledFlags(prefs, &flags);
871 for (std::set<std::string>::iterator it = flags.begin(); it != flags.end();
872 ++it) {
873 std::string action("AboutFlags_");
874 action += *it;
[email protected]7f6f44c2011-12-14 13:23:38875 content::RecordComputedAction(action);
[email protected]4bc5050c2010-11-18 17:55:54876 }
877 // Since flag metrics are recorded every startup, add a tick so that the
878 // stats can be made meaningful.
879 if (flags.size())
[email protected]7f6f44c2011-12-14 13:23:38880 content::RecordAction(UserMetricsAction("AboutFlags_StartupTick"));
881 content::RecordAction(UserMetricsAction("StartupTick"));
[email protected]4bc5050c2010-11-18 17:55:54882}
883
[email protected]e2ddbc92010-10-15 20:02:07884//////////////////////////////////////////////////////////////////////////////
885// FlagsState implementation.
886
887namespace {
888
889void FlagsState::ConvertFlagsToSwitches(
890 PrefService* prefs, CommandLine* command_line) {
[email protected]e2ddbc92010-10-15 20:02:07891 if (command_line->HasSwitch(switches::kNoExperiments))
892 return;
893
894 std::set<std::string> enabled_experiments;
[email protected]ba8164242010-11-16 21:31:00895
[email protected]a314ee5a2010-10-26 21:23:28896 GetSanitizedEnabledFlagsForCurrentPlatform(prefs, &enabled_experiments);
[email protected]e2ddbc92010-10-15 20:02:07897
[email protected]a82744532011-02-11 16:15:53898 typedef std::map<std::string, std::pair<std::string, std::string> >
899 NameToSwitchAndValueMap;
900 NameToSwitchAndValueMap name_to_switch_map;
[email protected]8a6ff28d2010-12-02 16:35:19901 for (size_t i = 0; i < num_experiments; ++i) {
902 const Experiment& e = experiments[i];
903 if (e.type == Experiment::SINGLE_VALUE) {
[email protected]a82744532011-02-11 16:15:53904 name_to_switch_map[e.internal_name] =
905 std::pair<std::string, std::string>(e.command_line_switch,
906 e.command_line_value);
[email protected]8a6ff28d2010-12-02 16:35:19907 } else {
908 for (int j = 0; j < e.num_choices; ++j)
[email protected]a82744532011-02-11 16:15:53909 name_to_switch_map[NameForChoice(e, j)] =
910 std::pair<std::string, std::string>(
911 e.choices[j].command_line_switch,
912 e.choices[j].command_line_value);
[email protected]8a6ff28d2010-12-02 16:35:19913 }
914 }
[email protected]e2ddbc92010-10-15 20:02:07915
916 command_line->AppendSwitch(switches::kFlagSwitchesBegin);
[email protected]a82744532011-02-11 16:15:53917 flags_switches_.insert(
918 std::pair<std::string, std::string>(switches::kFlagSwitchesBegin,
919 std::string()));
[email protected]e2ddbc92010-10-15 20:02:07920 for (std::set<std::string>::iterator it = enabled_experiments.begin();
921 it != enabled_experiments.end();
922 ++it) {
923 const std::string& experiment_name = *it;
[email protected]a82744532011-02-11 16:15:53924 NameToSwitchAndValueMap::const_iterator name_to_switch_it =
[email protected]8a6ff28d2010-12-02 16:35:19925 name_to_switch_map.find(experiment_name);
926 if (name_to_switch_it == name_to_switch_map.end()) {
927 NOTREACHED();
[email protected]e2ddbc92010-10-15 20:02:07928 continue;
[email protected]8a6ff28d2010-12-02 16:35:19929 }
[email protected]e2ddbc92010-10-15 20:02:07930
[email protected]a82744532011-02-11 16:15:53931 const std::pair<std::string, std::string>&
932 switch_and_value_pair = name_to_switch_it->second;
933
934 command_line->AppendSwitchASCII(switch_and_value_pair.first,
935 switch_and_value_pair.second);
936 flags_switches_[switch_and_value_pair.first] = switch_and_value_pair.second;
[email protected]e2ddbc92010-10-15 20:02:07937 }
938 command_line->AppendSwitch(switches::kFlagSwitchesEnd);
[email protected]a82744532011-02-11 16:15:53939 flags_switches_.insert(
940 std::pair<std::string, std::string>(switches::kFlagSwitchesEnd,
941 std::string()));
[email protected]e2ddbc92010-10-15 20:02:07942}
943
944bool FlagsState::IsRestartNeededToCommitChanges() {
945 return needs_restart_;
946}
947
948void FlagsState::SetExperimentEnabled(
949 PrefService* prefs, const std::string& internal_name, bool enable) {
[email protected]ad2a3ded2010-08-27 13:19:05950 needs_restart_ = true;
951
[email protected]8a6ff28d2010-12-02 16:35:19952 size_t at_index = internal_name.find(about_flags::testing::kMultiSeparator);
953 if (at_index != std::string::npos) {
954 DCHECK(enable);
955 // We're being asked to enable a multi-choice experiment. Disable the
956 // currently selected choice.
957 DCHECK_NE(at_index, 0u);
[email protected]28e35af2011-02-09 12:56:22958 const std::string experiment_name = internal_name.substr(0, at_index);
959 SetExperimentEnabled(prefs, experiment_name, false);
[email protected]8a6ff28d2010-12-02 16:35:19960
[email protected]28e35af2011-02-09 12:56:22961 // And enable the new choice, if it is not the default first choice.
962 if (internal_name != experiment_name + "@0") {
963 std::set<std::string> enabled_experiments;
964 GetSanitizedEnabledFlags(prefs, &enabled_experiments);
965 enabled_experiments.insert(internal_name);
966 SetEnabledFlags(prefs, enabled_experiments);
967 }
[email protected]8a6ff28d2010-12-02 16:35:19968 return;
969 }
970
[email protected]ad2a3ded2010-08-27 13:19:05971 std::set<std::string> enabled_experiments;
[email protected]1a47d7e2010-10-15 00:37:24972 GetSanitizedEnabledFlags(prefs, &enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05973
[email protected]8a6ff28d2010-12-02 16:35:19974 const Experiment* e = NULL;
975 for (size_t i = 0; i < num_experiments; ++i) {
976 if (experiments[i].internal_name == internal_name) {
977 e = experiments + i;
978 break;
979 }
980 }
981 DCHECK(e);
982
983 if (e->type == Experiment::SINGLE_VALUE) {
[email protected]8a2713682011-08-19 10:36:59984 if (enable)
[email protected]8a6ff28d2010-12-02 16:35:19985 enabled_experiments.insert(internal_name);
[email protected]8a2713682011-08-19 10:36:59986 else
[email protected]8a6ff28d2010-12-02 16:35:19987 enabled_experiments.erase(internal_name);
988 } else {
989 if (enable) {
990 // Enable the first choice.
991 enabled_experiments.insert(NameForChoice(*e, 0));
992 } else {
993 // Find the currently enabled choice and disable it.
994 for (int i = 0; i < e->num_choices; ++i) {
995 std::string choice_name = NameForChoice(*e, i);
996 if (enabled_experiments.find(choice_name) !=
997 enabled_experiments.end()) {
998 enabled_experiments.erase(choice_name);
999 // Continue on just in case there's a bug and more than one
1000 // experiment for this choice was enabled.
1001 }
1002 }
1003 }
1004 }
[email protected]ad2a3ded2010-08-27 13:19:051005
[email protected]1a47d7e2010-10-15 00:37:241006 SetEnabledFlags(prefs, enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:051007}
1008
[email protected]e2ddbc92010-10-15 20:02:071009void FlagsState::RemoveFlagsSwitches(
1010 std::map<std::string, CommandLine::StringType>* switch_list) {
[email protected]a82744532011-02-11 16:15:531011 for (std::map<std::string, std::string>::const_iterator
1012 it = flags_switches_.begin(); it != flags_switches_.end(); ++it) {
1013 switch_list->erase(it->first);
[email protected]e2ddbc92010-10-15 20:02:071014 }
1015}
1016
1017void FlagsState::reset() {
1018 needs_restart_ = false;
1019 flags_switches_.clear();
1020}
1021
[email protected]38e46812011-05-09 20:49:221022} // namespace
[email protected]e2ddbc92010-10-15 20:02:071023
1024namespace testing {
[email protected]8a6ff28d2010-12-02 16:35:191025
1026// WARNING: '@' is also used in the html file. If you update this constant you
1027// also need to update the html file.
1028const char kMultiSeparator[] = "@";
1029
[email protected]e2ddbc92010-10-15 20:02:071030void ClearState() {
[email protected]8e8bb6d2010-12-13 08:18:551031 FlagsState::GetInstance()->reset();
[email protected]e2ddbc92010-10-15 20:02:071032}
[email protected]a314ee5a2010-10-26 21:23:281033
1034void SetExperiments(const Experiment* e, size_t count) {
1035 if (!e) {
1036 experiments = kExperiments;
1037 num_experiments = arraysize(kExperiments);
1038 } else {
1039 experiments = e;
1040 num_experiments = count;
1041 }
1042}
1043
[email protected]8a6ff28d2010-12-02 16:35:191044const Experiment* GetExperiments(size_t* count) {
1045 *count = num_experiments;
1046 return experiments;
1047}
1048
[email protected]e2ddbc92010-10-15 20:02:071049} // namespace testing
1050
[email protected]1a47d7e2010-10-15 00:37:241051} // namespace about_flags