blob: 958328f0662eb3690fc5c3c1b78f7e75a5440d26 [file] [log] [blame]
[email protected]3828d6f2011-02-24 18:32:211// Copyright (c) 2011 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]3e14cad2011-12-20 21:14:2928#include "ui/aura_shell/aura_shell_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]a314ee5a2010-10-26 21:23:2845const unsigned kOsAll = kOsMac | kOsWin | kOsLinux | kOsCrOS;
[email protected]ad2a3ded2010-08-27 13:19:0546
[email protected]cc3e2052011-12-20 01:01:4047// Adds a |StringValue| to |list| for each platform where |bitmask| indicates
48// whether the experiment is available on that platform.
49void AddOsStrings(unsigned bitmask, ListValue* list) {
50 struct {
51 unsigned bit;
52 const char* const name;
53 } kBitsToOs[] = {
54 {kOsMac, "Mac"},
55 {kOsWin, "Windows"},
56 {kOsLinux, "Linux"},
57 {kOsCrOS, "Chrome OS"},
58 };
59 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kBitsToOs); ++i)
60 if (bitmask & kBitsToOs[i].bit)
61 list->Append(new StringValue(kBitsToOs[i].name));
62}
63
[email protected]ba8164242010-11-16 21:31:0064// Names for former Chrome OS Labs experiments, shared with prefs migration
65// code.
66const char kMediaPlayerExperimentName[] = "media-player";
67const char kAdvancedFileSystemExperimentName[] = "advanced-file-system";
68const char kVerticalTabsExperimentName[] = "vertical-tabs";
69
[email protected]778ef7c2011-10-11 15:37:0570const Experiment::Choice kPrerenderFromOmniboxChoices[] = {
71 { IDS_FLAGS_PRERENDER_FROM_OMNIBOX_AUTOMATIC, "", "" },
72 { IDS_FLAGS_PRERENDER_FROM_OMNIBOX_ENABLED, switches::kPrerenderFromOmnibox,
73 switches::kPrerenderFromOmniboxSwitchValueEnabled },
74 { IDS_FLAGS_PRERENDER_FROM_OMNIBOX_DISABLED, switches::kPrerenderFromOmnibox,
75 switches::kPrerenderFromOmniboxSwitchValueDisabled }
76};
77
[email protected]3fbd9c12011-12-16 21:35:1178#if defined(USE_AURA)
79const Experiment::Choice kAuraWindowModeChoices[] = {
80 { IDS_FLAGS_AURA_WINDOW_MODE_NORMAL, "", "" },
81 { IDS_FLAGS_AURA_WINDOW_MODE_COMPACT,
[email protected]3e14cad2011-12-20 21:14:2982 aura_shell::switches::kAuraWindowMode,
83 aura_shell::switches::kAuraWindowModeCompact }
[email protected]3fbd9c12011-12-16 21:35:1184};
85#endif
86
[email protected]4bc5050c2010-11-18 17:55:5487// RECORDING USER METRICS FOR FLAGS:
88// -----------------------------------------------------------------------------
89// The first line of the experiment is the internal name. If you'd like to
90// gather statistics about the usage of your flag, you should append a marker
91// comment to the end of the feature name, like so:
92// "my-special-feature", // FLAGS:RECORD_UMA
93//
94// After doing that, run //chrome/tools/extract_actions.py (see instructions at
95// the top of that file for details) to update the chromeactions.txt file, which
96// will enable UMA to record your feature flag.
97//
98// After your feature has shipped under a flag, you can locate the metrics
99// under the action name AboutFlags_internal-action-name. Actions are recorded
100// once per startup, so you should divide this number by AboutFlags_StartupTick
101// to get a sense of usage. Note that this will not be the same as number of
102// users with a given feature enabled because users can quit and relaunch
103// the application multiple times over a given time interval.
104// TODO(rsesek): See if there's a way to count per-user, rather than
105// per-startup.
106
[email protected]8a6ff28d2010-12-02 16:35:19107// To add a new experiment add to the end of kExperiments. There are two
108// distinct types of experiments:
109// . SINGLE_VALUE: experiment is either on or off. Use the SINGLE_VALUE_TYPE
110// macro for this type supplying the command line to the macro.
[email protected]28e35af2011-02-09 12:56:22111// . MULTI_VALUE: a list of choices, the first of which should correspond to a
112// deactivated state for this lab (i.e. no command line option). To specify
113// this type of experiment use the macro MULTI_VALUE_TYPE supplying it the
114// array of choices.
[email protected]8a6ff28d2010-12-02 16:35:19115// See the documentation of Experiment for details on the fields.
116//
117// When adding a new choice, add it to the end of the list.
[email protected]ad2a3ded2010-08-27 13:19:05118const Experiment kExperiments[] = {
119 {
[email protected]aac169d2011-03-18 19:53:03120 "expose-for-tabs", // FLAGS:RECORD_UMA
121 IDS_FLAGS_TABPOSE_NAME,
122 IDS_FLAGS_TABPOSE_DESCRIPTION,
123 kOsMac,
124#if defined(OS_MACOSX)
125 // The switch exists only on OS X.
126 SINGLE_VALUE_TYPE(switches::kEnableExposeForTabs)
127#else
128 SINGLE_VALUE_TYPE("")
129#endif
130 },
131 {
[email protected]4bc5050c2010-11-18 17:55:54132 "conflicting-modules-check", // FLAGS:RECORD_UMA
[email protected]c1bbaa82010-11-08 11:17:05133 IDS_FLAGS_CONFLICTS_CHECK_NAME,
134 IDS_FLAGS_CONFLICTS_CHECK_DESCRIPTION,
135 kOsWin,
[email protected]8a6ff28d2010-12-02 16:35:19136 SINGLE_VALUE_TYPE(switches::kConflictingModulesCheck)
[email protected]c1bbaa82010-11-08 11:17:05137 },
138 {
[email protected]4bc5050c2010-11-18 17:55:54139 "cloud-print-proxy", // FLAGS:RECORD_UMA
[email protected]9486c1f2010-10-14 19:52:12140 IDS_FLAGS_CLOUD_PRINT_PROXY_NAME,
141 IDS_FLAGS_CLOUD_PRINT_PROXY_DESCRIPTION,
[email protected]9f8872b32011-03-04 19:44:45142 // For a Chrome build, we know we have a PDF plug-in on Windows, so it's
[email protected]4fa24bf2011-08-20 02:15:22143 // fully enabled.
[email protected]5d10d57d2011-07-22 22:16:31144 // Otherwise, where we know Windows could be working if a viable PDF
[email protected]4fa24bf2011-08-20 02:15:22145 // plug-in could be supplied, we'll keep the lab enabled. Mac and Linux
146 // always have PDF rasterization available, so no flag needed there.
147#if !defined(GOOGLE_CHROME_BUILD)
148 kOsWin,
149#else
150 0,
[email protected]fa6d2a2f2010-11-30 21:47:19151#endif
[email protected]8a6ff28d2010-12-02 16:35:19152 SINGLE_VALUE_TYPE(switches::kEnableCloudPrintProxy)
[email protected]8b6588a2010-10-12 02:39:42153 },
[email protected]580939a2010-10-12 18:54:37154 {
[email protected]bb461532010-11-26 21:50:23155 "crxless-web-apps",
156 IDS_FLAGS_CRXLESS_WEB_APPS_NAME,
157 IDS_FLAGS_CRXLESS_WEB_APPS_DESCRIPTION,
158 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19159 SINGLE_VALUE_TYPE(switches::kEnableCrxlessWebApps)
[email protected]bb461532010-11-26 21:50:23160 },
161 {
[email protected]96c6f4c2011-05-18 19:36:22162 "ignore-gpu-blacklist",
163 IDS_FLAGS_IGNORE_GPU_BLACKLIST_NAME,
164 IDS_FLAGS_IGNORE_GPU_BLACKLIST_DESCRIPTION,
165 kOsAll,
166 SINGLE_VALUE_TYPE(switches::kIgnoreGpuBlacklist)
167 },
168 {
[email protected]0110cf112011-07-02 00:39:43169 "force-compositing-mode-2",
[email protected]96c6f4c2011-05-18 19:36:22170 IDS_FLAGS_FORCE_COMPOSITING_MODE_NAME,
171 IDS_FLAGS_FORCE_COMPOSITING_MODE_DESCRIPTION,
172 kOsAll,
173 SINGLE_VALUE_TYPE(switches::kForceCompositingMode)
174 },
175 {
[email protected]5963b772011-02-09 22:55:38176 "composited-layer-borders",
177 IDS_FLAGS_COMPOSITED_LAYER_BORDERS,
178 IDS_FLAGS_COMPOSITED_LAYER_BORDERS_DESCRIPTION,
179 kOsAll,
180 SINGLE_VALUE_TYPE(switches::kShowCompositedLayerBorders)
181 },
182 {
[email protected]db543d322011-12-15 20:40:15183 "accelerated-painting",
184 IDS_FLAGS_ACCELERATED_PAINTING_NAME,
185 IDS_FLAGS_ACCELERATED_PAINTING_DESCRIPTION,
[email protected]60dea122011-12-06 00:32:45186#if defined(USE_SKIA)
187 kOsAll,
188#else
189 0,
190#endif
[email protected]db543d322011-12-15 20:40:15191 SINGLE_VALUE_TYPE(switches::kEnableAcceleratedPainting)
[email protected]60dea122011-12-06 00:32:45192 },
193 {
[email protected]a8f1eaa2011-03-07 19:00:58194 "show-fps-counter",
195 IDS_FLAGS_SHOW_FPS_COUNTER,
196 IDS_FLAGS_SHOW_FPS_COUNTER_DESCRIPTION,
197 kOsAll,
198 SINGLE_VALUE_TYPE(switches::kShowFPSCounter)
199 },
[email protected]8ff7f342011-05-25 01:49:47200 {
[email protected]70c98a332011-12-21 20:51:52201 "accelerated-filters",
202 IDS_FLAGS_ACCELERATED_FILTERS,
203 IDS_FLAGS_ACCELERATED_FILTERS_DESCRIPTION,
204 kOsAll,
205 SINGLE_VALUE_TYPE(switches::kEnableAcceleratedFilters)
206 },
207 {
[email protected]8ff7f342011-05-25 01:49:47208 "disable-gpu-vsync",
209 IDS_FLAGS_DISABLE_GPU_VSYNC_NAME,
210 IDS_FLAGS_DISABLE_GPU_VSYNC_DESCRIPTION,
211 kOsAll,
212 SINGLE_VALUE_TYPE(switches::kDisableGpuVsync)
213 },
[email protected]deaba6d52011-09-23 14:47:12214 {
215 "disable-webgl",
216 IDS_FLAGS_DISABLE_WEBGL_NAME,
217 IDS_FLAGS_DISABLE_WEBGL_DESCRIPTION,
218 kOsAll,
219 SINGLE_VALUE_TYPE(switches::kDisableExperimentalWebGL)
220 },
[email protected]9de0ec12011-08-24 21:57:50221 // Exposed on all platforms until there is a workaround for easy access to
222 // the native print dialog for users that need it. Once that's done, revert
223 // back to:
224 // Only expose this for Chromium builds where users may not have the PDF
225 // plugin. Do not give Google Chrome users the option to disable it here.
226 // Also expose it for Chrome OS where print preview is still experimental.
[email protected]8d260e52010-10-13 01:03:05227 {
[email protected]4bc5050c2010-11-18 17:55:54228 "print-preview", // FLAGS:RECORD_UMA
[email protected]9486c1f2010-10-14 19:52:12229 IDS_FLAGS_PRINT_PREVIEW_NAME,
230 IDS_FLAGS_PRINT_PREVIEW_DESCRIPTION,
[email protected]b579afd2011-07-13 00:01:27231 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19232 SINGLE_VALUE_TYPE(switches::kEnablePrintPreview)
[email protected]2fe15fcb2010-10-21 20:39:53233 },
[email protected]d208f4d82011-05-23 21:52:03234 // TODO(dspringer): When NaCl is on by default, remove this flag entry.
[email protected]2fe15fcb2010-10-21 20:39:53235 {
[email protected]e3791ce92011-08-09 01:03:32236 "enable-nacl", // FLAGS:RECORD_UMA
[email protected]4ff87d202010-11-06 01:28:40237 IDS_FLAGS_ENABLE_NACL_NAME,
238 IDS_FLAGS_ENABLE_NACL_DESCRIPTION,
239 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19240 SINGLE_VALUE_TYPE(switches::kEnableNaCl)
[email protected]4ff87d202010-11-06 01:28:40241 },
242 {
[email protected]4bc5050c2010-11-18 17:55:54243 "extension-apis", // FLAGS:RECORD_UMA
[email protected]11dd68cd52010-11-12 01:15:32244 IDS_FLAGS_EXPERIMENTAL_EXTENSION_APIS_NAME,
245 IDS_FLAGS_EXPERIMENTAL_EXTENSION_APIS_DESCRIPTION,
246 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19247 SINGLE_VALUE_TYPE(switches::kEnableExperimentalExtensionApis)
[email protected]11dd68cd52010-11-12 01:15:32248 },
[email protected]3627b06d2010-11-12 16:36:16249 {
[email protected]cbe224d2011-08-04 22:12:49250 "apps-new-install-bubble",
251 IDS_FLAGS_APPS_NEW_INSTALL_BUBBLE_NAME,
252 IDS_FLAGS_APPS_NEW_INSTALL_BUBBLE_DESCRIPTION,
253 kOsAll,
254 SINGLE_VALUE_TYPE(switches::kAppsNewInstallBubble)
255 },
256 {
[email protected]4bc5050c2010-11-18 17:55:54257 "click-to-play", // FLAGS:RECORD_UMA
[email protected]3627b06d2010-11-12 16:36:16258 IDS_FLAGS_CLICK_TO_PLAY_NAME,
259 IDS_FLAGS_CLICK_TO_PLAY_DESCRIPTION,
260 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19261 SINGLE_VALUE_TYPE(switches::kEnableClickToPlay)
[email protected]3627b06d2010-11-12 16:36:16262 },
[email protected]80bd24e2010-11-30 09:34:38263 {
264 "disable-hyperlink-auditing",
265 IDS_FLAGS_DISABLE_HYPERLINK_AUDITING_NAME,
266 IDS_FLAGS_DISABLE_HYPERLINK_AUDITING_DESCRIPTION,
267 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19268 SINGLE_VALUE_TYPE(switches::kNoPings)
[email protected]feb28fef2010-12-01 10:52:51269 },
270 {
271 "experimental-location-features", // FLAGS:RECORD_UMA
272 IDS_FLAGS_EXPERIMENTAL_LOCATION_FEATURES_NAME,
273 IDS_FLAGS_EXPERIMENTAL_LOCATION_FEATURES_DESCRIPTION,
274 kOsMac | kOsWin | kOsLinux, // Currently does nothing on CrOS.
[email protected]8a6ff28d2010-12-02 16:35:19275 SINGLE_VALUE_TYPE(switches::kExperimentalLocationFeatures)
276 },
277 {
[email protected]04227962011-01-20 02:03:09278 "disable-interactive-form-validation",
279 IDS_FLAGS_DISABLE_INTERACTIVE_FORM_VALIDATION_NAME,
280 IDS_FLAGS_DISABLE_INTERACTIVE_FORM_VALIDATION_DESCRIPTION,
281 kOsAll,
282 SINGLE_VALUE_TYPE(switches::kDisableInteractiveFormValidation)
283 },
[email protected]8df51192011-01-22 20:05:03284 {
[email protected]07d490bc2011-03-07 17:05:26285 "focus-existing-tab-on-open", // FLAGS:RECORD_UMA
286 IDS_FLAGS_FOCUS_EXISTING_TAB_ON_OPEN_NAME,
287 IDS_FLAGS_FOCUS_EXISTING_TAB_ON_OPEN_DESCRIPTION,
288 kOsAll,
289 SINGLE_VALUE_TYPE(switches::kFocusExistingTabOnOpen)
290 },
[email protected]d5dcfb32011-03-19 00:49:24291 {
[email protected]5aea1862011-03-23 23:55:39292 "tab-groups-context-menu",
293 IDS_FLAGS_TAB_GROUPS_CONTEXT_MENU_NAME,
294 IDS_FLAGS_TAB_GROUPS_CONTEXT_MENU_DESCRIPTION,
295 kOsWin,
296 SINGLE_VALUE_TYPE(switches::kEnableTabGroupsContextMenu)
297 },
[email protected]e9bf9d92011-03-31 20:57:15298 {
[email protected]f2557bd2011-06-01 02:33:07299 "preload-instant-search",
300 IDS_FLAGS_PRELOAD_INSTANT_SEARCH_NAME,
301 IDS_FLAGS_PRELOAD_INSTANT_SEARCH_DESCRIPTION,
302 kOsAll,
303 SINGLE_VALUE_TYPE(switches::kPreloadInstantSearch)
304 },
[email protected]354e33b2011-06-15 00:29:10305 {
306 "static-ip-config",
307 IDS_FLAGS_STATIC_IP_CONFIG_NAME,
308 IDS_FLAGS_STATIC_IP_CONFIG_DESCRIPTION,
309 kOsCrOS,
310#if defined(OS_CHROMEOS)
311 // This switch exists only on Chrome OS.
312 SINGLE_VALUE_TYPE(switches::kEnableStaticIPConfig)
313#else
314 SINGLE_VALUE_TYPE("")
315#endif
316 },
[email protected]3eb5728c2011-06-20 22:32:24317 {
318 "show-autofill-type-predictions",
319 IDS_FLAGS_SHOW_AUTOFILL_TYPE_PREDICTIONS_NAME,
320 IDS_FLAGS_SHOW_AUTOFILL_TYPE_PREDICTIONS_DESCRIPTION,
321 kOsAll,
322 SINGLE_VALUE_TYPE(switches::kShowAutofillTypePredictions)
323 },
[email protected]bff4d3e2011-06-21 23:58:52324 {
[email protected]9a6180d7d2011-09-07 01:40:33325 "sync-tabs",
326 IDS_FLAGS_SYNC_TABS_NAME,
327 IDS_FLAGS_SYNC_TABS_DESCRIPTION,
[email protected]5b0ec7f2011-08-11 02:17:17328 kOsAll,
[email protected]9a6180d7d2011-09-07 01:40:33329 SINGLE_VALUE_TYPE(switches::kEnableSyncTabs)
[email protected]5b0ec7f2011-08-11 02:17:17330 },
331 {
[email protected]aae9eeb12011-10-21 21:59:26332 "sync-app-notifications",
333 IDS_FLAGS_SYNC_APP_NOTIFICATIONS_NAME,
334 IDS_FLAGS_SYNC_APP_NOTIFICATIONS_DESCRIPTION,
335 kOsAll,
[email protected]0b6fba82011-11-18 01:31:11336 SINGLE_VALUE_TYPE(switches::kDisableSyncAppNotifications)
[email protected]aae9eeb12011-10-21 21:59:26337 },
338 {
[email protected]a22ebd812011-06-23 00:05:39339 "enable-smooth-scrolling", // FLAGS:RECORD_UMA
340 IDS_FLAGS_ENABLE_SMOOTH_SCROLLING_NAME,
341 IDS_FLAGS_ENABLE_SMOOTH_SCROLLING_DESCRIPTION,
342 // Can't expose the switch unless the code is compiled in.
[email protected]554b7062011-09-03 03:09:40343 // On by default for the Mac (different implementation in WebKit).
[email protected]554b7062011-09-03 03:09:40344 kOsWin | kOsLinux | kOsCrOS,
[email protected]a22ebd812011-06-23 00:05:39345 SINGLE_VALUE_TYPE(switches::kEnableSmoothScrolling)
346 },
[email protected]81a6b0b2011-06-24 17:55:40347 {
[email protected]ae1eb29a2011-08-17 17:50:57348 "prerender-from-omnibox", // FLAGS:RECORD_UMA
[email protected]81a6b0b2011-06-24 17:55:40349 IDS_FLAGS_PRERENDER_FROM_OMNIBOX_NAME,
350 IDS_FLAGS_PRERENDER_FROM_OMNIBOX_DESCRIPTION,
351 kOsAll,
[email protected]778ef7c2011-10-11 15:37:05352 MULTI_VALUE_TYPE(kPrerenderFromOmniboxChoices)
[email protected]81a6b0b2011-06-24 17:55:40353 },
[email protected]40916632011-07-02 01:11:01354 {
[email protected]ed1e39502011-12-16 14:39:35355 "omnibox-aggressive-with-history-urls",
356 IDS_FLAGS_OMNIBOX_AGGRESSIVE_HISTORY_URL_SCORING_NAME,
357 IDS_FLAGS_OMNIBOX_AGGRESSIVE_HISTORY_URL_SCORING_DESCRIPTION,
358 kOsAll,
359 SINGLE_VALUE_TYPE(switches::kEnableOmniboxAggressiveHistoryURL)
360 },
361 {
[email protected]7e7a28092011-12-09 22:24:55362 "enable-panels",
363 IDS_FLAGS_ENABLE_PANELS_NAME,
364 IDS_FLAGS_ENABLE_PANELS_DESCRIPTION,
[email protected]73fb1fc52011-07-09 00:06:54365 kOsAll,
[email protected]7e7a28092011-12-09 22:24:55366 SINGLE_VALUE_TYPE(switches::kEnablePanels)
[email protected]73fb1fc52011-07-09 00:06:54367 },
[email protected]e3749d12011-07-25 22:22:12368 {
[email protected]9931875b2011-11-02 00:19:48369 "disable-shortcuts-provider",
370 IDS_FLAGS_DISABLE_SHORTCUTS_PROVIDER,
371 IDS_FLAGS_DISABLE_SHORTCUTS_PROVIDER_DESCRIPTION,
[email protected]e3749d12011-07-25 22:22:12372 kOsAll,
[email protected]9931875b2011-11-02 00:19:48373 SINGLE_VALUE_TYPE(switches::kDisableShortcutsProvider)
[email protected]e3749d12011-07-25 22:22:12374 },
[email protected]1a2966b92011-08-09 06:50:19375#if defined(OS_CHROMEOS)
376 {
[email protected]cd681c42011-09-29 02:49:44377 "enable-bluetooth",
378 IDS_FLAGS_ENABLE_BLUETOOTH_NAME,
379 IDS_FLAGS_ENABLE_BLUETOOTH_DESCRIPTION,
380 kOsCrOS,
381 SINGLE_VALUE_TYPE(switches::kEnableBluetooth)
382 },
[email protected]1a2966b92011-08-09 06:50:19383#endif
[email protected]80eb4262011-08-03 16:10:41384 {
385 "memory-widget",
386 IDS_FLAGS_MEMORY_WIDGET_NAME,
387 IDS_FLAGS_MEMORY_WIDGET_DESCRIPTION,
388 kOsCrOS,
389#if defined(OS_CHROMEOS)
390 // This switch exists only on Chrome OS.
391 SINGLE_VALUE_TYPE(switches::kMemoryWidget)
392#else
393 SINGLE_VALUE_TYPE("")
394#endif
[email protected]a0e4b072011-08-17 01:47:07395 },
396 {
397 "downloads-new-ui", // FLAGS:RECORD_UMA
398 IDS_FLAGS_DOWNLOADS_NEW_UI_NAME,
399 IDS_FLAGS_DOWNLOADS_NEW_UI_DESCRIPTION,
400 kOsAll,
401 SINGLE_VALUE_TYPE(switches::kDownloadsNewUI)
402 },
[email protected]b7bb44f2011-09-01 05:17:03403 {
404 "enable-autologin",
405 IDS_FLAGS_ENABLE_AUTOLOGIN_NAME,
406 IDS_FLAGS_ENABLE_AUTOLOGIN_DESCRIPTION,
407 kOsMac | kOsWin | kOsLinux,
408 SINGLE_VALUE_TYPE(switches::kEnableAutologin)
409 },
[email protected]b9841172011-09-26 23:36:09410 {
411 "use-more-webui",
412 IDS_FLAGS_USE_MORE_WEBUI_NAME,
413 IDS_FLAGS_USE_MORE_WEBUI_DESCRIPTION,
414 kOsAll,
415 SINGLE_VALUE_TYPE(switches::kUseMoreWebUI)
416 },
[email protected]bbadb112011-12-12 16:55:28417 {
418 "enable-http-pipelining",
419 IDS_FLAGS_ENABLE_HTTP_PIPELINING_NAME,
420 IDS_FLAGS_ENABLE_HTTP_PIPELINING_DESCRIPTION,
421 kOsAll,
422 SINGLE_VALUE_TYPE(switches::kEnableHttpPipelining)
423 },
[email protected]407a38f2011-11-23 18:28:29424 // TODO(flackr): Remove this flag and views screen locker when the WebUI
425 // locker is mature (crbug.com/105263).
[email protected]89c64cd2011-10-04 01:41:10426 {
[email protected]407a38f2011-11-23 18:28:29427 "disable-webui-lock-screen",
[email protected]d411c01d2011-10-18 16:00:27428 IDS_FLAGS_WEBUI_LOCK_NAME,
429 IDS_FLAGS_WEBUI_LOCK_DESCRIPTION,
430 kOsCrOS,
431#if defined(OS_CHROMEOS)
[email protected]407a38f2011-11-23 18:28:29432 SINGLE_VALUE_TYPE(switches::kDisableWebUILockScreen)
[email protected]d411c01d2011-10-18 16:00:27433#else
434 SINGLE_VALUE_TYPE("")
435#endif
436 },
437 {
[email protected]f5da41d2011-10-08 17:40:07438 "enable-video-track",
439 IDS_FLAGS_ENABLE_VIDEO_TRACK_NAME,
440 IDS_FLAGS_ENABLE_VIDEO_TRACK_DESCRIPTION,
441 kOsAll,
442 SINGLE_VALUE_TYPE(switches::kEnableVideoTrack)
443 },
[email protected]08b83362011-10-19 05:23:17444 {
445 "extension-alerts",
446 IDS_FLAGS_ENABLE_EXTENSION_ALERTS_NAME,
447 IDS_FLAGS_ENABLE_EXTENSION_ALERTS_DESCRIPTION,
448 kOsAll,
449 SINGLE_VALUE_TYPE(switches::kEnableExtensionAlerts)
450 },
[email protected]6aa03b32011-10-27 21:44:44451 {
452 "enable-media-source",
453 IDS_FLAGS_ENABLE_MEDIA_SOURCE_NAME,
454 IDS_FLAGS_ENABLE_MEDIA_SOURCE_DESCRIPTION,
455 kOsAll,
456 SINGLE_VALUE_TYPE(switches::kEnableMediaSource)
457 },
[email protected]e4e68dbb2011-11-18 01:50:22458 {
459 "enable-pointer-lock",
460 IDS_FLAGS_ENABLE_POINTER_LOCK_NAME,
461 IDS_FLAGS_ENABLE_POINTER_LOCK_DESCRIPTION,
462 kOsAll,
463 SINGLE_VALUE_TYPE(switches::kEnablePointerLock)
464 },
[email protected]8cc10df2011-11-03 23:57:50465#if defined(USE_AURA)
466 {
[email protected]20cea592011-12-10 01:55:30467 "aura-workspace-manager",
468 IDS_FLAGS_AURA_WORKSPACE_MANAGER_NAME,
469 IDS_FLAGS_AURA_WORKSPACE_MANAGER_DESCRIPTION,
[email protected]8cc10df2011-11-03 23:57:50470 kOsWin | kOsLinux | kOsCrOS,
[email protected]3e14cad2011-12-20 21:14:29471 SINGLE_VALUE_TYPE(aura_shell::switches::kAuraWorkspaceManager)
[email protected]8cc10df2011-11-03 23:57:50472 },
[email protected]20cea592011-12-10 01:55:30473 {
474 "aura-translucent-frames",
475 IDS_FLAGS_AURA_TRANSLUCENT_FRAMES_NAME,
476 IDS_FLAGS_AURA_TRANSLUCENT_FRAMES_DESCRIPTION,
477 kOsWin | kOsLinux | kOsCrOS,
[email protected]3e14cad2011-12-20 21:14:29478 SINGLE_VALUE_TYPE(aura_shell::switches::kAuraTranslucentFrames)
[email protected]20cea592011-12-10 01:55:30479 },
480#endif // defined(USE_AURA)
[email protected]edb051d2011-11-24 23:20:51481 {
482 "enable-gamepad",
483 IDS_FLAGS_ENABLE_GAMEPAD_NAME,
484 IDS_FLAGS_ENABLE_GAMEPAD_DESCRIPTION,
[email protected]02580552011-12-08 02:36:26485 kOsMac | kOsWin,
[email protected]edb051d2011-11-24 23:20:51486 SINGLE_VALUE_TYPE(switches::kEnableGamepad)
487 },
[email protected]35304ce2011-12-14 23:21:01488#if defined(USE_AURA)
489 // TODO(jamescook): Enable this for all ChromeOS builds when we're sure
490 // Aura laptop mode performance and feature set match traditional non-Aura
491 // builds.
492 {
[email protected]3fbd9c12011-12-16 21:35:11493 "aura-window-mode",
494 IDS_FLAGS_AURA_WINDOW_MODE_NAME,
495 IDS_FLAGS_AURA_WINDOW_MODE_DESCRIPTION,
[email protected]35304ce2011-12-14 23:21:01496 kOsWin | kOsLinux | kOsCrOS,
[email protected]3fbd9c12011-12-16 21:35:11497 MULTI_VALUE_TYPE(kAuraWindowModeChoices)
[email protected]35304ce2011-12-14 23:21:01498 },
499#endif
[email protected]db543d322011-12-15 20:40:15500 {
501 "per-tile-painting",
502 IDS_FLAGS_PER_TILE_PAINTING_NAME,
503 IDS_FLAGS_PER_TILE_PAINTING_DESCRIPTION,
504#if defined(USE_SKIA)
505 kOsAll,
506#else
507 0,
508#endif
509 SINGLE_VALUE_TYPE(switches::kEnablePerTilePainting)
510 },
[email protected]a0e4b072011-08-17 01:47:07511};
[email protected]ad2a3ded2010-08-27 13:19:05512
[email protected]a314ee5a2010-10-26 21:23:28513const Experiment* experiments = kExperiments;
514size_t num_experiments = arraysize(kExperiments);
515
[email protected]e2ddbc92010-10-15 20:02:07516// Stores and encapsulates the little state that about:flags has.
517class FlagsState {
518 public:
519 FlagsState() : needs_restart_(false) {}
520 void ConvertFlagsToSwitches(PrefService* prefs, CommandLine* command_line);
521 bool IsRestartNeededToCommitChanges();
522 void SetExperimentEnabled(
[email protected]a314ee5a2010-10-26 21:23:28523 PrefService* prefs, const std::string& internal_name, bool enable);
[email protected]e2ddbc92010-10-15 20:02:07524 void RemoveFlagsSwitches(
525 std::map<std::string, CommandLine::StringType>* switch_list);
526 void reset();
527
528 // Returns the singleton instance of this class
[email protected]8e8bb6d2010-12-13 08:18:55529 static FlagsState* GetInstance() {
[email protected]e2ddbc92010-10-15 20:02:07530 return Singleton<FlagsState>::get();
531 }
532
533 private:
534 bool needs_restart_;
[email protected]a82744532011-02-11 16:15:53535 std::map<std::string, std::string> flags_switches_;
[email protected]e2ddbc92010-10-15 20:02:07536
537 DISALLOW_COPY_AND_ASSIGN(FlagsState);
538};
539
[email protected]c7b7800a2010-10-07 18:51:35540// Extracts the list of enabled lab experiments from preferences and stores them
[email protected]ad2a3ded2010-08-27 13:19:05541// in a set.
[email protected]1a47d7e2010-10-15 00:37:24542void GetEnabledFlags(const PrefService* prefs, std::set<std::string>* result) {
[email protected]ad2a3ded2010-08-27 13:19:05543 const ListValue* enabled_experiments = prefs->GetList(
544 prefs::kEnabledLabsExperiments);
545 if (!enabled_experiments)
546 return;
547
548 for (ListValue::const_iterator it = enabled_experiments->begin();
549 it != enabled_experiments->end();
550 ++it) {
551 std::string experiment_name;
552 if (!(*it)->GetAsString(&experiment_name)) {
553 LOG(WARNING) << "Invalid entry in " << prefs::kEnabledLabsExperiments;
554 continue;
555 }
556 result->insert(experiment_name);
557 }
558}
559
560// Takes a set of enabled lab experiments
[email protected]1a47d7e2010-10-15 00:37:24561void SetEnabledFlags(
[email protected]ad2a3ded2010-08-27 13:19:05562 PrefService* prefs, const std::set<std::string>& enabled_experiments) {
[email protected]1bc78422011-03-31 08:41:38563 ListPrefUpdate update(prefs, prefs::kEnabledLabsExperiments);
564 ListValue* experiments_list = update.Get();
[email protected]ad2a3ded2010-08-27 13:19:05565
566 experiments_list->Clear();
567 for (std::set<std::string>::const_iterator it = enabled_experiments.begin();
568 it != enabled_experiments.end();
569 ++it) {
570 experiments_list->Append(new StringValue(*it));
571 }
572}
573
[email protected]8a6ff28d2010-12-02 16:35:19574// Returns the name used in prefs for the choice at the specified index.
575std::string NameForChoice(const Experiment& e, int index) {
[email protected]2ce9c89752011-02-25 18:24:34576 DCHECK_EQ(Experiment::MULTI_VALUE, e.type);
577 DCHECK_LT(index, e.num_choices);
[email protected]8a6ff28d2010-12-02 16:35:19578 return std::string(e.internal_name) + about_flags::testing::kMultiSeparator +
579 base::IntToString(index);
580}
581
582// Adds the internal names for the specified experiment to |names|.
583void AddInternalName(const Experiment& e, std::set<std::string>* names) {
584 if (e.type == Experiment::SINGLE_VALUE) {
585 names->insert(e.internal_name);
586 } else {
[email protected]2ce9c89752011-02-25 18:24:34587 DCHECK_EQ(Experiment::MULTI_VALUE, e.type);
[email protected]8a6ff28d2010-12-02 16:35:19588 for (int i = 0; i < e.num_choices; ++i)
589 names->insert(NameForChoice(e, i));
590 }
591}
592
[email protected]28e35af2011-02-09 12:56:22593// Confirms that an experiment is valid, used in a DCHECK in
594// SanitizeList below.
595bool ValidateExperiment(const Experiment& e) {
596 switch (e.type) {
597 case Experiment::SINGLE_VALUE:
598 DCHECK_EQ(0, e.num_choices);
599 DCHECK(!e.choices);
600 break;
601 case Experiment::MULTI_VALUE:
602 DCHECK_GT(e.num_choices, 0);
603 DCHECK(e.choices);
[email protected]a82744532011-02-11 16:15:53604 DCHECK(e.choices[0].command_line_switch);
605 DCHECK_EQ('\0', e.choices[0].command_line_switch[0]);
[email protected]28e35af2011-02-09 12:56:22606 break;
607 default:
608 NOTREACHED();
609 }
610 return true;
611}
612
[email protected]ad2a3ded2010-08-27 13:19:05613// Removes all experiments from prefs::kEnabledLabsExperiments that are
614// unknown, to prevent this list to become very long as experiments are added
615// and removed.
616void SanitizeList(PrefService* prefs) {
617 std::set<std::string> known_experiments;
[email protected]28e35af2011-02-09 12:56:22618 for (size_t i = 0; i < num_experiments; ++i) {
619 DCHECK(ValidateExperiment(experiments[i]));
[email protected]8a6ff28d2010-12-02 16:35:19620 AddInternalName(experiments[i], &known_experiments);
[email protected]28e35af2011-02-09 12:56:22621 }
[email protected]ad2a3ded2010-08-27 13:19:05622
623 std::set<std::string> enabled_experiments;
[email protected]1a47d7e2010-10-15 00:37:24624 GetEnabledFlags(prefs, &enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05625
626 std::set<std::string> new_enabled_experiments;
627 std::set_intersection(
628 known_experiments.begin(), known_experiments.end(),
629 enabled_experiments.begin(), enabled_experiments.end(),
630 std::inserter(new_enabled_experiments, new_enabled_experiments.begin()));
631
[email protected]1a47d7e2010-10-15 00:37:24632 SetEnabledFlags(prefs, new_enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05633}
634
[email protected]1a47d7e2010-10-15 00:37:24635void GetSanitizedEnabledFlags(
[email protected]ad2a3ded2010-08-27 13:19:05636 PrefService* prefs, std::set<std::string>* result) {
637 SanitizeList(prefs);
[email protected]1a47d7e2010-10-15 00:37:24638 GetEnabledFlags(prefs, result);
[email protected]ad2a3ded2010-08-27 13:19:05639}
640
[email protected]a314ee5a2010-10-26 21:23:28641// Variant of GetSanitizedEnabledFlags that also removes any flags that aren't
642// enabled on the current platform.
643void GetSanitizedEnabledFlagsForCurrentPlatform(
644 PrefService* prefs, std::set<std::string>* result) {
645 GetSanitizedEnabledFlags(prefs, result);
646
647 // Filter out any experiments that aren't enabled on the current platform. We
648 // don't remove these from prefs else syncing to a platform with a different
649 // set of experiments would be lossy.
650 std::set<std::string> platform_experiments;
651 int current_platform = GetCurrentPlatform();
652 for (size_t i = 0; i < num_experiments; ++i) {
653 if (experiments[i].supported_platforms & current_platform)
[email protected]8a6ff28d2010-12-02 16:35:19654 AddInternalName(experiments[i], &platform_experiments);
[email protected]a314ee5a2010-10-26 21:23:28655 }
656
657 std::set<std::string> new_enabled_experiments;
658 std::set_intersection(
659 platform_experiments.begin(), platform_experiments.end(),
660 result->begin(), result->end(),
661 std::inserter(new_enabled_experiments, new_enabled_experiments.begin()));
662
663 result->swap(new_enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05664}
665
[email protected]8a6ff28d2010-12-02 16:35:19666// Returns the Value representing the choice data in the specified experiment.
[email protected]8a6ff28d2010-12-02 16:35:19667Value* CreateChoiceData(const Experiment& experiment,
[email protected]28e35af2011-02-09 12:56:22668 const std::set<std::string>& enabled_experiments) {
[email protected]2ce9c89752011-02-25 18:24:34669 DCHECK_EQ(Experiment::MULTI_VALUE, experiment.type);
[email protected]8a6ff28d2010-12-02 16:35:19670 ListValue* result = new ListValue;
671 for (int i = 0; i < experiment.num_choices; ++i) {
672 const Experiment::Choice& choice = experiment.choices[i];
673 DictionaryValue* value = new DictionaryValue;
674 std::string name = NameForChoice(experiment, i);
675 value->SetString("description",
676 l10n_util::GetStringUTF16(choice.description_id));
677 value->SetString("internal_name", name);
[email protected]28e35af2011-02-09 12:56:22678 value->SetBoolean("selected", enabled_experiments.count(name) > 0);
[email protected]8a6ff28d2010-12-02 16:35:19679 result->Append(value);
680 }
681 return result;
682}
683
[email protected]e2ddbc92010-10-15 20:02:07684} // namespace
685
[email protected]1a47d7e2010-10-15 00:37:24686void ConvertFlagsToSwitches(PrefService* prefs, CommandLine* command_line) {
[email protected]8e8bb6d2010-12-13 08:18:55687 FlagsState::GetInstance()->ConvertFlagsToSwitches(prefs, command_line);
[email protected]ad2a3ded2010-08-27 13:19:05688}
689
[email protected]1a47d7e2010-10-15 00:37:24690ListValue* GetFlagsExperimentsData(PrefService* prefs) {
[email protected]ad2a3ded2010-08-27 13:19:05691 std::set<std::string> enabled_experiments;
[email protected]1a47d7e2010-10-15 00:37:24692 GetSanitizedEnabledFlags(prefs, &enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05693
694 int current_platform = GetCurrentPlatform();
695
696 ListValue* experiments_data = new ListValue();
[email protected]a314ee5a2010-10-26 21:23:28697 for (size_t i = 0; i < num_experiments; ++i) {
698 const Experiment& experiment = experiments[i];
[email protected]ad2a3ded2010-08-27 13:19:05699
700 DictionaryValue* data = new DictionaryValue();
701 data->SetString("internal_name", experiment.internal_name);
702 data->SetString("name",
703 l10n_util::GetStringUTF16(experiment.visible_name_id));
704 data->SetString("description",
705 l10n_util::GetStringUTF16(
706 experiment.visible_description_id));
[email protected]cc3e2052011-12-20 01:01:40707 bool supported = !!(experiment.supported_platforms & current_platform);
708 data->SetBoolean("supported", supported);
709
710 ListValue* supported_platforms = new ListValue();
711 AddOsStrings(experiment.supported_platforms, supported_platforms);
712 data->Set("supported_platforms", supported_platforms);
[email protected]ad2a3ded2010-08-27 13:19:05713
[email protected]28e35af2011-02-09 12:56:22714 switch (experiment.type) {
715 case Experiment::SINGLE_VALUE:
716 data->SetBoolean(
717 "enabled",
718 enabled_experiments.count(experiment.internal_name) > 0);
719 break;
720 case Experiment::MULTI_VALUE:
721 data->Set("choices", CreateChoiceData(experiment, enabled_experiments));
722 break;
723 default:
724 NOTREACHED();
[email protected]8a6ff28d2010-12-02 16:35:19725 }
726
[email protected]ad2a3ded2010-08-27 13:19:05727 experiments_data->Append(data);
728 }
729 return experiments_data;
730}
731
[email protected]ad2a3ded2010-08-27 13:19:05732bool IsRestartNeededToCommitChanges() {
[email protected]8e8bb6d2010-12-13 08:18:55733 return FlagsState::GetInstance()->IsRestartNeededToCommitChanges();
[email protected]ad2a3ded2010-08-27 13:19:05734}
735
736void SetExperimentEnabled(
[email protected]c7b7800a2010-10-07 18:51:35737 PrefService* prefs, const std::string& internal_name, bool enable) {
[email protected]8e8bb6d2010-12-13 08:18:55738 FlagsState::GetInstance()->SetExperimentEnabled(prefs, internal_name, enable);
[email protected]e2ddbc92010-10-15 20:02:07739}
740
741void RemoveFlagsSwitches(
742 std::map<std::string, CommandLine::StringType>* switch_list) {
[email protected]8e8bb6d2010-12-13 08:18:55743 FlagsState::GetInstance()->RemoveFlagsSwitches(switch_list);
[email protected]e2ddbc92010-10-15 20:02:07744}
745
[email protected]a314ee5a2010-10-26 21:23:28746int GetCurrentPlatform() {
747#if defined(OS_MACOSX)
748 return kOsMac;
749#elif defined(OS_WIN)
750 return kOsWin;
751#elif defined(OS_CHROMEOS) // Needs to be before the OS_LINUX check.
752 return kOsCrOS;
[email protected]c92f4ed2011-10-21 19:50:21753#elif defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]a314ee5a2010-10-26 21:23:28754 return kOsLinux;
755#else
756#error Unknown platform
757#endif
758}
759
[email protected]4bc5050c2010-11-18 17:55:54760void RecordUMAStatistics(const PrefService* prefs) {
761 std::set<std::string> flags;
762 GetEnabledFlags(prefs, &flags);
763 for (std::set<std::string>::iterator it = flags.begin(); it != flags.end();
764 ++it) {
765 std::string action("AboutFlags_");
766 action += *it;
[email protected]7f6f44c2011-12-14 13:23:38767 content::RecordComputedAction(action);
[email protected]4bc5050c2010-11-18 17:55:54768 }
769 // Since flag metrics are recorded every startup, add a tick so that the
770 // stats can be made meaningful.
771 if (flags.size())
[email protected]7f6f44c2011-12-14 13:23:38772 content::RecordAction(UserMetricsAction("AboutFlags_StartupTick"));
773 content::RecordAction(UserMetricsAction("StartupTick"));
[email protected]4bc5050c2010-11-18 17:55:54774}
775
[email protected]e2ddbc92010-10-15 20:02:07776//////////////////////////////////////////////////////////////////////////////
777// FlagsState implementation.
778
779namespace {
780
781void FlagsState::ConvertFlagsToSwitches(
782 PrefService* prefs, CommandLine* command_line) {
[email protected]e2ddbc92010-10-15 20:02:07783 if (command_line->HasSwitch(switches::kNoExperiments))
784 return;
785
786 std::set<std::string> enabled_experiments;
[email protected]ba8164242010-11-16 21:31:00787
[email protected]a314ee5a2010-10-26 21:23:28788 GetSanitizedEnabledFlagsForCurrentPlatform(prefs, &enabled_experiments);
[email protected]e2ddbc92010-10-15 20:02:07789
[email protected]a82744532011-02-11 16:15:53790 typedef std::map<std::string, std::pair<std::string, std::string> >
791 NameToSwitchAndValueMap;
792 NameToSwitchAndValueMap name_to_switch_map;
[email protected]8a6ff28d2010-12-02 16:35:19793 for (size_t i = 0; i < num_experiments; ++i) {
794 const Experiment& e = experiments[i];
795 if (e.type == Experiment::SINGLE_VALUE) {
[email protected]a82744532011-02-11 16:15:53796 name_to_switch_map[e.internal_name] =
797 std::pair<std::string, std::string>(e.command_line_switch,
798 e.command_line_value);
[email protected]8a6ff28d2010-12-02 16:35:19799 } else {
800 for (int j = 0; j < e.num_choices; ++j)
[email protected]a82744532011-02-11 16:15:53801 name_to_switch_map[NameForChoice(e, j)] =
802 std::pair<std::string, std::string>(
803 e.choices[j].command_line_switch,
804 e.choices[j].command_line_value);
[email protected]8a6ff28d2010-12-02 16:35:19805 }
806 }
[email protected]e2ddbc92010-10-15 20:02:07807
808 command_line->AppendSwitch(switches::kFlagSwitchesBegin);
[email protected]a82744532011-02-11 16:15:53809 flags_switches_.insert(
810 std::pair<std::string, std::string>(switches::kFlagSwitchesBegin,
811 std::string()));
[email protected]e2ddbc92010-10-15 20:02:07812 for (std::set<std::string>::iterator it = enabled_experiments.begin();
813 it != enabled_experiments.end();
814 ++it) {
815 const std::string& experiment_name = *it;
[email protected]a82744532011-02-11 16:15:53816 NameToSwitchAndValueMap::const_iterator name_to_switch_it =
[email protected]8a6ff28d2010-12-02 16:35:19817 name_to_switch_map.find(experiment_name);
818 if (name_to_switch_it == name_to_switch_map.end()) {
819 NOTREACHED();
[email protected]e2ddbc92010-10-15 20:02:07820 continue;
[email protected]8a6ff28d2010-12-02 16:35:19821 }
[email protected]e2ddbc92010-10-15 20:02:07822
[email protected]a82744532011-02-11 16:15:53823 const std::pair<std::string, std::string>&
824 switch_and_value_pair = name_to_switch_it->second;
825
826 command_line->AppendSwitchASCII(switch_and_value_pair.first,
827 switch_and_value_pair.second);
828 flags_switches_[switch_and_value_pair.first] = switch_and_value_pair.second;
[email protected]e2ddbc92010-10-15 20:02:07829 }
830 command_line->AppendSwitch(switches::kFlagSwitchesEnd);
[email protected]a82744532011-02-11 16:15:53831 flags_switches_.insert(
832 std::pair<std::string, std::string>(switches::kFlagSwitchesEnd,
833 std::string()));
[email protected]e2ddbc92010-10-15 20:02:07834}
835
836bool FlagsState::IsRestartNeededToCommitChanges() {
837 return needs_restart_;
838}
839
840void FlagsState::SetExperimentEnabled(
841 PrefService* prefs, const std::string& internal_name, bool enable) {
[email protected]ad2a3ded2010-08-27 13:19:05842 needs_restart_ = true;
843
[email protected]8a6ff28d2010-12-02 16:35:19844 size_t at_index = internal_name.find(about_flags::testing::kMultiSeparator);
845 if (at_index != std::string::npos) {
846 DCHECK(enable);
847 // We're being asked to enable a multi-choice experiment. Disable the
848 // currently selected choice.
849 DCHECK_NE(at_index, 0u);
[email protected]28e35af2011-02-09 12:56:22850 const std::string experiment_name = internal_name.substr(0, at_index);
851 SetExperimentEnabled(prefs, experiment_name, false);
[email protected]8a6ff28d2010-12-02 16:35:19852
[email protected]28e35af2011-02-09 12:56:22853 // And enable the new choice, if it is not the default first choice.
854 if (internal_name != experiment_name + "@0") {
855 std::set<std::string> enabled_experiments;
856 GetSanitizedEnabledFlags(prefs, &enabled_experiments);
857 enabled_experiments.insert(internal_name);
858 SetEnabledFlags(prefs, enabled_experiments);
859 }
[email protected]8a6ff28d2010-12-02 16:35:19860 return;
861 }
862
[email protected]ad2a3ded2010-08-27 13:19:05863 std::set<std::string> enabled_experiments;
[email protected]1a47d7e2010-10-15 00:37:24864 GetSanitizedEnabledFlags(prefs, &enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05865
[email protected]8a6ff28d2010-12-02 16:35:19866 const Experiment* e = NULL;
867 for (size_t i = 0; i < num_experiments; ++i) {
868 if (experiments[i].internal_name == internal_name) {
869 e = experiments + i;
870 break;
871 }
872 }
873 DCHECK(e);
874
875 if (e->type == Experiment::SINGLE_VALUE) {
[email protected]8a2713682011-08-19 10:36:59876 if (enable)
[email protected]8a6ff28d2010-12-02 16:35:19877 enabled_experiments.insert(internal_name);
[email protected]8a2713682011-08-19 10:36:59878 else
[email protected]8a6ff28d2010-12-02 16:35:19879 enabled_experiments.erase(internal_name);
880 } else {
881 if (enable) {
882 // Enable the first choice.
883 enabled_experiments.insert(NameForChoice(*e, 0));
884 } else {
885 // Find the currently enabled choice and disable it.
886 for (int i = 0; i < e->num_choices; ++i) {
887 std::string choice_name = NameForChoice(*e, i);
888 if (enabled_experiments.find(choice_name) !=
889 enabled_experiments.end()) {
890 enabled_experiments.erase(choice_name);
891 // Continue on just in case there's a bug and more than one
892 // experiment for this choice was enabled.
893 }
894 }
895 }
896 }
[email protected]ad2a3ded2010-08-27 13:19:05897
[email protected]1a47d7e2010-10-15 00:37:24898 SetEnabledFlags(prefs, enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05899}
900
[email protected]e2ddbc92010-10-15 20:02:07901void FlagsState::RemoveFlagsSwitches(
902 std::map<std::string, CommandLine::StringType>* switch_list) {
[email protected]a82744532011-02-11 16:15:53903 for (std::map<std::string, std::string>::const_iterator
904 it = flags_switches_.begin(); it != flags_switches_.end(); ++it) {
905 switch_list->erase(it->first);
[email protected]e2ddbc92010-10-15 20:02:07906 }
907}
908
909void FlagsState::reset() {
910 needs_restart_ = false;
911 flags_switches_.clear();
912}
913
[email protected]38e46812011-05-09 20:49:22914} // namespace
[email protected]e2ddbc92010-10-15 20:02:07915
916namespace testing {
[email protected]8a6ff28d2010-12-02 16:35:19917
918// WARNING: '@' is also used in the html file. If you update this constant you
919// also need to update the html file.
920const char kMultiSeparator[] = "@";
921
[email protected]e2ddbc92010-10-15 20:02:07922void ClearState() {
[email protected]8e8bb6d2010-12-13 08:18:55923 FlagsState::GetInstance()->reset();
[email protected]e2ddbc92010-10-15 20:02:07924}
[email protected]a314ee5a2010-10-26 21:23:28925
926void SetExperiments(const Experiment* e, size_t count) {
927 if (!e) {
928 experiments = kExperiments;
929 num_experiments = arraysize(kExperiments);
930 } else {
931 experiments = e;
932 num_experiments = count;
933 }
934}
935
[email protected]8a6ff28d2010-12-02 16:35:19936const Experiment* GetExperiments(size_t* count) {
937 *count = num_experiments;
938 return experiments;
939}
940
[email protected]e2ddbc92010-10-15 20:02:07941} // namespace testing
942
[email protected]1a47d7e2010-10-15 00:37:24943} // namespace about_flags