blob: 5a67cf81d644a36e42ee14f22e8730b90a25a252 [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]308aaa32012-03-12 13:14:5029#include "ui/aura/aura_switches.h"
[email protected]8cc10df2011-11-03 23:57:5030#endif
31
[email protected]7f6f44c2011-12-14 13:23:3832using content::UserMetricsAction;
33
[email protected]1a47d7e2010-10-15 00:37:2434namespace about_flags {
[email protected]ad2a3ded2010-08-27 13:19:0535
[email protected]8a6ff28d2010-12-02 16:35:1936// Macros to simplify specifying the type.
[email protected]a82744532011-02-11 16:15:5337#define SINGLE_VALUE_TYPE_AND_VALUE(command_line_switch, switch_value) \
38 Experiment::SINGLE_VALUE, command_line_switch, switch_value, NULL, 0
39#define SINGLE_VALUE_TYPE(command_line_switch) \
40 SINGLE_VALUE_TYPE_AND_VALUE(command_line_switch, "")
41#define MULTI_VALUE_TYPE(choices) \
[email protected]0e6f56d2011-02-12 23:45:1542 Experiment::MULTI_VALUE, "", "", choices, arraysize(choices)
[email protected]8a6ff28d2010-12-02 16:35:1943
[email protected]e2ddbc92010-10-15 20:02:0744namespace {
45
[email protected]9c7453d2012-01-21 00:45:4046const unsigned kOsAll = kOsMac | kOsWin | kOsLinux | kOsCrOS | kOsAndroid;
[email protected]ad2a3ded2010-08-27 13:19:0547
[email protected]cc3e2052011-12-20 01:01:4048// Adds a |StringValue| to |list| for each platform where |bitmask| indicates
49// whether the experiment is available on that platform.
50void AddOsStrings(unsigned bitmask, ListValue* list) {
51 struct {
52 unsigned bit;
53 const char* const name;
54 } kBitsToOs[] = {
55 {kOsMac, "Mac"},
56 {kOsWin, "Windows"},
57 {kOsLinux, "Linux"},
58 {kOsCrOS, "Chrome OS"},
59 };
60 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kBitsToOs); ++i)
61 if (bitmask & kBitsToOs[i].bit)
62 list->Append(new StringValue(kBitsToOs[i].name));
63}
64
[email protected]ba8164242010-11-16 21:31:0065// Names for former Chrome OS Labs experiments, shared with prefs migration
66// code.
67const char kMediaPlayerExperimentName[] = "media-player";
68const char kAdvancedFileSystemExperimentName[] = "advanced-file-system";
69const char kVerticalTabsExperimentName[] = "vertical-tabs";
70
[email protected]9b2c9f6a12012-01-27 21:00:0571const Experiment::Choice kOmniboxAggressiveHistoryURLChoices[] = {
72 { IDS_FLAGS_OMNIBOX_AGGRESSIVE_HISTORY_URL_SCORING_AUTOMATIC, "", "" },
73 { IDS_FLAGS_OMNIBOX_AGGRESSIVE_HISTORY_URL_SCORING_ENABLED,
74 switches::kOmniboxAggressiveHistoryURL,
75 switches::kOmniboxAggressiveHistoryURLEnabled },
76 { IDS_FLAGS_OMNIBOX_AGGRESSIVE_HISTORY_URL_SCORING_DISABLED,
77 switches::kOmniboxAggressiveHistoryURL,
78 switches::kOmniboxAggressiveHistoryURLDisabled }
79};
80
[email protected]032d5e6c2012-02-17 17:53:5581const Experiment::Choice kOmniboxInlineHistoryQuickProviderChoices[] = {
82 { IDS_FLAGS_OMNIBOX_INLINE_HISTORY_QUICK_PROVIDER_AUTOMATIC, "", "" },
83 { IDS_FLAGS_OMNIBOX_INLINE_HISTORY_QUICK_PROVIDER_ALLOWED,
84 switches::kOmniboxInlineHistoryQuickProvider,
85 switches::kOmniboxInlineHistoryQuickProviderAllowed },
86 { IDS_FLAGS_OMNIBOX_INLINE_HISTORY_QUICK_PROVIDER_PROHIBITED,
87 switches::kOmniboxInlineHistoryQuickProvider,
88 switches::kOmniboxInlineHistoryQuickProviderProhibited }
89};
90
[email protected]4bc5050c2010-11-18 17:55:5491// RECORDING USER METRICS FOR FLAGS:
92// -----------------------------------------------------------------------------
93// The first line of the experiment is the internal name. If you'd like to
94// gather statistics about the usage of your flag, you should append a marker
95// comment to the end of the feature name, like so:
96// "my-special-feature", // FLAGS:RECORD_UMA
97//
98// After doing that, run //chrome/tools/extract_actions.py (see instructions at
99// the top of that file for details) to update the chromeactions.txt file, which
100// will enable UMA to record your feature flag.
101//
102// After your feature has shipped under a flag, you can locate the metrics
103// under the action name AboutFlags_internal-action-name. Actions are recorded
104// once per startup, so you should divide this number by AboutFlags_StartupTick
105// to get a sense of usage. Note that this will not be the same as number of
106// users with a given feature enabled because users can quit and relaunch
107// the application multiple times over a given time interval.
108// TODO(rsesek): See if there's a way to count per-user, rather than
109// per-startup.
110
[email protected]8a6ff28d2010-12-02 16:35:19111// To add a new experiment add to the end of kExperiments. There are two
112// distinct types of experiments:
113// . SINGLE_VALUE: experiment is either on or off. Use the SINGLE_VALUE_TYPE
114// macro for this type supplying the command line to the macro.
[email protected]28e35af2011-02-09 12:56:22115// . MULTI_VALUE: a list of choices, the first of which should correspond to a
116// deactivated state for this lab (i.e. no command line option). To specify
117// this type of experiment use the macro MULTI_VALUE_TYPE supplying it the
118// array of choices.
[email protected]8a6ff28d2010-12-02 16:35:19119// See the documentation of Experiment for details on the fields.
120//
121// When adding a new choice, add it to the end of the list.
[email protected]ad2a3ded2010-08-27 13:19:05122const Experiment kExperiments[] = {
123 {
[email protected]aac169d2011-03-18 19:53:03124 "expose-for-tabs", // FLAGS:RECORD_UMA
125 IDS_FLAGS_TABPOSE_NAME,
126 IDS_FLAGS_TABPOSE_DESCRIPTION,
127 kOsMac,
128#if defined(OS_MACOSX)
129 // The switch exists only on OS X.
130 SINGLE_VALUE_TYPE(switches::kEnableExposeForTabs)
131#else
132 SINGLE_VALUE_TYPE("")
133#endif
134 },
135 {
[email protected]4bc5050c2010-11-18 17:55:54136 "conflicting-modules-check", // FLAGS:RECORD_UMA
[email protected]c1bbaa82010-11-08 11:17:05137 IDS_FLAGS_CONFLICTS_CHECK_NAME,
138 IDS_FLAGS_CONFLICTS_CHECK_DESCRIPTION,
139 kOsWin,
[email protected]8a6ff28d2010-12-02 16:35:19140 SINGLE_VALUE_TYPE(switches::kConflictingModulesCheck)
[email protected]c1bbaa82010-11-08 11:17:05141 },
142 {
[email protected]4bc5050c2010-11-18 17:55:54143 "cloud-print-proxy", // FLAGS:RECORD_UMA
[email protected]dae7325b2011-12-21 20:56:54144 IDS_FLAGS_CLOUD_PRINT_CONNECTOR_NAME,
145 IDS_FLAGS_CLOUD_PRINT_CONNECTOR_DESCRIPTION,
[email protected]9f8872b32011-03-04 19:44:45146 // For a Chrome build, we know we have a PDF plug-in on Windows, so it's
[email protected]4fa24bf2011-08-20 02:15:22147 // fully enabled.
[email protected]5d10d57d2011-07-22 22:16:31148 // Otherwise, where we know Windows could be working if a viable PDF
[email protected]4fa24bf2011-08-20 02:15:22149 // plug-in could be supplied, we'll keep the lab enabled. Mac and Linux
150 // always have PDF rasterization available, so no flag needed there.
151#if !defined(GOOGLE_CHROME_BUILD)
152 kOsWin,
153#else
154 0,
[email protected]fa6d2a2f2010-11-30 21:47:19155#endif
[email protected]8a6ff28d2010-12-02 16:35:19156 SINGLE_VALUE_TYPE(switches::kEnableCloudPrintProxy)
[email protected]8b6588a2010-10-12 02:39:42157 },
[email protected]580939a2010-10-12 18:54:37158 {
[email protected]bb461532010-11-26 21:50:23159 "crxless-web-apps",
160 IDS_FLAGS_CRXLESS_WEB_APPS_NAME,
161 IDS_FLAGS_CRXLESS_WEB_APPS_DESCRIPTION,
162 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19163 SINGLE_VALUE_TYPE(switches::kEnableCrxlessWebApps)
[email protected]bb461532010-11-26 21:50:23164 },
165 {
[email protected]96c6f4c2011-05-18 19:36:22166 "ignore-gpu-blacklist",
167 IDS_FLAGS_IGNORE_GPU_BLACKLIST_NAME,
168 IDS_FLAGS_IGNORE_GPU_BLACKLIST_DESCRIPTION,
169 kOsAll,
170 SINGLE_VALUE_TYPE(switches::kIgnoreGpuBlacklist)
171 },
172 {
[email protected]0110cf112011-07-02 00:39:43173 "force-compositing-mode-2",
[email protected]96c6f4c2011-05-18 19:36:22174 IDS_FLAGS_FORCE_COMPOSITING_MODE_NAME,
175 IDS_FLAGS_FORCE_COMPOSITING_MODE_DESCRIPTION,
176 kOsAll,
177 SINGLE_VALUE_TYPE(switches::kForceCompositingMode)
178 },
179 {
[email protected]5963b772011-02-09 22:55:38180 "composited-layer-borders",
181 IDS_FLAGS_COMPOSITED_LAYER_BORDERS,
182 IDS_FLAGS_COMPOSITED_LAYER_BORDERS_DESCRIPTION,
183 kOsAll,
184 SINGLE_VALUE_TYPE(switches::kShowCompositedLayerBorders)
185 },
186 {
[email protected]a8f1eaa2011-03-07 19:00:58187 "show-fps-counter",
188 IDS_FLAGS_SHOW_FPS_COUNTER,
189 IDS_FLAGS_SHOW_FPS_COUNTER_DESCRIPTION,
190 kOsAll,
191 SINGLE_VALUE_TYPE(switches::kShowFPSCounter)
192 },
[email protected]8ff7f342011-05-25 01:49:47193 {
[email protected]70c98a332011-12-21 20:51:52194 "accelerated-filters",
195 IDS_FLAGS_ACCELERATED_FILTERS,
196 IDS_FLAGS_ACCELERATED_FILTERS_DESCRIPTION,
197 kOsAll,
198 SINGLE_VALUE_TYPE(switches::kEnableAcceleratedFilters)
199 },
200 {
[email protected]8ff7f342011-05-25 01:49:47201 "disable-gpu-vsync",
202 IDS_FLAGS_DISABLE_GPU_VSYNC_NAME,
203 IDS_FLAGS_DISABLE_GPU_VSYNC_DESCRIPTION,
204 kOsAll,
205 SINGLE_VALUE_TYPE(switches::kDisableGpuVsync)
206 },
[email protected]deaba6d52011-09-23 14:47:12207 {
208 "disable-webgl",
209 IDS_FLAGS_DISABLE_WEBGL_NAME,
210 IDS_FLAGS_DISABLE_WEBGL_DESCRIPTION,
211 kOsAll,
212 SINGLE_VALUE_TYPE(switches::kDisableExperimentalWebGL)
213 },
[email protected]eb00a762012-01-18 07:29:28214
215#if defined(GOOGLE_CHROME_BUILD)
216 // TODO(thestig) Remove this for bug 107600.
217 {
218 "disable-print-preview", // FLAGS:RECORD_UMA
219 IDS_FLAGS_DISABLE_PRINT_PREVIEW_NAME,
220 IDS_FLAGS_DISABLE_PRINT_PREVIEW_DESCRIPTION,
221 kOsAll,
222 SINGLE_VALUE_TYPE(switches::kDisablePrintPreview)
223 },
224#else
225 // For Chromium builds where users may not have the PDF plugin.
[email protected]8d260e52010-10-13 01:03:05226 {
[email protected]4bc5050c2010-11-18 17:55:54227 "print-preview", // FLAGS:RECORD_UMA
[email protected]9486c1f2010-10-14 19:52:12228 IDS_FLAGS_PRINT_PREVIEW_NAME,
229 IDS_FLAGS_PRINT_PREVIEW_DESCRIPTION,
[email protected]b579afd2011-07-13 00:01:27230 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19231 SINGLE_VALUE_TYPE(switches::kEnablePrintPreview)
[email protected]2fe15fcb2010-10-21 20:39:53232 },
[email protected]eb00a762012-01-18 07:29:28233#endif
234
[email protected]d208f4d82011-05-23 21:52:03235 // TODO(dspringer): When NaCl is on by default, remove this flag entry.
[email protected]2fe15fcb2010-10-21 20:39:53236 {
[email protected]e3791ce92011-08-09 01:03:32237 "enable-nacl", // FLAGS:RECORD_UMA
[email protected]4ff87d202010-11-06 01:28:40238 IDS_FLAGS_ENABLE_NACL_NAME,
239 IDS_FLAGS_ENABLE_NACL_DESCRIPTION,
240 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19241 SINGLE_VALUE_TYPE(switches::kEnableNaCl)
[email protected]4ff87d202010-11-06 01:28:40242 },
[email protected]b39c6d92012-01-31 16:38:41243 // TODO(halyavin): When exception handling is on by default, replace this
244 // flag with disable-nacl-exception-handling.
245 {
246 "enable-nacl-exception-handling", // FLAGS:RECORD_UMA
247 IDS_FLAGS_ENABLE_NACL_EXCEPTION_HANDLING_NAME,
248 IDS_FLAGS_ENABLE_NACL_EXCEPTION_HANDLING_DESCRIPTION,
249 kOsWin,
250 SINGLE_VALUE_TYPE(switches::kEnableNaClExceptionHandling)
251 },
[email protected]4ff87d202010-11-06 01:28:40252 {
[email protected]31a665e72012-03-11 12:37:46253 "nacl-gdb", // FLAGS:RECORD_UMA
254 IDS_FLAGS_NACL_GDB_NAME,
255 IDS_FLAGS_NACL_GDB_DESCRIPTION,
256 kOsWin,
257 SINGLE_VALUE_TYPE(switches::kNaClGdb)
258 },
259 {
[email protected]4bc5050c2010-11-18 17:55:54260 "extension-apis", // FLAGS:RECORD_UMA
[email protected]11dd68cd52010-11-12 01:15:32261 IDS_FLAGS_EXPERIMENTAL_EXTENSION_APIS_NAME,
262 IDS_FLAGS_EXPERIMENTAL_EXTENSION_APIS_DESCRIPTION,
263 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19264 SINGLE_VALUE_TYPE(switches::kEnableExperimentalExtensionApis)
[email protected]11dd68cd52010-11-12 01:15:32265 },
[email protected]3627b06d2010-11-12 16:36:16266 {
[email protected]cbe224d2011-08-04 22:12:49267 "apps-new-install-bubble",
268 IDS_FLAGS_APPS_NEW_INSTALL_BUBBLE_NAME,
269 IDS_FLAGS_APPS_NEW_INSTALL_BUBBLE_DESCRIPTION,
270 kOsAll,
271 SINGLE_VALUE_TYPE(switches::kAppsNewInstallBubble)
272 },
273 {
[email protected]80bd24e2010-11-30 09:34:38274 "disable-hyperlink-auditing",
275 IDS_FLAGS_DISABLE_HYPERLINK_AUDITING_NAME,
276 IDS_FLAGS_DISABLE_HYPERLINK_AUDITING_DESCRIPTION,
277 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19278 SINGLE_VALUE_TYPE(switches::kNoPings)
[email protected]feb28fef2010-12-01 10:52:51279 },
280 {
281 "experimental-location-features", // FLAGS:RECORD_UMA
282 IDS_FLAGS_EXPERIMENTAL_LOCATION_FEATURES_NAME,
283 IDS_FLAGS_EXPERIMENTAL_LOCATION_FEATURES_DESCRIPTION,
284 kOsMac | kOsWin | kOsLinux, // Currently does nothing on CrOS.
[email protected]8a6ff28d2010-12-02 16:35:19285 SINGLE_VALUE_TYPE(switches::kExperimentalLocationFeatures)
286 },
287 {
[email protected]04227962011-01-20 02:03:09288 "disable-interactive-form-validation",
289 IDS_FLAGS_DISABLE_INTERACTIVE_FORM_VALIDATION_NAME,
290 IDS_FLAGS_DISABLE_INTERACTIVE_FORM_VALIDATION_DESCRIPTION,
291 kOsAll,
292 SINGLE_VALUE_TYPE(switches::kDisableInteractiveFormValidation)
293 },
[email protected]8df51192011-01-22 20:05:03294 {
[email protected]07d490bc2011-03-07 17:05:26295 "focus-existing-tab-on-open", // FLAGS:RECORD_UMA
296 IDS_FLAGS_FOCUS_EXISTING_TAB_ON_OPEN_NAME,
297 IDS_FLAGS_FOCUS_EXISTING_TAB_ON_OPEN_DESCRIPTION,
298 kOsAll,
299 SINGLE_VALUE_TYPE(switches::kFocusExistingTabOnOpen)
300 },
[email protected]d5dcfb32011-03-19 00:49:24301 {
[email protected]5aea1862011-03-23 23:55:39302 "tab-groups-context-menu",
303 IDS_FLAGS_TAB_GROUPS_CONTEXT_MENU_NAME,
304 IDS_FLAGS_TAB_GROUPS_CONTEXT_MENU_DESCRIPTION,
305 kOsWin,
306 SINGLE_VALUE_TYPE(switches::kEnableTabGroupsContextMenu)
307 },
[email protected]e9bf9d92011-03-31 20:57:15308 {
[email protected]f2557bd2011-06-01 02:33:07309 "preload-instant-search",
310 IDS_FLAGS_PRELOAD_INSTANT_SEARCH_NAME,
311 IDS_FLAGS_PRELOAD_INSTANT_SEARCH_DESCRIPTION,
312 kOsAll,
313 SINGLE_VALUE_TYPE(switches::kPreloadInstantSearch)
314 },
[email protected]354e33b2011-06-15 00:29:10315 {
316 "static-ip-config",
317 IDS_FLAGS_STATIC_IP_CONFIG_NAME,
318 IDS_FLAGS_STATIC_IP_CONFIG_DESCRIPTION,
319 kOsCrOS,
320#if defined(OS_CHROMEOS)
321 // This switch exists only on Chrome OS.
322 SINGLE_VALUE_TYPE(switches::kEnableStaticIPConfig)
323#else
324 SINGLE_VALUE_TYPE("")
325#endif
326 },
[email protected]3eb5728c2011-06-20 22:32:24327 {
328 "show-autofill-type-predictions",
329 IDS_FLAGS_SHOW_AUTOFILL_TYPE_PREDICTIONS_NAME,
330 IDS_FLAGS_SHOW_AUTOFILL_TYPE_PREDICTIONS_DESCRIPTION,
331 kOsAll,
332 SINGLE_VALUE_TYPE(switches::kShowAutofillTypePredictions)
333 },
[email protected]bff4d3e2011-06-21 23:58:52334 {
[email protected]9a6180d7d2011-09-07 01:40:33335 "sync-tabs",
336 IDS_FLAGS_SYNC_TABS_NAME,
337 IDS_FLAGS_SYNC_TABS_DESCRIPTION,
[email protected]5b0ec7f2011-08-11 02:17:17338 kOsAll,
[email protected]9a6180d7d2011-09-07 01:40:33339 SINGLE_VALUE_TYPE(switches::kEnableSyncTabs)
[email protected]5b0ec7f2011-08-11 02:17:17340 },
341 {
[email protected]aae9eeb12011-10-21 21:59:26342 "sync-app-notifications",
343 IDS_FLAGS_SYNC_APP_NOTIFICATIONS_NAME,
344 IDS_FLAGS_SYNC_APP_NOTIFICATIONS_DESCRIPTION,
345 kOsAll,
[email protected]0b6fba82011-11-18 01:31:11346 SINGLE_VALUE_TYPE(switches::kDisableSyncAppNotifications)
[email protected]aae9eeb12011-10-21 21:59:26347 },
348 {
[email protected]a22ebd812011-06-23 00:05:39349 "enable-smooth-scrolling", // FLAGS:RECORD_UMA
350 IDS_FLAGS_ENABLE_SMOOTH_SCROLLING_NAME,
351 IDS_FLAGS_ENABLE_SMOOTH_SCROLLING_DESCRIPTION,
352 // Can't expose the switch unless the code is compiled in.
[email protected]554b7062011-09-03 03:09:40353 // On by default for the Mac (different implementation in WebKit).
[email protected]554b7062011-09-03 03:09:40354 kOsWin | kOsLinux | kOsCrOS,
[email protected]a22ebd812011-06-23 00:05:39355 SINGLE_VALUE_TYPE(switches::kEnableSmoothScrolling)
356 },
[email protected]81a6b0b2011-06-24 17:55:40357 {
[email protected]9b2c9f6a12012-01-27 21:00:05358 "omnibox-aggressive-with-history-url",
[email protected]ed1e39502011-12-16 14:39:35359 IDS_FLAGS_OMNIBOX_AGGRESSIVE_HISTORY_URL_SCORING_NAME,
360 IDS_FLAGS_OMNIBOX_AGGRESSIVE_HISTORY_URL_SCORING_DESCRIPTION,
361 kOsAll,
[email protected]9b2c9f6a12012-01-27 21:00:05362 MULTI_VALUE_TYPE(kOmniboxAggressiveHistoryURLChoices)
[email protected]ed1e39502011-12-16 14:39:35363 },
364 {
[email protected]032d5e6c2012-02-17 17:53:55365 "omnibox-inline-history-quick-provider",
366 IDS_FLAGS_OMNIBOX_INLINE_HISTORY_QUICK_PROVIDER_NAME,
367 IDS_FLAGS_OMNIBOX_INLINE_HISTORY_QUICK_PROVIDER_DESCRIPTION,
368 kOsAll,
369 MULTI_VALUE_TYPE(kOmniboxInlineHistoryQuickProviderChoices)
370 },
371 {
[email protected]7e7a28092011-12-09 22:24:55372 "enable-panels",
373 IDS_FLAGS_ENABLE_PANELS_NAME,
374 IDS_FLAGS_ENABLE_PANELS_DESCRIPTION,
[email protected]73fb1fc52011-07-09 00:06:54375 kOsAll,
[email protected]7e7a28092011-12-09 22:24:55376 SINGLE_VALUE_TYPE(switches::kEnablePanels)
[email protected]73fb1fc52011-07-09 00:06:54377 },
[email protected]e3749d12011-07-25 22:22:12378 {
[email protected]9931875b2011-11-02 00:19:48379 "disable-shortcuts-provider",
380 IDS_FLAGS_DISABLE_SHORTCUTS_PROVIDER,
381 IDS_FLAGS_DISABLE_SHORTCUTS_PROVIDER_DESCRIPTION,
[email protected]e3749d12011-07-25 22:22:12382 kOsAll,
[email protected]9931875b2011-11-02 00:19:48383 SINGLE_VALUE_TYPE(switches::kDisableShortcutsProvider)
[email protected]e3749d12011-07-25 22:22:12384 },
[email protected]1a2966b92011-08-09 06:50:19385#if defined(OS_CHROMEOS)
386 {
[email protected]cd681c42011-09-29 02:49:44387 "enable-bluetooth",
388 IDS_FLAGS_ENABLE_BLUETOOTH_NAME,
389 IDS_FLAGS_ENABLE_BLUETOOTH_DESCRIPTION,
390 kOsCrOS,
391 SINGLE_VALUE_TYPE(switches::kEnableBluetooth)
392 },
[email protected]1a2966b92011-08-09 06:50:19393#endif
[email protected]80eb4262011-08-03 16:10:41394 {
395 "memory-widget",
396 IDS_FLAGS_MEMORY_WIDGET_NAME,
397 IDS_FLAGS_MEMORY_WIDGET_DESCRIPTION,
398 kOsCrOS,
399#if defined(OS_CHROMEOS)
400 // This switch exists only on Chrome OS.
401 SINGLE_VALUE_TYPE(switches::kMemoryWidget)
402#else
403 SINGLE_VALUE_TYPE("")
404#endif
[email protected]a0e4b072011-08-17 01:47:07405 },
406 {
407 "downloads-new-ui", // FLAGS:RECORD_UMA
408 IDS_FLAGS_DOWNLOADS_NEW_UI_NAME,
409 IDS_FLAGS_DOWNLOADS_NEW_UI_DESCRIPTION,
410 kOsAll,
411 SINGLE_VALUE_TYPE(switches::kDownloadsNewUI)
412 },
[email protected]b7bb44f2011-09-01 05:17:03413 {
414 "enable-autologin",
415 IDS_FLAGS_ENABLE_AUTOLOGIN_NAME,
416 IDS_FLAGS_ENABLE_AUTOLOGIN_DESCRIPTION,
417 kOsMac | kOsWin | kOsLinux,
418 SINGLE_VALUE_TYPE(switches::kEnableAutologin)
419 },
[email protected]b9841172011-09-26 23:36:09420 {
[email protected]bbadb112011-12-12 16:55:28421 "enable-http-pipelining",
422 IDS_FLAGS_ENABLE_HTTP_PIPELINING_NAME,
423 IDS_FLAGS_ENABLE_HTTP_PIPELINING_DESCRIPTION,
424 kOsAll,
425 SINGLE_VALUE_TYPE(switches::kEnableHttpPipelining)
426 },
[email protected]d411c01d2011-10-18 16:00:27427 {
[email protected]f5da41d2011-10-08 17:40:07428 "enable-video-track",
429 IDS_FLAGS_ENABLE_VIDEO_TRACK_NAME,
430 IDS_FLAGS_ENABLE_VIDEO_TRACK_DESCRIPTION,
431 kOsAll,
432 SINGLE_VALUE_TYPE(switches::kEnableVideoTrack)
433 },
[email protected]08b83362011-10-19 05:23:17434 {
[email protected]6aa03b32011-10-27 21:44:44435 "enable-media-source",
436 IDS_FLAGS_ENABLE_MEDIA_SOURCE_NAME,
437 IDS_FLAGS_ENABLE_MEDIA_SOURCE_DESCRIPTION,
438 kOsAll,
439 SINGLE_VALUE_TYPE(switches::kEnableMediaSource)
440 },
[email protected]e4e68dbb2011-11-18 01:50:22441 {
442 "enable-pointer-lock",
443 IDS_FLAGS_ENABLE_POINTER_LOCK_NAME,
444 IDS_FLAGS_ENABLE_POINTER_LOCK_DESCRIPTION,
445 kOsAll,
446 SINGLE_VALUE_TYPE(switches::kEnablePointerLock)
447 },
[email protected]8cc10df2011-11-03 23:57:50448#if defined(USE_AURA)
449 {
[email protected]57b8bb352012-01-11 05:11:46450 "aura-google-dialog-frames",
451 IDS_FLAGS_AURA_GOOGLE_DIALOG_FRAMES_NAME,
452 IDS_FLAGS_AURA_GOOGLE_DIALOG_FRAMES_DESCRIPTION,
453 kOsWin | kOsLinux | kOsCrOS,
454 SINGLE_VALUE_TYPE(ash::switches::kAuraGoogleDialogFrames)
455 },
[email protected]308aaa32012-03-12 13:14:50456 {
457 "aura-disable-hold-mouse-moves",
458 IDS_FLAGS_AURA_DISABLE_HOLD_MOUSE_MOVES_NAME,
459 IDS_FLAGS_AURA_DISABLE_HOLD_MOUSE_MOVES_DESCRIPTION,
460 kOsWin | kOsLinux | kOsCrOS,
461 SINGLE_VALUE_TYPE(switches::kAuraDisableHoldMouseMoves)
462 },
[email protected]eaae8b462012-01-20 22:20:39463#endif // defined(USE_AURA)
464 {
465 "enable-gamepad",
466 IDS_FLAGS_ENABLE_GAMEPAD_NAME,
467 IDS_FLAGS_ENABLE_GAMEPAD_DESCRIPTION,
468 kOsAll,
469 SINGLE_VALUE_TYPE(switches::kEnableGamepad)
470 },
[email protected]db543d322011-12-15 20:40:15471 {
472 "per-tile-painting",
473 IDS_FLAGS_PER_TILE_PAINTING_NAME,
474 IDS_FLAGS_PER_TILE_PAINTING_DESCRIPTION,
475#if defined(USE_SKIA)
[email protected]a5b1b272012-01-06 20:44:37476 kOsMac | kOsLinux | kOsCrOS,
[email protected]db543d322011-12-15 20:40:15477#else
478 0,
479#endif
480 SINGLE_VALUE_TYPE(switches::kEnablePerTilePainting)
481 },
[email protected]bf88c032011-12-22 19:05:47482 {
483 "enable-javascript-harmony",
484 IDS_FLAGS_ENABLE_JAVASCRIPT_HARMONY_NAME,
485 IDS_FLAGS_ENABLE_JAVASCRIPT_HARMONY_DESCRIPTION,
486 kOsAll,
487 SINGLE_VALUE_TYPE_AND_VALUE(switches::kJavaScriptFlags, "--harmony")
488 },
[email protected]7e7f378a2012-01-05 14:35:37489 {
[email protected]85646172012-01-09 22:45:54490 "enable-tab-browser-dragging",
491 IDS_FLAGS_ENABLE_TAB_BROWSER_DRAGGING_NAME,
492 IDS_FLAGS_ENABLE_TAB_BROWSER_DRAGGING_DESCRIPTION,
493 kOsWin,
494 SINGLE_VALUE_TYPE(switches::kTabBrowserDragging)
495 },
496 {
[email protected]068b7b52012-02-27 12:41:44497 "disable-restore-session-state",
498 IDS_FLAGS_DISABLE_RESTORE_SESSION_STATE_NAME,
499 IDS_FLAGS_DISABLE_RESTORE_SESSION_STATE_DESCRIPTION,
[email protected]7e7f378a2012-01-05 14:35:37500 kOsAll,
[email protected]068b7b52012-02-27 12:41:44501 SINGLE_VALUE_TYPE(switches::kDisableRestoreSessionState)
[email protected]7e7f378a2012-01-05 14:35:37502 },
[email protected]88864db2012-01-18 20:56:35503 {
504 "disable-software-rasterizer",
505 IDS_FLAGS_DISABLE_SOFTWARE_RASTERIZER_NAME,
506 IDS_FLAGS_DISABLE_SOFTWARE_RASTERIZER_DESCRIPTION,
507#if defined(ENABLE_SWIFTSHADER)
508 kOsAll,
509#else
510 0,
511#endif
512 SINGLE_VALUE_TYPE(switches::kDisableSoftwareRasterizer)
513 },
[email protected]15a5d722012-01-23 09:11:14514 {
515 "enable-media-stream",
516 IDS_FLAGS_MEDIA_STREAM_NAME,
517 IDS_FLAGS_MEDIA_STREAM_DESCRIPTION,
[email protected]fa82b6772012-02-20 13:19:05518 kOsAll,
[email protected]15a5d722012-01-23 09:11:14519 SINGLE_VALUE_TYPE(switches::kEnableMediaStream)
520 },
[email protected]f5ec7242012-01-27 07:15:15521 {
[email protected]fa12e2d2012-02-06 21:03:10522 "disable-uber-page",
523 IDS_FLAGS_DISABLE_UBER_PAGE_NAME,
524 IDS_FLAGS_DISABLE_UBER_PAGE_DESCRIPTION,
[email protected]f5ec7242012-01-27 07:15:15525 kOsAll,
[email protected]fa12e2d2012-02-06 21:03:10526 SINGLE_VALUE_TYPE(switches::kDisableUberPage)
[email protected]f5ec7242012-01-27 07:15:15527 },
[email protected]d2edc6702012-01-30 09:13:16528 {
529 "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]31cf1c52012-02-29 20:55:01577#if defined(USE_AURA)
578 {
579 "enable-ash-uber-tray",
580 IDS_FLAGS_ENABLE_ASH_UBER_TRAY_NAME,
581 IDS_FLAGS_ENABLE_ASH_UBER_TRAY_DESCRIPTION,
582 kOsAll,
583 SINGLE_VALUE_TYPE(ash::switches::kAshUberTray),
584 },
[email protected]3cd198a22012-03-12 20:38:01585 {
586 "enable-ash-oak",
587 IDS_FLAGS_ENABLE_ASH_OAK_NAME,
588 IDS_FLAGS_ENABLE_ASH_OAK_DESCRIPTION,
589 kOsAll,
590 SINGLE_VALUE_TYPE(ash::switches::kAshEnableOak),
591 },
[email protected]31cf1c52012-02-29 20:55:01592#endif
[email protected]184ec592012-03-01 11:54:28593 {
594 "enable-devtools-experiments",
595 IDS_FLAGS_ENABLE_DEVTOOLS_EXPERIMENTS_NAME,
596 IDS_FLAGS_ENABLE_DEVTOOLS_EXPERIMENTS_DESCRIPTION,
597 kOsAll,
598 SINGLE_VALUE_TYPE(switches::kEnableDevToolsExperiments)
599 },
[email protected]76d1854e2012-03-02 23:57:44600 {
601 "enable-suggestions-ntp",
602 IDS_FLAGS_NTP_SUGGESTIONS_PAGE_NAME,
603 IDS_FLAGS_NTP_SUGGESTIONS_PAGE_DESCRIPTION,
604 kOsAll,
605 SINGLE_VALUE_TYPE(switches::kEnableSuggestionsTabPage)
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);
804 data->SetBoolean("supported", supported);
805
806 ListValue* supported_platforms = new ListValue();
807 AddOsStrings(experiment.supported_platforms, supported_platforms);
808 data->Set("supported_platforms", supported_platforms);
[email protected]ad2a3ded2010-08-27 13:19:05809
[email protected]28e35af2011-02-09 12:56:22810 switch (experiment.type) {
811 case Experiment::SINGLE_VALUE:
812 data->SetBoolean(
813 "enabled",
814 enabled_experiments.count(experiment.internal_name) > 0);
815 break;
816 case Experiment::MULTI_VALUE:
817 data->Set("choices", CreateChoiceData(experiment, enabled_experiments));
818 break;
819 default:
820 NOTREACHED();
[email protected]8a6ff28d2010-12-02 16:35:19821 }
822
[email protected]ad2a3ded2010-08-27 13:19:05823 experiments_data->Append(data);
824 }
825 return experiments_data;
826}
827
[email protected]ad2a3ded2010-08-27 13:19:05828bool IsRestartNeededToCommitChanges() {
[email protected]8e8bb6d2010-12-13 08:18:55829 return FlagsState::GetInstance()->IsRestartNeededToCommitChanges();
[email protected]ad2a3ded2010-08-27 13:19:05830}
831
832void SetExperimentEnabled(
[email protected]c7b7800a2010-10-07 18:51:35833 PrefService* prefs, const std::string& internal_name, bool enable) {
[email protected]8e8bb6d2010-12-13 08:18:55834 FlagsState::GetInstance()->SetExperimentEnabled(prefs, internal_name, enable);
[email protected]e2ddbc92010-10-15 20:02:07835}
836
837void RemoveFlagsSwitches(
838 std::map<std::string, CommandLine::StringType>* switch_list) {
[email protected]8e8bb6d2010-12-13 08:18:55839 FlagsState::GetInstance()->RemoveFlagsSwitches(switch_list);
[email protected]e2ddbc92010-10-15 20:02:07840}
841
[email protected]a314ee5a2010-10-26 21:23:28842int GetCurrentPlatform() {
843#if defined(OS_MACOSX)
844 return kOsMac;
845#elif defined(OS_WIN)
846 return kOsWin;
847#elif defined(OS_CHROMEOS) // Needs to be before the OS_LINUX check.
848 return kOsCrOS;
[email protected]c92f4ed2011-10-21 19:50:21849#elif defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]a314ee5a2010-10-26 21:23:28850 return kOsLinux;
[email protected]9c7453d2012-01-21 00:45:40851#elif defined(OS_ANDROID)
852 return kOsAndroid;
[email protected]a314ee5a2010-10-26 21:23:28853#else
854#error Unknown platform
855#endif
856}
857
[email protected]4bc5050c2010-11-18 17:55:54858void RecordUMAStatistics(const PrefService* prefs) {
859 std::set<std::string> flags;
860 GetEnabledFlags(prefs, &flags);
861 for (std::set<std::string>::iterator it = flags.begin(); it != flags.end();
862 ++it) {
863 std::string action("AboutFlags_");
864 action += *it;
[email protected]7f6f44c2011-12-14 13:23:38865 content::RecordComputedAction(action);
[email protected]4bc5050c2010-11-18 17:55:54866 }
867 // Since flag metrics are recorded every startup, add a tick so that the
868 // stats can be made meaningful.
869 if (flags.size())
[email protected]7f6f44c2011-12-14 13:23:38870 content::RecordAction(UserMetricsAction("AboutFlags_StartupTick"));
871 content::RecordAction(UserMetricsAction("StartupTick"));
[email protected]4bc5050c2010-11-18 17:55:54872}
873
[email protected]e2ddbc92010-10-15 20:02:07874//////////////////////////////////////////////////////////////////////////////
875// FlagsState implementation.
876
877namespace {
878
879void FlagsState::ConvertFlagsToSwitches(
880 PrefService* prefs, CommandLine* command_line) {
[email protected]e2ddbc92010-10-15 20:02:07881 if (command_line->HasSwitch(switches::kNoExperiments))
882 return;
883
884 std::set<std::string> enabled_experiments;
[email protected]ba8164242010-11-16 21:31:00885
[email protected]a314ee5a2010-10-26 21:23:28886 GetSanitizedEnabledFlagsForCurrentPlatform(prefs, &enabled_experiments);
[email protected]e2ddbc92010-10-15 20:02:07887
[email protected]a82744532011-02-11 16:15:53888 typedef std::map<std::string, std::pair<std::string, std::string> >
889 NameToSwitchAndValueMap;
890 NameToSwitchAndValueMap name_to_switch_map;
[email protected]8a6ff28d2010-12-02 16:35:19891 for (size_t i = 0; i < num_experiments; ++i) {
892 const Experiment& e = experiments[i];
893 if (e.type == Experiment::SINGLE_VALUE) {
[email protected]a82744532011-02-11 16:15:53894 name_to_switch_map[e.internal_name] =
895 std::pair<std::string, std::string>(e.command_line_switch,
896 e.command_line_value);
[email protected]8a6ff28d2010-12-02 16:35:19897 } else {
898 for (int j = 0; j < e.num_choices; ++j)
[email protected]a82744532011-02-11 16:15:53899 name_to_switch_map[NameForChoice(e, j)] =
900 std::pair<std::string, std::string>(
901 e.choices[j].command_line_switch,
902 e.choices[j].command_line_value);
[email protected]8a6ff28d2010-12-02 16:35:19903 }
904 }
[email protected]e2ddbc92010-10-15 20:02:07905
906 command_line->AppendSwitch(switches::kFlagSwitchesBegin);
[email protected]a82744532011-02-11 16:15:53907 flags_switches_.insert(
908 std::pair<std::string, std::string>(switches::kFlagSwitchesBegin,
909 std::string()));
[email protected]e2ddbc92010-10-15 20:02:07910 for (std::set<std::string>::iterator it = enabled_experiments.begin();
911 it != enabled_experiments.end();
912 ++it) {
913 const std::string& experiment_name = *it;
[email protected]a82744532011-02-11 16:15:53914 NameToSwitchAndValueMap::const_iterator name_to_switch_it =
[email protected]8a6ff28d2010-12-02 16:35:19915 name_to_switch_map.find(experiment_name);
916 if (name_to_switch_it == name_to_switch_map.end()) {
917 NOTREACHED();
[email protected]e2ddbc92010-10-15 20:02:07918 continue;
[email protected]8a6ff28d2010-12-02 16:35:19919 }
[email protected]e2ddbc92010-10-15 20:02:07920
[email protected]a82744532011-02-11 16:15:53921 const std::pair<std::string, std::string>&
922 switch_and_value_pair = name_to_switch_it->second;
923
924 command_line->AppendSwitchASCII(switch_and_value_pair.first,
925 switch_and_value_pair.second);
926 flags_switches_[switch_and_value_pair.first] = switch_and_value_pair.second;
[email protected]e2ddbc92010-10-15 20:02:07927 }
928 command_line->AppendSwitch(switches::kFlagSwitchesEnd);
[email protected]a82744532011-02-11 16:15:53929 flags_switches_.insert(
930 std::pair<std::string, std::string>(switches::kFlagSwitchesEnd,
931 std::string()));
[email protected]e2ddbc92010-10-15 20:02:07932}
933
934bool FlagsState::IsRestartNeededToCommitChanges() {
935 return needs_restart_;
936}
937
938void FlagsState::SetExperimentEnabled(
939 PrefService* prefs, const std::string& internal_name, bool enable) {
[email protected]ad2a3ded2010-08-27 13:19:05940 needs_restart_ = true;
941
[email protected]8a6ff28d2010-12-02 16:35:19942 size_t at_index = internal_name.find(about_flags::testing::kMultiSeparator);
943 if (at_index != std::string::npos) {
944 DCHECK(enable);
945 // We're being asked to enable a multi-choice experiment. Disable the
946 // currently selected choice.
947 DCHECK_NE(at_index, 0u);
[email protected]28e35af2011-02-09 12:56:22948 const std::string experiment_name = internal_name.substr(0, at_index);
949 SetExperimentEnabled(prefs, experiment_name, false);
[email protected]8a6ff28d2010-12-02 16:35:19950
[email protected]28e35af2011-02-09 12:56:22951 // And enable the new choice, if it is not the default first choice.
952 if (internal_name != experiment_name + "@0") {
953 std::set<std::string> enabled_experiments;
954 GetSanitizedEnabledFlags(prefs, &enabled_experiments);
955 enabled_experiments.insert(internal_name);
956 SetEnabledFlags(prefs, enabled_experiments);
957 }
[email protected]8a6ff28d2010-12-02 16:35:19958 return;
959 }
960
[email protected]ad2a3ded2010-08-27 13:19:05961 std::set<std::string> enabled_experiments;
[email protected]1a47d7e2010-10-15 00:37:24962 GetSanitizedEnabledFlags(prefs, &enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05963
[email protected]8a6ff28d2010-12-02 16:35:19964 const Experiment* e = NULL;
965 for (size_t i = 0; i < num_experiments; ++i) {
966 if (experiments[i].internal_name == internal_name) {
967 e = experiments + i;
968 break;
969 }
970 }
971 DCHECK(e);
972
973 if (e->type == Experiment::SINGLE_VALUE) {
[email protected]8a2713682011-08-19 10:36:59974 if (enable)
[email protected]8a6ff28d2010-12-02 16:35:19975 enabled_experiments.insert(internal_name);
[email protected]8a2713682011-08-19 10:36:59976 else
[email protected]8a6ff28d2010-12-02 16:35:19977 enabled_experiments.erase(internal_name);
978 } else {
979 if (enable) {
980 // Enable the first choice.
981 enabled_experiments.insert(NameForChoice(*e, 0));
982 } else {
983 // Find the currently enabled choice and disable it.
984 for (int i = 0; i < e->num_choices; ++i) {
985 std::string choice_name = NameForChoice(*e, i);
986 if (enabled_experiments.find(choice_name) !=
987 enabled_experiments.end()) {
988 enabled_experiments.erase(choice_name);
989 // Continue on just in case there's a bug and more than one
990 // experiment for this choice was enabled.
991 }
992 }
993 }
994 }
[email protected]ad2a3ded2010-08-27 13:19:05995
[email protected]1a47d7e2010-10-15 00:37:24996 SetEnabledFlags(prefs, enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05997}
998
[email protected]e2ddbc92010-10-15 20:02:07999void FlagsState::RemoveFlagsSwitches(
1000 std::map<std::string, CommandLine::StringType>* switch_list) {
[email protected]a82744532011-02-11 16:15:531001 for (std::map<std::string, std::string>::const_iterator
1002 it = flags_switches_.begin(); it != flags_switches_.end(); ++it) {
1003 switch_list->erase(it->first);
[email protected]e2ddbc92010-10-15 20:02:071004 }
1005}
1006
1007void FlagsState::reset() {
1008 needs_restart_ = false;
1009 flags_switches_.clear();
1010}
1011
[email protected]38e46812011-05-09 20:49:221012} // namespace
[email protected]e2ddbc92010-10-15 20:02:071013
1014namespace testing {
[email protected]8a6ff28d2010-12-02 16:35:191015
1016// WARNING: '@' is also used in the html file. If you update this constant you
1017// also need to update the html file.
1018const char kMultiSeparator[] = "@";
1019
[email protected]e2ddbc92010-10-15 20:02:071020void ClearState() {
[email protected]8e8bb6d2010-12-13 08:18:551021 FlagsState::GetInstance()->reset();
[email protected]e2ddbc92010-10-15 20:02:071022}
[email protected]a314ee5a2010-10-26 21:23:281023
1024void SetExperiments(const Experiment* e, size_t count) {
1025 if (!e) {
1026 experiments = kExperiments;
1027 num_experiments = arraysize(kExperiments);
1028 } else {
1029 experiments = e;
1030 num_experiments = count;
1031 }
1032}
1033
[email protected]8a6ff28d2010-12-02 16:35:191034const Experiment* GetExperiments(size_t* count) {
1035 *count = num_experiments;
1036 return experiments;
1037}
1038
[email protected]e2ddbc92010-10-15 20:02:071039} // namespace testing
1040
[email protected]1a47d7e2010-10-15 00:37:241041} // namespace about_flags