blob: 6517f87a68dd4a2024233609ce4e5898d5ab73b2 [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 },
468#endif // defined(USE_AURA)
[email protected]edb051d2011-11-24 23:20:51469 {
470 "enable-gamepad",
471 IDS_FLAGS_ENABLE_GAMEPAD_NAME,
472 IDS_FLAGS_ENABLE_GAMEPAD_DESCRIPTION,
[email protected]cdb28552012-01-06 20:34:35473 kOsMac | kOsWin,
[email protected]edb051d2011-11-24 23:20:51474 SINGLE_VALUE_TYPE(switches::kEnableGamepad)
475 },
[email protected]35304ce2011-12-14 23:21:01476#if defined(USE_AURA)
477 // TODO(jamescook): Enable this for all ChromeOS builds when we're sure
478 // Aura laptop mode performance and feature set match traditional non-Aura
479 // builds.
480 {
[email protected]3fbd9c12011-12-16 21:35:11481 "aura-window-mode",
482 IDS_FLAGS_AURA_WINDOW_MODE_NAME,
483 IDS_FLAGS_AURA_WINDOW_MODE_DESCRIPTION,
[email protected]35304ce2011-12-14 23:21:01484 kOsWin | kOsLinux | kOsCrOS,
[email protected]3fbd9c12011-12-16 21:35:11485 MULTI_VALUE_TYPE(kAuraWindowModeChoices)
[email protected]35304ce2011-12-14 23:21:01486 },
487#endif
[email protected]db543d322011-12-15 20:40:15488 {
489 "per-tile-painting",
490 IDS_FLAGS_PER_TILE_PAINTING_NAME,
491 IDS_FLAGS_PER_TILE_PAINTING_DESCRIPTION,
492#if defined(USE_SKIA)
[email protected]a5b1b272012-01-06 20:44:37493 kOsMac | kOsLinux | kOsCrOS,
[email protected]db543d322011-12-15 20:40:15494#else
495 0,
496#endif
497 SINGLE_VALUE_TYPE(switches::kEnablePerTilePainting)
498 },
[email protected]bf88c032011-12-22 19:05:47499 {
500 "enable-javascript-harmony",
501 IDS_FLAGS_ENABLE_JAVASCRIPT_HARMONY_NAME,
502 IDS_FLAGS_ENABLE_JAVASCRIPT_HARMONY_DESCRIPTION,
503 kOsAll,
504 SINGLE_VALUE_TYPE_AND_VALUE(switches::kJavaScriptFlags, "--harmony")
505 },
[email protected]7e7f378a2012-01-05 14:35:37506 {
507 "enable-restore-session-state",
508 IDS_FLAGS_ENABLE_RESTORE_SESSION_STATE_NAME,
509 IDS_FLAGS_ENABLE_RESTORE_SESSION_STATE_DESCRIPTION,
510 kOsAll,
511 SINGLE_VALUE_TYPE(switches::kEnableRestoreSessionState)
512 },
[email protected]a0e4b072011-08-17 01:47:07513};
[email protected]ad2a3ded2010-08-27 13:19:05514
[email protected]a314ee5a2010-10-26 21:23:28515const Experiment* experiments = kExperiments;
516size_t num_experiments = arraysize(kExperiments);
517
[email protected]e2ddbc92010-10-15 20:02:07518// Stores and encapsulates the little state that about:flags has.
519class FlagsState {
520 public:
521 FlagsState() : needs_restart_(false) {}
522 void ConvertFlagsToSwitches(PrefService* prefs, CommandLine* command_line);
523 bool IsRestartNeededToCommitChanges();
524 void SetExperimentEnabled(
[email protected]a314ee5a2010-10-26 21:23:28525 PrefService* prefs, const std::string& internal_name, bool enable);
[email protected]e2ddbc92010-10-15 20:02:07526 void RemoveFlagsSwitches(
527 std::map<std::string, CommandLine::StringType>* switch_list);
528 void reset();
529
530 // Returns the singleton instance of this class
[email protected]8e8bb6d2010-12-13 08:18:55531 static FlagsState* GetInstance() {
[email protected]e2ddbc92010-10-15 20:02:07532 return Singleton<FlagsState>::get();
533 }
534
535 private:
536 bool needs_restart_;
[email protected]a82744532011-02-11 16:15:53537 std::map<std::string, std::string> flags_switches_;
[email protected]e2ddbc92010-10-15 20:02:07538
539 DISALLOW_COPY_AND_ASSIGN(FlagsState);
540};
541
[email protected]c7b7800a2010-10-07 18:51:35542// Extracts the list of enabled lab experiments from preferences and stores them
[email protected]ad2a3ded2010-08-27 13:19:05543// in a set.
[email protected]1a47d7e2010-10-15 00:37:24544void GetEnabledFlags(const PrefService* prefs, std::set<std::string>* result) {
[email protected]ad2a3ded2010-08-27 13:19:05545 const ListValue* enabled_experiments = prefs->GetList(
546 prefs::kEnabledLabsExperiments);
547 if (!enabled_experiments)
548 return;
549
550 for (ListValue::const_iterator it = enabled_experiments->begin();
551 it != enabled_experiments->end();
552 ++it) {
553 std::string experiment_name;
554 if (!(*it)->GetAsString(&experiment_name)) {
555 LOG(WARNING) << "Invalid entry in " << prefs::kEnabledLabsExperiments;
556 continue;
557 }
558 result->insert(experiment_name);
559 }
560}
561
562// Takes a set of enabled lab experiments
[email protected]1a47d7e2010-10-15 00:37:24563void SetEnabledFlags(
[email protected]ad2a3ded2010-08-27 13:19:05564 PrefService* prefs, const std::set<std::string>& enabled_experiments) {
[email protected]1bc78422011-03-31 08:41:38565 ListPrefUpdate update(prefs, prefs::kEnabledLabsExperiments);
566 ListValue* experiments_list = update.Get();
[email protected]ad2a3ded2010-08-27 13:19:05567
568 experiments_list->Clear();
569 for (std::set<std::string>::const_iterator it = enabled_experiments.begin();
570 it != enabled_experiments.end();
571 ++it) {
572 experiments_list->Append(new StringValue(*it));
573 }
574}
575
[email protected]8a6ff28d2010-12-02 16:35:19576// Returns the name used in prefs for the choice at the specified index.
577std::string NameForChoice(const Experiment& e, int index) {
[email protected]2ce9c89752011-02-25 18:24:34578 DCHECK_EQ(Experiment::MULTI_VALUE, e.type);
579 DCHECK_LT(index, e.num_choices);
[email protected]8a6ff28d2010-12-02 16:35:19580 return std::string(e.internal_name) + about_flags::testing::kMultiSeparator +
581 base::IntToString(index);
582}
583
584// Adds the internal names for the specified experiment to |names|.
585void AddInternalName(const Experiment& e, std::set<std::string>* names) {
586 if (e.type == Experiment::SINGLE_VALUE) {
587 names->insert(e.internal_name);
588 } else {
[email protected]2ce9c89752011-02-25 18:24:34589 DCHECK_EQ(Experiment::MULTI_VALUE, e.type);
[email protected]8a6ff28d2010-12-02 16:35:19590 for (int i = 0; i < e.num_choices; ++i)
591 names->insert(NameForChoice(e, i));
592 }
593}
594
[email protected]28e35af2011-02-09 12:56:22595// Confirms that an experiment is valid, used in a DCHECK in
596// SanitizeList below.
597bool ValidateExperiment(const Experiment& e) {
598 switch (e.type) {
599 case Experiment::SINGLE_VALUE:
600 DCHECK_EQ(0, e.num_choices);
601 DCHECK(!e.choices);
602 break;
603 case Experiment::MULTI_VALUE:
604 DCHECK_GT(e.num_choices, 0);
605 DCHECK(e.choices);
[email protected]a82744532011-02-11 16:15:53606 DCHECK(e.choices[0].command_line_switch);
607 DCHECK_EQ('\0', e.choices[0].command_line_switch[0]);
[email protected]28e35af2011-02-09 12:56:22608 break;
609 default:
610 NOTREACHED();
611 }
612 return true;
613}
614
[email protected]ad2a3ded2010-08-27 13:19:05615// Removes all experiments from prefs::kEnabledLabsExperiments that are
616// unknown, to prevent this list to become very long as experiments are added
617// and removed.
618void SanitizeList(PrefService* prefs) {
619 std::set<std::string> known_experiments;
[email protected]28e35af2011-02-09 12:56:22620 for (size_t i = 0; i < num_experiments; ++i) {
621 DCHECK(ValidateExperiment(experiments[i]));
[email protected]8a6ff28d2010-12-02 16:35:19622 AddInternalName(experiments[i], &known_experiments);
[email protected]28e35af2011-02-09 12:56:22623 }
[email protected]ad2a3ded2010-08-27 13:19:05624
625 std::set<std::string> enabled_experiments;
[email protected]1a47d7e2010-10-15 00:37:24626 GetEnabledFlags(prefs, &enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05627
628 std::set<std::string> new_enabled_experiments;
629 std::set_intersection(
630 known_experiments.begin(), known_experiments.end(),
631 enabled_experiments.begin(), enabled_experiments.end(),
632 std::inserter(new_enabled_experiments, new_enabled_experiments.begin()));
633
[email protected]1a47d7e2010-10-15 00:37:24634 SetEnabledFlags(prefs, new_enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05635}
636
[email protected]1a47d7e2010-10-15 00:37:24637void GetSanitizedEnabledFlags(
[email protected]ad2a3ded2010-08-27 13:19:05638 PrefService* prefs, std::set<std::string>* result) {
639 SanitizeList(prefs);
[email protected]1a47d7e2010-10-15 00:37:24640 GetEnabledFlags(prefs, result);
[email protected]ad2a3ded2010-08-27 13:19:05641}
642
[email protected]a314ee5a2010-10-26 21:23:28643// Variant of GetSanitizedEnabledFlags that also removes any flags that aren't
644// enabled on the current platform.
645void GetSanitizedEnabledFlagsForCurrentPlatform(
646 PrefService* prefs, std::set<std::string>* result) {
647 GetSanitizedEnabledFlags(prefs, result);
648
649 // Filter out any experiments that aren't enabled on the current platform. We
650 // don't remove these from prefs else syncing to a platform with a different
651 // set of experiments would be lossy.
652 std::set<std::string> platform_experiments;
653 int current_platform = GetCurrentPlatform();
654 for (size_t i = 0; i < num_experiments; ++i) {
655 if (experiments[i].supported_platforms & current_platform)
[email protected]8a6ff28d2010-12-02 16:35:19656 AddInternalName(experiments[i], &platform_experiments);
[email protected]a314ee5a2010-10-26 21:23:28657 }
658
659 std::set<std::string> new_enabled_experiments;
660 std::set_intersection(
661 platform_experiments.begin(), platform_experiments.end(),
662 result->begin(), result->end(),
663 std::inserter(new_enabled_experiments, new_enabled_experiments.begin()));
664
665 result->swap(new_enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05666}
667
[email protected]8a6ff28d2010-12-02 16:35:19668// Returns the Value representing the choice data in the specified experiment.
[email protected]8a6ff28d2010-12-02 16:35:19669Value* CreateChoiceData(const Experiment& experiment,
[email protected]28e35af2011-02-09 12:56:22670 const std::set<std::string>& enabled_experiments) {
[email protected]2ce9c89752011-02-25 18:24:34671 DCHECK_EQ(Experiment::MULTI_VALUE, experiment.type);
[email protected]8a6ff28d2010-12-02 16:35:19672 ListValue* result = new ListValue;
673 for (int i = 0; i < experiment.num_choices; ++i) {
674 const Experiment::Choice& choice = experiment.choices[i];
675 DictionaryValue* value = new DictionaryValue;
676 std::string name = NameForChoice(experiment, i);
677 value->SetString("description",
678 l10n_util::GetStringUTF16(choice.description_id));
679 value->SetString("internal_name", name);
[email protected]28e35af2011-02-09 12:56:22680 value->SetBoolean("selected", enabled_experiments.count(name) > 0);
[email protected]8a6ff28d2010-12-02 16:35:19681 result->Append(value);
682 }
683 return result;
684}
685
[email protected]e2ddbc92010-10-15 20:02:07686} // namespace
687
[email protected]1a47d7e2010-10-15 00:37:24688void ConvertFlagsToSwitches(PrefService* prefs, CommandLine* command_line) {
[email protected]8e8bb6d2010-12-13 08:18:55689 FlagsState::GetInstance()->ConvertFlagsToSwitches(prefs, command_line);
[email protected]ad2a3ded2010-08-27 13:19:05690}
691
[email protected]1a47d7e2010-10-15 00:37:24692ListValue* GetFlagsExperimentsData(PrefService* prefs) {
[email protected]ad2a3ded2010-08-27 13:19:05693 std::set<std::string> enabled_experiments;
[email protected]1a47d7e2010-10-15 00:37:24694 GetSanitizedEnabledFlags(prefs, &enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05695
696 int current_platform = GetCurrentPlatform();
697
698 ListValue* experiments_data = new ListValue();
[email protected]a314ee5a2010-10-26 21:23:28699 for (size_t i = 0; i < num_experiments; ++i) {
700 const Experiment& experiment = experiments[i];
[email protected]ad2a3ded2010-08-27 13:19:05701
702 DictionaryValue* data = new DictionaryValue();
703 data->SetString("internal_name", experiment.internal_name);
704 data->SetString("name",
705 l10n_util::GetStringUTF16(experiment.visible_name_id));
706 data->SetString("description",
707 l10n_util::GetStringUTF16(
708 experiment.visible_description_id));
[email protected]cc3e2052011-12-20 01:01:40709 bool supported = !!(experiment.supported_platforms & current_platform);
710 data->SetBoolean("supported", supported);
711
712 ListValue* supported_platforms = new ListValue();
713 AddOsStrings(experiment.supported_platforms, supported_platforms);
714 data->Set("supported_platforms", supported_platforms);
[email protected]ad2a3ded2010-08-27 13:19:05715
[email protected]28e35af2011-02-09 12:56:22716 switch (experiment.type) {
717 case Experiment::SINGLE_VALUE:
718 data->SetBoolean(
719 "enabled",
720 enabled_experiments.count(experiment.internal_name) > 0);
721 break;
722 case Experiment::MULTI_VALUE:
723 data->Set("choices", CreateChoiceData(experiment, enabled_experiments));
724 break;
725 default:
726 NOTREACHED();
[email protected]8a6ff28d2010-12-02 16:35:19727 }
728
[email protected]ad2a3ded2010-08-27 13:19:05729 experiments_data->Append(data);
730 }
731 return experiments_data;
732}
733
[email protected]ad2a3ded2010-08-27 13:19:05734bool IsRestartNeededToCommitChanges() {
[email protected]8e8bb6d2010-12-13 08:18:55735 return FlagsState::GetInstance()->IsRestartNeededToCommitChanges();
[email protected]ad2a3ded2010-08-27 13:19:05736}
737
738void SetExperimentEnabled(
[email protected]c7b7800a2010-10-07 18:51:35739 PrefService* prefs, const std::string& internal_name, bool enable) {
[email protected]8e8bb6d2010-12-13 08:18:55740 FlagsState::GetInstance()->SetExperimentEnabled(prefs, internal_name, enable);
[email protected]e2ddbc92010-10-15 20:02:07741}
742
743void RemoveFlagsSwitches(
744 std::map<std::string, CommandLine::StringType>* switch_list) {
[email protected]8e8bb6d2010-12-13 08:18:55745 FlagsState::GetInstance()->RemoveFlagsSwitches(switch_list);
[email protected]e2ddbc92010-10-15 20:02:07746}
747
[email protected]a314ee5a2010-10-26 21:23:28748int GetCurrentPlatform() {
749#if defined(OS_MACOSX)
750 return kOsMac;
751#elif defined(OS_WIN)
752 return kOsWin;
753#elif defined(OS_CHROMEOS) // Needs to be before the OS_LINUX check.
754 return kOsCrOS;
[email protected]c92f4ed2011-10-21 19:50:21755#elif defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]a314ee5a2010-10-26 21:23:28756 return kOsLinux;
757#else
758#error Unknown platform
759#endif
760}
761
[email protected]4bc5050c2010-11-18 17:55:54762void RecordUMAStatistics(const PrefService* prefs) {
763 std::set<std::string> flags;
764 GetEnabledFlags(prefs, &flags);
765 for (std::set<std::string>::iterator it = flags.begin(); it != flags.end();
766 ++it) {
767 std::string action("AboutFlags_");
768 action += *it;
[email protected]7f6f44c2011-12-14 13:23:38769 content::RecordComputedAction(action);
[email protected]4bc5050c2010-11-18 17:55:54770 }
771 // Since flag metrics are recorded every startup, add a tick so that the
772 // stats can be made meaningful.
773 if (flags.size())
[email protected]7f6f44c2011-12-14 13:23:38774 content::RecordAction(UserMetricsAction("AboutFlags_StartupTick"));
775 content::RecordAction(UserMetricsAction("StartupTick"));
[email protected]4bc5050c2010-11-18 17:55:54776}
777
[email protected]e2ddbc92010-10-15 20:02:07778//////////////////////////////////////////////////////////////////////////////
779// FlagsState implementation.
780
781namespace {
782
783void FlagsState::ConvertFlagsToSwitches(
784 PrefService* prefs, CommandLine* command_line) {
[email protected]e2ddbc92010-10-15 20:02:07785 if (command_line->HasSwitch(switches::kNoExperiments))
786 return;
787
788 std::set<std::string> enabled_experiments;
[email protected]ba8164242010-11-16 21:31:00789
[email protected]a314ee5a2010-10-26 21:23:28790 GetSanitizedEnabledFlagsForCurrentPlatform(prefs, &enabled_experiments);
[email protected]e2ddbc92010-10-15 20:02:07791
[email protected]a82744532011-02-11 16:15:53792 typedef std::map<std::string, std::pair<std::string, std::string> >
793 NameToSwitchAndValueMap;
794 NameToSwitchAndValueMap name_to_switch_map;
[email protected]8a6ff28d2010-12-02 16:35:19795 for (size_t i = 0; i < num_experiments; ++i) {
796 const Experiment& e = experiments[i];
797 if (e.type == Experiment::SINGLE_VALUE) {
[email protected]a82744532011-02-11 16:15:53798 name_to_switch_map[e.internal_name] =
799 std::pair<std::string, std::string>(e.command_line_switch,
800 e.command_line_value);
[email protected]8a6ff28d2010-12-02 16:35:19801 } else {
802 for (int j = 0; j < e.num_choices; ++j)
[email protected]a82744532011-02-11 16:15:53803 name_to_switch_map[NameForChoice(e, j)] =
804 std::pair<std::string, std::string>(
805 e.choices[j].command_line_switch,
806 e.choices[j].command_line_value);
[email protected]8a6ff28d2010-12-02 16:35:19807 }
808 }
[email protected]e2ddbc92010-10-15 20:02:07809
810 command_line->AppendSwitch(switches::kFlagSwitchesBegin);
[email protected]a82744532011-02-11 16:15:53811 flags_switches_.insert(
812 std::pair<std::string, std::string>(switches::kFlagSwitchesBegin,
813 std::string()));
[email protected]e2ddbc92010-10-15 20:02:07814 for (std::set<std::string>::iterator it = enabled_experiments.begin();
815 it != enabled_experiments.end();
816 ++it) {
817 const std::string& experiment_name = *it;
[email protected]a82744532011-02-11 16:15:53818 NameToSwitchAndValueMap::const_iterator name_to_switch_it =
[email protected]8a6ff28d2010-12-02 16:35:19819 name_to_switch_map.find(experiment_name);
820 if (name_to_switch_it == name_to_switch_map.end()) {
821 NOTREACHED();
[email protected]e2ddbc92010-10-15 20:02:07822 continue;
[email protected]8a6ff28d2010-12-02 16:35:19823 }
[email protected]e2ddbc92010-10-15 20:02:07824
[email protected]a82744532011-02-11 16:15:53825 const std::pair<std::string, std::string>&
826 switch_and_value_pair = name_to_switch_it->second;
827
828 command_line->AppendSwitchASCII(switch_and_value_pair.first,
829 switch_and_value_pair.second);
830 flags_switches_[switch_and_value_pair.first] = switch_and_value_pair.second;
[email protected]e2ddbc92010-10-15 20:02:07831 }
832 command_line->AppendSwitch(switches::kFlagSwitchesEnd);
[email protected]a82744532011-02-11 16:15:53833 flags_switches_.insert(
834 std::pair<std::string, std::string>(switches::kFlagSwitchesEnd,
835 std::string()));
[email protected]e2ddbc92010-10-15 20:02:07836}
837
838bool FlagsState::IsRestartNeededToCommitChanges() {
839 return needs_restart_;
840}
841
842void FlagsState::SetExperimentEnabled(
843 PrefService* prefs, const std::string& internal_name, bool enable) {
[email protected]ad2a3ded2010-08-27 13:19:05844 needs_restart_ = true;
845
[email protected]8a6ff28d2010-12-02 16:35:19846 size_t at_index = internal_name.find(about_flags::testing::kMultiSeparator);
847 if (at_index != std::string::npos) {
848 DCHECK(enable);
849 // We're being asked to enable a multi-choice experiment. Disable the
850 // currently selected choice.
851 DCHECK_NE(at_index, 0u);
[email protected]28e35af2011-02-09 12:56:22852 const std::string experiment_name = internal_name.substr(0, at_index);
853 SetExperimentEnabled(prefs, experiment_name, false);
[email protected]8a6ff28d2010-12-02 16:35:19854
[email protected]28e35af2011-02-09 12:56:22855 // And enable the new choice, if it is not the default first choice.
856 if (internal_name != experiment_name + "@0") {
857 std::set<std::string> enabled_experiments;
858 GetSanitizedEnabledFlags(prefs, &enabled_experiments);
859 enabled_experiments.insert(internal_name);
860 SetEnabledFlags(prefs, enabled_experiments);
861 }
[email protected]8a6ff28d2010-12-02 16:35:19862 return;
863 }
864
[email protected]ad2a3ded2010-08-27 13:19:05865 std::set<std::string> enabled_experiments;
[email protected]1a47d7e2010-10-15 00:37:24866 GetSanitizedEnabledFlags(prefs, &enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05867
[email protected]8a6ff28d2010-12-02 16:35:19868 const Experiment* e = NULL;
869 for (size_t i = 0; i < num_experiments; ++i) {
870 if (experiments[i].internal_name == internal_name) {
871 e = experiments + i;
872 break;
873 }
874 }
875 DCHECK(e);
876
877 if (e->type == Experiment::SINGLE_VALUE) {
[email protected]8a2713682011-08-19 10:36:59878 if (enable)
[email protected]8a6ff28d2010-12-02 16:35:19879 enabled_experiments.insert(internal_name);
[email protected]8a2713682011-08-19 10:36:59880 else
[email protected]8a6ff28d2010-12-02 16:35:19881 enabled_experiments.erase(internal_name);
882 } else {
883 if (enable) {
884 // Enable the first choice.
885 enabled_experiments.insert(NameForChoice(*e, 0));
886 } else {
887 // Find the currently enabled choice and disable it.
888 for (int i = 0; i < e->num_choices; ++i) {
889 std::string choice_name = NameForChoice(*e, i);
890 if (enabled_experiments.find(choice_name) !=
891 enabled_experiments.end()) {
892 enabled_experiments.erase(choice_name);
893 // Continue on just in case there's a bug and more than one
894 // experiment for this choice was enabled.
895 }
896 }
897 }
898 }
[email protected]ad2a3ded2010-08-27 13:19:05899
[email protected]1a47d7e2010-10-15 00:37:24900 SetEnabledFlags(prefs, enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05901}
902
[email protected]e2ddbc92010-10-15 20:02:07903void FlagsState::RemoveFlagsSwitches(
904 std::map<std::string, CommandLine::StringType>* switch_list) {
[email protected]a82744532011-02-11 16:15:53905 for (std::map<std::string, std::string>::const_iterator
906 it = flags_switches_.begin(); it != flags_switches_.end(); ++it) {
907 switch_list->erase(it->first);
[email protected]e2ddbc92010-10-15 20:02:07908 }
909}
910
911void FlagsState::reset() {
912 needs_restart_ = false;
913 flags_switches_.clear();
914}
915
[email protected]38e46812011-05-09 20:49:22916} // namespace
[email protected]e2ddbc92010-10-15 20:02:07917
918namespace testing {
[email protected]8a6ff28d2010-12-02 16:35:19919
920// WARNING: '@' is also used in the html file. If you update this constant you
921// also need to update the html file.
922const char kMultiSeparator[] = "@";
923
[email protected]e2ddbc92010-10-15 20:02:07924void ClearState() {
[email protected]8e8bb6d2010-12-13 08:18:55925 FlagsState::GetInstance()->reset();
[email protected]e2ddbc92010-10-15 20:02:07926}
[email protected]a314ee5a2010-10-26 21:23:28927
928void SetExperiments(const Experiment* e, size_t count) {
929 if (!e) {
930 experiments = kExperiments;
931 num_experiments = arraysize(kExperiments);
932 } else {
933 experiments = e;
934 num_experiments = count;
935 }
936}
937
[email protected]8a6ff28d2010-12-02 16:35:19938const Experiment* GetExperiments(size_t* count) {
939 *count = num_experiments;
940 return experiments;
941}
942
[email protected]e2ddbc92010-10-15 20:02:07943} // namespace testing
944
[email protected]1a47d7e2010-10-15 00:37:24945} // namespace about_flags