blob: 21ff5d7c74b86d3cd8bdff05b196c541529df382 [file] [log] [blame]
[email protected]9c66adc2012-01-05 02:10:161// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]ad2a3ded2010-08-27 13:19:052// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]1a47d7e2010-10-15 00:37:245#include "chrome/browser/about_flags.h"
[email protected]ad2a3ded2010-08-27 13:19:056
7#include <algorithm>
8#include <iterator>
9#include <map>
10#include <set>
11
[email protected]ad2a3ded2010-08-27 13:19:0512#include "base/command_line.h"
[email protected]3b63f8f42011-03-28 01:54:1513#include "base/memory/singleton.h"
[email protected]8a6ff28d2010-12-02 16:35:1914#include "base/string_number_conversions.h"
[email protected]d208f4d82011-05-23 21:52:0315#include "base/utf_string_conversions.h"
[email protected]ad2a3ded2010-08-27 13:19:0516#include "base/values.h"
[email protected]ad2a3ded2010-08-27 13:19:0517#include "chrome/browser/prefs/pref_service.h"
[email protected]1bc78422011-03-31 08:41:3818#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]d208f4d82011-05-23 21:52:0319#include "chrome/common/chrome_content_client.h"
[email protected]ad2a3ded2010-08-27 13:19:0520#include "chrome/common/chrome_switches.h"
21#include "chrome/common/pref_names.h"
[email protected]7f6f44c2011-12-14 13:23:3822#include "content/public/browser/user_metrics.h"
[email protected]ad2a3ded2010-08-27 13:19:0523#include "grit/generated_resources.h"
[email protected]c051a1b2011-01-21 23:30:1724#include "ui/base/l10n/l10n_util.h"
[email protected]8ff7f342011-05-25 01:49:4725#include "ui/gfx/gl/gl_switches.h"
[email protected]ad2a3ded2010-08-27 13:19:0526
[email protected]8cc10df2011-11-03 23:57:5027#if defined(USE_AURA)
[email protected]b65bdda2011-12-23 23:35:3128#include "ash/ash_switches.h"
[email protected]8cc10df2011-11-03 23:57:5029#endif
30
[email protected]7f6f44c2011-12-14 13:23:3831using content::UserMetricsAction;
32
[email protected]1a47d7e2010-10-15 00:37:2433namespace about_flags {
[email protected]ad2a3ded2010-08-27 13:19:0534
[email protected]8a6ff28d2010-12-02 16:35:1935// Macros to simplify specifying the type.
[email protected]a82744532011-02-11 16:15:5336#define SINGLE_VALUE_TYPE_AND_VALUE(command_line_switch, switch_value) \
37 Experiment::SINGLE_VALUE, command_line_switch, switch_value, NULL, 0
38#define SINGLE_VALUE_TYPE(command_line_switch) \
39 SINGLE_VALUE_TYPE_AND_VALUE(command_line_switch, "")
40#define MULTI_VALUE_TYPE(choices) \
[email protected]0e6f56d2011-02-12 23:45:1541 Experiment::MULTI_VALUE, "", "", choices, arraysize(choices)
[email protected]8a6ff28d2010-12-02 16:35:1942
[email protected]e2ddbc92010-10-15 20:02:0743namespace {
44
[email protected]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[] = {
[email protected]9c66adc2012-01-05 02:10:1680 { IDS_FLAGS_AURA_WINDOW_MODE_AUTOMATIC, "", "" },
81 { IDS_FLAGS_AURA_WINDOW_MODE_NORMAL,
82 ash::switches::kAuraWindowMode, ash::switches::kAuraWindowModeNormal },
[email protected]3fbd9c12011-12-16 21:35:1183 { IDS_FLAGS_AURA_WINDOW_MODE_COMPACT,
[email protected]9c66adc2012-01-05 02:10:1684 ash::switches::kAuraWindowMode, ash::switches::kAuraWindowModeCompact }
[email protected]3fbd9c12011-12-16 21:35:1185};
86#endif
87
[email protected]4bc5050c2010-11-18 17:55:5488// RECORDING USER METRICS FOR FLAGS:
89// -----------------------------------------------------------------------------
90// The first line of the experiment is the internal name. If you'd like to
91// gather statistics about the usage of your flag, you should append a marker
92// comment to the end of the feature name, like so:
93// "my-special-feature", // FLAGS:RECORD_UMA
94//
95// After doing that, run //chrome/tools/extract_actions.py (see instructions at
96// the top of that file for details) to update the chromeactions.txt file, which
97// will enable UMA to record your feature flag.
98//
99// After your feature has shipped under a flag, you can locate the metrics
100// under the action name AboutFlags_internal-action-name. Actions are recorded
101// once per startup, so you should divide this number by AboutFlags_StartupTick
102// to get a sense of usage. Note that this will not be the same as number of
103// users with a given feature enabled because users can quit and relaunch
104// the application multiple times over a given time interval.
105// TODO(rsesek): See if there's a way to count per-user, rather than
106// per-startup.
107
[email protected]8a6ff28d2010-12-02 16:35:19108// To add a new experiment add to the end of kExperiments. There are two
109// distinct types of experiments:
110// . SINGLE_VALUE: experiment is either on or off. Use the SINGLE_VALUE_TYPE
111// macro for this type supplying the command line to the macro.
[email protected]28e35af2011-02-09 12:56:22112// . MULTI_VALUE: a list of choices, the first of which should correspond to a
113// deactivated state for this lab (i.e. no command line option). To specify
114// this type of experiment use the macro MULTI_VALUE_TYPE supplying it the
115// array of choices.
[email protected]8a6ff28d2010-12-02 16:35:19116// See the documentation of Experiment for details on the fields.
117//
118// When adding a new choice, add it to the end of the list.
[email protected]ad2a3ded2010-08-27 13:19:05119const Experiment kExperiments[] = {
120 {
[email protected]aac169d2011-03-18 19:53:03121 "expose-for-tabs", // FLAGS:RECORD_UMA
122 IDS_FLAGS_TABPOSE_NAME,
123 IDS_FLAGS_TABPOSE_DESCRIPTION,
124 kOsMac,
125#if defined(OS_MACOSX)
126 // The switch exists only on OS X.
127 SINGLE_VALUE_TYPE(switches::kEnableExposeForTabs)
128#else
129 SINGLE_VALUE_TYPE("")
130#endif
131 },
132 {
[email protected]4bc5050c2010-11-18 17:55:54133 "conflicting-modules-check", // FLAGS:RECORD_UMA
[email protected]c1bbaa82010-11-08 11:17:05134 IDS_FLAGS_CONFLICTS_CHECK_NAME,
135 IDS_FLAGS_CONFLICTS_CHECK_DESCRIPTION,
136 kOsWin,
[email protected]8a6ff28d2010-12-02 16:35:19137 SINGLE_VALUE_TYPE(switches::kConflictingModulesCheck)
[email protected]c1bbaa82010-11-08 11:17:05138 },
139 {
[email protected]4bc5050c2010-11-18 17:55:54140 "cloud-print-proxy", // FLAGS:RECORD_UMA
[email protected]dae7325b2011-12-21 20:56:54141 IDS_FLAGS_CLOUD_PRINT_CONNECTOR_NAME,
142 IDS_FLAGS_CLOUD_PRINT_CONNECTOR_DESCRIPTION,
[email protected]9f8872b32011-03-04 19:44:45143 // For a Chrome build, we know we have a PDF plug-in on Windows, so it's
[email protected]4fa24bf2011-08-20 02:15:22144 // fully enabled.
[email protected]5d10d57d2011-07-22 22:16:31145 // Otherwise, where we know Windows could be working if a viable PDF
[email protected]4fa24bf2011-08-20 02:15:22146 // plug-in could be supplied, we'll keep the lab enabled. Mac and Linux
147 // always have PDF rasterization available, so no flag needed there.
148#if !defined(GOOGLE_CHROME_BUILD)
149 kOsWin,
150#else
151 0,
[email protected]fa6d2a2f2010-11-30 21:47:19152#endif
[email protected]8a6ff28d2010-12-02 16:35:19153 SINGLE_VALUE_TYPE(switches::kEnableCloudPrintProxy)
[email protected]8b6588a2010-10-12 02:39:42154 },
[email protected]580939a2010-10-12 18:54:37155 {
[email protected]bb461532010-11-26 21:50:23156 "crxless-web-apps",
157 IDS_FLAGS_CRXLESS_WEB_APPS_NAME,
158 IDS_FLAGS_CRXLESS_WEB_APPS_DESCRIPTION,
159 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19160 SINGLE_VALUE_TYPE(switches::kEnableCrxlessWebApps)
[email protected]bb461532010-11-26 21:50:23161 },
162 {
[email protected]96c6f4c2011-05-18 19:36:22163 "ignore-gpu-blacklist",
164 IDS_FLAGS_IGNORE_GPU_BLACKLIST_NAME,
165 IDS_FLAGS_IGNORE_GPU_BLACKLIST_DESCRIPTION,
166 kOsAll,
167 SINGLE_VALUE_TYPE(switches::kIgnoreGpuBlacklist)
168 },
169 {
[email protected]0110cf112011-07-02 00:39:43170 "force-compositing-mode-2",
[email protected]96c6f4c2011-05-18 19:36:22171 IDS_FLAGS_FORCE_COMPOSITING_MODE_NAME,
172 IDS_FLAGS_FORCE_COMPOSITING_MODE_DESCRIPTION,
173 kOsAll,
174 SINGLE_VALUE_TYPE(switches::kForceCompositingMode)
175 },
176 {
[email protected]5963b772011-02-09 22:55:38177 "composited-layer-borders",
178 IDS_FLAGS_COMPOSITED_LAYER_BORDERS,
179 IDS_FLAGS_COMPOSITED_LAYER_BORDERS_DESCRIPTION,
180 kOsAll,
181 SINGLE_VALUE_TYPE(switches::kShowCompositedLayerBorders)
182 },
183 {
[email protected]db543d322011-12-15 20:40:15184 "accelerated-painting",
185 IDS_FLAGS_ACCELERATED_PAINTING_NAME,
186 IDS_FLAGS_ACCELERATED_PAINTING_DESCRIPTION,
[email protected]60dea122011-12-06 00:32:45187#if defined(USE_SKIA)
188 kOsAll,
189#else
190 0,
191#endif
[email protected]db543d322011-12-15 20:40:15192 SINGLE_VALUE_TYPE(switches::kEnableAcceleratedPainting)
[email protected]60dea122011-12-06 00:32:45193 },
194 {
[email protected]a8f1eaa2011-03-07 19:00:58195 "show-fps-counter",
196 IDS_FLAGS_SHOW_FPS_COUNTER,
197 IDS_FLAGS_SHOW_FPS_COUNTER_DESCRIPTION,
198 kOsAll,
199 SINGLE_VALUE_TYPE(switches::kShowFPSCounter)
200 },
[email protected]8ff7f342011-05-25 01:49:47201 {
[email protected]70c98a332011-12-21 20:51:52202 "accelerated-filters",
203 IDS_FLAGS_ACCELERATED_FILTERS,
204 IDS_FLAGS_ACCELERATED_FILTERS_DESCRIPTION,
205 kOsAll,
206 SINGLE_VALUE_TYPE(switches::kEnableAcceleratedFilters)
207 },
208 {
[email protected]8ff7f342011-05-25 01:49:47209 "disable-gpu-vsync",
210 IDS_FLAGS_DISABLE_GPU_VSYNC_NAME,
211 IDS_FLAGS_DISABLE_GPU_VSYNC_DESCRIPTION,
212 kOsAll,
213 SINGLE_VALUE_TYPE(switches::kDisableGpuVsync)
214 },
[email protected]deaba6d52011-09-23 14:47:12215 {
216 "disable-webgl",
217 IDS_FLAGS_DISABLE_WEBGL_NAME,
218 IDS_FLAGS_DISABLE_WEBGL_DESCRIPTION,
219 kOsAll,
220 SINGLE_VALUE_TYPE(switches::kDisableExperimentalWebGL)
221 },
[email protected]9de0ec12011-08-24 21:57:50222 // Exposed on all platforms until there is a workaround for easy access to
223 // the native print dialog for users that need it. Once that's done, revert
224 // back to:
225 // Only expose this for Chromium builds where users may not have the PDF
226 // plugin. Do not give Google Chrome users the option to disable it here.
227 // Also expose it for Chrome OS where print preview is still experimental.
[email protected]8d260e52010-10-13 01:03:05228 {
[email protected]4bc5050c2010-11-18 17:55:54229 "print-preview", // FLAGS:RECORD_UMA
[email protected]9486c1f2010-10-14 19:52:12230 IDS_FLAGS_PRINT_PREVIEW_NAME,
231 IDS_FLAGS_PRINT_PREVIEW_DESCRIPTION,
[email protected]b579afd2011-07-13 00:01:27232 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19233 SINGLE_VALUE_TYPE(switches::kEnablePrintPreview)
[email protected]2fe15fcb2010-10-21 20:39:53234 },
[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 },
243 {
[email protected]4bc5050c2010-11-18 17:55:54244 "extension-apis", // FLAGS:RECORD_UMA
[email protected]11dd68cd52010-11-12 01:15:32245 IDS_FLAGS_EXPERIMENTAL_EXTENSION_APIS_NAME,
246 IDS_FLAGS_EXPERIMENTAL_EXTENSION_APIS_DESCRIPTION,
247 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19248 SINGLE_VALUE_TYPE(switches::kEnableExperimentalExtensionApis)
[email protected]11dd68cd52010-11-12 01:15:32249 },
[email protected]3627b06d2010-11-12 16:36:16250 {
[email protected]cbe224d2011-08-04 22:12:49251 "apps-new-install-bubble",
252 IDS_FLAGS_APPS_NEW_INSTALL_BUBBLE_NAME,
253 IDS_FLAGS_APPS_NEW_INSTALL_BUBBLE_DESCRIPTION,
254 kOsAll,
255 SINGLE_VALUE_TYPE(switches::kAppsNewInstallBubble)
256 },
257 {
[email protected]4bc5050c2010-11-18 17:55:54258 "click-to-play", // FLAGS:RECORD_UMA
[email protected]3627b06d2010-11-12 16:36:16259 IDS_FLAGS_CLICK_TO_PLAY_NAME,
260 IDS_FLAGS_CLICK_TO_PLAY_DESCRIPTION,
261 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19262 SINGLE_VALUE_TYPE(switches::kEnableClickToPlay)
[email protected]3627b06d2010-11-12 16:36:16263 },
[email protected]80bd24e2010-11-30 09:34:38264 {
265 "disable-hyperlink-auditing",
266 IDS_FLAGS_DISABLE_HYPERLINK_AUDITING_NAME,
267 IDS_FLAGS_DISABLE_HYPERLINK_AUDITING_DESCRIPTION,
268 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19269 SINGLE_VALUE_TYPE(switches::kNoPings)
[email protected]feb28fef2010-12-01 10:52:51270 },
271 {
272 "experimental-location-features", // FLAGS:RECORD_UMA
273 IDS_FLAGS_EXPERIMENTAL_LOCATION_FEATURES_NAME,
274 IDS_FLAGS_EXPERIMENTAL_LOCATION_FEATURES_DESCRIPTION,
275 kOsMac | kOsWin | kOsLinux, // Currently does nothing on CrOS.
[email protected]8a6ff28d2010-12-02 16:35:19276 SINGLE_VALUE_TYPE(switches::kExperimentalLocationFeatures)
277 },
278 {
[email protected]04227962011-01-20 02:03:09279 "disable-interactive-form-validation",
280 IDS_FLAGS_DISABLE_INTERACTIVE_FORM_VALIDATION_NAME,
281 IDS_FLAGS_DISABLE_INTERACTIVE_FORM_VALIDATION_DESCRIPTION,
282 kOsAll,
283 SINGLE_VALUE_TYPE(switches::kDisableInteractiveFormValidation)
284 },
[email protected]8df51192011-01-22 20:05:03285 {
[email protected]07d490bc2011-03-07 17:05:26286 "focus-existing-tab-on-open", // FLAGS:RECORD_UMA
287 IDS_FLAGS_FOCUS_EXISTING_TAB_ON_OPEN_NAME,
288 IDS_FLAGS_FOCUS_EXISTING_TAB_ON_OPEN_DESCRIPTION,
289 kOsAll,
290 SINGLE_VALUE_TYPE(switches::kFocusExistingTabOnOpen)
291 },
[email protected]d5dcfb32011-03-19 00:49:24292 {
[email protected]5aea1862011-03-23 23:55:39293 "tab-groups-context-menu",
294 IDS_FLAGS_TAB_GROUPS_CONTEXT_MENU_NAME,
295 IDS_FLAGS_TAB_GROUPS_CONTEXT_MENU_DESCRIPTION,
296 kOsWin,
297 SINGLE_VALUE_TYPE(switches::kEnableTabGroupsContextMenu)
298 },
[email protected]e9bf9d92011-03-31 20:57:15299 {
[email protected]f2557bd2011-06-01 02:33:07300 "preload-instant-search",
301 IDS_FLAGS_PRELOAD_INSTANT_SEARCH_NAME,
302 IDS_FLAGS_PRELOAD_INSTANT_SEARCH_DESCRIPTION,
303 kOsAll,
304 SINGLE_VALUE_TYPE(switches::kPreloadInstantSearch)
305 },
[email protected]354e33b2011-06-15 00:29:10306 {
307 "static-ip-config",
308 IDS_FLAGS_STATIC_IP_CONFIG_NAME,
309 IDS_FLAGS_STATIC_IP_CONFIG_DESCRIPTION,
310 kOsCrOS,
311#if defined(OS_CHROMEOS)
312 // This switch exists only on Chrome OS.
313 SINGLE_VALUE_TYPE(switches::kEnableStaticIPConfig)
314#else
315 SINGLE_VALUE_TYPE("")
316#endif
317 },
[email protected]3eb5728c2011-06-20 22:32:24318 {
319 "show-autofill-type-predictions",
320 IDS_FLAGS_SHOW_AUTOFILL_TYPE_PREDICTIONS_NAME,
321 IDS_FLAGS_SHOW_AUTOFILL_TYPE_PREDICTIONS_DESCRIPTION,
322 kOsAll,
323 SINGLE_VALUE_TYPE(switches::kShowAutofillTypePredictions)
324 },
[email protected]bff4d3e2011-06-21 23:58:52325 {
[email protected]9a6180d7d2011-09-07 01:40:33326 "sync-tabs",
327 IDS_FLAGS_SYNC_TABS_NAME,
328 IDS_FLAGS_SYNC_TABS_DESCRIPTION,
[email protected]5b0ec7f2011-08-11 02:17:17329 kOsAll,
[email protected]9a6180d7d2011-09-07 01:40:33330 SINGLE_VALUE_TYPE(switches::kEnableSyncTabs)
[email protected]5b0ec7f2011-08-11 02:17:17331 },
332 {
[email protected]aae9eeb12011-10-21 21:59:26333 "sync-app-notifications",
334 IDS_FLAGS_SYNC_APP_NOTIFICATIONS_NAME,
335 IDS_FLAGS_SYNC_APP_NOTIFICATIONS_DESCRIPTION,
336 kOsAll,
[email protected]0b6fba82011-11-18 01:31:11337 SINGLE_VALUE_TYPE(switches::kDisableSyncAppNotifications)
[email protected]aae9eeb12011-10-21 21:59:26338 },
339 {
[email protected]a22ebd812011-06-23 00:05:39340 "enable-smooth-scrolling", // FLAGS:RECORD_UMA
341 IDS_FLAGS_ENABLE_SMOOTH_SCROLLING_NAME,
342 IDS_FLAGS_ENABLE_SMOOTH_SCROLLING_DESCRIPTION,
343 // Can't expose the switch unless the code is compiled in.
[email protected]554b7062011-09-03 03:09:40344 // On by default for the Mac (different implementation in WebKit).
[email protected]554b7062011-09-03 03:09:40345 kOsWin | kOsLinux | kOsCrOS,
[email protected]a22ebd812011-06-23 00:05:39346 SINGLE_VALUE_TYPE(switches::kEnableSmoothScrolling)
347 },
[email protected]81a6b0b2011-06-24 17:55:40348 {
[email protected]ae1eb29a2011-08-17 17:50:57349 "prerender-from-omnibox", // FLAGS:RECORD_UMA
[email protected]81a6b0b2011-06-24 17:55:40350 IDS_FLAGS_PRERENDER_FROM_OMNIBOX_NAME,
351 IDS_FLAGS_PRERENDER_FROM_OMNIBOX_DESCRIPTION,
352 kOsAll,
[email protected]778ef7c2011-10-11 15:37:05353 MULTI_VALUE_TYPE(kPrerenderFromOmniboxChoices)
[email protected]81a6b0b2011-06-24 17:55:40354 },
[email protected]40916632011-07-02 01:11:01355 {
[email protected]ed1e39502011-12-16 14:39:35356 "omnibox-aggressive-with-history-urls",
357 IDS_FLAGS_OMNIBOX_AGGRESSIVE_HISTORY_URL_SCORING_NAME,
358 IDS_FLAGS_OMNIBOX_AGGRESSIVE_HISTORY_URL_SCORING_DESCRIPTION,
359 kOsAll,
360 SINGLE_VALUE_TYPE(switches::kEnableOmniboxAggressiveHistoryURL)
361 },
362 {
[email protected]7e7a28092011-12-09 22:24:55363 "enable-panels",
364 IDS_FLAGS_ENABLE_PANELS_NAME,
365 IDS_FLAGS_ENABLE_PANELS_DESCRIPTION,
[email protected]73fb1fc52011-07-09 00:06:54366 kOsAll,
[email protected]7e7a28092011-12-09 22:24:55367 SINGLE_VALUE_TYPE(switches::kEnablePanels)
[email protected]73fb1fc52011-07-09 00:06:54368 },
[email protected]e3749d12011-07-25 22:22:12369 {
[email protected]9931875b2011-11-02 00:19:48370 "disable-shortcuts-provider",
371 IDS_FLAGS_DISABLE_SHORTCUTS_PROVIDER,
372 IDS_FLAGS_DISABLE_SHORTCUTS_PROVIDER_DESCRIPTION,
[email protected]e3749d12011-07-25 22:22:12373 kOsAll,
[email protected]9931875b2011-11-02 00:19:48374 SINGLE_VALUE_TYPE(switches::kDisableShortcutsProvider)
[email protected]e3749d12011-07-25 22:22:12375 },
[email protected]1a2966b92011-08-09 06:50:19376#if defined(OS_CHROMEOS)
377 {
[email protected]cd681c42011-09-29 02:49:44378 "enable-bluetooth",
379 IDS_FLAGS_ENABLE_BLUETOOTH_NAME,
380 IDS_FLAGS_ENABLE_BLUETOOTH_DESCRIPTION,
381 kOsCrOS,
382 SINGLE_VALUE_TYPE(switches::kEnableBluetooth)
383 },
[email protected]1a2966b92011-08-09 06:50:19384#endif
[email protected]80eb4262011-08-03 16:10:41385 {
386 "memory-widget",
387 IDS_FLAGS_MEMORY_WIDGET_NAME,
388 IDS_FLAGS_MEMORY_WIDGET_DESCRIPTION,
389 kOsCrOS,
390#if defined(OS_CHROMEOS)
391 // This switch exists only on Chrome OS.
392 SINGLE_VALUE_TYPE(switches::kMemoryWidget)
393#else
394 SINGLE_VALUE_TYPE("")
395#endif
[email protected]a0e4b072011-08-17 01:47:07396 },
397 {
398 "downloads-new-ui", // FLAGS:RECORD_UMA
399 IDS_FLAGS_DOWNLOADS_NEW_UI_NAME,
400 IDS_FLAGS_DOWNLOADS_NEW_UI_DESCRIPTION,
401 kOsAll,
402 SINGLE_VALUE_TYPE(switches::kDownloadsNewUI)
403 },
[email protected]b7bb44f2011-09-01 05:17:03404 {
405 "enable-autologin",
406 IDS_FLAGS_ENABLE_AUTOLOGIN_NAME,
407 IDS_FLAGS_ENABLE_AUTOLOGIN_DESCRIPTION,
408 kOsMac | kOsWin | kOsLinux,
409 SINGLE_VALUE_TYPE(switches::kEnableAutologin)
410 },
[email protected]b9841172011-09-26 23:36:09411 {
412 "use-more-webui",
413 IDS_FLAGS_USE_MORE_WEBUI_NAME,
414 IDS_FLAGS_USE_MORE_WEBUI_DESCRIPTION,
415 kOsAll,
416 SINGLE_VALUE_TYPE(switches::kUseMoreWebUI)
417 },
[email protected]bbadb112011-12-12 16:55:28418 {
419 "enable-http-pipelining",
420 IDS_FLAGS_ENABLE_HTTP_PIPELINING_NAME,
421 IDS_FLAGS_ENABLE_HTTP_PIPELINING_DESCRIPTION,
422 kOsAll,
423 SINGLE_VALUE_TYPE(switches::kEnableHttpPipelining)
424 },
[email protected]d411c01d2011-10-18 16:00:27425 {
[email protected]f5da41d2011-10-08 17:40:07426 "enable-video-track",
427 IDS_FLAGS_ENABLE_VIDEO_TRACK_NAME,
428 IDS_FLAGS_ENABLE_VIDEO_TRACK_DESCRIPTION,
429 kOsAll,
430 SINGLE_VALUE_TYPE(switches::kEnableVideoTrack)
431 },
[email protected]08b83362011-10-19 05:23:17432 {
433 "extension-alerts",
434 IDS_FLAGS_ENABLE_EXTENSION_ALERTS_NAME,
435 IDS_FLAGS_ENABLE_EXTENSION_ALERTS_DESCRIPTION,
436 kOsAll,
437 SINGLE_VALUE_TYPE(switches::kEnableExtensionAlerts)
438 },
[email protected]6aa03b32011-10-27 21:44:44439 {
440 "enable-media-source",
441 IDS_FLAGS_ENABLE_MEDIA_SOURCE_NAME,
442 IDS_FLAGS_ENABLE_MEDIA_SOURCE_DESCRIPTION,
443 kOsAll,
444 SINGLE_VALUE_TYPE(switches::kEnableMediaSource)
445 },
[email protected]e4e68dbb2011-11-18 01:50:22446 {
447 "enable-pointer-lock",
448 IDS_FLAGS_ENABLE_POINTER_LOCK_NAME,
449 IDS_FLAGS_ENABLE_POINTER_LOCK_DESCRIPTION,
450 kOsAll,
451 SINGLE_VALUE_TYPE(switches::kEnablePointerLock)
452 },
[email protected]8cc10df2011-11-03 23:57:50453#if defined(USE_AURA)
454 {
[email protected]20cea592011-12-10 01:55:30455 "aura-workspace-manager",
456 IDS_FLAGS_AURA_WORKSPACE_MANAGER_NAME,
457 IDS_FLAGS_AURA_WORKSPACE_MANAGER_DESCRIPTION,
[email protected]8cc10df2011-11-03 23:57:50458 kOsWin | kOsLinux | kOsCrOS,
[email protected]55f593352011-12-24 05:42:46459 SINGLE_VALUE_TYPE(ash::switches::kAuraWorkspaceManager)
[email protected]8cc10df2011-11-03 23:57:50460 },
[email protected]20cea592011-12-10 01:55:30461 {
462 "aura-translucent-frames",
463 IDS_FLAGS_AURA_TRANSLUCENT_FRAMES_NAME,
464 IDS_FLAGS_AURA_TRANSLUCENT_FRAMES_DESCRIPTION,
465 kOsWin | kOsLinux | kOsCrOS,
[email protected]55f593352011-12-24 05:42:46466 SINGLE_VALUE_TYPE(ash::switches::kAuraTranslucentFrames)
[email protected]20cea592011-12-10 01:55:30467 },
[email protected]57b8bb352012-01-11 05:11:46468 {
469 "aura-google-dialog-frames",
470 IDS_FLAGS_AURA_GOOGLE_DIALOG_FRAMES_NAME,
471 IDS_FLAGS_AURA_GOOGLE_DIALOG_FRAMES_DESCRIPTION,
472 kOsWin | kOsLinux | kOsCrOS,
473 SINGLE_VALUE_TYPE(ash::switches::kAuraGoogleDialogFrames)
474 },
[email protected]20cea592011-12-10 01:55:30475#endif // defined(USE_AURA)
[email protected]edb051d2011-11-24 23:20:51476 {
477 "enable-gamepad",
478 IDS_FLAGS_ENABLE_GAMEPAD_NAME,
479 IDS_FLAGS_ENABLE_GAMEPAD_DESCRIPTION,
[email protected]47ced5e2012-01-06 22:28:08480 kOsAll,
[email protected]edb051d2011-11-24 23:20:51481 SINGLE_VALUE_TYPE(switches::kEnableGamepad)
482 },
[email protected]5cc74312012-01-10 00:13:38483#if defined(AURA_SHOW_ABOUT_FLAG_WINDOW_MODE)
[email protected]35304ce2011-12-14 23:21:01484 // TODO(jamescook): Enable this for all ChromeOS builds when we're sure
485 // Aura laptop mode performance and feature set match traditional non-Aura
486 // builds.
487 {
[email protected]3fbd9c12011-12-16 21:35:11488 "aura-window-mode",
489 IDS_FLAGS_AURA_WINDOW_MODE_NAME,
490 IDS_FLAGS_AURA_WINDOW_MODE_DESCRIPTION,
[email protected]35304ce2011-12-14 23:21:01491 kOsWin | kOsLinux | kOsCrOS,
[email protected]3fbd9c12011-12-16 21:35:11492 MULTI_VALUE_TYPE(kAuraWindowModeChoices)
[email protected]35304ce2011-12-14 23:21:01493 },
494#endif
[email protected]db543d322011-12-15 20:40:15495 {
496 "per-tile-painting",
497 IDS_FLAGS_PER_TILE_PAINTING_NAME,
498 IDS_FLAGS_PER_TILE_PAINTING_DESCRIPTION,
499#if defined(USE_SKIA)
[email protected]a5b1b272012-01-06 20:44:37500 kOsMac | kOsLinux | kOsCrOS,
[email protected]db543d322011-12-15 20:40:15501#else
502 0,
503#endif
504 SINGLE_VALUE_TYPE(switches::kEnablePerTilePainting)
505 },
[email protected]bf88c032011-12-22 19:05:47506 {
507 "enable-javascript-harmony",
508 IDS_FLAGS_ENABLE_JAVASCRIPT_HARMONY_NAME,
509 IDS_FLAGS_ENABLE_JAVASCRIPT_HARMONY_DESCRIPTION,
510 kOsAll,
511 SINGLE_VALUE_TYPE_AND_VALUE(switches::kJavaScriptFlags, "--harmony")
512 },
[email protected]7e7f378a2012-01-05 14:35:37513 {
[email protected]85646172012-01-09 22:45:54514 "enable-tab-browser-dragging",
515 IDS_FLAGS_ENABLE_TAB_BROWSER_DRAGGING_NAME,
516 IDS_FLAGS_ENABLE_TAB_BROWSER_DRAGGING_DESCRIPTION,
517 kOsWin,
518 SINGLE_VALUE_TYPE(switches::kTabBrowserDragging)
519 },
520 {
[email protected]7e7f378a2012-01-05 14:35:37521 "enable-restore-session-state",
522 IDS_FLAGS_ENABLE_RESTORE_SESSION_STATE_NAME,
523 IDS_FLAGS_ENABLE_RESTORE_SESSION_STATE_DESCRIPTION,
524 kOsAll,
525 SINGLE_VALUE_TYPE(switches::kEnableRestoreSessionState)
526 },
[email protected]a0e4b072011-08-17 01:47:07527};
[email protected]ad2a3ded2010-08-27 13:19:05528
[email protected]a314ee5a2010-10-26 21:23:28529const Experiment* experiments = kExperiments;
530size_t num_experiments = arraysize(kExperiments);
531
[email protected]e2ddbc92010-10-15 20:02:07532// Stores and encapsulates the little state that about:flags has.
533class FlagsState {
534 public:
535 FlagsState() : needs_restart_(false) {}
536 void ConvertFlagsToSwitches(PrefService* prefs, CommandLine* command_line);
537 bool IsRestartNeededToCommitChanges();
538 void SetExperimentEnabled(
[email protected]a314ee5a2010-10-26 21:23:28539 PrefService* prefs, const std::string& internal_name, bool enable);
[email protected]e2ddbc92010-10-15 20:02:07540 void RemoveFlagsSwitches(
541 std::map<std::string, CommandLine::StringType>* switch_list);
542 void reset();
543
544 // Returns the singleton instance of this class
[email protected]8e8bb6d2010-12-13 08:18:55545 static FlagsState* GetInstance() {
[email protected]e2ddbc92010-10-15 20:02:07546 return Singleton<FlagsState>::get();
547 }
548
549 private:
550 bool needs_restart_;
[email protected]a82744532011-02-11 16:15:53551 std::map<std::string, std::string> flags_switches_;
[email protected]e2ddbc92010-10-15 20:02:07552
553 DISALLOW_COPY_AND_ASSIGN(FlagsState);
554};
555
[email protected]c7b7800a2010-10-07 18:51:35556// Extracts the list of enabled lab experiments from preferences and stores them
[email protected]ad2a3ded2010-08-27 13:19:05557// in a set.
[email protected]1a47d7e2010-10-15 00:37:24558void GetEnabledFlags(const PrefService* prefs, std::set<std::string>* result) {
[email protected]ad2a3ded2010-08-27 13:19:05559 const ListValue* enabled_experiments = prefs->GetList(
560 prefs::kEnabledLabsExperiments);
561 if (!enabled_experiments)
562 return;
563
564 for (ListValue::const_iterator it = enabled_experiments->begin();
565 it != enabled_experiments->end();
566 ++it) {
567 std::string experiment_name;
568 if (!(*it)->GetAsString(&experiment_name)) {
569 LOG(WARNING) << "Invalid entry in " << prefs::kEnabledLabsExperiments;
570 continue;
571 }
572 result->insert(experiment_name);
573 }
574}
575
576// Takes a set of enabled lab experiments
[email protected]1a47d7e2010-10-15 00:37:24577void SetEnabledFlags(
[email protected]ad2a3ded2010-08-27 13:19:05578 PrefService* prefs, const std::set<std::string>& enabled_experiments) {
[email protected]1bc78422011-03-31 08:41:38579 ListPrefUpdate update(prefs, prefs::kEnabledLabsExperiments);
580 ListValue* experiments_list = update.Get();
[email protected]ad2a3ded2010-08-27 13:19:05581
582 experiments_list->Clear();
583 for (std::set<std::string>::const_iterator it = enabled_experiments.begin();
584 it != enabled_experiments.end();
585 ++it) {
586 experiments_list->Append(new StringValue(*it));
587 }
588}
589
[email protected]8a6ff28d2010-12-02 16:35:19590// Returns the name used in prefs for the choice at the specified index.
591std::string NameForChoice(const Experiment& e, int index) {
[email protected]2ce9c89752011-02-25 18:24:34592 DCHECK_EQ(Experiment::MULTI_VALUE, e.type);
593 DCHECK_LT(index, e.num_choices);
[email protected]8a6ff28d2010-12-02 16:35:19594 return std::string(e.internal_name) + about_flags::testing::kMultiSeparator +
595 base::IntToString(index);
596}
597
598// Adds the internal names for the specified experiment to |names|.
599void AddInternalName(const Experiment& e, std::set<std::string>* names) {
600 if (e.type == Experiment::SINGLE_VALUE) {
601 names->insert(e.internal_name);
602 } else {
[email protected]2ce9c89752011-02-25 18:24:34603 DCHECK_EQ(Experiment::MULTI_VALUE, e.type);
[email protected]8a6ff28d2010-12-02 16:35:19604 for (int i = 0; i < e.num_choices; ++i)
605 names->insert(NameForChoice(e, i));
606 }
607}
608
[email protected]28e35af2011-02-09 12:56:22609// Confirms that an experiment is valid, used in a DCHECK in
610// SanitizeList below.
611bool ValidateExperiment(const Experiment& e) {
612 switch (e.type) {
613 case Experiment::SINGLE_VALUE:
614 DCHECK_EQ(0, e.num_choices);
615 DCHECK(!e.choices);
616 break;
617 case Experiment::MULTI_VALUE:
618 DCHECK_GT(e.num_choices, 0);
619 DCHECK(e.choices);
[email protected]a82744532011-02-11 16:15:53620 DCHECK(e.choices[0].command_line_switch);
621 DCHECK_EQ('\0', e.choices[0].command_line_switch[0]);
[email protected]28e35af2011-02-09 12:56:22622 break;
623 default:
624 NOTREACHED();
625 }
626 return true;
627}
628
[email protected]ad2a3ded2010-08-27 13:19:05629// Removes all experiments from prefs::kEnabledLabsExperiments that are
630// unknown, to prevent this list to become very long as experiments are added
631// and removed.
632void SanitizeList(PrefService* prefs) {
633 std::set<std::string> known_experiments;
[email protected]28e35af2011-02-09 12:56:22634 for (size_t i = 0; i < num_experiments; ++i) {
635 DCHECK(ValidateExperiment(experiments[i]));
[email protected]8a6ff28d2010-12-02 16:35:19636 AddInternalName(experiments[i], &known_experiments);
[email protected]28e35af2011-02-09 12:56:22637 }
[email protected]ad2a3ded2010-08-27 13:19:05638
639 std::set<std::string> enabled_experiments;
[email protected]1a47d7e2010-10-15 00:37:24640 GetEnabledFlags(prefs, &enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05641
642 std::set<std::string> new_enabled_experiments;
643 std::set_intersection(
644 known_experiments.begin(), known_experiments.end(),
645 enabled_experiments.begin(), enabled_experiments.end(),
646 std::inserter(new_enabled_experiments, new_enabled_experiments.begin()));
647
[email protected]1a47d7e2010-10-15 00:37:24648 SetEnabledFlags(prefs, new_enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05649}
650
[email protected]1a47d7e2010-10-15 00:37:24651void GetSanitizedEnabledFlags(
[email protected]ad2a3ded2010-08-27 13:19:05652 PrefService* prefs, std::set<std::string>* result) {
653 SanitizeList(prefs);
[email protected]1a47d7e2010-10-15 00:37:24654 GetEnabledFlags(prefs, result);
[email protected]ad2a3ded2010-08-27 13:19:05655}
656
[email protected]a314ee5a2010-10-26 21:23:28657// Variant of GetSanitizedEnabledFlags that also removes any flags that aren't
658// enabled on the current platform.
659void GetSanitizedEnabledFlagsForCurrentPlatform(
660 PrefService* prefs, std::set<std::string>* result) {
661 GetSanitizedEnabledFlags(prefs, result);
662
663 // Filter out any experiments that aren't enabled on the current platform. We
664 // don't remove these from prefs else syncing to a platform with a different
665 // set of experiments would be lossy.
666 std::set<std::string> platform_experiments;
667 int current_platform = GetCurrentPlatform();
668 for (size_t i = 0; i < num_experiments; ++i) {
669 if (experiments[i].supported_platforms & current_platform)
[email protected]8a6ff28d2010-12-02 16:35:19670 AddInternalName(experiments[i], &platform_experiments);
[email protected]a314ee5a2010-10-26 21:23:28671 }
672
673 std::set<std::string> new_enabled_experiments;
674 std::set_intersection(
675 platform_experiments.begin(), platform_experiments.end(),
676 result->begin(), result->end(),
677 std::inserter(new_enabled_experiments, new_enabled_experiments.begin()));
678
679 result->swap(new_enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05680}
681
[email protected]8a6ff28d2010-12-02 16:35:19682// Returns the Value representing the choice data in the specified experiment.
[email protected]8a6ff28d2010-12-02 16:35:19683Value* CreateChoiceData(const Experiment& experiment,
[email protected]28e35af2011-02-09 12:56:22684 const std::set<std::string>& enabled_experiments) {
[email protected]2ce9c89752011-02-25 18:24:34685 DCHECK_EQ(Experiment::MULTI_VALUE, experiment.type);
[email protected]8a6ff28d2010-12-02 16:35:19686 ListValue* result = new ListValue;
687 for (int i = 0; i < experiment.num_choices; ++i) {
688 const Experiment::Choice& choice = experiment.choices[i];
689 DictionaryValue* value = new DictionaryValue;
690 std::string name = NameForChoice(experiment, i);
691 value->SetString("description",
692 l10n_util::GetStringUTF16(choice.description_id));
693 value->SetString("internal_name", name);
[email protected]28e35af2011-02-09 12:56:22694 value->SetBoolean("selected", enabled_experiments.count(name) > 0);
[email protected]8a6ff28d2010-12-02 16:35:19695 result->Append(value);
696 }
697 return result;
698}
699
[email protected]e2ddbc92010-10-15 20:02:07700} // namespace
701
[email protected]1a47d7e2010-10-15 00:37:24702void ConvertFlagsToSwitches(PrefService* prefs, CommandLine* command_line) {
[email protected]8e8bb6d2010-12-13 08:18:55703 FlagsState::GetInstance()->ConvertFlagsToSwitches(prefs, command_line);
[email protected]ad2a3ded2010-08-27 13:19:05704}
705
[email protected]1a47d7e2010-10-15 00:37:24706ListValue* GetFlagsExperimentsData(PrefService* prefs) {
[email protected]ad2a3ded2010-08-27 13:19:05707 std::set<std::string> enabled_experiments;
[email protected]1a47d7e2010-10-15 00:37:24708 GetSanitizedEnabledFlags(prefs, &enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05709
710 int current_platform = GetCurrentPlatform();
711
712 ListValue* experiments_data = new ListValue();
[email protected]a314ee5a2010-10-26 21:23:28713 for (size_t i = 0; i < num_experiments; ++i) {
714 const Experiment& experiment = experiments[i];
[email protected]ad2a3ded2010-08-27 13:19:05715
716 DictionaryValue* data = new DictionaryValue();
717 data->SetString("internal_name", experiment.internal_name);
718 data->SetString("name",
719 l10n_util::GetStringUTF16(experiment.visible_name_id));
720 data->SetString("description",
721 l10n_util::GetStringUTF16(
722 experiment.visible_description_id));
[email protected]cc3e2052011-12-20 01:01:40723 bool supported = !!(experiment.supported_platforms & current_platform);
724 data->SetBoolean("supported", supported);
725
726 ListValue* supported_platforms = new ListValue();
727 AddOsStrings(experiment.supported_platforms, supported_platforms);
728 data->Set("supported_platforms", supported_platforms);
[email protected]ad2a3ded2010-08-27 13:19:05729
[email protected]28e35af2011-02-09 12:56:22730 switch (experiment.type) {
731 case Experiment::SINGLE_VALUE:
732 data->SetBoolean(
733 "enabled",
734 enabled_experiments.count(experiment.internal_name) > 0);
735 break;
736 case Experiment::MULTI_VALUE:
737 data->Set("choices", CreateChoiceData(experiment, enabled_experiments));
738 break;
739 default:
740 NOTREACHED();
[email protected]8a6ff28d2010-12-02 16:35:19741 }
742
[email protected]ad2a3ded2010-08-27 13:19:05743 experiments_data->Append(data);
744 }
745 return experiments_data;
746}
747
[email protected]ad2a3ded2010-08-27 13:19:05748bool IsRestartNeededToCommitChanges() {
[email protected]8e8bb6d2010-12-13 08:18:55749 return FlagsState::GetInstance()->IsRestartNeededToCommitChanges();
[email protected]ad2a3ded2010-08-27 13:19:05750}
751
752void SetExperimentEnabled(
[email protected]c7b7800a2010-10-07 18:51:35753 PrefService* prefs, const std::string& internal_name, bool enable) {
[email protected]8e8bb6d2010-12-13 08:18:55754 FlagsState::GetInstance()->SetExperimentEnabled(prefs, internal_name, enable);
[email protected]e2ddbc92010-10-15 20:02:07755}
756
757void RemoveFlagsSwitches(
758 std::map<std::string, CommandLine::StringType>* switch_list) {
[email protected]8e8bb6d2010-12-13 08:18:55759 FlagsState::GetInstance()->RemoveFlagsSwitches(switch_list);
[email protected]e2ddbc92010-10-15 20:02:07760}
761
[email protected]a314ee5a2010-10-26 21:23:28762int GetCurrentPlatform() {
763#if defined(OS_MACOSX)
764 return kOsMac;
765#elif defined(OS_WIN)
766 return kOsWin;
767#elif defined(OS_CHROMEOS) // Needs to be before the OS_LINUX check.
768 return kOsCrOS;
[email protected]c92f4ed2011-10-21 19:50:21769#elif defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]a314ee5a2010-10-26 21:23:28770 return kOsLinux;
771#else
772#error Unknown platform
773#endif
774}
775
[email protected]4bc5050c2010-11-18 17:55:54776void RecordUMAStatistics(const PrefService* prefs) {
777 std::set<std::string> flags;
778 GetEnabledFlags(prefs, &flags);
779 for (std::set<std::string>::iterator it = flags.begin(); it != flags.end();
780 ++it) {
781 std::string action("AboutFlags_");
782 action += *it;
[email protected]7f6f44c2011-12-14 13:23:38783 content::RecordComputedAction(action);
[email protected]4bc5050c2010-11-18 17:55:54784 }
785 // Since flag metrics are recorded every startup, add a tick so that the
786 // stats can be made meaningful.
787 if (flags.size())
[email protected]7f6f44c2011-12-14 13:23:38788 content::RecordAction(UserMetricsAction("AboutFlags_StartupTick"));
789 content::RecordAction(UserMetricsAction("StartupTick"));
[email protected]4bc5050c2010-11-18 17:55:54790}
791
[email protected]e2ddbc92010-10-15 20:02:07792//////////////////////////////////////////////////////////////////////////////
793// FlagsState implementation.
794
795namespace {
796
797void FlagsState::ConvertFlagsToSwitches(
798 PrefService* prefs, CommandLine* command_line) {
[email protected]e2ddbc92010-10-15 20:02:07799 if (command_line->HasSwitch(switches::kNoExperiments))
800 return;
801
802 std::set<std::string> enabled_experiments;
[email protected]ba8164242010-11-16 21:31:00803
[email protected]a314ee5a2010-10-26 21:23:28804 GetSanitizedEnabledFlagsForCurrentPlatform(prefs, &enabled_experiments);
[email protected]e2ddbc92010-10-15 20:02:07805
[email protected]a82744532011-02-11 16:15:53806 typedef std::map<std::string, std::pair<std::string, std::string> >
807 NameToSwitchAndValueMap;
808 NameToSwitchAndValueMap name_to_switch_map;
[email protected]8a6ff28d2010-12-02 16:35:19809 for (size_t i = 0; i < num_experiments; ++i) {
810 const Experiment& e = experiments[i];
811 if (e.type == Experiment::SINGLE_VALUE) {
[email protected]a82744532011-02-11 16:15:53812 name_to_switch_map[e.internal_name] =
813 std::pair<std::string, std::string>(e.command_line_switch,
814 e.command_line_value);
[email protected]8a6ff28d2010-12-02 16:35:19815 } else {
816 for (int j = 0; j < e.num_choices; ++j)
[email protected]a82744532011-02-11 16:15:53817 name_to_switch_map[NameForChoice(e, j)] =
818 std::pair<std::string, std::string>(
819 e.choices[j].command_line_switch,
820 e.choices[j].command_line_value);
[email protected]8a6ff28d2010-12-02 16:35:19821 }
822 }
[email protected]e2ddbc92010-10-15 20:02:07823
824 command_line->AppendSwitch(switches::kFlagSwitchesBegin);
[email protected]a82744532011-02-11 16:15:53825 flags_switches_.insert(
826 std::pair<std::string, std::string>(switches::kFlagSwitchesBegin,
827 std::string()));
[email protected]e2ddbc92010-10-15 20:02:07828 for (std::set<std::string>::iterator it = enabled_experiments.begin();
829 it != enabled_experiments.end();
830 ++it) {
831 const std::string& experiment_name = *it;
[email protected]a82744532011-02-11 16:15:53832 NameToSwitchAndValueMap::const_iterator name_to_switch_it =
[email protected]8a6ff28d2010-12-02 16:35:19833 name_to_switch_map.find(experiment_name);
834 if (name_to_switch_it == name_to_switch_map.end()) {
835 NOTREACHED();
[email protected]e2ddbc92010-10-15 20:02:07836 continue;
[email protected]8a6ff28d2010-12-02 16:35:19837 }
[email protected]e2ddbc92010-10-15 20:02:07838
[email protected]a82744532011-02-11 16:15:53839 const std::pair<std::string, std::string>&
840 switch_and_value_pair = name_to_switch_it->second;
841
842 command_line->AppendSwitchASCII(switch_and_value_pair.first,
843 switch_and_value_pair.second);
844 flags_switches_[switch_and_value_pair.first] = switch_and_value_pair.second;
[email protected]e2ddbc92010-10-15 20:02:07845 }
846 command_line->AppendSwitch(switches::kFlagSwitchesEnd);
[email protected]a82744532011-02-11 16:15:53847 flags_switches_.insert(
848 std::pair<std::string, std::string>(switches::kFlagSwitchesEnd,
849 std::string()));
[email protected]e2ddbc92010-10-15 20:02:07850}
851
852bool FlagsState::IsRestartNeededToCommitChanges() {
853 return needs_restart_;
854}
855
856void FlagsState::SetExperimentEnabled(
857 PrefService* prefs, const std::string& internal_name, bool enable) {
[email protected]ad2a3ded2010-08-27 13:19:05858 needs_restart_ = true;
859
[email protected]8a6ff28d2010-12-02 16:35:19860 size_t at_index = internal_name.find(about_flags::testing::kMultiSeparator);
861 if (at_index != std::string::npos) {
862 DCHECK(enable);
863 // We're being asked to enable a multi-choice experiment. Disable the
864 // currently selected choice.
865 DCHECK_NE(at_index, 0u);
[email protected]28e35af2011-02-09 12:56:22866 const std::string experiment_name = internal_name.substr(0, at_index);
867 SetExperimentEnabled(prefs, experiment_name, false);
[email protected]8a6ff28d2010-12-02 16:35:19868
[email protected]28e35af2011-02-09 12:56:22869 // And enable the new choice, if it is not the default first choice.
870 if (internal_name != experiment_name + "@0") {
871 std::set<std::string> enabled_experiments;
872 GetSanitizedEnabledFlags(prefs, &enabled_experiments);
873 enabled_experiments.insert(internal_name);
874 SetEnabledFlags(prefs, enabled_experiments);
875 }
[email protected]8a6ff28d2010-12-02 16:35:19876 return;
877 }
878
[email protected]ad2a3ded2010-08-27 13:19:05879 std::set<std::string> enabled_experiments;
[email protected]1a47d7e2010-10-15 00:37:24880 GetSanitizedEnabledFlags(prefs, &enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05881
[email protected]8a6ff28d2010-12-02 16:35:19882 const Experiment* e = NULL;
883 for (size_t i = 0; i < num_experiments; ++i) {
884 if (experiments[i].internal_name == internal_name) {
885 e = experiments + i;
886 break;
887 }
888 }
889 DCHECK(e);
890
891 if (e->type == Experiment::SINGLE_VALUE) {
[email protected]8a2713682011-08-19 10:36:59892 if (enable)
[email protected]8a6ff28d2010-12-02 16:35:19893 enabled_experiments.insert(internal_name);
[email protected]8a2713682011-08-19 10:36:59894 else
[email protected]8a6ff28d2010-12-02 16:35:19895 enabled_experiments.erase(internal_name);
896 } else {
897 if (enable) {
898 // Enable the first choice.
899 enabled_experiments.insert(NameForChoice(*e, 0));
900 } else {
901 // Find the currently enabled choice and disable it.
902 for (int i = 0; i < e->num_choices; ++i) {
903 std::string choice_name = NameForChoice(*e, i);
904 if (enabled_experiments.find(choice_name) !=
905 enabled_experiments.end()) {
906 enabled_experiments.erase(choice_name);
907 // Continue on just in case there's a bug and more than one
908 // experiment for this choice was enabled.
909 }
910 }
911 }
912 }
[email protected]ad2a3ded2010-08-27 13:19:05913
[email protected]1a47d7e2010-10-15 00:37:24914 SetEnabledFlags(prefs, enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05915}
916
[email protected]e2ddbc92010-10-15 20:02:07917void FlagsState::RemoveFlagsSwitches(
918 std::map<std::string, CommandLine::StringType>* switch_list) {
[email protected]a82744532011-02-11 16:15:53919 for (std::map<std::string, std::string>::const_iterator
920 it = flags_switches_.begin(); it != flags_switches_.end(); ++it) {
921 switch_list->erase(it->first);
[email protected]e2ddbc92010-10-15 20:02:07922 }
923}
924
925void FlagsState::reset() {
926 needs_restart_ = false;
927 flags_switches_.clear();
928}
929
[email protected]38e46812011-05-09 20:49:22930} // namespace
[email protected]e2ddbc92010-10-15 20:02:07931
932namespace testing {
[email protected]8a6ff28d2010-12-02 16:35:19933
934// WARNING: '@' is also used in the html file. If you update this constant you
935// also need to update the html file.
936const char kMultiSeparator[] = "@";
937
[email protected]e2ddbc92010-10-15 20:02:07938void ClearState() {
[email protected]8e8bb6d2010-12-13 08:18:55939 FlagsState::GetInstance()->reset();
[email protected]e2ddbc92010-10-15 20:02:07940}
[email protected]a314ee5a2010-10-26 21:23:28941
942void SetExperiments(const Experiment* e, size_t count) {
943 if (!e) {
944 experiments = kExperiments;
945 num_experiments = arraysize(kExperiments);
946 } else {
947 experiments = e;
948 num_experiments = count;
949 }
950}
951
[email protected]8a6ff28d2010-12-02 16:35:19952const Experiment* GetExperiments(size_t* count) {
953 *count = num_experiments;
954 return experiments;
955}
956
[email protected]e2ddbc92010-10-15 20:02:07957} // namespace testing
958
[email protected]1a47d7e2010-10-15 00:37:24959} // namespace about_flags