[email protected] | 9c66adc | 2012-01-05 02:10:16 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 5 | #include "chrome/browser/about_flags.h" |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 6 | |
| 7 | #include <algorithm> |
| 8 | #include <iterator> |
| 9 | #include <map> |
| 10 | #include <set> |
| 11 | |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 12 | #include "base/command_line.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 13 | #include "base/memory/singleton.h" |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 14 | #include "base/string_number_conversions.h" |
[email protected] | d208f4d8 | 2011-05-23 21:52:03 | [diff] [blame] | 15 | #include "base/utf_string_conversions.h" |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 16 | #include "base/values.h" |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 17 | #include "chrome/browser/prefs/pref_service.h" |
[email protected] | 1bc7842 | 2011-03-31 08:41:38 | [diff] [blame] | 18 | #include "chrome/browser/prefs/scoped_user_pref_update.h" |
[email protected] | d208f4d8 | 2011-05-23 21:52:03 | [diff] [blame] | 19 | #include "chrome/common/chrome_content_client.h" |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 20 | #include "chrome/common/chrome_switches.h" |
| 21 | #include "chrome/common/pref_names.h" |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 22 | #include "content/public/browser/user_metrics.h" |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 23 | #include "grit/generated_resources.h" |
[email protected] | c051a1b | 2011-01-21 23:30:17 | [diff] [blame] | 24 | #include "ui/base/l10n/l10n_util.h" |
[email protected] | 8ff7f34 | 2011-05-25 01:49:47 | [diff] [blame] | 25 | #include "ui/gfx/gl/gl_switches.h" |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 26 | |
[email protected] | 8cc10df | 2011-11-03 23:57:50 | [diff] [blame] | 27 | #if defined(USE_AURA) |
[email protected] | b65bdda | 2011-12-23 23:35:31 | [diff] [blame] | 28 | #include "ash/ash_switches.h" |
[email protected] | 8cc10df | 2011-11-03 23:57:50 | [diff] [blame] | 29 | #endif |
| 30 | |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 31 | using content::UserMetricsAction; |
| 32 | |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 33 | namespace about_flags { |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 34 | |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 35 | // Macros to simplify specifying the type. |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 36 | #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] | 0e6f56d | 2011-02-12 23:45:15 | [diff] [blame] | 41 | Experiment::MULTI_VALUE, "", "", choices, arraysize(choices) |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 42 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 43 | namespace { |
| 44 | |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 45 | const unsigned kOsAll = kOsMac | kOsWin | kOsLinux | kOsCrOS; |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 46 | |
[email protected] | cc3e205 | 2011-12-20 01:01:40 | [diff] [blame] | 47 | // Adds a |StringValue| to |list| for each platform where |bitmask| indicates |
| 48 | // whether the experiment is available on that platform. |
| 49 | void 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] | ba816424 | 2010-11-16 21:31:00 | [diff] [blame] | 64 | // Names for former Chrome OS Labs experiments, shared with prefs migration |
| 65 | // code. |
| 66 | const char kMediaPlayerExperimentName[] = "media-player"; |
| 67 | const char kAdvancedFileSystemExperimentName[] = "advanced-file-system"; |
| 68 | const char kVerticalTabsExperimentName[] = "vertical-tabs"; |
| 69 | |
[email protected] | 778ef7c | 2011-10-11 15:37:05 | [diff] [blame] | 70 | const 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] | 3fbd9c1 | 2011-12-16 21:35:11 | [diff] [blame] | 78 | #if defined(USE_AURA) |
| 79 | const Experiment::Choice kAuraWindowModeChoices[] = { |
[email protected] | 9c66adc | 2012-01-05 02:10:16 | [diff] [blame] | 80 | { IDS_FLAGS_AURA_WINDOW_MODE_AUTOMATIC, "", "" }, |
| 81 | { IDS_FLAGS_AURA_WINDOW_MODE_NORMAL, |
| 82 | ash::switches::kAuraWindowMode, ash::switches::kAuraWindowModeNormal }, |
[email protected] | 3fbd9c1 | 2011-12-16 21:35:11 | [diff] [blame] | 83 | { IDS_FLAGS_AURA_WINDOW_MODE_COMPACT, |
[email protected] | 9c66adc | 2012-01-05 02:10:16 | [diff] [blame] | 84 | ash::switches::kAuraWindowMode, ash::switches::kAuraWindowModeCompact } |
[email protected] | 3fbd9c1 | 2011-12-16 21:35:11 | [diff] [blame] | 85 | }; |
| 86 | #endif |
| 87 | |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 88 | // 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] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 108 | // 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] | 28e35af | 2011-02-09 12:56:22 | [diff] [blame] | 112 | // . 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] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 116 | // 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] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 119 | const Experiment kExperiments[] = { |
| 120 | { |
[email protected] | aac169d | 2011-03-18 19:53:03 | [diff] [blame] | 121 | "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] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 133 | "conflicting-modules-check", // FLAGS:RECORD_UMA |
[email protected] | c1bbaa8 | 2010-11-08 11:17:05 | [diff] [blame] | 134 | IDS_FLAGS_CONFLICTS_CHECK_NAME, |
| 135 | IDS_FLAGS_CONFLICTS_CHECK_DESCRIPTION, |
| 136 | kOsWin, |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 137 | SINGLE_VALUE_TYPE(switches::kConflictingModulesCheck) |
[email protected] | c1bbaa8 | 2010-11-08 11:17:05 | [diff] [blame] | 138 | }, |
| 139 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 140 | "cloud-print-proxy", // FLAGS:RECORD_UMA |
[email protected] | dae7325b | 2011-12-21 20:56:54 | [diff] [blame] | 141 | IDS_FLAGS_CLOUD_PRINT_CONNECTOR_NAME, |
| 142 | IDS_FLAGS_CLOUD_PRINT_CONNECTOR_DESCRIPTION, |
[email protected] | 9f8872b3 | 2011-03-04 19:44:45 | [diff] [blame] | 143 | // For a Chrome build, we know we have a PDF plug-in on Windows, so it's |
[email protected] | 4fa24bf | 2011-08-20 02:15:22 | [diff] [blame] | 144 | // fully enabled. |
[email protected] | 5d10d57d | 2011-07-22 22:16:31 | [diff] [blame] | 145 | // Otherwise, where we know Windows could be working if a viable PDF |
[email protected] | 4fa24bf | 2011-08-20 02:15:22 | [diff] [blame] | 146 | // 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] | fa6d2a2f | 2010-11-30 21:47:19 | [diff] [blame] | 152 | #endif |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 153 | SINGLE_VALUE_TYPE(switches::kEnableCloudPrintProxy) |
[email protected] | 8b6588a | 2010-10-12 02:39:42 | [diff] [blame] | 154 | }, |
[email protected] | 580939a | 2010-10-12 18:54:37 | [diff] [blame] | 155 | { |
[email protected] | bb46153 | 2010-11-26 21:50:23 | [diff] [blame] | 156 | "crxless-web-apps", |
| 157 | IDS_FLAGS_CRXLESS_WEB_APPS_NAME, |
| 158 | IDS_FLAGS_CRXLESS_WEB_APPS_DESCRIPTION, |
| 159 | kOsAll, |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 160 | SINGLE_VALUE_TYPE(switches::kEnableCrxlessWebApps) |
[email protected] | bb46153 | 2010-11-26 21:50:23 | [diff] [blame] | 161 | }, |
| 162 | { |
[email protected] | 96c6f4c | 2011-05-18 19:36:22 | [diff] [blame] | 163 | "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] | 0110cf11 | 2011-07-02 00:39:43 | [diff] [blame] | 170 | "force-compositing-mode-2", |
[email protected] | 96c6f4c | 2011-05-18 19:36:22 | [diff] [blame] | 171 | 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] | 5963b77 | 2011-02-09 22:55:38 | [diff] [blame] | 177 | "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] | db543d32 | 2011-12-15 20:40:15 | [diff] [blame] | 184 | "accelerated-painting", |
| 185 | IDS_FLAGS_ACCELERATED_PAINTING_NAME, |
| 186 | IDS_FLAGS_ACCELERATED_PAINTING_DESCRIPTION, |
[email protected] | 60dea12 | 2011-12-06 00:32:45 | [diff] [blame] | 187 | #if defined(USE_SKIA) |
| 188 | kOsAll, |
| 189 | #else |
| 190 | 0, |
| 191 | #endif |
[email protected] | db543d32 | 2011-12-15 20:40:15 | [diff] [blame] | 192 | SINGLE_VALUE_TYPE(switches::kEnableAcceleratedPainting) |
[email protected] | 60dea12 | 2011-12-06 00:32:45 | [diff] [blame] | 193 | }, |
| 194 | { |
[email protected] | a8f1eaa | 2011-03-07 19:00:58 | [diff] [blame] | 195 | "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] | 8ff7f34 | 2011-05-25 01:49:47 | [diff] [blame] | 201 | { |
[email protected] | 70c98a33 | 2011-12-21 20:51:52 | [diff] [blame] | 202 | "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] | 8ff7f34 | 2011-05-25 01:49:47 | [diff] [blame] | 209 | "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] | deaba6d5 | 2011-09-23 14:47:12 | [diff] [blame] | 215 | { |
| 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] | 9de0ec1 | 2011-08-24 21:57:50 | [diff] [blame] | 222 | // 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] | 8d260e5 | 2010-10-13 01:03:05 | [diff] [blame] | 228 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 229 | "print-preview", // FLAGS:RECORD_UMA |
[email protected] | 9486c1f | 2010-10-14 19:52:12 | [diff] [blame] | 230 | IDS_FLAGS_PRINT_PREVIEW_NAME, |
| 231 | IDS_FLAGS_PRINT_PREVIEW_DESCRIPTION, |
[email protected] | b579afd | 2011-07-13 00:01:27 | [diff] [blame] | 232 | kOsAll, |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 233 | SINGLE_VALUE_TYPE(switches::kEnablePrintPreview) |
[email protected] | 2fe15fcb | 2010-10-21 20:39:53 | [diff] [blame] | 234 | }, |
[email protected] | d208f4d8 | 2011-05-23 21:52:03 | [diff] [blame] | 235 | // TODO(dspringer): When NaCl is on by default, remove this flag entry. |
[email protected] | 2fe15fcb | 2010-10-21 20:39:53 | [diff] [blame] | 236 | { |
[email protected] | e3791ce9 | 2011-08-09 01:03:32 | [diff] [blame] | 237 | "enable-nacl", // FLAGS:RECORD_UMA |
[email protected] | 4ff87d20 | 2010-11-06 01:28:40 | [diff] [blame] | 238 | IDS_FLAGS_ENABLE_NACL_NAME, |
| 239 | IDS_FLAGS_ENABLE_NACL_DESCRIPTION, |
| 240 | kOsAll, |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 241 | SINGLE_VALUE_TYPE(switches::kEnableNaCl) |
[email protected] | 4ff87d20 | 2010-11-06 01:28:40 | [diff] [blame] | 242 | }, |
| 243 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 244 | "extension-apis", // FLAGS:RECORD_UMA |
[email protected] | 11dd68cd5 | 2010-11-12 01:15:32 | [diff] [blame] | 245 | IDS_FLAGS_EXPERIMENTAL_EXTENSION_APIS_NAME, |
| 246 | IDS_FLAGS_EXPERIMENTAL_EXTENSION_APIS_DESCRIPTION, |
| 247 | kOsAll, |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 248 | SINGLE_VALUE_TYPE(switches::kEnableExperimentalExtensionApis) |
[email protected] | 11dd68cd5 | 2010-11-12 01:15:32 | [diff] [blame] | 249 | }, |
[email protected] | 3627b06d | 2010-11-12 16:36:16 | [diff] [blame] | 250 | { |
[email protected] | cbe224d | 2011-08-04 22:12:49 | [diff] [blame] | 251 | "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] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 258 | "click-to-play", // FLAGS:RECORD_UMA |
[email protected] | 3627b06d | 2010-11-12 16:36:16 | [diff] [blame] | 259 | IDS_FLAGS_CLICK_TO_PLAY_NAME, |
| 260 | IDS_FLAGS_CLICK_TO_PLAY_DESCRIPTION, |
| 261 | kOsAll, |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 262 | SINGLE_VALUE_TYPE(switches::kEnableClickToPlay) |
[email protected] | 3627b06d | 2010-11-12 16:36:16 | [diff] [blame] | 263 | }, |
[email protected] | 80bd24e | 2010-11-30 09:34:38 | [diff] [blame] | 264 | { |
| 265 | "disable-hyperlink-auditing", |
| 266 | IDS_FLAGS_DISABLE_HYPERLINK_AUDITING_NAME, |
| 267 | IDS_FLAGS_DISABLE_HYPERLINK_AUDITING_DESCRIPTION, |
| 268 | kOsAll, |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 269 | SINGLE_VALUE_TYPE(switches::kNoPings) |
[email protected] | feb28fef | 2010-12-01 10:52:51 | [diff] [blame] | 270 | }, |
| 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] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 276 | SINGLE_VALUE_TYPE(switches::kExperimentalLocationFeatures) |
| 277 | }, |
| 278 | { |
[email protected] | 0422796 | 2011-01-20 02:03:09 | [diff] [blame] | 279 | "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] | 8df5119 | 2011-01-22 20:05:03 | [diff] [blame] | 285 | { |
[email protected] | 07d490bc | 2011-03-07 17:05:26 | [diff] [blame] | 286 | "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] | d5dcfb3 | 2011-03-19 00:49:24 | [diff] [blame] | 292 | { |
[email protected] | 5aea186 | 2011-03-23 23:55:39 | [diff] [blame] | 293 | "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] | e9bf9d9 | 2011-03-31 20:57:15 | [diff] [blame] | 299 | { |
[email protected] | f2557bd | 2011-06-01 02:33:07 | [diff] [blame] | 300 | "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] | 354e33b | 2011-06-15 00:29:10 | [diff] [blame] | 306 | { |
| 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] | 3eb5728c | 2011-06-20 22:32:24 | [diff] [blame] | 318 | { |
| 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] | bff4d3e | 2011-06-21 23:58:52 | [diff] [blame] | 325 | { |
[email protected] | 9a6180d7d | 2011-09-07 01:40:33 | [diff] [blame] | 326 | "sync-tabs", |
| 327 | IDS_FLAGS_SYNC_TABS_NAME, |
| 328 | IDS_FLAGS_SYNC_TABS_DESCRIPTION, |
[email protected] | 5b0ec7f | 2011-08-11 02:17:17 | [diff] [blame] | 329 | kOsAll, |
[email protected] | 9a6180d7d | 2011-09-07 01:40:33 | [diff] [blame] | 330 | SINGLE_VALUE_TYPE(switches::kEnableSyncTabs) |
[email protected] | 5b0ec7f | 2011-08-11 02:17:17 | [diff] [blame] | 331 | }, |
| 332 | { |
[email protected] | aae9eeb1 | 2011-10-21 21:59:26 | [diff] [blame] | 333 | "sync-app-notifications", |
| 334 | IDS_FLAGS_SYNC_APP_NOTIFICATIONS_NAME, |
| 335 | IDS_FLAGS_SYNC_APP_NOTIFICATIONS_DESCRIPTION, |
| 336 | kOsAll, |
[email protected] | 0b6fba8 | 2011-11-18 01:31:11 | [diff] [blame] | 337 | SINGLE_VALUE_TYPE(switches::kDisableSyncAppNotifications) |
[email protected] | aae9eeb1 | 2011-10-21 21:59:26 | [diff] [blame] | 338 | }, |
| 339 | { |
[email protected] | a22ebd81 | 2011-06-23 00:05:39 | [diff] [blame] | 340 | "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] | 554b706 | 2011-09-03 03:09:40 | [diff] [blame] | 344 | // On by default for the Mac (different implementation in WebKit). |
[email protected] | 554b706 | 2011-09-03 03:09:40 | [diff] [blame] | 345 | kOsWin | kOsLinux | kOsCrOS, |
[email protected] | a22ebd81 | 2011-06-23 00:05:39 | [diff] [blame] | 346 | SINGLE_VALUE_TYPE(switches::kEnableSmoothScrolling) |
| 347 | }, |
[email protected] | 81a6b0b | 2011-06-24 17:55:40 | [diff] [blame] | 348 | { |
[email protected] | ae1eb29a | 2011-08-17 17:50:57 | [diff] [blame] | 349 | "prerender-from-omnibox", // FLAGS:RECORD_UMA |
[email protected] | 81a6b0b | 2011-06-24 17:55:40 | [diff] [blame] | 350 | IDS_FLAGS_PRERENDER_FROM_OMNIBOX_NAME, |
| 351 | IDS_FLAGS_PRERENDER_FROM_OMNIBOX_DESCRIPTION, |
| 352 | kOsAll, |
[email protected] | 778ef7c | 2011-10-11 15:37:05 | [diff] [blame] | 353 | MULTI_VALUE_TYPE(kPrerenderFromOmniboxChoices) |
[email protected] | 81a6b0b | 2011-06-24 17:55:40 | [diff] [blame] | 354 | }, |
[email protected] | 4091663 | 2011-07-02 01:11:01 | [diff] [blame] | 355 | { |
[email protected] | ed1e3950 | 2011-12-16 14:39:35 | [diff] [blame] | 356 | "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] | 7e7a2809 | 2011-12-09 22:24:55 | [diff] [blame] | 363 | "enable-panels", |
| 364 | IDS_FLAGS_ENABLE_PANELS_NAME, |
| 365 | IDS_FLAGS_ENABLE_PANELS_DESCRIPTION, |
[email protected] | 73fb1fc5 | 2011-07-09 00:06:54 | [diff] [blame] | 366 | kOsAll, |
[email protected] | 7e7a2809 | 2011-12-09 22:24:55 | [diff] [blame] | 367 | SINGLE_VALUE_TYPE(switches::kEnablePanels) |
[email protected] | 73fb1fc5 | 2011-07-09 00:06:54 | [diff] [blame] | 368 | }, |
[email protected] | e3749d1 | 2011-07-25 22:22:12 | [diff] [blame] | 369 | { |
[email protected] | 9931875b | 2011-11-02 00:19:48 | [diff] [blame] | 370 | "disable-shortcuts-provider", |
| 371 | IDS_FLAGS_DISABLE_SHORTCUTS_PROVIDER, |
| 372 | IDS_FLAGS_DISABLE_SHORTCUTS_PROVIDER_DESCRIPTION, |
[email protected] | e3749d1 | 2011-07-25 22:22:12 | [diff] [blame] | 373 | kOsAll, |
[email protected] | 9931875b | 2011-11-02 00:19:48 | [diff] [blame] | 374 | SINGLE_VALUE_TYPE(switches::kDisableShortcutsProvider) |
[email protected] | e3749d1 | 2011-07-25 22:22:12 | [diff] [blame] | 375 | }, |
[email protected] | 1a2966b9 | 2011-08-09 06:50:19 | [diff] [blame] | 376 | #if defined(OS_CHROMEOS) |
| 377 | { |
[email protected] | cd681c4 | 2011-09-29 02:49:44 | [diff] [blame] | 378 | "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] | 1a2966b9 | 2011-08-09 06:50:19 | [diff] [blame] | 384 | #endif |
[email protected] | 80eb426 | 2011-08-03 16:10:41 | [diff] [blame] | 385 | { |
| 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] | a0e4b07 | 2011-08-17 01:47:07 | [diff] [blame] | 396 | }, |
| 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] | b7bb44f | 2011-09-01 05:17:03 | [diff] [blame] | 404 | { |
| 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] | b984117 | 2011-09-26 23:36:09 | [diff] [blame] | 411 | { |
| 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] | bbadb11 | 2011-12-12 16:55:28 | [diff] [blame] | 418 | { |
| 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] | d411c01d | 2011-10-18 16:00:27 | [diff] [blame] | 425 | { |
[email protected] | f5da41d | 2011-10-08 17:40:07 | [diff] [blame] | 426 | "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] | 08b8336 | 2011-10-19 05:23:17 | [diff] [blame] | 432 | { |
| 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] | 6aa03b3 | 2011-10-27 21:44:44 | [diff] [blame] | 439 | { |
| 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] | e4e68dbb | 2011-11-18 01:50:22 | [diff] [blame] | 446 | { |
| 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] | 8cc10df | 2011-11-03 23:57:50 | [diff] [blame] | 453 | #if defined(USE_AURA) |
| 454 | { |
[email protected] | 20cea59 | 2011-12-10 01:55:30 | [diff] [blame] | 455 | "aura-workspace-manager", |
| 456 | IDS_FLAGS_AURA_WORKSPACE_MANAGER_NAME, |
| 457 | IDS_FLAGS_AURA_WORKSPACE_MANAGER_DESCRIPTION, |
[email protected] | 8cc10df | 2011-11-03 23:57:50 | [diff] [blame] | 458 | kOsWin | kOsLinux | kOsCrOS, |
[email protected] | 55f59335 | 2011-12-24 05:42:46 | [diff] [blame] | 459 | SINGLE_VALUE_TYPE(ash::switches::kAuraWorkspaceManager) |
[email protected] | 8cc10df | 2011-11-03 23:57:50 | [diff] [blame] | 460 | }, |
[email protected] | 20cea59 | 2011-12-10 01:55:30 | [diff] [blame] | 461 | { |
| 462 | "aura-translucent-frames", |
| 463 | IDS_FLAGS_AURA_TRANSLUCENT_FRAMES_NAME, |
| 464 | IDS_FLAGS_AURA_TRANSLUCENT_FRAMES_DESCRIPTION, |
| 465 | kOsWin | kOsLinux | kOsCrOS, |
[email protected] | 55f59335 | 2011-12-24 05:42:46 | [diff] [blame] | 466 | SINGLE_VALUE_TYPE(ash::switches::kAuraTranslucentFrames) |
[email protected] | 20cea59 | 2011-12-10 01:55:30 | [diff] [blame] | 467 | }, |
[email protected] | 57b8bb35 | 2012-01-11 05:11:46 | [diff] [blame^] | 468 | { |
| 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] | 20cea59 | 2011-12-10 01:55:30 | [diff] [blame] | 475 | #endif // defined(USE_AURA) |
[email protected] | edb051d | 2011-11-24 23:20:51 | [diff] [blame] | 476 | { |
| 477 | "enable-gamepad", |
| 478 | IDS_FLAGS_ENABLE_GAMEPAD_NAME, |
| 479 | IDS_FLAGS_ENABLE_GAMEPAD_DESCRIPTION, |
[email protected] | 47ced5e | 2012-01-06 22:28:08 | [diff] [blame] | 480 | kOsAll, |
[email protected] | edb051d | 2011-11-24 23:20:51 | [diff] [blame] | 481 | SINGLE_VALUE_TYPE(switches::kEnableGamepad) |
| 482 | }, |
[email protected] | 5cc7431 | 2012-01-10 00:13:38 | [diff] [blame] | 483 | #if defined(AURA_SHOW_ABOUT_FLAG_WINDOW_MODE) |
[email protected] | 35304ce | 2011-12-14 23:21:01 | [diff] [blame] | 484 | // 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] | 3fbd9c1 | 2011-12-16 21:35:11 | [diff] [blame] | 488 | "aura-window-mode", |
| 489 | IDS_FLAGS_AURA_WINDOW_MODE_NAME, |
| 490 | IDS_FLAGS_AURA_WINDOW_MODE_DESCRIPTION, |
[email protected] | 35304ce | 2011-12-14 23:21:01 | [diff] [blame] | 491 | kOsWin | kOsLinux | kOsCrOS, |
[email protected] | 3fbd9c1 | 2011-12-16 21:35:11 | [diff] [blame] | 492 | MULTI_VALUE_TYPE(kAuraWindowModeChoices) |
[email protected] | 35304ce | 2011-12-14 23:21:01 | [diff] [blame] | 493 | }, |
| 494 | #endif |
[email protected] | db543d32 | 2011-12-15 20:40:15 | [diff] [blame] | 495 | { |
| 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] | a5b1b27 | 2012-01-06 20:44:37 | [diff] [blame] | 500 | kOsMac | kOsLinux | kOsCrOS, |
[email protected] | db543d32 | 2011-12-15 20:40:15 | [diff] [blame] | 501 | #else |
| 502 | 0, |
| 503 | #endif |
| 504 | SINGLE_VALUE_TYPE(switches::kEnablePerTilePainting) |
| 505 | }, |
[email protected] | bf88c03 | 2011-12-22 19:05:47 | [diff] [blame] | 506 | { |
| 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] | 7e7f378a | 2012-01-05 14:35:37 | [diff] [blame] | 513 | { |
[email protected] | 8564617 | 2012-01-09 22:45:54 | [diff] [blame] | 514 | "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] | 7e7f378a | 2012-01-05 14:35:37 | [diff] [blame] | 521 | "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] | a0e4b07 | 2011-08-17 01:47:07 | [diff] [blame] | 527 | }; |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 528 | |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 529 | const Experiment* experiments = kExperiments; |
| 530 | size_t num_experiments = arraysize(kExperiments); |
| 531 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 532 | // Stores and encapsulates the little state that about:flags has. |
| 533 | class FlagsState { |
| 534 | public: |
| 535 | FlagsState() : needs_restart_(false) {} |
| 536 | void ConvertFlagsToSwitches(PrefService* prefs, CommandLine* command_line); |
| 537 | bool IsRestartNeededToCommitChanges(); |
| 538 | void SetExperimentEnabled( |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 539 | PrefService* prefs, const std::string& internal_name, bool enable); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 540 | 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] | 8e8bb6d | 2010-12-13 08:18:55 | [diff] [blame] | 545 | static FlagsState* GetInstance() { |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 546 | return Singleton<FlagsState>::get(); |
| 547 | } |
| 548 | |
| 549 | private: |
| 550 | bool needs_restart_; |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 551 | std::map<std::string, std::string> flags_switches_; |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 552 | |
| 553 | DISALLOW_COPY_AND_ASSIGN(FlagsState); |
| 554 | }; |
| 555 | |
[email protected] | c7b7800a | 2010-10-07 18:51:35 | [diff] [blame] | 556 | // Extracts the list of enabled lab experiments from preferences and stores them |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 557 | // in a set. |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 558 | void GetEnabledFlags(const PrefService* prefs, std::set<std::string>* result) { |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 559 | 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] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 577 | void SetEnabledFlags( |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 578 | PrefService* prefs, const std::set<std::string>& enabled_experiments) { |
[email protected] | 1bc7842 | 2011-03-31 08:41:38 | [diff] [blame] | 579 | ListPrefUpdate update(prefs, prefs::kEnabledLabsExperiments); |
| 580 | ListValue* experiments_list = update.Get(); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 581 | |
| 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] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 590 | // Returns the name used in prefs for the choice at the specified index. |
| 591 | std::string NameForChoice(const Experiment& e, int index) { |
[email protected] | 2ce9c8975 | 2011-02-25 18:24:34 | [diff] [blame] | 592 | DCHECK_EQ(Experiment::MULTI_VALUE, e.type); |
| 593 | DCHECK_LT(index, e.num_choices); |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 594 | 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|. |
| 599 | void 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] | 2ce9c8975 | 2011-02-25 18:24:34 | [diff] [blame] | 603 | DCHECK_EQ(Experiment::MULTI_VALUE, e.type); |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 604 | for (int i = 0; i < e.num_choices; ++i) |
| 605 | names->insert(NameForChoice(e, i)); |
| 606 | } |
| 607 | } |
| 608 | |
[email protected] | 28e35af | 2011-02-09 12:56:22 | [diff] [blame] | 609 | // Confirms that an experiment is valid, used in a DCHECK in |
| 610 | // SanitizeList below. |
| 611 | bool 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] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 620 | DCHECK(e.choices[0].command_line_switch); |
| 621 | DCHECK_EQ('\0', e.choices[0].command_line_switch[0]); |
[email protected] | 28e35af | 2011-02-09 12:56:22 | [diff] [blame] | 622 | break; |
| 623 | default: |
| 624 | NOTREACHED(); |
| 625 | } |
| 626 | return true; |
| 627 | } |
| 628 | |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 629 | // 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. |
| 632 | void SanitizeList(PrefService* prefs) { |
| 633 | std::set<std::string> known_experiments; |
[email protected] | 28e35af | 2011-02-09 12:56:22 | [diff] [blame] | 634 | for (size_t i = 0; i < num_experiments; ++i) { |
| 635 | DCHECK(ValidateExperiment(experiments[i])); |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 636 | AddInternalName(experiments[i], &known_experiments); |
[email protected] | 28e35af | 2011-02-09 12:56:22 | [diff] [blame] | 637 | } |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 638 | |
| 639 | std::set<std::string> enabled_experiments; |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 640 | GetEnabledFlags(prefs, &enabled_experiments); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 641 | |
| 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] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 648 | SetEnabledFlags(prefs, new_enabled_experiments); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 649 | } |
| 650 | |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 651 | void GetSanitizedEnabledFlags( |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 652 | PrefService* prefs, std::set<std::string>* result) { |
| 653 | SanitizeList(prefs); |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 654 | GetEnabledFlags(prefs, result); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 655 | } |
| 656 | |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 657 | // Variant of GetSanitizedEnabledFlags that also removes any flags that aren't |
| 658 | // enabled on the current platform. |
| 659 | void 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] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 670 | AddInternalName(experiments[i], &platform_experiments); |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 671 | } |
| 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] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 680 | } |
| 681 | |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 682 | // Returns the Value representing the choice data in the specified experiment. |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 683 | Value* CreateChoiceData(const Experiment& experiment, |
[email protected] | 28e35af | 2011-02-09 12:56:22 | [diff] [blame] | 684 | const std::set<std::string>& enabled_experiments) { |
[email protected] | 2ce9c8975 | 2011-02-25 18:24:34 | [diff] [blame] | 685 | DCHECK_EQ(Experiment::MULTI_VALUE, experiment.type); |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 686 | 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] | 28e35af | 2011-02-09 12:56:22 | [diff] [blame] | 694 | value->SetBoolean("selected", enabled_experiments.count(name) > 0); |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 695 | result->Append(value); |
| 696 | } |
| 697 | return result; |
| 698 | } |
| 699 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 700 | } // namespace |
| 701 | |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 702 | void ConvertFlagsToSwitches(PrefService* prefs, CommandLine* command_line) { |
[email protected] | 8e8bb6d | 2010-12-13 08:18:55 | [diff] [blame] | 703 | FlagsState::GetInstance()->ConvertFlagsToSwitches(prefs, command_line); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 704 | } |
| 705 | |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 706 | ListValue* GetFlagsExperimentsData(PrefService* prefs) { |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 707 | std::set<std::string> enabled_experiments; |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 708 | GetSanitizedEnabledFlags(prefs, &enabled_experiments); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 709 | |
| 710 | int current_platform = GetCurrentPlatform(); |
| 711 | |
| 712 | ListValue* experiments_data = new ListValue(); |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 713 | for (size_t i = 0; i < num_experiments; ++i) { |
| 714 | const Experiment& experiment = experiments[i]; |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 715 | |
| 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] | cc3e205 | 2011-12-20 01:01:40 | [diff] [blame] | 723 | 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] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 729 | |
[email protected] | 28e35af | 2011-02-09 12:56:22 | [diff] [blame] | 730 | 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] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 741 | } |
| 742 | |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 743 | experiments_data->Append(data); |
| 744 | } |
| 745 | return experiments_data; |
| 746 | } |
| 747 | |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 748 | bool IsRestartNeededToCommitChanges() { |
[email protected] | 8e8bb6d | 2010-12-13 08:18:55 | [diff] [blame] | 749 | return FlagsState::GetInstance()->IsRestartNeededToCommitChanges(); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | void SetExperimentEnabled( |
[email protected] | c7b7800a | 2010-10-07 18:51:35 | [diff] [blame] | 753 | PrefService* prefs, const std::string& internal_name, bool enable) { |
[email protected] | 8e8bb6d | 2010-12-13 08:18:55 | [diff] [blame] | 754 | FlagsState::GetInstance()->SetExperimentEnabled(prefs, internal_name, enable); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | void RemoveFlagsSwitches( |
| 758 | std::map<std::string, CommandLine::StringType>* switch_list) { |
[email protected] | 8e8bb6d | 2010-12-13 08:18:55 | [diff] [blame] | 759 | FlagsState::GetInstance()->RemoveFlagsSwitches(switch_list); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 760 | } |
| 761 | |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 762 | int 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] | c92f4ed | 2011-10-21 19:50:21 | [diff] [blame] | 769 | #elif defined(OS_LINUX) || defined(OS_OPENBSD) |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 770 | return kOsLinux; |
| 771 | #else |
| 772 | #error Unknown platform |
| 773 | #endif |
| 774 | } |
| 775 | |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 776 | void 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] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 783 | content::RecordComputedAction(action); |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 784 | } |
| 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] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 788 | content::RecordAction(UserMetricsAction("AboutFlags_StartupTick")); |
| 789 | content::RecordAction(UserMetricsAction("StartupTick")); |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 790 | } |
| 791 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 792 | ////////////////////////////////////////////////////////////////////////////// |
| 793 | // FlagsState implementation. |
| 794 | |
| 795 | namespace { |
| 796 | |
| 797 | void FlagsState::ConvertFlagsToSwitches( |
| 798 | PrefService* prefs, CommandLine* command_line) { |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 799 | if (command_line->HasSwitch(switches::kNoExperiments)) |
| 800 | return; |
| 801 | |
| 802 | std::set<std::string> enabled_experiments; |
[email protected] | ba816424 | 2010-11-16 21:31:00 | [diff] [blame] | 803 | |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 804 | GetSanitizedEnabledFlagsForCurrentPlatform(prefs, &enabled_experiments); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 805 | |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 806 | typedef std::map<std::string, std::pair<std::string, std::string> > |
| 807 | NameToSwitchAndValueMap; |
| 808 | NameToSwitchAndValueMap name_to_switch_map; |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 809 | for (size_t i = 0; i < num_experiments; ++i) { |
| 810 | const Experiment& e = experiments[i]; |
| 811 | if (e.type == Experiment::SINGLE_VALUE) { |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 812 | 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] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 815 | } else { |
| 816 | for (int j = 0; j < e.num_choices; ++j) |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 817 | 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] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 821 | } |
| 822 | } |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 823 | |
| 824 | command_line->AppendSwitch(switches::kFlagSwitchesBegin); |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 825 | flags_switches_.insert( |
| 826 | std::pair<std::string, std::string>(switches::kFlagSwitchesBegin, |
| 827 | std::string())); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 828 | 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] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 832 | NameToSwitchAndValueMap::const_iterator name_to_switch_it = |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 833 | name_to_switch_map.find(experiment_name); |
| 834 | if (name_to_switch_it == name_to_switch_map.end()) { |
| 835 | NOTREACHED(); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 836 | continue; |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 837 | } |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 838 | |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 839 | 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] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 845 | } |
| 846 | command_line->AppendSwitch(switches::kFlagSwitchesEnd); |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 847 | flags_switches_.insert( |
| 848 | std::pair<std::string, std::string>(switches::kFlagSwitchesEnd, |
| 849 | std::string())); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | bool FlagsState::IsRestartNeededToCommitChanges() { |
| 853 | return needs_restart_; |
| 854 | } |
| 855 | |
| 856 | void FlagsState::SetExperimentEnabled( |
| 857 | PrefService* prefs, const std::string& internal_name, bool enable) { |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 858 | needs_restart_ = true; |
| 859 | |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 860 | 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] | 28e35af | 2011-02-09 12:56:22 | [diff] [blame] | 866 | const std::string experiment_name = internal_name.substr(0, at_index); |
| 867 | SetExperimentEnabled(prefs, experiment_name, false); |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 868 | |
[email protected] | 28e35af | 2011-02-09 12:56:22 | [diff] [blame] | 869 | // 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] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 876 | return; |
| 877 | } |
| 878 | |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 879 | std::set<std::string> enabled_experiments; |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 880 | GetSanitizedEnabledFlags(prefs, &enabled_experiments); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 881 | |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 882 | 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] | 8a271368 | 2011-08-19 10:36:59 | [diff] [blame] | 892 | if (enable) |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 893 | enabled_experiments.insert(internal_name); |
[email protected] | 8a271368 | 2011-08-19 10:36:59 | [diff] [blame] | 894 | else |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 895 | 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] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 913 | |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 914 | SetEnabledFlags(prefs, enabled_experiments); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 915 | } |
| 916 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 917 | void FlagsState::RemoveFlagsSwitches( |
| 918 | std::map<std::string, CommandLine::StringType>* switch_list) { |
[email protected] | a8274453 | 2011-02-11 16:15:53 | [diff] [blame] | 919 | 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] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 922 | } |
| 923 | } |
| 924 | |
| 925 | void FlagsState::reset() { |
| 926 | needs_restart_ = false; |
| 927 | flags_switches_.clear(); |
| 928 | } |
| 929 | |
[email protected] | 38e4681 | 2011-05-09 20:49:22 | [diff] [blame] | 930 | } // namespace |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 931 | |
| 932 | namespace testing { |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 933 | |
| 934 | // WARNING: '@' is also used in the html file. If you update this constant you |
| 935 | // also need to update the html file. |
| 936 | const char kMultiSeparator[] = "@"; |
| 937 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 938 | void ClearState() { |
[email protected] | 8e8bb6d | 2010-12-13 08:18:55 | [diff] [blame] | 939 | FlagsState::GetInstance()->reset(); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 940 | } |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 941 | |
| 942 | void 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] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 952 | const Experiment* GetExperiments(size_t* count) { |
| 953 | *count = num_experiments; |
| 954 | return experiments; |
| 955 | } |
| 956 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 957 | } // namespace testing |
| 958 | |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 959 | } // namespace about_flags |