blob: 9117a9fae87e77f9a7007e94d33f78e6dd311a19 [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]afd1e522011-04-27 23:29:5922#include "content/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)
28#include "ui/aura/aura_switches.h"
29#endif
30
[email protected]1a47d7e2010-10-15 00:37:2431namespace about_flags {
[email protected]ad2a3ded2010-08-27 13:19:0532
[email protected]8a6ff28d2010-12-02 16:35:1933// Macros to simplify specifying the type.
[email protected]a82744532011-02-11 16:15:5334#define SINGLE_VALUE_TYPE_AND_VALUE(command_line_switch, switch_value) \
35 Experiment::SINGLE_VALUE, command_line_switch, switch_value, NULL, 0
36#define SINGLE_VALUE_TYPE(command_line_switch) \
37 SINGLE_VALUE_TYPE_AND_VALUE(command_line_switch, "")
38#define MULTI_VALUE_TYPE(choices) \
[email protected]0e6f56d2011-02-12 23:45:1539 Experiment::MULTI_VALUE, "", "", choices, arraysize(choices)
[email protected]8a6ff28d2010-12-02 16:35:1940
[email protected]e2ddbc92010-10-15 20:02:0741namespace {
42
[email protected]a314ee5a2010-10-26 21:23:2843const unsigned kOsAll = kOsMac | kOsWin | kOsLinux | kOsCrOS;
[email protected]ad2a3ded2010-08-27 13:19:0544
[email protected]ba8164242010-11-16 21:31:0045// Names for former Chrome OS Labs experiments, shared with prefs migration
46// code.
47const char kMediaPlayerExperimentName[] = "media-player";
48const char kAdvancedFileSystemExperimentName[] = "advanced-file-system";
49const char kVerticalTabsExperimentName[] = "vertical-tabs";
50
[email protected]778ef7c2011-10-11 15:37:0551const Experiment::Choice kPrerenderFromOmniboxChoices[] = {
52 { IDS_FLAGS_PRERENDER_FROM_OMNIBOX_AUTOMATIC, "", "" },
53 { IDS_FLAGS_PRERENDER_FROM_OMNIBOX_ENABLED, switches::kPrerenderFromOmnibox,
54 switches::kPrerenderFromOmniboxSwitchValueEnabled },
55 { IDS_FLAGS_PRERENDER_FROM_OMNIBOX_DISABLED, switches::kPrerenderFromOmnibox,
56 switches::kPrerenderFromOmniboxSwitchValueDisabled }
57};
58
[email protected]4bc5050c2010-11-18 17:55:5459// RECORDING USER METRICS FOR FLAGS:
60// -----------------------------------------------------------------------------
61// The first line of the experiment is the internal name. If you'd like to
62// gather statistics about the usage of your flag, you should append a marker
63// comment to the end of the feature name, like so:
64// "my-special-feature", // FLAGS:RECORD_UMA
65//
66// After doing that, run //chrome/tools/extract_actions.py (see instructions at
67// the top of that file for details) to update the chromeactions.txt file, which
68// will enable UMA to record your feature flag.
69//
70// After your feature has shipped under a flag, you can locate the metrics
71// under the action name AboutFlags_internal-action-name. Actions are recorded
72// once per startup, so you should divide this number by AboutFlags_StartupTick
73// to get a sense of usage. Note that this will not be the same as number of
74// users with a given feature enabled because users can quit and relaunch
75// the application multiple times over a given time interval.
76// TODO(rsesek): See if there's a way to count per-user, rather than
77// per-startup.
78
[email protected]8a6ff28d2010-12-02 16:35:1979// To add a new experiment add to the end of kExperiments. There are two
80// distinct types of experiments:
81// . SINGLE_VALUE: experiment is either on or off. Use the SINGLE_VALUE_TYPE
82// macro for this type supplying the command line to the macro.
[email protected]28e35af2011-02-09 12:56:2283// . MULTI_VALUE: a list of choices, the first of which should correspond to a
84// deactivated state for this lab (i.e. no command line option). To specify
85// this type of experiment use the macro MULTI_VALUE_TYPE supplying it the
86// array of choices.
[email protected]8a6ff28d2010-12-02 16:35:1987// See the documentation of Experiment for details on the fields.
88//
89// When adding a new choice, add it to the end of the list.
[email protected]ad2a3ded2010-08-27 13:19:0590const Experiment kExperiments[] = {
91 {
[email protected]aac169d2011-03-18 19:53:0392 "expose-for-tabs", // FLAGS:RECORD_UMA
93 IDS_FLAGS_TABPOSE_NAME,
94 IDS_FLAGS_TABPOSE_DESCRIPTION,
95 kOsMac,
96#if defined(OS_MACOSX)
97 // The switch exists only on OS X.
98 SINGLE_VALUE_TYPE(switches::kEnableExposeForTabs)
99#else
100 SINGLE_VALUE_TYPE("")
101#endif
102 },
103 {
[email protected]4bc5050c2010-11-18 17:55:54104 "conflicting-modules-check", // FLAGS:RECORD_UMA
[email protected]c1bbaa82010-11-08 11:17:05105 IDS_FLAGS_CONFLICTS_CHECK_NAME,
106 IDS_FLAGS_CONFLICTS_CHECK_DESCRIPTION,
107 kOsWin,
[email protected]8a6ff28d2010-12-02 16:35:19108 SINGLE_VALUE_TYPE(switches::kConflictingModulesCheck)
[email protected]c1bbaa82010-11-08 11:17:05109 },
110 {
[email protected]4bc5050c2010-11-18 17:55:54111 "cloud-print-proxy", // FLAGS:RECORD_UMA
[email protected]9486c1f2010-10-14 19:52:12112 IDS_FLAGS_CLOUD_PRINT_PROXY_NAME,
113 IDS_FLAGS_CLOUD_PRINT_PROXY_DESCRIPTION,
[email protected]9f8872b32011-03-04 19:44:45114 // For a Chrome build, we know we have a PDF plug-in on Windows, so it's
[email protected]4fa24bf2011-08-20 02:15:22115 // fully enabled.
[email protected]5d10d57d2011-07-22 22:16:31116 // Otherwise, where we know Windows could be working if a viable PDF
[email protected]4fa24bf2011-08-20 02:15:22117 // plug-in could be supplied, we'll keep the lab enabled. Mac and Linux
118 // always have PDF rasterization available, so no flag needed there.
119#if !defined(GOOGLE_CHROME_BUILD)
120 kOsWin,
121#else
122 0,
[email protected]fa6d2a2f2010-11-30 21:47:19123#endif
[email protected]8a6ff28d2010-12-02 16:35:19124 SINGLE_VALUE_TYPE(switches::kEnableCloudPrintProxy)
[email protected]8b6588a2010-10-12 02:39:42125 },
[email protected]580939a2010-10-12 18:54:37126 {
[email protected]bb461532010-11-26 21:50:23127 "crxless-web-apps",
128 IDS_FLAGS_CRXLESS_WEB_APPS_NAME,
129 IDS_FLAGS_CRXLESS_WEB_APPS_DESCRIPTION,
130 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19131 SINGLE_VALUE_TYPE(switches::kEnableCrxlessWebApps)
[email protected]bb461532010-11-26 21:50:23132 },
133 {
[email protected]96c6f4c2011-05-18 19:36:22134 "ignore-gpu-blacklist",
135 IDS_FLAGS_IGNORE_GPU_BLACKLIST_NAME,
136 IDS_FLAGS_IGNORE_GPU_BLACKLIST_DESCRIPTION,
137 kOsAll,
138 SINGLE_VALUE_TYPE(switches::kIgnoreGpuBlacklist)
139 },
140 {
[email protected]0110cf112011-07-02 00:39:43141 "force-compositing-mode-2",
[email protected]96c6f4c2011-05-18 19:36:22142 IDS_FLAGS_FORCE_COMPOSITING_MODE_NAME,
143 IDS_FLAGS_FORCE_COMPOSITING_MODE_DESCRIPTION,
144 kOsAll,
145 SINGLE_VALUE_TYPE(switches::kForceCompositingMode)
146 },
147 {
[email protected]5963b772011-02-09 22:55:38148 "composited-layer-borders",
149 IDS_FLAGS_COMPOSITED_LAYER_BORDERS,
150 IDS_FLAGS_COMPOSITED_LAYER_BORDERS_DESCRIPTION,
151 kOsAll,
152 SINGLE_VALUE_TYPE(switches::kShowCompositedLayerBorders)
153 },
154 {
[email protected]a8f1eaa2011-03-07 19:00:58155 "show-fps-counter",
156 IDS_FLAGS_SHOW_FPS_COUNTER,
157 IDS_FLAGS_SHOW_FPS_COUNTER_DESCRIPTION,
158 kOsAll,
159 SINGLE_VALUE_TYPE(switches::kShowFPSCounter)
160 },
[email protected]8ff7f342011-05-25 01:49:47161 {
162 "disable-gpu-vsync",
163 IDS_FLAGS_DISABLE_GPU_VSYNC_NAME,
164 IDS_FLAGS_DISABLE_GPU_VSYNC_DESCRIPTION,
165 kOsAll,
166 SINGLE_VALUE_TYPE(switches::kDisableGpuVsync)
167 },
[email protected]deaba6d52011-09-23 14:47:12168 {
169 "disable-webgl",
170 IDS_FLAGS_DISABLE_WEBGL_NAME,
171 IDS_FLAGS_DISABLE_WEBGL_DESCRIPTION,
172 kOsAll,
173 SINGLE_VALUE_TYPE(switches::kDisableExperimentalWebGL)
174 },
[email protected]9de0ec12011-08-24 21:57:50175 // Exposed on all platforms until there is a workaround for easy access to
176 // the native print dialog for users that need it. Once that's done, revert
177 // back to:
178 // Only expose this for Chromium builds where users may not have the PDF
179 // plugin. Do not give Google Chrome users the option to disable it here.
180 // Also expose it for Chrome OS where print preview is still experimental.
[email protected]8d260e52010-10-13 01:03:05181 {
[email protected]4bc5050c2010-11-18 17:55:54182 "print-preview", // FLAGS:RECORD_UMA
[email protected]9486c1f2010-10-14 19:52:12183 IDS_FLAGS_PRINT_PREVIEW_NAME,
184 IDS_FLAGS_PRINT_PREVIEW_DESCRIPTION,
[email protected]b579afd2011-07-13 00:01:27185 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19186 SINGLE_VALUE_TYPE(switches::kEnablePrintPreview)
[email protected]2fe15fcb2010-10-21 20:39:53187 },
[email protected]d208f4d82011-05-23 21:52:03188 // TODO(dspringer): When NaCl is on by default, remove this flag entry.
[email protected]2fe15fcb2010-10-21 20:39:53189 {
[email protected]e3791ce92011-08-09 01:03:32190 "enable-nacl", // FLAGS:RECORD_UMA
[email protected]4ff87d202010-11-06 01:28:40191 IDS_FLAGS_ENABLE_NACL_NAME,
192 IDS_FLAGS_ENABLE_NACL_DESCRIPTION,
193 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19194 SINGLE_VALUE_TYPE(switches::kEnableNaCl)
[email protected]4ff87d202010-11-06 01:28:40195 },
196 {
[email protected]4bc5050c2010-11-18 17:55:54197 "extension-apis", // FLAGS:RECORD_UMA
[email protected]11dd68cd52010-11-12 01:15:32198 IDS_FLAGS_EXPERIMENTAL_EXTENSION_APIS_NAME,
199 IDS_FLAGS_EXPERIMENTAL_EXTENSION_APIS_DESCRIPTION,
200 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19201 SINGLE_VALUE_TYPE(switches::kEnableExperimentalExtensionApis)
[email protected]11dd68cd52010-11-12 01:15:32202 },
[email protected]3627b06d2010-11-12 16:36:16203 {
[email protected]cbe224d2011-08-04 22:12:49204 "apps-new-install-bubble",
205 IDS_FLAGS_APPS_NEW_INSTALL_BUBBLE_NAME,
206 IDS_FLAGS_APPS_NEW_INSTALL_BUBBLE_DESCRIPTION,
207 kOsAll,
208 SINGLE_VALUE_TYPE(switches::kAppsNewInstallBubble)
209 },
210 {
[email protected]4bc5050c2010-11-18 17:55:54211 "click-to-play", // FLAGS:RECORD_UMA
[email protected]3627b06d2010-11-12 16:36:16212 IDS_FLAGS_CLICK_TO_PLAY_NAME,
213 IDS_FLAGS_CLICK_TO_PLAY_DESCRIPTION,
214 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19215 SINGLE_VALUE_TYPE(switches::kEnableClickToPlay)
[email protected]3627b06d2010-11-12 16:36:16216 },
[email protected]80bd24e2010-11-30 09:34:38217 {
218 "disable-hyperlink-auditing",
219 IDS_FLAGS_DISABLE_HYPERLINK_AUDITING_NAME,
220 IDS_FLAGS_DISABLE_HYPERLINK_AUDITING_DESCRIPTION,
221 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19222 SINGLE_VALUE_TYPE(switches::kNoPings)
[email protected]feb28fef2010-12-01 10:52:51223 },
224 {
225 "experimental-location-features", // FLAGS:RECORD_UMA
226 IDS_FLAGS_EXPERIMENTAL_LOCATION_FEATURES_NAME,
227 IDS_FLAGS_EXPERIMENTAL_LOCATION_FEATURES_DESCRIPTION,
228 kOsMac | kOsWin | kOsLinux, // Currently does nothing on CrOS.
[email protected]8a6ff28d2010-12-02 16:35:19229 SINGLE_VALUE_TYPE(switches::kExperimentalLocationFeatures)
230 },
231 {
[email protected]04227962011-01-20 02:03:09232 "disable-interactive-form-validation",
233 IDS_FLAGS_DISABLE_INTERACTIVE_FORM_VALIDATION_NAME,
234 IDS_FLAGS_DISABLE_INTERACTIVE_FORM_VALIDATION_DESCRIPTION,
235 kOsAll,
236 SINGLE_VALUE_TYPE(switches::kDisableInteractiveFormValidation)
237 },
[email protected]8df51192011-01-22 20:05:03238 {
[email protected]07d490bc2011-03-07 17:05:26239 "focus-existing-tab-on-open", // FLAGS:RECORD_UMA
240 IDS_FLAGS_FOCUS_EXISTING_TAB_ON_OPEN_NAME,
241 IDS_FLAGS_FOCUS_EXISTING_TAB_ON_OPEN_DESCRIPTION,
242 kOsAll,
243 SINGLE_VALUE_TYPE(switches::kFocusExistingTabOnOpen)
244 },
[email protected]d5dcfb32011-03-19 00:49:24245 {
[email protected]5aea1862011-03-23 23:55:39246 "tab-groups-context-menu",
247 IDS_FLAGS_TAB_GROUPS_CONTEXT_MENU_NAME,
248 IDS_FLAGS_TAB_GROUPS_CONTEXT_MENU_DESCRIPTION,
249 kOsWin,
250 SINGLE_VALUE_TYPE(switches::kEnableTabGroupsContextMenu)
251 },
[email protected]e9bf9d92011-03-31 20:57:15252 {
253 "ppapi-flash-in-process",
254 IDS_FLAGS_PPAPI_FLASH_IN_PROCESS_NAME,
255 IDS_FLAGS_PPAPI_FLASH_IN_PROCESS_DESCRIPTION,
[email protected]f2d3ce0d2011-04-01 18:19:30256 kOsAll,
[email protected]e9bf9d92011-03-31 20:57:15257 SINGLE_VALUE_TYPE(switches::kPpapiFlashInProcess)
258 },
[email protected]ce5737142011-04-14 23:35:09259 {
[email protected]f2557bd2011-06-01 02:33:07260 "preload-instant-search",
261 IDS_FLAGS_PRELOAD_INSTANT_SEARCH_NAME,
262 IDS_FLAGS_PRELOAD_INSTANT_SEARCH_DESCRIPTION,
263 kOsAll,
264 SINGLE_VALUE_TYPE(switches::kPreloadInstantSearch)
265 },
[email protected]354e33b2011-06-15 00:29:10266 {
267 "static-ip-config",
268 IDS_FLAGS_STATIC_IP_CONFIG_NAME,
269 IDS_FLAGS_STATIC_IP_CONFIG_DESCRIPTION,
270 kOsCrOS,
271#if defined(OS_CHROMEOS)
272 // This switch exists only on Chrome OS.
273 SINGLE_VALUE_TYPE(switches::kEnableStaticIPConfig)
274#else
275 SINGLE_VALUE_TYPE("")
276#endif
277 },
[email protected]3eb5728c2011-06-20 22:32:24278 {
279 "show-autofill-type-predictions",
280 IDS_FLAGS_SHOW_AUTOFILL_TYPE_PREDICTIONS_NAME,
281 IDS_FLAGS_SHOW_AUTOFILL_TYPE_PREDICTIONS_DESCRIPTION,
282 kOsAll,
283 SINGLE_VALUE_TYPE(switches::kShowAutofillTypePredictions)
284 },
[email protected]bff4d3e2011-06-21 23:58:52285 {
[email protected]9a6180d7d2011-09-07 01:40:33286 "sync-tabs",
287 IDS_FLAGS_SYNC_TABS_NAME,
288 IDS_FLAGS_SYNC_TABS_DESCRIPTION,
[email protected]5b0ec7f2011-08-11 02:17:17289 kOsAll,
[email protected]9a6180d7d2011-09-07 01:40:33290 SINGLE_VALUE_TYPE(switches::kEnableSyncTabs)
[email protected]5b0ec7f2011-08-11 02:17:17291 },
292 {
[email protected]aae9eeb12011-10-21 21:59:26293 "sync-app-notifications",
294 IDS_FLAGS_SYNC_APP_NOTIFICATIONS_NAME,
295 IDS_FLAGS_SYNC_APP_NOTIFICATIONS_DESCRIPTION,
296 kOsAll,
[email protected]0b6fba82011-11-18 01:31:11297 SINGLE_VALUE_TYPE(switches::kDisableSyncAppNotifications)
[email protected]aae9eeb12011-10-21 21:59:26298 },
299 {
[email protected]a22ebd812011-06-23 00:05:39300 "enable-smooth-scrolling", // FLAGS:RECORD_UMA
301 IDS_FLAGS_ENABLE_SMOOTH_SCROLLING_NAME,
302 IDS_FLAGS_ENABLE_SMOOTH_SCROLLING_DESCRIPTION,
303 // Can't expose the switch unless the code is compiled in.
[email protected]554b7062011-09-03 03:09:40304 // On by default for the Mac (different implementation in WebKit).
[email protected]554b7062011-09-03 03:09:40305 kOsWin | kOsLinux | kOsCrOS,
[email protected]a22ebd812011-06-23 00:05:39306 SINGLE_VALUE_TYPE(switches::kEnableSmoothScrolling)
307 },
[email protected]81a6b0b2011-06-24 17:55:40308 {
[email protected]ae1eb29a2011-08-17 17:50:57309 "prerender-from-omnibox", // FLAGS:RECORD_UMA
[email protected]81a6b0b2011-06-24 17:55:40310 IDS_FLAGS_PRERENDER_FROM_OMNIBOX_NAME,
311 IDS_FLAGS_PRERENDER_FROM_OMNIBOX_DESCRIPTION,
312 kOsAll,
[email protected]778ef7c2011-10-11 15:37:05313 MULTI_VALUE_TYPE(kPrerenderFromOmniboxChoices)
[email protected]81a6b0b2011-06-24 17:55:40314 },
[email protected]40916632011-07-02 01:11:01315 {
[email protected]845be522011-10-27 19:01:19316 "disable-panels",
[email protected]d5c14062011-10-27 00:02:13317 IDS_FLAGS_DISABLE_PANELS_NAME,
318 IDS_FLAGS_DISABLE_PANELS_DESCRIPTION,
[email protected]73fb1fc52011-07-09 00:06:54319 kOsAll,
[email protected]d5c14062011-10-27 00:02:13320 SINGLE_VALUE_TYPE(switches::kDisablePanels)
[email protected]73fb1fc52011-07-09 00:06:54321 },
[email protected]e3749d12011-07-25 22:22:12322 {
[email protected]9931875b2011-11-02 00:19:48323 "disable-shortcuts-provider",
324 IDS_FLAGS_DISABLE_SHORTCUTS_PROVIDER,
325 IDS_FLAGS_DISABLE_SHORTCUTS_PROVIDER_DESCRIPTION,
[email protected]e3749d12011-07-25 22:22:12326 kOsAll,
[email protected]9931875b2011-11-02 00:19:48327 SINGLE_VALUE_TYPE(switches::kDisableShortcutsProvider)
[email protected]e3749d12011-07-25 22:22:12328 },
[email protected]1a2966b92011-08-09 06:50:19329#if defined(OS_CHROMEOS)
330 {
[email protected]cd681c42011-09-29 02:49:44331 "enable-bluetooth",
332 IDS_FLAGS_ENABLE_BLUETOOTH_NAME,
333 IDS_FLAGS_ENABLE_BLUETOOTH_DESCRIPTION,
334 kOsCrOS,
335 SINGLE_VALUE_TYPE(switches::kEnableBluetooth)
336 },
[email protected]1a2966b92011-08-09 06:50:19337#endif
[email protected]80eb4262011-08-03 16:10:41338 {
339 "memory-widget",
340 IDS_FLAGS_MEMORY_WIDGET_NAME,
341 IDS_FLAGS_MEMORY_WIDGET_DESCRIPTION,
342 kOsCrOS,
343#if defined(OS_CHROMEOS)
344 // This switch exists only on Chrome OS.
345 SINGLE_VALUE_TYPE(switches::kMemoryWidget)
346#else
347 SINGLE_VALUE_TYPE("")
348#endif
[email protected]a0e4b072011-08-17 01:47:07349 },
[email protected]6ec18e62011-09-10 00:28:18350#if defined(TOUCH_UI)
351 {
352 "touchui-views-desktop",
353 IDS_FLAGS_DISABLE_VIEWS_DESKTOP_NAME,
354 IDS_FLAGS_DISABLE_VIEWS_DESKTOP_DESCRIPTION,
355 kOsCrOS,
356 SINGLE_VALUE_TYPE_AND_VALUE(switches::kViewsDesktop, "disabled")
357 },
358#endif
[email protected]a0e4b072011-08-17 01:47:07359 {
360 "downloads-new-ui", // FLAGS:RECORD_UMA
361 IDS_FLAGS_DOWNLOADS_NEW_UI_NAME,
362 IDS_FLAGS_DOWNLOADS_NEW_UI_DESCRIPTION,
363 kOsAll,
364 SINGLE_VALUE_TYPE(switches::kDownloadsNewUI)
365 },
[email protected]b7bb44f2011-09-01 05:17:03366 {
367 "enable-autologin",
368 IDS_FLAGS_ENABLE_AUTOLOGIN_NAME,
369 IDS_FLAGS_ENABLE_AUTOLOGIN_DESCRIPTION,
370 kOsMac | kOsWin | kOsLinux,
371 SINGLE_VALUE_TYPE(switches::kEnableAutologin)
372 },
[email protected]b9841172011-09-26 23:36:09373 {
374 "use-more-webui",
375 IDS_FLAGS_USE_MORE_WEBUI_NAME,
376 IDS_FLAGS_USE_MORE_WEBUI_DESCRIPTION,
377 kOsAll,
378 SINGLE_VALUE_TYPE(switches::kUseMoreWebUI)
379 },
[email protected]89c64cd2011-10-04 01:41:10380 {
[email protected]d411c01d2011-10-18 16:00:27381 "webui-lock-screen",
382 IDS_FLAGS_WEBUI_LOCK_NAME,
383 IDS_FLAGS_WEBUI_LOCK_DESCRIPTION,
384 kOsCrOS,
385#if defined(OS_CHROMEOS)
386 SINGLE_VALUE_TYPE(switches::kWebUILockScreen)
387#else
388 SINGLE_VALUE_TYPE("")
389#endif
390 },
391 {
[email protected]89c64cd2011-10-04 01:41:10392 "enable-ntp-bookmark-features",
393 IDS_FLAGS_ENABLE_NTP_BOOKMARK_FEATURES_NAME,
394 IDS_FLAGS_ENABLE_NTP_BOOKMARK_FEATURES_DESCRIPTION,
395 kOsAll,
396 SINGLE_VALUE_TYPE(switches::kEnableNTPBookmarkFeatures)
397 },
[email protected]f5da41d2011-10-08 17:40:07398 {
399 "enable-video-track",
400 IDS_FLAGS_ENABLE_VIDEO_TRACK_NAME,
401 IDS_FLAGS_ENABLE_VIDEO_TRACK_DESCRIPTION,
402 kOsAll,
403 SINGLE_VALUE_TYPE(switches::kEnableVideoTrack)
404 },
[email protected]08b83362011-10-19 05:23:17405 {
406 "extension-alerts",
407 IDS_FLAGS_ENABLE_EXTENSION_ALERTS_NAME,
408 IDS_FLAGS_ENABLE_EXTENSION_ALERTS_DESCRIPTION,
409 kOsAll,
410 SINGLE_VALUE_TYPE(switches::kEnableExtensionAlerts)
411 },
[email protected]5a60c8b2011-10-19 20:14:29412 {
413 "enable-http-pipelining",
414 IDS_FLAGS_ENABLE_HTTP_PIPELINING_NAME,
415 IDS_FLAGS_ENABLE_HTTP_PIPELINING_DESCRIPTION,
416 kOsAll,
417 SINGLE_VALUE_TYPE(switches::kEnableHttpPipelining)
418 },
[email protected]e3aaa93782011-10-26 16:04:28419#if defined(OS_CHROMEOS)
420 {
421 "enable-photo-editor",
422 IDS_FLAGS_ENABLE_PHOTO_EDITOR_NAME,
423 IDS_FLAGS_ENABLE_PHOTO_EDITOR_DESCRIPTION,
424 kOsCrOS,
425 SINGLE_VALUE_TYPE(switches::kEnablePhotoEditor)
426 },
427#endif
[email protected]6aa03b32011-10-27 21:44:44428 {
429 "enable-media-source",
430 IDS_FLAGS_ENABLE_MEDIA_SOURCE_NAME,
431 IDS_FLAGS_ENABLE_MEDIA_SOURCE_DESCRIPTION,
432 kOsAll,
433 SINGLE_VALUE_TYPE(switches::kEnableMediaSource)
434 },
[email protected]e4e68dbb2011-11-18 01:50:22435 {
436 "enable-pointer-lock",
437 IDS_FLAGS_ENABLE_POINTER_LOCK_NAME,
438 IDS_FLAGS_ENABLE_POINTER_LOCK_DESCRIPTION,
439 kOsAll,
440 SINGLE_VALUE_TYPE(switches::kEnablePointerLock)
441 },
[email protected]8cc10df2011-11-03 23:57:50442#if defined(USE_AURA)
443 {
444 "aura-windows",
445 IDS_FLAGS_AURA_WINDOWS_NAME,
446 IDS_FLAGS_AURA_WINDOWS_DESCRIPTION,
447 kOsWin | kOsLinux | kOsCrOS,
448 SINGLE_VALUE_TYPE(switches::kAuraWindows)
449 },
450#endif
[email protected]a0e4b072011-08-17 01:47:07451};
[email protected]ad2a3ded2010-08-27 13:19:05452
[email protected]a314ee5a2010-10-26 21:23:28453const Experiment* experiments = kExperiments;
454size_t num_experiments = arraysize(kExperiments);
455
[email protected]e2ddbc92010-10-15 20:02:07456// Stores and encapsulates the little state that about:flags has.
457class FlagsState {
458 public:
459 FlagsState() : needs_restart_(false) {}
460 void ConvertFlagsToSwitches(PrefService* prefs, CommandLine* command_line);
461 bool IsRestartNeededToCommitChanges();
462 void SetExperimentEnabled(
[email protected]a314ee5a2010-10-26 21:23:28463 PrefService* prefs, const std::string& internal_name, bool enable);
[email protected]e2ddbc92010-10-15 20:02:07464 void RemoveFlagsSwitches(
465 std::map<std::string, CommandLine::StringType>* switch_list);
466 void reset();
467
468 // Returns the singleton instance of this class
[email protected]8e8bb6d2010-12-13 08:18:55469 static FlagsState* GetInstance() {
[email protected]e2ddbc92010-10-15 20:02:07470 return Singleton<FlagsState>::get();
471 }
472
473 private:
474 bool needs_restart_;
[email protected]a82744532011-02-11 16:15:53475 std::map<std::string, std::string> flags_switches_;
[email protected]e2ddbc92010-10-15 20:02:07476
477 DISALLOW_COPY_AND_ASSIGN(FlagsState);
478};
479
[email protected]c7b7800a2010-10-07 18:51:35480// Extracts the list of enabled lab experiments from preferences and stores them
[email protected]ad2a3ded2010-08-27 13:19:05481// in a set.
[email protected]1a47d7e2010-10-15 00:37:24482void GetEnabledFlags(const PrefService* prefs, std::set<std::string>* result) {
[email protected]ad2a3ded2010-08-27 13:19:05483 const ListValue* enabled_experiments = prefs->GetList(
484 prefs::kEnabledLabsExperiments);
485 if (!enabled_experiments)
486 return;
487
488 for (ListValue::const_iterator it = enabled_experiments->begin();
489 it != enabled_experiments->end();
490 ++it) {
491 std::string experiment_name;
492 if (!(*it)->GetAsString(&experiment_name)) {
493 LOG(WARNING) << "Invalid entry in " << prefs::kEnabledLabsExperiments;
494 continue;
495 }
496 result->insert(experiment_name);
497 }
498}
499
500// Takes a set of enabled lab experiments
[email protected]1a47d7e2010-10-15 00:37:24501void SetEnabledFlags(
[email protected]ad2a3ded2010-08-27 13:19:05502 PrefService* prefs, const std::set<std::string>& enabled_experiments) {
[email protected]1bc78422011-03-31 08:41:38503 ListPrefUpdate update(prefs, prefs::kEnabledLabsExperiments);
504 ListValue* experiments_list = update.Get();
[email protected]ad2a3ded2010-08-27 13:19:05505
506 experiments_list->Clear();
507 for (std::set<std::string>::const_iterator it = enabled_experiments.begin();
508 it != enabled_experiments.end();
509 ++it) {
510 experiments_list->Append(new StringValue(*it));
511 }
512}
513
[email protected]8a6ff28d2010-12-02 16:35:19514// Returns the name used in prefs for the choice at the specified index.
515std::string NameForChoice(const Experiment& e, int index) {
[email protected]2ce9c89752011-02-25 18:24:34516 DCHECK_EQ(Experiment::MULTI_VALUE, e.type);
517 DCHECK_LT(index, e.num_choices);
[email protected]8a6ff28d2010-12-02 16:35:19518 return std::string(e.internal_name) + about_flags::testing::kMultiSeparator +
519 base::IntToString(index);
520}
521
522// Adds the internal names for the specified experiment to |names|.
523void AddInternalName(const Experiment& e, std::set<std::string>* names) {
524 if (e.type == Experiment::SINGLE_VALUE) {
525 names->insert(e.internal_name);
526 } else {
[email protected]2ce9c89752011-02-25 18:24:34527 DCHECK_EQ(Experiment::MULTI_VALUE, e.type);
[email protected]8a6ff28d2010-12-02 16:35:19528 for (int i = 0; i < e.num_choices; ++i)
529 names->insert(NameForChoice(e, i));
530 }
531}
532
[email protected]28e35af2011-02-09 12:56:22533// Confirms that an experiment is valid, used in a DCHECK in
534// SanitizeList below.
535bool ValidateExperiment(const Experiment& e) {
536 switch (e.type) {
537 case Experiment::SINGLE_VALUE:
538 DCHECK_EQ(0, e.num_choices);
539 DCHECK(!e.choices);
540 break;
541 case Experiment::MULTI_VALUE:
542 DCHECK_GT(e.num_choices, 0);
543 DCHECK(e.choices);
[email protected]a82744532011-02-11 16:15:53544 DCHECK(e.choices[0].command_line_switch);
545 DCHECK_EQ('\0', e.choices[0].command_line_switch[0]);
[email protected]28e35af2011-02-09 12:56:22546 break;
547 default:
548 NOTREACHED();
549 }
550 return true;
551}
552
[email protected]ad2a3ded2010-08-27 13:19:05553// Removes all experiments from prefs::kEnabledLabsExperiments that are
554// unknown, to prevent this list to become very long as experiments are added
555// and removed.
556void SanitizeList(PrefService* prefs) {
557 std::set<std::string> known_experiments;
[email protected]28e35af2011-02-09 12:56:22558 for (size_t i = 0; i < num_experiments; ++i) {
559 DCHECK(ValidateExperiment(experiments[i]));
[email protected]8a6ff28d2010-12-02 16:35:19560 AddInternalName(experiments[i], &known_experiments);
[email protected]28e35af2011-02-09 12:56:22561 }
[email protected]ad2a3ded2010-08-27 13:19:05562
563 std::set<std::string> enabled_experiments;
[email protected]1a47d7e2010-10-15 00:37:24564 GetEnabledFlags(prefs, &enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05565
566 std::set<std::string> new_enabled_experiments;
567 std::set_intersection(
568 known_experiments.begin(), known_experiments.end(),
569 enabled_experiments.begin(), enabled_experiments.end(),
570 std::inserter(new_enabled_experiments, new_enabled_experiments.begin()));
571
[email protected]1a47d7e2010-10-15 00:37:24572 SetEnabledFlags(prefs, new_enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05573}
574
[email protected]1a47d7e2010-10-15 00:37:24575void GetSanitizedEnabledFlags(
[email protected]ad2a3ded2010-08-27 13:19:05576 PrefService* prefs, std::set<std::string>* result) {
577 SanitizeList(prefs);
[email protected]1a47d7e2010-10-15 00:37:24578 GetEnabledFlags(prefs, result);
[email protected]ad2a3ded2010-08-27 13:19:05579}
580
[email protected]a314ee5a2010-10-26 21:23:28581// Variant of GetSanitizedEnabledFlags that also removes any flags that aren't
582// enabled on the current platform.
583void GetSanitizedEnabledFlagsForCurrentPlatform(
584 PrefService* prefs, std::set<std::string>* result) {
585 GetSanitizedEnabledFlags(prefs, result);
586
587 // Filter out any experiments that aren't enabled on the current platform. We
588 // don't remove these from prefs else syncing to a platform with a different
589 // set of experiments would be lossy.
590 std::set<std::string> platform_experiments;
591 int current_platform = GetCurrentPlatform();
592 for (size_t i = 0; i < num_experiments; ++i) {
593 if (experiments[i].supported_platforms & current_platform)
[email protected]8a6ff28d2010-12-02 16:35:19594 AddInternalName(experiments[i], &platform_experiments);
[email protected]a314ee5a2010-10-26 21:23:28595 }
596
597 std::set<std::string> new_enabled_experiments;
598 std::set_intersection(
599 platform_experiments.begin(), platform_experiments.end(),
600 result->begin(), result->end(),
601 std::inserter(new_enabled_experiments, new_enabled_experiments.begin()));
602
603 result->swap(new_enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05604}
605
[email protected]8a6ff28d2010-12-02 16:35:19606// Returns the Value representing the choice data in the specified experiment.
[email protected]8a6ff28d2010-12-02 16:35:19607Value* CreateChoiceData(const Experiment& experiment,
[email protected]28e35af2011-02-09 12:56:22608 const std::set<std::string>& enabled_experiments) {
[email protected]2ce9c89752011-02-25 18:24:34609 DCHECK_EQ(Experiment::MULTI_VALUE, experiment.type);
[email protected]8a6ff28d2010-12-02 16:35:19610 ListValue* result = new ListValue;
611 for (int i = 0; i < experiment.num_choices; ++i) {
612 const Experiment::Choice& choice = experiment.choices[i];
613 DictionaryValue* value = new DictionaryValue;
614 std::string name = NameForChoice(experiment, i);
615 value->SetString("description",
616 l10n_util::GetStringUTF16(choice.description_id));
617 value->SetString("internal_name", name);
[email protected]28e35af2011-02-09 12:56:22618 value->SetBoolean("selected", enabled_experiments.count(name) > 0);
[email protected]8a6ff28d2010-12-02 16:35:19619 result->Append(value);
620 }
621 return result;
622}
623
[email protected]e2ddbc92010-10-15 20:02:07624} // namespace
625
[email protected]1a47d7e2010-10-15 00:37:24626void ConvertFlagsToSwitches(PrefService* prefs, CommandLine* command_line) {
[email protected]8e8bb6d2010-12-13 08:18:55627 FlagsState::GetInstance()->ConvertFlagsToSwitches(prefs, command_line);
[email protected]ad2a3ded2010-08-27 13:19:05628}
629
[email protected]1a47d7e2010-10-15 00:37:24630ListValue* GetFlagsExperimentsData(PrefService* prefs) {
[email protected]ad2a3ded2010-08-27 13:19:05631 std::set<std::string> enabled_experiments;
[email protected]1a47d7e2010-10-15 00:37:24632 GetSanitizedEnabledFlags(prefs, &enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05633
634 int current_platform = GetCurrentPlatform();
635
636 ListValue* experiments_data = new ListValue();
[email protected]a314ee5a2010-10-26 21:23:28637 for (size_t i = 0; i < num_experiments; ++i) {
638 const Experiment& experiment = experiments[i];
[email protected]ad2a3ded2010-08-27 13:19:05639 if (!(experiment.supported_platforms & current_platform))
640 continue;
641
642 DictionaryValue* data = new DictionaryValue();
643 data->SetString("internal_name", experiment.internal_name);
644 data->SetString("name",
645 l10n_util::GetStringUTF16(experiment.visible_name_id));
646 data->SetString("description",
647 l10n_util::GetStringUTF16(
648 experiment.visible_description_id));
[email protected]ad2a3ded2010-08-27 13:19:05649
[email protected]28e35af2011-02-09 12:56:22650 switch (experiment.type) {
651 case Experiment::SINGLE_VALUE:
652 data->SetBoolean(
653 "enabled",
654 enabled_experiments.count(experiment.internal_name) > 0);
655 break;
656 case Experiment::MULTI_VALUE:
657 data->Set("choices", CreateChoiceData(experiment, enabled_experiments));
658 break;
659 default:
660 NOTREACHED();
[email protected]8a6ff28d2010-12-02 16:35:19661 }
662
[email protected]ad2a3ded2010-08-27 13:19:05663 experiments_data->Append(data);
664 }
665 return experiments_data;
666}
667
[email protected]ad2a3ded2010-08-27 13:19:05668bool IsRestartNeededToCommitChanges() {
[email protected]8e8bb6d2010-12-13 08:18:55669 return FlagsState::GetInstance()->IsRestartNeededToCommitChanges();
[email protected]ad2a3ded2010-08-27 13:19:05670}
671
672void SetExperimentEnabled(
[email protected]c7b7800a2010-10-07 18:51:35673 PrefService* prefs, const std::string& internal_name, bool enable) {
[email protected]8e8bb6d2010-12-13 08:18:55674 FlagsState::GetInstance()->SetExperimentEnabled(prefs, internal_name, enable);
[email protected]e2ddbc92010-10-15 20:02:07675}
676
677void RemoveFlagsSwitches(
678 std::map<std::string, CommandLine::StringType>* switch_list) {
[email protected]8e8bb6d2010-12-13 08:18:55679 FlagsState::GetInstance()->RemoveFlagsSwitches(switch_list);
[email protected]e2ddbc92010-10-15 20:02:07680}
681
[email protected]a314ee5a2010-10-26 21:23:28682int GetCurrentPlatform() {
683#if defined(OS_MACOSX)
684 return kOsMac;
685#elif defined(OS_WIN)
686 return kOsWin;
687#elif defined(OS_CHROMEOS) // Needs to be before the OS_LINUX check.
688 return kOsCrOS;
[email protected]c92f4ed2011-10-21 19:50:21689#elif defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]a314ee5a2010-10-26 21:23:28690 return kOsLinux;
691#else
692#error Unknown platform
693#endif
694}
695
[email protected]4bc5050c2010-11-18 17:55:54696void RecordUMAStatistics(const PrefService* prefs) {
697 std::set<std::string> flags;
698 GetEnabledFlags(prefs, &flags);
699 for (std::set<std::string>::iterator it = flags.begin(); it != flags.end();
700 ++it) {
701 std::string action("AboutFlags_");
702 action += *it;
703 UserMetrics::RecordComputedAction(action);
704 }
705 // Since flag metrics are recorded every startup, add a tick so that the
706 // stats can be made meaningful.
707 if (flags.size())
708 UserMetrics::RecordAction(UserMetricsAction("AboutFlags_StartupTick"));
[email protected]970b2fd2011-01-22 18:06:45709 UserMetrics::RecordAction(UserMetricsAction("StartupTick"));
[email protected]4bc5050c2010-11-18 17:55:54710}
711
[email protected]e2ddbc92010-10-15 20:02:07712//////////////////////////////////////////////////////////////////////////////
713// FlagsState implementation.
714
715namespace {
716
717void FlagsState::ConvertFlagsToSwitches(
718 PrefService* prefs, CommandLine* command_line) {
[email protected]e2ddbc92010-10-15 20:02:07719 if (command_line->HasSwitch(switches::kNoExperiments))
720 return;
721
722 std::set<std::string> enabled_experiments;
[email protected]ba8164242010-11-16 21:31:00723
[email protected]a314ee5a2010-10-26 21:23:28724 GetSanitizedEnabledFlagsForCurrentPlatform(prefs, &enabled_experiments);
[email protected]e2ddbc92010-10-15 20:02:07725
[email protected]a82744532011-02-11 16:15:53726 typedef std::map<std::string, std::pair<std::string, std::string> >
727 NameToSwitchAndValueMap;
728 NameToSwitchAndValueMap name_to_switch_map;
[email protected]8a6ff28d2010-12-02 16:35:19729 for (size_t i = 0; i < num_experiments; ++i) {
730 const Experiment& e = experiments[i];
731 if (e.type == Experiment::SINGLE_VALUE) {
[email protected]a82744532011-02-11 16:15:53732 name_to_switch_map[e.internal_name] =
733 std::pair<std::string, std::string>(e.command_line_switch,
734 e.command_line_value);
[email protected]8a6ff28d2010-12-02 16:35:19735 } else {
736 for (int j = 0; j < e.num_choices; ++j)
[email protected]a82744532011-02-11 16:15:53737 name_to_switch_map[NameForChoice(e, j)] =
738 std::pair<std::string, std::string>(
739 e.choices[j].command_line_switch,
740 e.choices[j].command_line_value);
[email protected]8a6ff28d2010-12-02 16:35:19741 }
742 }
[email protected]e2ddbc92010-10-15 20:02:07743
744 command_line->AppendSwitch(switches::kFlagSwitchesBegin);
[email protected]a82744532011-02-11 16:15:53745 flags_switches_.insert(
746 std::pair<std::string, std::string>(switches::kFlagSwitchesBegin,
747 std::string()));
[email protected]e2ddbc92010-10-15 20:02:07748 for (std::set<std::string>::iterator it = enabled_experiments.begin();
749 it != enabled_experiments.end();
750 ++it) {
751 const std::string& experiment_name = *it;
[email protected]a82744532011-02-11 16:15:53752 NameToSwitchAndValueMap::const_iterator name_to_switch_it =
[email protected]8a6ff28d2010-12-02 16:35:19753 name_to_switch_map.find(experiment_name);
754 if (name_to_switch_it == name_to_switch_map.end()) {
755 NOTREACHED();
[email protected]e2ddbc92010-10-15 20:02:07756 continue;
[email protected]8a6ff28d2010-12-02 16:35:19757 }
[email protected]e2ddbc92010-10-15 20:02:07758
[email protected]a82744532011-02-11 16:15:53759 const std::pair<std::string, std::string>&
760 switch_and_value_pair = name_to_switch_it->second;
761
762 command_line->AppendSwitchASCII(switch_and_value_pair.first,
763 switch_and_value_pair.second);
764 flags_switches_[switch_and_value_pair.first] = switch_and_value_pair.second;
[email protected]e2ddbc92010-10-15 20:02:07765 }
766 command_line->AppendSwitch(switches::kFlagSwitchesEnd);
[email protected]a82744532011-02-11 16:15:53767 flags_switches_.insert(
768 std::pair<std::string, std::string>(switches::kFlagSwitchesEnd,
769 std::string()));
[email protected]e2ddbc92010-10-15 20:02:07770}
771
772bool FlagsState::IsRestartNeededToCommitChanges() {
773 return needs_restart_;
774}
775
776void FlagsState::SetExperimentEnabled(
777 PrefService* prefs, const std::string& internal_name, bool enable) {
[email protected]ad2a3ded2010-08-27 13:19:05778 needs_restart_ = true;
779
[email protected]8a6ff28d2010-12-02 16:35:19780 size_t at_index = internal_name.find(about_flags::testing::kMultiSeparator);
781 if (at_index != std::string::npos) {
782 DCHECK(enable);
783 // We're being asked to enable a multi-choice experiment. Disable the
784 // currently selected choice.
785 DCHECK_NE(at_index, 0u);
[email protected]28e35af2011-02-09 12:56:22786 const std::string experiment_name = internal_name.substr(0, at_index);
787 SetExperimentEnabled(prefs, experiment_name, false);
[email protected]8a6ff28d2010-12-02 16:35:19788
[email protected]28e35af2011-02-09 12:56:22789 // And enable the new choice, if it is not the default first choice.
790 if (internal_name != experiment_name + "@0") {
791 std::set<std::string> enabled_experiments;
792 GetSanitizedEnabledFlags(prefs, &enabled_experiments);
793 enabled_experiments.insert(internal_name);
794 SetEnabledFlags(prefs, enabled_experiments);
795 }
[email protected]8a6ff28d2010-12-02 16:35:19796 return;
797 }
798
[email protected]ad2a3ded2010-08-27 13:19:05799 std::set<std::string> enabled_experiments;
[email protected]1a47d7e2010-10-15 00:37:24800 GetSanitizedEnabledFlags(prefs, &enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05801
[email protected]8a6ff28d2010-12-02 16:35:19802 const Experiment* e = NULL;
803 for (size_t i = 0; i < num_experiments; ++i) {
804 if (experiments[i].internal_name == internal_name) {
805 e = experiments + i;
806 break;
807 }
808 }
809 DCHECK(e);
810
811 if (e->type == Experiment::SINGLE_VALUE) {
[email protected]8a2713682011-08-19 10:36:59812 if (enable)
[email protected]8a6ff28d2010-12-02 16:35:19813 enabled_experiments.insert(internal_name);
[email protected]8a2713682011-08-19 10:36:59814 else
[email protected]8a6ff28d2010-12-02 16:35:19815 enabled_experiments.erase(internal_name);
816 } else {
817 if (enable) {
818 // Enable the first choice.
819 enabled_experiments.insert(NameForChoice(*e, 0));
820 } else {
821 // Find the currently enabled choice and disable it.
822 for (int i = 0; i < e->num_choices; ++i) {
823 std::string choice_name = NameForChoice(*e, i);
824 if (enabled_experiments.find(choice_name) !=
825 enabled_experiments.end()) {
826 enabled_experiments.erase(choice_name);
827 // Continue on just in case there's a bug and more than one
828 // experiment for this choice was enabled.
829 }
830 }
831 }
832 }
[email protected]ad2a3ded2010-08-27 13:19:05833
[email protected]1a47d7e2010-10-15 00:37:24834 SetEnabledFlags(prefs, enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05835}
836
[email protected]e2ddbc92010-10-15 20:02:07837void FlagsState::RemoveFlagsSwitches(
838 std::map<std::string, CommandLine::StringType>* switch_list) {
[email protected]a82744532011-02-11 16:15:53839 for (std::map<std::string, std::string>::const_iterator
840 it = flags_switches_.begin(); it != flags_switches_.end(); ++it) {
841 switch_list->erase(it->first);
[email protected]e2ddbc92010-10-15 20:02:07842 }
843}
844
845void FlagsState::reset() {
846 needs_restart_ = false;
847 flags_switches_.clear();
848}
849
[email protected]38e46812011-05-09 20:49:22850} // namespace
[email protected]e2ddbc92010-10-15 20:02:07851
852namespace testing {
[email protected]8a6ff28d2010-12-02 16:35:19853
854// WARNING: '@' is also used in the html file. If you update this constant you
855// also need to update the html file.
856const char kMultiSeparator[] = "@";
857
[email protected]e2ddbc92010-10-15 20:02:07858void ClearState() {
[email protected]8e8bb6d2010-12-13 08:18:55859 FlagsState::GetInstance()->reset();
[email protected]e2ddbc92010-10-15 20:02:07860}
[email protected]a314ee5a2010-10-26 21:23:28861
862void SetExperiments(const Experiment* e, size_t count) {
863 if (!e) {
864 experiments = kExperiments;
865 num_experiments = arraysize(kExperiments);
866 } else {
867 experiments = e;
868 num_experiments = count;
869 }
870}
871
[email protected]8a6ff28d2010-12-02 16:35:19872const Experiment* GetExperiments(size_t* count) {
873 *count = num_experiments;
874 return experiments;
875}
876
[email protected]e2ddbc92010-10-15 20:02:07877} // namespace testing
878
[email protected]1a47d7e2010-10-15 00:37:24879} // namespace about_flags