blob: d7eb3646337a675ef4c6ea147c6b8fd0ac71dd49 [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]eb00a762012-01-18 07:29:28222
223#if defined(GOOGLE_CHROME_BUILD)
224 // TODO(thestig) Remove this for bug 107600.
225 {
226 "disable-print-preview", // FLAGS:RECORD_UMA
227 IDS_FLAGS_DISABLE_PRINT_PREVIEW_NAME,
228 IDS_FLAGS_DISABLE_PRINT_PREVIEW_DESCRIPTION,
229 kOsAll,
230 SINGLE_VALUE_TYPE(switches::kDisablePrintPreview)
231 },
232#else
233 // For Chromium builds where users may not have the PDF plugin.
[email protected]8d260e52010-10-13 01:03:05234 {
[email protected]4bc5050c2010-11-18 17:55:54235 "print-preview", // FLAGS:RECORD_UMA
[email protected]9486c1f2010-10-14 19:52:12236 IDS_FLAGS_PRINT_PREVIEW_NAME,
237 IDS_FLAGS_PRINT_PREVIEW_DESCRIPTION,
[email protected]b579afd2011-07-13 00:01:27238 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19239 SINGLE_VALUE_TYPE(switches::kEnablePrintPreview)
[email protected]2fe15fcb2010-10-21 20:39:53240 },
[email protected]eb00a762012-01-18 07:29:28241#endif
242
[email protected]d208f4d82011-05-23 21:52:03243 // TODO(dspringer): When NaCl is on by default, remove this flag entry.
[email protected]2fe15fcb2010-10-21 20:39:53244 {
[email protected]e3791ce92011-08-09 01:03:32245 "enable-nacl", // FLAGS:RECORD_UMA
[email protected]4ff87d202010-11-06 01:28:40246 IDS_FLAGS_ENABLE_NACL_NAME,
247 IDS_FLAGS_ENABLE_NACL_DESCRIPTION,
248 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19249 SINGLE_VALUE_TYPE(switches::kEnableNaCl)
[email protected]4ff87d202010-11-06 01:28:40250 },
251 {
[email protected]4bc5050c2010-11-18 17:55:54252 "extension-apis", // FLAGS:RECORD_UMA
[email protected]11dd68cd52010-11-12 01:15:32253 IDS_FLAGS_EXPERIMENTAL_EXTENSION_APIS_NAME,
254 IDS_FLAGS_EXPERIMENTAL_EXTENSION_APIS_DESCRIPTION,
255 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19256 SINGLE_VALUE_TYPE(switches::kEnableExperimentalExtensionApis)
[email protected]11dd68cd52010-11-12 01:15:32257 },
[email protected]3627b06d2010-11-12 16:36:16258 {
[email protected]cbe224d2011-08-04 22:12:49259 "apps-new-install-bubble",
260 IDS_FLAGS_APPS_NEW_INSTALL_BUBBLE_NAME,
261 IDS_FLAGS_APPS_NEW_INSTALL_BUBBLE_DESCRIPTION,
262 kOsAll,
263 SINGLE_VALUE_TYPE(switches::kAppsNewInstallBubble)
264 },
265 {
[email protected]4bc5050c2010-11-18 17:55:54266 "click-to-play", // FLAGS:RECORD_UMA
[email protected]3627b06d2010-11-12 16:36:16267 IDS_FLAGS_CLICK_TO_PLAY_NAME,
268 IDS_FLAGS_CLICK_TO_PLAY_DESCRIPTION,
269 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19270 SINGLE_VALUE_TYPE(switches::kEnableClickToPlay)
[email protected]3627b06d2010-11-12 16:36:16271 },
[email protected]80bd24e2010-11-30 09:34:38272 {
273 "disable-hyperlink-auditing",
274 IDS_FLAGS_DISABLE_HYPERLINK_AUDITING_NAME,
275 IDS_FLAGS_DISABLE_HYPERLINK_AUDITING_DESCRIPTION,
276 kOsAll,
[email protected]8a6ff28d2010-12-02 16:35:19277 SINGLE_VALUE_TYPE(switches::kNoPings)
[email protected]feb28fef2010-12-01 10:52:51278 },
279 {
280 "experimental-location-features", // FLAGS:RECORD_UMA
281 IDS_FLAGS_EXPERIMENTAL_LOCATION_FEATURES_NAME,
282 IDS_FLAGS_EXPERIMENTAL_LOCATION_FEATURES_DESCRIPTION,
283 kOsMac | kOsWin | kOsLinux, // Currently does nothing on CrOS.
[email protected]8a6ff28d2010-12-02 16:35:19284 SINGLE_VALUE_TYPE(switches::kExperimentalLocationFeatures)
285 },
286 {
[email protected]04227962011-01-20 02:03:09287 "disable-interactive-form-validation",
288 IDS_FLAGS_DISABLE_INTERACTIVE_FORM_VALIDATION_NAME,
289 IDS_FLAGS_DISABLE_INTERACTIVE_FORM_VALIDATION_DESCRIPTION,
290 kOsAll,
291 SINGLE_VALUE_TYPE(switches::kDisableInteractiveFormValidation)
292 },
[email protected]8df51192011-01-22 20:05:03293 {
[email protected]07d490bc2011-03-07 17:05:26294 "focus-existing-tab-on-open", // FLAGS:RECORD_UMA
295 IDS_FLAGS_FOCUS_EXISTING_TAB_ON_OPEN_NAME,
296 IDS_FLAGS_FOCUS_EXISTING_TAB_ON_OPEN_DESCRIPTION,
297 kOsAll,
298 SINGLE_VALUE_TYPE(switches::kFocusExistingTabOnOpen)
299 },
[email protected]d5dcfb32011-03-19 00:49:24300 {
[email protected]5aea1862011-03-23 23:55:39301 "tab-groups-context-menu",
302 IDS_FLAGS_TAB_GROUPS_CONTEXT_MENU_NAME,
303 IDS_FLAGS_TAB_GROUPS_CONTEXT_MENU_DESCRIPTION,
304 kOsWin,
305 SINGLE_VALUE_TYPE(switches::kEnableTabGroupsContextMenu)
306 },
[email protected]e9bf9d92011-03-31 20:57:15307 {
[email protected]f2557bd2011-06-01 02:33:07308 "preload-instant-search",
309 IDS_FLAGS_PRELOAD_INSTANT_SEARCH_NAME,
310 IDS_FLAGS_PRELOAD_INSTANT_SEARCH_DESCRIPTION,
311 kOsAll,
312 SINGLE_VALUE_TYPE(switches::kPreloadInstantSearch)
313 },
[email protected]354e33b2011-06-15 00:29:10314 {
315 "static-ip-config",
316 IDS_FLAGS_STATIC_IP_CONFIG_NAME,
317 IDS_FLAGS_STATIC_IP_CONFIG_DESCRIPTION,
318 kOsCrOS,
319#if defined(OS_CHROMEOS)
320 // This switch exists only on Chrome OS.
321 SINGLE_VALUE_TYPE(switches::kEnableStaticIPConfig)
322#else
323 SINGLE_VALUE_TYPE("")
324#endif
325 },
[email protected]3eb5728c2011-06-20 22:32:24326 {
327 "show-autofill-type-predictions",
328 IDS_FLAGS_SHOW_AUTOFILL_TYPE_PREDICTIONS_NAME,
329 IDS_FLAGS_SHOW_AUTOFILL_TYPE_PREDICTIONS_DESCRIPTION,
330 kOsAll,
331 SINGLE_VALUE_TYPE(switches::kShowAutofillTypePredictions)
332 },
[email protected]bff4d3e2011-06-21 23:58:52333 {
[email protected]9a6180d7d2011-09-07 01:40:33334 "sync-tabs",
335 IDS_FLAGS_SYNC_TABS_NAME,
336 IDS_FLAGS_SYNC_TABS_DESCRIPTION,
[email protected]5b0ec7f2011-08-11 02:17:17337 kOsAll,
[email protected]9a6180d7d2011-09-07 01:40:33338 SINGLE_VALUE_TYPE(switches::kEnableSyncTabs)
[email protected]5b0ec7f2011-08-11 02:17:17339 },
340 {
[email protected]aae9eeb12011-10-21 21:59:26341 "sync-app-notifications",
342 IDS_FLAGS_SYNC_APP_NOTIFICATIONS_NAME,
343 IDS_FLAGS_SYNC_APP_NOTIFICATIONS_DESCRIPTION,
344 kOsAll,
[email protected]0b6fba82011-11-18 01:31:11345 SINGLE_VALUE_TYPE(switches::kDisableSyncAppNotifications)
[email protected]aae9eeb12011-10-21 21:59:26346 },
347 {
[email protected]a22ebd812011-06-23 00:05:39348 "enable-smooth-scrolling", // FLAGS:RECORD_UMA
349 IDS_FLAGS_ENABLE_SMOOTH_SCROLLING_NAME,
350 IDS_FLAGS_ENABLE_SMOOTH_SCROLLING_DESCRIPTION,
351 // Can't expose the switch unless the code is compiled in.
[email protected]554b7062011-09-03 03:09:40352 // On by default for the Mac (different implementation in WebKit).
[email protected]554b7062011-09-03 03:09:40353 kOsWin | kOsLinux | kOsCrOS,
[email protected]a22ebd812011-06-23 00:05:39354 SINGLE_VALUE_TYPE(switches::kEnableSmoothScrolling)
355 },
[email protected]81a6b0b2011-06-24 17:55:40356 {
[email protected]ae1eb29a2011-08-17 17:50:57357 "prerender-from-omnibox", // FLAGS:RECORD_UMA
[email protected]81a6b0b2011-06-24 17:55:40358 IDS_FLAGS_PRERENDER_FROM_OMNIBOX_NAME,
359 IDS_FLAGS_PRERENDER_FROM_OMNIBOX_DESCRIPTION,
360 kOsAll,
[email protected]778ef7c2011-10-11 15:37:05361 MULTI_VALUE_TYPE(kPrerenderFromOmniboxChoices)
[email protected]81a6b0b2011-06-24 17:55:40362 },
[email protected]40916632011-07-02 01:11:01363 {
[email protected]ed1e39502011-12-16 14:39:35364 "omnibox-aggressive-with-history-urls",
365 IDS_FLAGS_OMNIBOX_AGGRESSIVE_HISTORY_URL_SCORING_NAME,
366 IDS_FLAGS_OMNIBOX_AGGRESSIVE_HISTORY_URL_SCORING_DESCRIPTION,
367 kOsAll,
368 SINGLE_VALUE_TYPE(switches::kEnableOmniboxAggressiveHistoryURL)
369 },
370 {
[email protected]7e7a28092011-12-09 22:24:55371 "enable-panels",
372 IDS_FLAGS_ENABLE_PANELS_NAME,
373 IDS_FLAGS_ENABLE_PANELS_DESCRIPTION,
[email protected]73fb1fc52011-07-09 00:06:54374 kOsAll,
[email protected]7e7a28092011-12-09 22:24:55375 SINGLE_VALUE_TYPE(switches::kEnablePanels)
[email protected]73fb1fc52011-07-09 00:06:54376 },
[email protected]e3749d12011-07-25 22:22:12377 {
[email protected]9931875b2011-11-02 00:19:48378 "disable-shortcuts-provider",
379 IDS_FLAGS_DISABLE_SHORTCUTS_PROVIDER,
380 IDS_FLAGS_DISABLE_SHORTCUTS_PROVIDER_DESCRIPTION,
[email protected]e3749d12011-07-25 22:22:12381 kOsAll,
[email protected]9931875b2011-11-02 00:19:48382 SINGLE_VALUE_TYPE(switches::kDisableShortcutsProvider)
[email protected]e3749d12011-07-25 22:22:12383 },
[email protected]1a2966b92011-08-09 06:50:19384#if defined(OS_CHROMEOS)
385 {
[email protected]cd681c42011-09-29 02:49:44386 "enable-bluetooth",
387 IDS_FLAGS_ENABLE_BLUETOOTH_NAME,
388 IDS_FLAGS_ENABLE_BLUETOOTH_DESCRIPTION,
389 kOsCrOS,
390 SINGLE_VALUE_TYPE(switches::kEnableBluetooth)
391 },
[email protected]1a2966b92011-08-09 06:50:19392#endif
[email protected]80eb4262011-08-03 16:10:41393 {
394 "memory-widget",
395 IDS_FLAGS_MEMORY_WIDGET_NAME,
396 IDS_FLAGS_MEMORY_WIDGET_DESCRIPTION,
397 kOsCrOS,
398#if defined(OS_CHROMEOS)
399 // This switch exists only on Chrome OS.
400 SINGLE_VALUE_TYPE(switches::kMemoryWidget)
401#else
402 SINGLE_VALUE_TYPE("")
403#endif
[email protected]a0e4b072011-08-17 01:47:07404 },
405 {
406 "downloads-new-ui", // FLAGS:RECORD_UMA
407 IDS_FLAGS_DOWNLOADS_NEW_UI_NAME,
408 IDS_FLAGS_DOWNLOADS_NEW_UI_DESCRIPTION,
409 kOsAll,
410 SINGLE_VALUE_TYPE(switches::kDownloadsNewUI)
411 },
[email protected]b7bb44f2011-09-01 05:17:03412 {
413 "enable-autologin",
414 IDS_FLAGS_ENABLE_AUTOLOGIN_NAME,
415 IDS_FLAGS_ENABLE_AUTOLOGIN_DESCRIPTION,
416 kOsMac | kOsWin | kOsLinux,
417 SINGLE_VALUE_TYPE(switches::kEnableAutologin)
418 },
[email protected]b9841172011-09-26 23:36:09419 {
420 "use-more-webui",
421 IDS_FLAGS_USE_MORE_WEBUI_NAME,
422 IDS_FLAGS_USE_MORE_WEBUI_DESCRIPTION,
423 kOsAll,
424 SINGLE_VALUE_TYPE(switches::kUseMoreWebUI)
425 },
[email protected]bbadb112011-12-12 16:55:28426 {
427 "enable-http-pipelining",
428 IDS_FLAGS_ENABLE_HTTP_PIPELINING_NAME,
429 IDS_FLAGS_ENABLE_HTTP_PIPELINING_DESCRIPTION,
430 kOsAll,
431 SINGLE_VALUE_TYPE(switches::kEnableHttpPipelining)
432 },
[email protected]d411c01d2011-10-18 16:00:27433 {
[email protected]f5da41d2011-10-08 17:40:07434 "enable-video-track",
435 IDS_FLAGS_ENABLE_VIDEO_TRACK_NAME,
436 IDS_FLAGS_ENABLE_VIDEO_TRACK_DESCRIPTION,
437 kOsAll,
438 SINGLE_VALUE_TYPE(switches::kEnableVideoTrack)
439 },
[email protected]08b83362011-10-19 05:23:17440 {
[email protected]d399d4e2012-01-13 23:02:31441 "extension-alerts",
442 IDS_FLAGS_ENABLE_EXTENSION_ALERTS_NAME,
443 IDS_FLAGS_ENABLE_EXTENSION_ALERTS_DESCRIPTION,
444 kOsAll,
445 SINGLE_VALUE_TYPE(switches::kEnableExtensionAlerts)
446 },
447 {
[email protected]6aa03b32011-10-27 21:44:44448 "enable-media-source",
449 IDS_FLAGS_ENABLE_MEDIA_SOURCE_NAME,
450 IDS_FLAGS_ENABLE_MEDIA_SOURCE_DESCRIPTION,
451 kOsAll,
452 SINGLE_VALUE_TYPE(switches::kEnableMediaSource)
453 },
[email protected]e4e68dbb2011-11-18 01:50:22454 {
455 "enable-pointer-lock",
456 IDS_FLAGS_ENABLE_POINTER_LOCK_NAME,
457 IDS_FLAGS_ENABLE_POINTER_LOCK_DESCRIPTION,
458 kOsAll,
459 SINGLE_VALUE_TYPE(switches::kEnablePointerLock)
460 },
[email protected]8cc10df2011-11-03 23:57:50461#if defined(USE_AURA)
462 {
[email protected]20cea592011-12-10 01:55:30463 "aura-workspace-manager",
464 IDS_FLAGS_AURA_WORKSPACE_MANAGER_NAME,
465 IDS_FLAGS_AURA_WORKSPACE_MANAGER_DESCRIPTION,
[email protected]8cc10df2011-11-03 23:57:50466 kOsWin | kOsLinux | kOsCrOS,
[email protected]55f593352011-12-24 05:42:46467 SINGLE_VALUE_TYPE(ash::switches::kAuraWorkspaceManager)
[email protected]8cc10df2011-11-03 23:57:50468 },
[email protected]20cea592011-12-10 01:55:30469 {
470 "aura-translucent-frames",
471 IDS_FLAGS_AURA_TRANSLUCENT_FRAMES_NAME,
472 IDS_FLAGS_AURA_TRANSLUCENT_FRAMES_DESCRIPTION,
473 kOsWin | kOsLinux | kOsCrOS,
[email protected]55f593352011-12-24 05:42:46474 SINGLE_VALUE_TYPE(ash::switches::kAuraTranslucentFrames)
[email protected]20cea592011-12-10 01:55:30475 },
[email protected]57b8bb352012-01-11 05:11:46476 {
477 "aura-google-dialog-frames",
478 IDS_FLAGS_AURA_GOOGLE_DIALOG_FRAMES_NAME,
479 IDS_FLAGS_AURA_GOOGLE_DIALOG_FRAMES_DESCRIPTION,
480 kOsWin | kOsLinux | kOsCrOS,
481 SINGLE_VALUE_TYPE(ash::switches::kAuraGoogleDialogFrames)
482 },
[email protected]20cea592011-12-10 01:55:30483#endif // defined(USE_AURA)
[email protected]edb051d2011-11-24 23:20:51484 {
485 "enable-gamepad",
486 IDS_FLAGS_ENABLE_GAMEPAD_NAME,
487 IDS_FLAGS_ENABLE_GAMEPAD_DESCRIPTION,
[email protected]47ced5e2012-01-06 22:28:08488 kOsAll,
[email protected]edb051d2011-11-24 23:20:51489 SINGLE_VALUE_TYPE(switches::kEnableGamepad)
490 },
[email protected]5cc74312012-01-10 00:13:38491#if defined(AURA_SHOW_ABOUT_FLAG_WINDOW_MODE)
[email protected]35304ce2011-12-14 23:21:01492 // TODO(jamescook): Enable this for all ChromeOS builds when we're sure
493 // Aura laptop mode performance and feature set match traditional non-Aura
494 // builds.
495 {
[email protected]3fbd9c12011-12-16 21:35:11496 "aura-window-mode",
497 IDS_FLAGS_AURA_WINDOW_MODE_NAME,
498 IDS_FLAGS_AURA_WINDOW_MODE_DESCRIPTION,
[email protected]35304ce2011-12-14 23:21:01499 kOsWin | kOsLinux | kOsCrOS,
[email protected]3fbd9c12011-12-16 21:35:11500 MULTI_VALUE_TYPE(kAuraWindowModeChoices)
[email protected]35304ce2011-12-14 23:21:01501 },
502#endif
[email protected]db543d322011-12-15 20:40:15503 {
504 "per-tile-painting",
505 IDS_FLAGS_PER_TILE_PAINTING_NAME,
506 IDS_FLAGS_PER_TILE_PAINTING_DESCRIPTION,
507#if defined(USE_SKIA)
[email protected]a5b1b272012-01-06 20:44:37508 kOsMac | kOsLinux | kOsCrOS,
[email protected]db543d322011-12-15 20:40:15509#else
510 0,
511#endif
512 SINGLE_VALUE_TYPE(switches::kEnablePerTilePainting)
513 },
[email protected]bf88c032011-12-22 19:05:47514 {
515 "enable-javascript-harmony",
516 IDS_FLAGS_ENABLE_JAVASCRIPT_HARMONY_NAME,
517 IDS_FLAGS_ENABLE_JAVASCRIPT_HARMONY_DESCRIPTION,
518 kOsAll,
519 SINGLE_VALUE_TYPE_AND_VALUE(switches::kJavaScriptFlags, "--harmony")
520 },
[email protected]7e7f378a2012-01-05 14:35:37521 {
[email protected]85646172012-01-09 22:45:54522 "enable-tab-browser-dragging",
523 IDS_FLAGS_ENABLE_TAB_BROWSER_DRAGGING_NAME,
524 IDS_FLAGS_ENABLE_TAB_BROWSER_DRAGGING_DESCRIPTION,
525 kOsWin,
526 SINGLE_VALUE_TYPE(switches::kTabBrowserDragging)
527 },
528 {
[email protected]7e7f378a2012-01-05 14:35:37529 "enable-restore-session-state",
530 IDS_FLAGS_ENABLE_RESTORE_SESSION_STATE_NAME,
531 IDS_FLAGS_ENABLE_RESTORE_SESSION_STATE_DESCRIPTION,
532 kOsAll,
533 SINGLE_VALUE_TYPE(switches::kEnableRestoreSessionState)
534 },
[email protected]a0e4b072011-08-17 01:47:07535};
[email protected]ad2a3ded2010-08-27 13:19:05536
[email protected]a314ee5a2010-10-26 21:23:28537const Experiment* experiments = kExperiments;
538size_t num_experiments = arraysize(kExperiments);
539
[email protected]e2ddbc92010-10-15 20:02:07540// Stores and encapsulates the little state that about:flags has.
541class FlagsState {
542 public:
543 FlagsState() : needs_restart_(false) {}
544 void ConvertFlagsToSwitches(PrefService* prefs, CommandLine* command_line);
545 bool IsRestartNeededToCommitChanges();
546 void SetExperimentEnabled(
[email protected]a314ee5a2010-10-26 21:23:28547 PrefService* prefs, const std::string& internal_name, bool enable);
[email protected]e2ddbc92010-10-15 20:02:07548 void RemoveFlagsSwitches(
549 std::map<std::string, CommandLine::StringType>* switch_list);
550 void reset();
551
552 // Returns the singleton instance of this class
[email protected]8e8bb6d2010-12-13 08:18:55553 static FlagsState* GetInstance() {
[email protected]e2ddbc92010-10-15 20:02:07554 return Singleton<FlagsState>::get();
555 }
556
557 private:
558 bool needs_restart_;
[email protected]a82744532011-02-11 16:15:53559 std::map<std::string, std::string> flags_switches_;
[email protected]e2ddbc92010-10-15 20:02:07560
561 DISALLOW_COPY_AND_ASSIGN(FlagsState);
562};
563
[email protected]c7b7800a2010-10-07 18:51:35564// Extracts the list of enabled lab experiments from preferences and stores them
[email protected]ad2a3ded2010-08-27 13:19:05565// in a set.
[email protected]1a47d7e2010-10-15 00:37:24566void GetEnabledFlags(const PrefService* prefs, std::set<std::string>* result) {
[email protected]ad2a3ded2010-08-27 13:19:05567 const ListValue* enabled_experiments = prefs->GetList(
568 prefs::kEnabledLabsExperiments);
569 if (!enabled_experiments)
570 return;
571
572 for (ListValue::const_iterator it = enabled_experiments->begin();
573 it != enabled_experiments->end();
574 ++it) {
575 std::string experiment_name;
576 if (!(*it)->GetAsString(&experiment_name)) {
577 LOG(WARNING) << "Invalid entry in " << prefs::kEnabledLabsExperiments;
578 continue;
579 }
580 result->insert(experiment_name);
581 }
582}
583
584// Takes a set of enabled lab experiments
[email protected]1a47d7e2010-10-15 00:37:24585void SetEnabledFlags(
[email protected]ad2a3ded2010-08-27 13:19:05586 PrefService* prefs, const std::set<std::string>& enabled_experiments) {
[email protected]1bc78422011-03-31 08:41:38587 ListPrefUpdate update(prefs, prefs::kEnabledLabsExperiments);
588 ListValue* experiments_list = update.Get();
[email protected]ad2a3ded2010-08-27 13:19:05589
590 experiments_list->Clear();
591 for (std::set<std::string>::const_iterator it = enabled_experiments.begin();
592 it != enabled_experiments.end();
593 ++it) {
594 experiments_list->Append(new StringValue(*it));
595 }
596}
597
[email protected]8a6ff28d2010-12-02 16:35:19598// Returns the name used in prefs for the choice at the specified index.
599std::string NameForChoice(const Experiment& e, int index) {
[email protected]2ce9c89752011-02-25 18:24:34600 DCHECK_EQ(Experiment::MULTI_VALUE, e.type);
601 DCHECK_LT(index, e.num_choices);
[email protected]8a6ff28d2010-12-02 16:35:19602 return std::string(e.internal_name) + about_flags::testing::kMultiSeparator +
603 base::IntToString(index);
604}
605
606// Adds the internal names for the specified experiment to |names|.
607void AddInternalName(const Experiment& e, std::set<std::string>* names) {
608 if (e.type == Experiment::SINGLE_VALUE) {
609 names->insert(e.internal_name);
610 } else {
[email protected]2ce9c89752011-02-25 18:24:34611 DCHECK_EQ(Experiment::MULTI_VALUE, e.type);
[email protected]8a6ff28d2010-12-02 16:35:19612 for (int i = 0; i < e.num_choices; ++i)
613 names->insert(NameForChoice(e, i));
614 }
615}
616
[email protected]28e35af2011-02-09 12:56:22617// Confirms that an experiment is valid, used in a DCHECK in
618// SanitizeList below.
619bool ValidateExperiment(const Experiment& e) {
620 switch (e.type) {
621 case Experiment::SINGLE_VALUE:
622 DCHECK_EQ(0, e.num_choices);
623 DCHECK(!e.choices);
624 break;
625 case Experiment::MULTI_VALUE:
626 DCHECK_GT(e.num_choices, 0);
627 DCHECK(e.choices);
[email protected]a82744532011-02-11 16:15:53628 DCHECK(e.choices[0].command_line_switch);
629 DCHECK_EQ('\0', e.choices[0].command_line_switch[0]);
[email protected]28e35af2011-02-09 12:56:22630 break;
631 default:
632 NOTREACHED();
633 }
634 return true;
635}
636
[email protected]ad2a3ded2010-08-27 13:19:05637// Removes all experiments from prefs::kEnabledLabsExperiments that are
638// unknown, to prevent this list to become very long as experiments are added
639// and removed.
640void SanitizeList(PrefService* prefs) {
641 std::set<std::string> known_experiments;
[email protected]28e35af2011-02-09 12:56:22642 for (size_t i = 0; i < num_experiments; ++i) {
643 DCHECK(ValidateExperiment(experiments[i]));
[email protected]8a6ff28d2010-12-02 16:35:19644 AddInternalName(experiments[i], &known_experiments);
[email protected]28e35af2011-02-09 12:56:22645 }
[email protected]ad2a3ded2010-08-27 13:19:05646
647 std::set<std::string> enabled_experiments;
[email protected]1a47d7e2010-10-15 00:37:24648 GetEnabledFlags(prefs, &enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05649
650 std::set<std::string> new_enabled_experiments;
651 std::set_intersection(
652 known_experiments.begin(), known_experiments.end(),
653 enabled_experiments.begin(), enabled_experiments.end(),
654 std::inserter(new_enabled_experiments, new_enabled_experiments.begin()));
655
[email protected]1a47d7e2010-10-15 00:37:24656 SetEnabledFlags(prefs, new_enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05657}
658
[email protected]1a47d7e2010-10-15 00:37:24659void GetSanitizedEnabledFlags(
[email protected]ad2a3ded2010-08-27 13:19:05660 PrefService* prefs, std::set<std::string>* result) {
661 SanitizeList(prefs);
[email protected]1a47d7e2010-10-15 00:37:24662 GetEnabledFlags(prefs, result);
[email protected]ad2a3ded2010-08-27 13:19:05663}
664
[email protected]a314ee5a2010-10-26 21:23:28665// Variant of GetSanitizedEnabledFlags that also removes any flags that aren't
666// enabled on the current platform.
667void GetSanitizedEnabledFlagsForCurrentPlatform(
668 PrefService* prefs, std::set<std::string>* result) {
669 GetSanitizedEnabledFlags(prefs, result);
670
671 // Filter out any experiments that aren't enabled on the current platform. We
672 // don't remove these from prefs else syncing to a platform with a different
673 // set of experiments would be lossy.
674 std::set<std::string> platform_experiments;
675 int current_platform = GetCurrentPlatform();
676 for (size_t i = 0; i < num_experiments; ++i) {
677 if (experiments[i].supported_platforms & current_platform)
[email protected]8a6ff28d2010-12-02 16:35:19678 AddInternalName(experiments[i], &platform_experiments);
[email protected]a314ee5a2010-10-26 21:23:28679 }
680
681 std::set<std::string> new_enabled_experiments;
682 std::set_intersection(
683 platform_experiments.begin(), platform_experiments.end(),
684 result->begin(), result->end(),
685 std::inserter(new_enabled_experiments, new_enabled_experiments.begin()));
686
687 result->swap(new_enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05688}
689
[email protected]8a6ff28d2010-12-02 16:35:19690// Returns the Value representing the choice data in the specified experiment.
[email protected]8a6ff28d2010-12-02 16:35:19691Value* CreateChoiceData(const Experiment& experiment,
[email protected]28e35af2011-02-09 12:56:22692 const std::set<std::string>& enabled_experiments) {
[email protected]2ce9c89752011-02-25 18:24:34693 DCHECK_EQ(Experiment::MULTI_VALUE, experiment.type);
[email protected]8a6ff28d2010-12-02 16:35:19694 ListValue* result = new ListValue;
695 for (int i = 0; i < experiment.num_choices; ++i) {
696 const Experiment::Choice& choice = experiment.choices[i];
697 DictionaryValue* value = new DictionaryValue;
698 std::string name = NameForChoice(experiment, i);
699 value->SetString("description",
700 l10n_util::GetStringUTF16(choice.description_id));
701 value->SetString("internal_name", name);
[email protected]28e35af2011-02-09 12:56:22702 value->SetBoolean("selected", enabled_experiments.count(name) > 0);
[email protected]8a6ff28d2010-12-02 16:35:19703 result->Append(value);
704 }
705 return result;
706}
707
[email protected]e2ddbc92010-10-15 20:02:07708} // namespace
709
[email protected]1a47d7e2010-10-15 00:37:24710void ConvertFlagsToSwitches(PrefService* prefs, CommandLine* command_line) {
[email protected]8e8bb6d2010-12-13 08:18:55711 FlagsState::GetInstance()->ConvertFlagsToSwitches(prefs, command_line);
[email protected]ad2a3ded2010-08-27 13:19:05712}
713
[email protected]1a47d7e2010-10-15 00:37:24714ListValue* GetFlagsExperimentsData(PrefService* prefs) {
[email protected]ad2a3ded2010-08-27 13:19:05715 std::set<std::string> enabled_experiments;
[email protected]1a47d7e2010-10-15 00:37:24716 GetSanitizedEnabledFlags(prefs, &enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05717
718 int current_platform = GetCurrentPlatform();
719
720 ListValue* experiments_data = new ListValue();
[email protected]a314ee5a2010-10-26 21:23:28721 for (size_t i = 0; i < num_experiments; ++i) {
722 const Experiment& experiment = experiments[i];
[email protected]ad2a3ded2010-08-27 13:19:05723
724 DictionaryValue* data = new DictionaryValue();
725 data->SetString("internal_name", experiment.internal_name);
726 data->SetString("name",
727 l10n_util::GetStringUTF16(experiment.visible_name_id));
728 data->SetString("description",
729 l10n_util::GetStringUTF16(
730 experiment.visible_description_id));
[email protected]cc3e2052011-12-20 01:01:40731 bool supported = !!(experiment.supported_platforms & current_platform);
732 data->SetBoolean("supported", supported);
733
734 ListValue* supported_platforms = new ListValue();
735 AddOsStrings(experiment.supported_platforms, supported_platforms);
736 data->Set("supported_platforms", supported_platforms);
[email protected]ad2a3ded2010-08-27 13:19:05737
[email protected]28e35af2011-02-09 12:56:22738 switch (experiment.type) {
739 case Experiment::SINGLE_VALUE:
740 data->SetBoolean(
741 "enabled",
742 enabled_experiments.count(experiment.internal_name) > 0);
743 break;
744 case Experiment::MULTI_VALUE:
745 data->Set("choices", CreateChoiceData(experiment, enabled_experiments));
746 break;
747 default:
748 NOTREACHED();
[email protected]8a6ff28d2010-12-02 16:35:19749 }
750
[email protected]ad2a3ded2010-08-27 13:19:05751 experiments_data->Append(data);
752 }
753 return experiments_data;
754}
755
[email protected]ad2a3ded2010-08-27 13:19:05756bool IsRestartNeededToCommitChanges() {
[email protected]8e8bb6d2010-12-13 08:18:55757 return FlagsState::GetInstance()->IsRestartNeededToCommitChanges();
[email protected]ad2a3ded2010-08-27 13:19:05758}
759
760void SetExperimentEnabled(
[email protected]c7b7800a2010-10-07 18:51:35761 PrefService* prefs, const std::string& internal_name, bool enable) {
[email protected]8e8bb6d2010-12-13 08:18:55762 FlagsState::GetInstance()->SetExperimentEnabled(prefs, internal_name, enable);
[email protected]e2ddbc92010-10-15 20:02:07763}
764
765void RemoveFlagsSwitches(
766 std::map<std::string, CommandLine::StringType>* switch_list) {
[email protected]8e8bb6d2010-12-13 08:18:55767 FlagsState::GetInstance()->RemoveFlagsSwitches(switch_list);
[email protected]e2ddbc92010-10-15 20:02:07768}
769
[email protected]a314ee5a2010-10-26 21:23:28770int GetCurrentPlatform() {
771#if defined(OS_MACOSX)
772 return kOsMac;
773#elif defined(OS_WIN)
774 return kOsWin;
775#elif defined(OS_CHROMEOS) // Needs to be before the OS_LINUX check.
776 return kOsCrOS;
[email protected]c92f4ed2011-10-21 19:50:21777#elif defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]a314ee5a2010-10-26 21:23:28778 return kOsLinux;
779#else
780#error Unknown platform
781#endif
782}
783
[email protected]4bc5050c2010-11-18 17:55:54784void RecordUMAStatistics(const PrefService* prefs) {
785 std::set<std::string> flags;
786 GetEnabledFlags(prefs, &flags);
787 for (std::set<std::string>::iterator it = flags.begin(); it != flags.end();
788 ++it) {
789 std::string action("AboutFlags_");
790 action += *it;
[email protected]7f6f44c2011-12-14 13:23:38791 content::RecordComputedAction(action);
[email protected]4bc5050c2010-11-18 17:55:54792 }
793 // Since flag metrics are recorded every startup, add a tick so that the
794 // stats can be made meaningful.
795 if (flags.size())
[email protected]7f6f44c2011-12-14 13:23:38796 content::RecordAction(UserMetricsAction("AboutFlags_StartupTick"));
797 content::RecordAction(UserMetricsAction("StartupTick"));
[email protected]4bc5050c2010-11-18 17:55:54798}
799
[email protected]e2ddbc92010-10-15 20:02:07800//////////////////////////////////////////////////////////////////////////////
801// FlagsState implementation.
802
803namespace {
804
805void FlagsState::ConvertFlagsToSwitches(
806 PrefService* prefs, CommandLine* command_line) {
[email protected]e2ddbc92010-10-15 20:02:07807 if (command_line->HasSwitch(switches::kNoExperiments))
808 return;
809
810 std::set<std::string> enabled_experiments;
[email protected]ba8164242010-11-16 21:31:00811
[email protected]a314ee5a2010-10-26 21:23:28812 GetSanitizedEnabledFlagsForCurrentPlatform(prefs, &enabled_experiments);
[email protected]e2ddbc92010-10-15 20:02:07813
[email protected]a82744532011-02-11 16:15:53814 typedef std::map<std::string, std::pair<std::string, std::string> >
815 NameToSwitchAndValueMap;
816 NameToSwitchAndValueMap name_to_switch_map;
[email protected]8a6ff28d2010-12-02 16:35:19817 for (size_t i = 0; i < num_experiments; ++i) {
818 const Experiment& e = experiments[i];
819 if (e.type == Experiment::SINGLE_VALUE) {
[email protected]a82744532011-02-11 16:15:53820 name_to_switch_map[e.internal_name] =
821 std::pair<std::string, std::string>(e.command_line_switch,
822 e.command_line_value);
[email protected]8a6ff28d2010-12-02 16:35:19823 } else {
824 for (int j = 0; j < e.num_choices; ++j)
[email protected]a82744532011-02-11 16:15:53825 name_to_switch_map[NameForChoice(e, j)] =
826 std::pair<std::string, std::string>(
827 e.choices[j].command_line_switch,
828 e.choices[j].command_line_value);
[email protected]8a6ff28d2010-12-02 16:35:19829 }
830 }
[email protected]e2ddbc92010-10-15 20:02:07831
832 command_line->AppendSwitch(switches::kFlagSwitchesBegin);
[email protected]a82744532011-02-11 16:15:53833 flags_switches_.insert(
834 std::pair<std::string, std::string>(switches::kFlagSwitchesBegin,
835 std::string()));
[email protected]e2ddbc92010-10-15 20:02:07836 for (std::set<std::string>::iterator it = enabled_experiments.begin();
837 it != enabled_experiments.end();
838 ++it) {
839 const std::string& experiment_name = *it;
[email protected]a82744532011-02-11 16:15:53840 NameToSwitchAndValueMap::const_iterator name_to_switch_it =
[email protected]8a6ff28d2010-12-02 16:35:19841 name_to_switch_map.find(experiment_name);
842 if (name_to_switch_it == name_to_switch_map.end()) {
843 NOTREACHED();
[email protected]e2ddbc92010-10-15 20:02:07844 continue;
[email protected]8a6ff28d2010-12-02 16:35:19845 }
[email protected]e2ddbc92010-10-15 20:02:07846
[email protected]a82744532011-02-11 16:15:53847 const std::pair<std::string, std::string>&
848 switch_and_value_pair = name_to_switch_it->second;
849
850 command_line->AppendSwitchASCII(switch_and_value_pair.first,
851 switch_and_value_pair.second);
852 flags_switches_[switch_and_value_pair.first] = switch_and_value_pair.second;
[email protected]e2ddbc92010-10-15 20:02:07853 }
854 command_line->AppendSwitch(switches::kFlagSwitchesEnd);
[email protected]a82744532011-02-11 16:15:53855 flags_switches_.insert(
856 std::pair<std::string, std::string>(switches::kFlagSwitchesEnd,
857 std::string()));
[email protected]e2ddbc92010-10-15 20:02:07858}
859
860bool FlagsState::IsRestartNeededToCommitChanges() {
861 return needs_restart_;
862}
863
864void FlagsState::SetExperimentEnabled(
865 PrefService* prefs, const std::string& internal_name, bool enable) {
[email protected]ad2a3ded2010-08-27 13:19:05866 needs_restart_ = true;
867
[email protected]8a6ff28d2010-12-02 16:35:19868 size_t at_index = internal_name.find(about_flags::testing::kMultiSeparator);
869 if (at_index != std::string::npos) {
870 DCHECK(enable);
871 // We're being asked to enable a multi-choice experiment. Disable the
872 // currently selected choice.
873 DCHECK_NE(at_index, 0u);
[email protected]28e35af2011-02-09 12:56:22874 const std::string experiment_name = internal_name.substr(0, at_index);
875 SetExperimentEnabled(prefs, experiment_name, false);
[email protected]8a6ff28d2010-12-02 16:35:19876
[email protected]28e35af2011-02-09 12:56:22877 // And enable the new choice, if it is not the default first choice.
878 if (internal_name != experiment_name + "@0") {
879 std::set<std::string> enabled_experiments;
880 GetSanitizedEnabledFlags(prefs, &enabled_experiments);
881 enabled_experiments.insert(internal_name);
882 SetEnabledFlags(prefs, enabled_experiments);
883 }
[email protected]8a6ff28d2010-12-02 16:35:19884 return;
885 }
886
[email protected]ad2a3ded2010-08-27 13:19:05887 std::set<std::string> enabled_experiments;
[email protected]1a47d7e2010-10-15 00:37:24888 GetSanitizedEnabledFlags(prefs, &enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05889
[email protected]8a6ff28d2010-12-02 16:35:19890 const Experiment* e = NULL;
891 for (size_t i = 0; i < num_experiments; ++i) {
892 if (experiments[i].internal_name == internal_name) {
893 e = experiments + i;
894 break;
895 }
896 }
897 DCHECK(e);
898
899 if (e->type == Experiment::SINGLE_VALUE) {
[email protected]8a2713682011-08-19 10:36:59900 if (enable)
[email protected]8a6ff28d2010-12-02 16:35:19901 enabled_experiments.insert(internal_name);
[email protected]8a2713682011-08-19 10:36:59902 else
[email protected]8a6ff28d2010-12-02 16:35:19903 enabled_experiments.erase(internal_name);
904 } else {
905 if (enable) {
906 // Enable the first choice.
907 enabled_experiments.insert(NameForChoice(*e, 0));
908 } else {
909 // Find the currently enabled choice and disable it.
910 for (int i = 0; i < e->num_choices; ++i) {
911 std::string choice_name = NameForChoice(*e, i);
912 if (enabled_experiments.find(choice_name) !=
913 enabled_experiments.end()) {
914 enabled_experiments.erase(choice_name);
915 // Continue on just in case there's a bug and more than one
916 // experiment for this choice was enabled.
917 }
918 }
919 }
920 }
[email protected]ad2a3ded2010-08-27 13:19:05921
[email protected]1a47d7e2010-10-15 00:37:24922 SetEnabledFlags(prefs, enabled_experiments);
[email protected]ad2a3ded2010-08-27 13:19:05923}
924
[email protected]e2ddbc92010-10-15 20:02:07925void FlagsState::RemoveFlagsSwitches(
926 std::map<std::string, CommandLine::StringType>* switch_list) {
[email protected]a82744532011-02-11 16:15:53927 for (std::map<std::string, std::string>::const_iterator
928 it = flags_switches_.begin(); it != flags_switches_.end(); ++it) {
929 switch_list->erase(it->first);
[email protected]e2ddbc92010-10-15 20:02:07930 }
931}
932
933void FlagsState::reset() {
934 needs_restart_ = false;
935 flags_switches_.clear();
936}
937
[email protected]38e46812011-05-09 20:49:22938} // namespace
[email protected]e2ddbc92010-10-15 20:02:07939
940namespace testing {
[email protected]8a6ff28d2010-12-02 16:35:19941
942// WARNING: '@' is also used in the html file. If you update this constant you
943// also need to update the html file.
944const char kMultiSeparator[] = "@";
945
[email protected]e2ddbc92010-10-15 20:02:07946void ClearState() {
[email protected]8e8bb6d2010-12-13 08:18:55947 FlagsState::GetInstance()->reset();
[email protected]e2ddbc92010-10-15 20:02:07948}
[email protected]a314ee5a2010-10-26 21:23:28949
950void SetExperiments(const Experiment* e, size_t count) {
951 if (!e) {
952 experiments = kExperiments;
953 num_experiments = arraysize(kExperiments);
954 } else {
955 experiments = e;
956 num_experiments = count;
957 }
958}
959
[email protected]8a6ff28d2010-12-02 16:35:19960const Experiment* GetExperiments(size_t* count) {
961 *count = num_experiments;
962 return experiments;
963}
964
[email protected]e2ddbc92010-10-15 20:02:07965} // namespace testing
966
[email protected]1a47d7e2010-10-15 00:37:24967} // namespace about_flags