[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 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 | |
| 12 | #include "app/l10n_util.h" |
| 13 | #include "base/command_line.h" |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 14 | #include "base/singleton.h" |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame^] | 15 | #include "base/string_number_conversions.h" |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 16 | #include "base/values.h" |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 17 | #include "chrome/browser/metrics/user_metrics.h" |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 18 | #include "chrome/browser/prefs/pref_service.h" |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 19 | #include "chrome/common/chrome_switches.h" |
| 20 | #include "chrome/common/pref_names.h" |
| 21 | #include "grit/generated_resources.h" |
| 22 | |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 23 | namespace about_flags { |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 24 | |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame^] | 25 | // Macros to simplify specifying the type. |
| 26 | #define SINGLE_VALUE_TYPE(command_line) Experiment::SINGLE_VALUE, \ |
| 27 | command_line, NULL, 0 |
| 28 | #define MULTI_VALUE_TYPE(choices) Experiment::MULTI_VALUE, "", choices, \ |
| 29 | arraysize(choices) |
| 30 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 31 | namespace { |
| 32 | |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 33 | const unsigned kOsAll = kOsMac | kOsWin | kOsLinux | kOsCrOS; |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 34 | |
[email protected] | ba816424 | 2010-11-16 21:31:00 | [diff] [blame] | 35 | // Names for former Chrome OS Labs experiments, shared with prefs migration |
| 36 | // code. |
| 37 | const char kMediaPlayerExperimentName[] = "media-player"; |
| 38 | const char kAdvancedFileSystemExperimentName[] = "advanced-file-system"; |
| 39 | const char kVerticalTabsExperimentName[] = "vertical-tabs"; |
| 40 | |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame^] | 41 | // If adding a new choice, add it to the end of the list. |
| 42 | const Experiment::Choice kInstantChoices[] = { |
| 43 | { IDS_FLAGS_INSTANT_TYPE_VERBATIM, switches::kEnableVerbatimInstant }, |
| 44 | { IDS_FLAGS_INSTANT_TYPE_PREDICTIVE, switches::kEnablePredictiveInstant }, |
| 45 | { IDS_FLAGS_INSTANT_TYPE_PREDICTIVE_NO_AUTO_COMPLETE, |
| 46 | switches::kEnablePredictiveNoAutoCompleteInstant |
| 47 | }, |
| 48 | }; |
| 49 | |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 50 | // RECORDING USER METRICS FOR FLAGS: |
| 51 | // ----------------------------------------------------------------------------- |
| 52 | // The first line of the experiment is the internal name. If you'd like to |
| 53 | // gather statistics about the usage of your flag, you should append a marker |
| 54 | // comment to the end of the feature name, like so: |
| 55 | // "my-special-feature", // FLAGS:RECORD_UMA |
| 56 | // |
| 57 | // After doing that, run //chrome/tools/extract_actions.py (see instructions at |
| 58 | // the top of that file for details) to update the chromeactions.txt file, which |
| 59 | // will enable UMA to record your feature flag. |
| 60 | // |
| 61 | // After your feature has shipped under a flag, you can locate the metrics |
| 62 | // under the action name AboutFlags_internal-action-name. Actions are recorded |
| 63 | // once per startup, so you should divide this number by AboutFlags_StartupTick |
| 64 | // to get a sense of usage. Note that this will not be the same as number of |
| 65 | // users with a given feature enabled because users can quit and relaunch |
| 66 | // the application multiple times over a given time interval. |
| 67 | // TODO(rsesek): See if there's a way to count per-user, rather than |
| 68 | // per-startup. |
| 69 | |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame^] | 70 | // To add a new experiment add to the end of kExperiments. There are two |
| 71 | // distinct types of experiments: |
| 72 | // . SINGLE_VALUE: experiment is either on or off. Use the SINGLE_VALUE_TYPE |
| 73 | // macro for this type supplying the command line to the macro. |
| 74 | // . MULTI_VALUE: if enabled the command line of the selected choice is enabled. |
| 75 | // To specify this type of experiment use the macro MULTI_VALUE_TYPE supplying |
| 76 | // it the array of choices. |
| 77 | // See the documentation of Experiment for details on the fields. |
| 78 | // |
| 79 | // When adding a new choice, add it to the end of the list. |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 80 | const Experiment kExperiments[] = { |
| 81 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 82 | "expose-for-tabs", // FLAGS:RECORD_UMA |
[email protected] | 9486c1f | 2010-10-14 19:52:12 | [diff] [blame] | 83 | IDS_FLAGS_TABPOSE_NAME, |
| 84 | IDS_FLAGS_TABPOSE_DESCRIPTION, |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 85 | kOsMac, |
| 86 | #if defined(OS_MACOSX) |
| 87 | // The switch exists only on OS X. |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame^] | 88 | SINGLE_VALUE_TYPE(switches::kEnableExposeForTabs) |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 89 | #else |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame^] | 90 | SINGLE_VALUE_TYPE("") |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 91 | #endif |
| 92 | }, |
| 93 | { |
[email protected] | ba816424 | 2010-11-16 21:31:00 | [diff] [blame] | 94 | kMediaPlayerExperimentName, |
| 95 | IDS_FLAGS_MEDIA_PLAYER_NAME, |
| 96 | IDS_FLAGS_MEDIA_PLAYER_DESCRIPTION, |
| 97 | kOsCrOS, |
| 98 | #if defined(OS_CHROMEOS) |
| 99 | // The switch exists only on Chrome OS. |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame^] | 100 | SINGLE_VALUE_TYPE(switches::kEnableMediaPlayer) |
[email protected] | ba816424 | 2010-11-16 21:31:00 | [diff] [blame] | 101 | #else |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame^] | 102 | SINGLE_VALUE_TYPE("") |
[email protected] | ba816424 | 2010-11-16 21:31:00 | [diff] [blame] | 103 | #endif |
| 104 | }, |
| 105 | { |
| 106 | kAdvancedFileSystemExperimentName, |
| 107 | IDS_FLAGS_ADVANCED_FS_NAME, |
| 108 | IDS_FLAGS_ADVANCED_FS_DESCRIPTION, |
| 109 | kOsCrOS, |
| 110 | #if defined(OS_CHROMEOS) |
| 111 | // The switch exists only on Chrome OS. |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame^] | 112 | SINGLE_VALUE_TYPE(switches::kEnableAdvancedFileSystem) |
[email protected] | ba816424 | 2010-11-16 21:31:00 | [diff] [blame] | 113 | #else |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame^] | 114 | SINGLE_VALUE_TYPE("") |
[email protected] | ba816424 | 2010-11-16 21:31:00 | [diff] [blame] | 115 | #endif |
| 116 | }, |
| 117 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 118 | "vertical-tabs", // FLAGS:RECORD_UMA |
[email protected] | 9486c1f | 2010-10-14 19:52:12 | [diff] [blame] | 119 | IDS_FLAGS_SIDE_TABS_NAME, |
| 120 | IDS_FLAGS_SIDE_TABS_DESCRIPTION, |
[email protected] | ba816424 | 2010-11-16 21:31:00 | [diff] [blame] | 121 | kOsWin | kOsCrOS, |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame^] | 122 | SINGLE_VALUE_TYPE(switches::kEnableVerticalTabs) |
[email protected] | 65415187 | 2010-09-13 22:43:05 | [diff] [blame] | 123 | }, |
| 124 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 125 | "tabbed-options", // FLAGS:RECORD_UMA |
[email protected] | 9486c1f | 2010-10-14 19:52:12 | [diff] [blame] | 126 | IDS_FLAGS_TABBED_OPTIONS_NAME, |
| 127 | IDS_FLAGS_TABBED_OPTIONS_DESCRIPTION, |
[email protected] | 1af1dfe | 2010-10-19 23:49:14 | [diff] [blame] | 128 | kOsWin | kOsLinux | kOsMac, // Enabled by default on CrOS. |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame^] | 129 | SINGLE_VALUE_TYPE(switches::kEnableTabbedOptions) |
[email protected] | 65415187 | 2010-09-13 22:43:05 | [diff] [blame] | 130 | }, |
[email protected] | bcf9167 | 2010-09-16 15:40:21 | [diff] [blame] | 131 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 132 | "remoting", // FLAGS:RECORD_UMA |
[email protected] | 9486c1f | 2010-10-14 19:52:12 | [diff] [blame] | 133 | IDS_FLAGS_REMOTING_NAME, |
[email protected] | 4fb2f119 | 2010-09-25 14:56:31 | [diff] [blame] | 134 | #if defined(OS_WIN) |
[email protected] | 52fa2d5 | 2010-09-25 14:08:56 | [diff] [blame] | 135 | // Windows only supports host functionality at the moment. |
[email protected] | 9486c1f | 2010-10-14 19:52:12 | [diff] [blame] | 136 | IDS_FLAGS_REMOTING_HOST_DESCRIPTION, |
[email protected] | 1af1dfe | 2010-10-19 23:49:14 | [diff] [blame] | 137 | #elif defined(OS_LINUX) // Also true for CrOS. |
[email protected] | 52fa2d5 | 2010-09-25 14:08:56 | [diff] [blame] | 138 | // Linux only supports client functionality at the moment. |
[email protected] | 9486c1f | 2010-10-14 19:52:12 | [diff] [blame] | 139 | IDS_FLAGS_REMOTING_CLIENT_DESCRIPTION, |
[email protected] | 52fa2d5 | 2010-09-25 14:08:56 | [diff] [blame] | 140 | #else |
[email protected] | a694085 | 2010-09-25 14:25:32 | [diff] [blame] | 141 | // On other platforms, this lab isn't available at all. |
| 142 | 0, |
[email protected] | 52fa2d5 | 2010-09-25 14:08:56 | [diff] [blame] | 143 | #endif |
[email protected] | 1af1dfe | 2010-10-19 23:49:14 | [diff] [blame] | 144 | kOsWin | kOsLinux | kOsCrOS, |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame^] | 145 | SINGLE_VALUE_TYPE(switches::kEnableRemoting) |
[email protected] | 52fa2d5 | 2010-09-25 14:08:56 | [diff] [blame] | 146 | }, |
[email protected] | a6f0365 | 2010-09-28 15:59:07 | [diff] [blame] | 147 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 148 | "disable-outdated-plugins", // FLAGS:RECORD_UMA |
[email protected] | 9486c1f | 2010-10-14 19:52:12 | [diff] [blame] | 149 | IDS_FLAGS_DISABLE_OUTDATED_PLUGINS_NAME, |
| 150 | IDS_FLAGS_DISABLE_OUTDATED_PLUGINS_DESCRIPTION, |
[email protected] | 57b66d0 | 2010-09-30 11:24:51 | [diff] [blame] | 151 | kOsAll, |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame^] | 152 | SINGLE_VALUE_TYPE(switches::kDisableOutdatedPlugins) |
[email protected] | 57b66d0 | 2010-09-30 11:24:51 | [diff] [blame] | 153 | }, |
[email protected] | b3ce30ea | 2010-10-01 09:33:53 | [diff] [blame] | 154 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 155 | "xss-auditor", // FLAGS:RECORD_UMA |
[email protected] | 9486c1f | 2010-10-14 19:52:12 | [diff] [blame] | 156 | IDS_FLAGS_XSS_AUDITOR_NAME, |
| 157 | IDS_FLAGS_XSS_AUDITOR_DESCRIPTION, |
[email protected] | b3ce30ea | 2010-10-01 09:33:53 | [diff] [blame] | 158 | kOsAll, |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame^] | 159 | SINGLE_VALUE_TYPE(switches::kEnableXSSAuditor) |
[email protected] | b3ce30ea | 2010-10-01 09:33:53 | [diff] [blame] | 160 | }, |
[email protected] | aea2ff4 | 2010-10-04 18:04:19 | [diff] [blame] | 161 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 162 | "background-webapps", // FLAGS:RECORD_UMA |
[email protected] | 9486c1f | 2010-10-14 19:52:12 | [diff] [blame] | 163 | IDS_FLAGS_BACKGROUND_WEBAPPS_NAME, |
| 164 | IDS_FLAGS_BACKGROUND_WEBAPPS_DESCRIPTION, |
[email protected] | 186c8af | 2010-11-24 07:01:10 | [diff] [blame] | 165 | kOsMac | kOsLinux | kOsCrOS, // Enabled by default on windows |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame^] | 166 | SINGLE_VALUE_TYPE(switches::kEnableBackgroundMode) |
[email protected] | 7bee0b2 | 2010-10-05 17:00:47 | [diff] [blame] | 167 | }, |
| 168 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 169 | "conflicting-modules-check", // FLAGS:RECORD_UMA |
[email protected] | c1bbaa8 | 2010-11-08 11:17:05 | [diff] [blame] | 170 | IDS_FLAGS_CONFLICTS_CHECK_NAME, |
| 171 | IDS_FLAGS_CONFLICTS_CHECK_DESCRIPTION, |
| 172 | kOsWin, |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame^] | 173 | SINGLE_VALUE_TYPE(switches::kConflictingModulesCheck) |
[email protected] | c1bbaa8 | 2010-11-08 11:17:05 | [diff] [blame] | 174 | }, |
| 175 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 176 | "cloud-print-proxy", // FLAGS:RECORD_UMA |
[email protected] | 9486c1f | 2010-10-14 19:52:12 | [diff] [blame] | 177 | IDS_FLAGS_CLOUD_PRINT_PROXY_NAME, |
| 178 | IDS_FLAGS_CLOUD_PRINT_PROXY_DESCRIPTION, |
[email protected] | fa6d2a2f | 2010-11-30 21:47:19 | [diff] [blame] | 179 | #if defined(GOOGLE_CHROME_BUILD) |
| 180 | // For a Chrome build, we know we have a PDF plug-in, and so we'll |
| 181 | // enable by platform as we get things working. |
| 182 | 0, |
| 183 | #else |
| 184 | // Otherwise, where we know it could be working if a viable PDF |
| 185 | // plug-in could be supplied, we'll keep the lab enabled. |
[email protected] | 7bee0b2 | 2010-10-05 17:00:47 | [diff] [blame] | 186 | kOsWin, |
[email protected] | fa6d2a2f | 2010-11-30 21:47:19 | [diff] [blame] | 187 | #endif |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame^] | 188 | SINGLE_VALUE_TYPE(switches::kEnableCloudPrintProxy) |
[email protected] | 8b6588a | 2010-10-12 02:39:42 | [diff] [blame] | 189 | }, |
[email protected] | 580939a | 2010-10-12 18:54:37 | [diff] [blame] | 190 | { |
[email protected] | bb46153 | 2010-11-26 21:50:23 | [diff] [blame] | 191 | "crxless-web-apps", |
| 192 | IDS_FLAGS_CRXLESS_WEB_APPS_NAME, |
| 193 | IDS_FLAGS_CRXLESS_WEB_APPS_DESCRIPTION, |
| 194 | kOsAll, |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame^] | 195 | SINGLE_VALUE_TYPE(switches::kEnableCrxlessWebApps) |
[email protected] | bb46153 | 2010-11-26 21:50:23 | [diff] [blame] | 196 | }, |
| 197 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 198 | "match-preview", // FLAGS:RECORD_UMA |
[email protected] | fdf773c5 | 2010-11-01 20:58:19 | [diff] [blame] | 199 | IDS_FLAGS_PREDICTIVE_INSTANT_NAME, |
| 200 | IDS_FLAGS_PREDICTIVE_INSTANT_DESCRIPTION, |
[email protected] | cab03077 | 2010-11-03 21:37:36 | [diff] [blame] | 201 | kOsMac, |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame^] | 202 | SINGLE_VALUE_TYPE(switches::kEnablePredictiveInstant) |
[email protected] | fdf773c5 | 2010-11-01 20:58:19 | [diff] [blame] | 203 | }, |
[email protected] | 11c4c81 | 2010-10-22 19:50:12 | [diff] [blame] | 204 | // FIXME(scheib): Add Flags entry for accelerated Compositing, |
| 205 | // or pull it and the strings in generated_resources.grd by Dec 2010 |
| 206 | // { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 207 | // "gpu-compositing", |
[email protected] | 11c4c81 | 2010-10-22 19:50:12 | [diff] [blame] | 208 | // IDS_FLAGS_ACCELERATED_COMPOSITING_NAME, |
| 209 | // IDS_FLAGS_ACCELERATED_COMPOSITING_DESCRIPTION, |
| 210 | // kOsAll, |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame^] | 211 | // SINGLE_VALUE_TYPE(switches::kDisableAcceleratedCompositing) |
[email protected] | 11c4c81 | 2010-10-22 19:50:12 | [diff] [blame] | 212 | // }, |
[email protected] | 8b6588a | 2010-10-12 02:39:42 | [diff] [blame] | 213 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 214 | "gpu-canvas-2d", // FLAGS:RECORD_UMA |
[email protected] | 9486c1f | 2010-10-14 19:52:12 | [diff] [blame] | 215 | IDS_FLAGS_ACCELERATED_CANVAS_2D_NAME, |
| 216 | IDS_FLAGS_ACCELERATED_CANVAS_2D_DESCRIPTION, |
[email protected] | 1af1dfe | 2010-10-19 23:49:14 | [diff] [blame] | 217 | kOsWin | kOsLinux | kOsCrOS, |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame^] | 218 | SINGLE_VALUE_TYPE(switches::kEnableAccelerated2dCanvas) |
[email protected] | 8d260e5 | 2010-10-13 01:03:05 | [diff] [blame] | 219 | }, |
[email protected] | 11c4c81 | 2010-10-22 19:50:12 | [diff] [blame] | 220 | // FIXME(scheib): Add Flags entry for WebGL, |
| 221 | // or pull it and the strings in generated_resources.grd by Dec 2010 |
| 222 | // { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 223 | // "webgl", |
[email protected] | 11c4c81 | 2010-10-22 19:50:12 | [diff] [blame] | 224 | // IDS_FLAGS_WEBGL_NAME, |
| 225 | // IDS_FLAGS_WEBGL_DESCRIPTION, |
| 226 | // kOsAll, |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame^] | 227 | // SINGLE_VALUE_TYPE(switches::kDisableExperimentalWebGL) |
[email protected] | 11c4c81 | 2010-10-22 19:50:12 | [diff] [blame] | 228 | // } |
[email protected] | 8d260e5 | 2010-10-13 01:03:05 | [diff] [blame] | 229 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 230 | "print-preview", // FLAGS:RECORD_UMA |
[email protected] | 9486c1f | 2010-10-14 19:52:12 | [diff] [blame] | 231 | IDS_FLAGS_PRINT_PREVIEW_NAME, |
| 232 | IDS_FLAGS_PRINT_PREVIEW_DESCRIPTION, |
[email protected] | 8d260e5 | 2010-10-13 01:03:05 | [diff] [blame] | 233 | kOsAll, |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame^] | 234 | SINGLE_VALUE_TYPE(switches::kEnablePrintPreview) |
[email protected] | 2fe15fcb | 2010-10-21 20:39:53 | [diff] [blame] | 235 | }, |
| 236 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [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 | "dns-server", // FLAGS:RECORD_UMA |
[email protected] | 2fe15fcb | 2010-10-21 20:39:53 | [diff] [blame] | 245 | IDS_FLAGS_DNS_SERVER_NAME, |
| 246 | IDS_FLAGS_DNS_SERVER_DESCRIPTION, |
| 247 | kOsLinux, |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame^] | 248 | SINGLE_VALUE_TYPE(switches::kDnsServer) |
[email protected] | 2fe15fcb | 2010-10-21 20:39:53 | [diff] [blame] | 249 | }, |
[email protected] | 177aceb | 2010-11-03 16:17:41 | [diff] [blame] | 250 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 251 | "page-prerender", // FLAGS:RECORD_UMA |
[email protected] | 83d00d9 | 2010-11-04 19:20:21 | [diff] [blame] | 252 | IDS_FLAGS_PAGE_PRERENDER_NAME, |
| 253 | IDS_FLAGS_PAGE_PRERENDER_DESCRIPTION, |
| 254 | kOsAll, |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame^] | 255 | SINGLE_VALUE_TYPE(switches::kEnablePagePrerender) |
[email protected] | 83d00d9 | 2010-11-04 19:20:21 | [diff] [blame] | 256 | }, |
| 257 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 258 | "confirm-to-quit", // FLAGS:RECORD_UMA |
[email protected] | 177aceb | 2010-11-03 16:17:41 | [diff] [blame] | 259 | IDS_FLAGS_CONFIRM_TO_QUIT_NAME, |
| 260 | IDS_FLAGS_CONFIRM_TO_QUIT_DESCRIPTION, |
| 261 | kOsMac, |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame^] | 262 | SINGLE_VALUE_TYPE(switches::kEnableConfirmToQuit) |
[email protected] | 177aceb | 2010-11-03 16:17:41 | [diff] [blame] | 263 | }, |
[email protected] | 9a40ebef | 2010-11-10 17:49:13 | [diff] [blame] | 264 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 265 | "extension-apis", // FLAGS:RECORD_UMA |
[email protected] | 11dd68cd5 | 2010-11-12 01:15:32 | [diff] [blame] | 266 | IDS_FLAGS_EXPERIMENTAL_EXTENSION_APIS_NAME, |
| 267 | IDS_FLAGS_EXPERIMENTAL_EXTENSION_APIS_DESCRIPTION, |
| 268 | kOsAll, |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame^] | 269 | SINGLE_VALUE_TYPE(switches::kEnableExperimentalExtensionApis) |
[email protected] | 11dd68cd5 | 2010-11-12 01:15:32 | [diff] [blame] | 270 | }, |
[email protected] | 3627b06d | 2010-11-12 16:36:16 | [diff] [blame] | 271 | { |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 272 | "click-to-play", // FLAGS:RECORD_UMA |
[email protected] | 3627b06d | 2010-11-12 16:36:16 | [diff] [blame] | 273 | IDS_FLAGS_CLICK_TO_PLAY_NAME, |
| 274 | IDS_FLAGS_CLICK_TO_PLAY_DESCRIPTION, |
| 275 | kOsAll, |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame^] | 276 | SINGLE_VALUE_TYPE(switches::kEnableClickToPlay) |
[email protected] | 3627b06d | 2010-11-12 16:36:16 | [diff] [blame] | 277 | }, |
[email protected] | 80bd24e | 2010-11-30 09:34:38 | [diff] [blame] | 278 | { |
| 279 | "disable-hyperlink-auditing", |
| 280 | IDS_FLAGS_DISABLE_HYPERLINK_AUDITING_NAME, |
| 281 | IDS_FLAGS_DISABLE_HYPERLINK_AUDITING_DESCRIPTION, |
| 282 | kOsAll, |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame^] | 283 | SINGLE_VALUE_TYPE(switches::kNoPings) |
[email protected] | feb28fef | 2010-12-01 10:52:51 | [diff] [blame] | 284 | }, |
| 285 | { |
| 286 | "experimental-location-features", // FLAGS:RECORD_UMA |
| 287 | IDS_FLAGS_EXPERIMENTAL_LOCATION_FEATURES_NAME, |
| 288 | IDS_FLAGS_EXPERIMENTAL_LOCATION_FEATURES_DESCRIPTION, |
| 289 | kOsMac | kOsWin | kOsLinux, // Currently does nothing on CrOS. |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame^] | 290 | SINGLE_VALUE_TYPE(switches::kExperimentalLocationFeatures) |
| 291 | }, |
| 292 | { |
| 293 | "instant-type", // FLAGS:RECORD_UMA |
| 294 | IDS_FLAGS_INSTANT_TYPE_NAME, |
| 295 | IDS_FLAGS_INSTANT_TYPE_DESCRIPTION, |
| 296 | kOsWin, |
| 297 | MULTI_VALUE_TYPE(kInstantChoices) |
| 298 | }, |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 299 | }; |
| 300 | |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 301 | const Experiment* experiments = kExperiments; |
| 302 | size_t num_experiments = arraysize(kExperiments); |
| 303 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 304 | // Stores and encapsulates the little state that about:flags has. |
| 305 | class FlagsState { |
| 306 | public: |
| 307 | FlagsState() : needs_restart_(false) {} |
| 308 | void ConvertFlagsToSwitches(PrefService* prefs, CommandLine* command_line); |
| 309 | bool IsRestartNeededToCommitChanges(); |
| 310 | void SetExperimentEnabled( |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 311 | PrefService* prefs, const std::string& internal_name, bool enable); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 312 | void RemoveFlagsSwitches( |
| 313 | std::map<std::string, CommandLine::StringType>* switch_list); |
| 314 | void reset(); |
| 315 | |
| 316 | // Returns the singleton instance of this class |
| 317 | static FlagsState* instance() { |
| 318 | return Singleton<FlagsState>::get(); |
| 319 | } |
| 320 | |
| 321 | private: |
| 322 | bool needs_restart_; |
| 323 | std::set<std::string> flags_switches_; |
| 324 | |
| 325 | DISALLOW_COPY_AND_ASSIGN(FlagsState); |
| 326 | }; |
| 327 | |
[email protected] | ba816424 | 2010-11-16 21:31:00 | [diff] [blame] | 328 | #if defined(OS_CHROMEOS) |
| 329 | // Migrates Chrome OS Labs settings to experiments adding flags to enabled |
| 330 | // experiment list if the corresponding pref is on. |
| 331 | void MigrateChromeOSLabsPrefs(PrefService* prefs, |
| 332 | std::set<std::string>* result) { |
| 333 | DCHECK(prefs); |
| 334 | DCHECK(result); |
| 335 | if (prefs->GetBoolean(prefs::kLabsMediaplayerEnabled)) |
| 336 | result->insert(kMediaPlayerExperimentName); |
| 337 | if (prefs->GetBoolean(prefs::kLabsAdvancedFilesystemEnabled)) |
| 338 | result->insert(kAdvancedFileSystemExperimentName); |
| 339 | if (prefs->GetBoolean(prefs::kUseVerticalTabs)) |
| 340 | result->insert(kVerticalTabsExperimentName); |
| 341 | prefs->SetBoolean(prefs::kLabsMediaplayerEnabled, false); |
| 342 | prefs->SetBoolean(prefs::kLabsAdvancedFilesystemEnabled, false); |
| 343 | prefs->SetBoolean(prefs::kUseVerticalTabs, false); |
| 344 | } |
| 345 | #endif |
| 346 | |
[email protected] | c7b7800a | 2010-10-07 18:51:35 | [diff] [blame] | 347 | // Extracts the list of enabled lab experiments from preferences and stores them |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 348 | // in a set. |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 349 | void GetEnabledFlags(const PrefService* prefs, std::set<std::string>* result) { |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 350 | const ListValue* enabled_experiments = prefs->GetList( |
| 351 | prefs::kEnabledLabsExperiments); |
| 352 | if (!enabled_experiments) |
| 353 | return; |
| 354 | |
| 355 | for (ListValue::const_iterator it = enabled_experiments->begin(); |
| 356 | it != enabled_experiments->end(); |
| 357 | ++it) { |
| 358 | std::string experiment_name; |
| 359 | if (!(*it)->GetAsString(&experiment_name)) { |
| 360 | LOG(WARNING) << "Invalid entry in " << prefs::kEnabledLabsExperiments; |
| 361 | continue; |
| 362 | } |
| 363 | result->insert(experiment_name); |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | // Takes a set of enabled lab experiments |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 368 | void SetEnabledFlags( |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 369 | PrefService* prefs, const std::set<std::string>& enabled_experiments) { |
| 370 | ListValue* experiments_list = prefs->GetMutableList( |
| 371 | prefs::kEnabledLabsExperiments); |
| 372 | if (!experiments_list) |
| 373 | return; |
| 374 | |
| 375 | experiments_list->Clear(); |
| 376 | for (std::set<std::string>::const_iterator it = enabled_experiments.begin(); |
| 377 | it != enabled_experiments.end(); |
| 378 | ++it) { |
| 379 | experiments_list->Append(new StringValue(*it)); |
| 380 | } |
| 381 | } |
| 382 | |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame^] | 383 | // Returns the name used in prefs for the choice at the specified index. |
| 384 | std::string NameForChoice(const Experiment& e, int index) { |
| 385 | DCHECK(e.type == Experiment::MULTI_VALUE); |
| 386 | DCHECK(index < e.num_choices); |
| 387 | return std::string(e.internal_name) + about_flags::testing::kMultiSeparator + |
| 388 | base::IntToString(index); |
| 389 | } |
| 390 | |
| 391 | // Adds the internal names for the specified experiment to |names|. |
| 392 | void AddInternalName(const Experiment& e, std::set<std::string>* names) { |
| 393 | if (e.type == Experiment::SINGLE_VALUE) { |
| 394 | names->insert(e.internal_name); |
| 395 | } else { |
| 396 | DCHECK(e.type == Experiment::MULTI_VALUE); |
| 397 | for (int i = 0; i < e.num_choices; ++i) |
| 398 | names->insert(NameForChoice(e, i)); |
| 399 | } |
| 400 | } |
| 401 | |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 402 | // Removes all experiments from prefs::kEnabledLabsExperiments that are |
| 403 | // unknown, to prevent this list to become very long as experiments are added |
| 404 | // and removed. |
| 405 | void SanitizeList(PrefService* prefs) { |
| 406 | std::set<std::string> known_experiments; |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 407 | for (size_t i = 0; i < num_experiments; ++i) |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame^] | 408 | AddInternalName(experiments[i], &known_experiments); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 409 | |
| 410 | std::set<std::string> enabled_experiments; |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 411 | GetEnabledFlags(prefs, &enabled_experiments); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 412 | |
| 413 | std::set<std::string> new_enabled_experiments; |
| 414 | std::set_intersection( |
| 415 | known_experiments.begin(), known_experiments.end(), |
| 416 | enabled_experiments.begin(), enabled_experiments.end(), |
| 417 | std::inserter(new_enabled_experiments, new_enabled_experiments.begin())); |
| 418 | |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 419 | SetEnabledFlags(prefs, new_enabled_experiments); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 420 | } |
| 421 | |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 422 | void GetSanitizedEnabledFlags( |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 423 | PrefService* prefs, std::set<std::string>* result) { |
| 424 | SanitizeList(prefs); |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 425 | GetEnabledFlags(prefs, result); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 426 | } |
| 427 | |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 428 | // Variant of GetSanitizedEnabledFlags that also removes any flags that aren't |
| 429 | // enabled on the current platform. |
| 430 | void GetSanitizedEnabledFlagsForCurrentPlatform( |
| 431 | PrefService* prefs, std::set<std::string>* result) { |
| 432 | GetSanitizedEnabledFlags(prefs, result); |
| 433 | |
| 434 | // Filter out any experiments that aren't enabled on the current platform. We |
| 435 | // don't remove these from prefs else syncing to a platform with a different |
| 436 | // set of experiments would be lossy. |
| 437 | std::set<std::string> platform_experiments; |
| 438 | int current_platform = GetCurrentPlatform(); |
| 439 | for (size_t i = 0; i < num_experiments; ++i) { |
| 440 | if (experiments[i].supported_platforms & current_platform) |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame^] | 441 | AddInternalName(experiments[i], &platform_experiments); |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | std::set<std::string> new_enabled_experiments; |
| 445 | std::set_intersection( |
| 446 | platform_experiments.begin(), platform_experiments.end(), |
| 447 | result->begin(), result->end(), |
| 448 | std::inserter(new_enabled_experiments, new_enabled_experiments.begin())); |
| 449 | |
| 450 | result->swap(new_enabled_experiments); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 451 | } |
| 452 | |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame^] | 453 | // Returns the Value representing the choice data in the specified experiment. |
| 454 | // If one of the choices is enabled |is_one_selected| is set to true. |
| 455 | Value* CreateChoiceData(const Experiment& experiment, |
| 456 | const std::set<std::string>& enabled_experiments, |
| 457 | bool* is_one_selected) { |
| 458 | DCHECK(experiment.type == Experiment::MULTI_VALUE); |
| 459 | ListValue* result = new ListValue; |
| 460 | for (int i = 0; i < experiment.num_choices; ++i) { |
| 461 | const Experiment::Choice& choice = experiment.choices[i]; |
| 462 | DictionaryValue* value = new DictionaryValue; |
| 463 | std::string name = NameForChoice(experiment, i); |
| 464 | value->SetString("description", |
| 465 | l10n_util::GetStringUTF16(choice.description_id)); |
| 466 | value->SetString("internal_name", name); |
| 467 | bool is_selected = enabled_experiments.count(name) > 0; |
| 468 | if (is_selected) |
| 469 | *is_one_selected = true; |
| 470 | value->SetBoolean("selected", is_selected); |
| 471 | result->Append(value); |
| 472 | } |
| 473 | return result; |
| 474 | } |
| 475 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 476 | } // namespace |
| 477 | |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 478 | void ConvertFlagsToSwitches(PrefService* prefs, CommandLine* command_line) { |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 479 | FlagsState::instance()->ConvertFlagsToSwitches(prefs, command_line); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 480 | } |
| 481 | |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 482 | ListValue* GetFlagsExperimentsData(PrefService* prefs) { |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 483 | std::set<std::string> enabled_experiments; |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 484 | GetSanitizedEnabledFlags(prefs, &enabled_experiments); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 485 | |
| 486 | int current_platform = GetCurrentPlatform(); |
| 487 | |
| 488 | ListValue* experiments_data = new ListValue(); |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 489 | for (size_t i = 0; i < num_experiments; ++i) { |
| 490 | const Experiment& experiment = experiments[i]; |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 491 | if (!(experiment.supported_platforms & current_platform)) |
| 492 | continue; |
| 493 | |
| 494 | DictionaryValue* data = new DictionaryValue(); |
| 495 | data->SetString("internal_name", experiment.internal_name); |
| 496 | data->SetString("name", |
| 497 | l10n_util::GetStringUTF16(experiment.visible_name_id)); |
| 498 | data->SetString("description", |
| 499 | l10n_util::GetStringUTF16( |
| 500 | experiment.visible_description_id)); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 501 | |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame^] | 502 | bool enabled = enabled_experiments.count(experiment.internal_name) > 0; |
| 503 | |
| 504 | if (experiment.type == Experiment::MULTI_VALUE) { |
| 505 | data->Set("choices", CreateChoiceData(experiment, enabled_experiments, |
| 506 | &enabled)); |
| 507 | } |
| 508 | |
| 509 | data->SetBoolean("enabled", enabled); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 510 | experiments_data->Append(data); |
| 511 | } |
| 512 | return experiments_data; |
| 513 | } |
| 514 | |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 515 | bool IsRestartNeededToCommitChanges() { |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 516 | return FlagsState::instance()->IsRestartNeededToCommitChanges(); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | void SetExperimentEnabled( |
[email protected] | c7b7800a | 2010-10-07 18:51:35 | [diff] [blame] | 520 | PrefService* prefs, const std::string& internal_name, bool enable) { |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 521 | FlagsState::instance()->SetExperimentEnabled(prefs, internal_name, enable); |
| 522 | } |
| 523 | |
| 524 | void RemoveFlagsSwitches( |
| 525 | std::map<std::string, CommandLine::StringType>* switch_list) { |
| 526 | FlagsState::instance()->RemoveFlagsSwitches(switch_list); |
| 527 | } |
| 528 | |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 529 | int GetCurrentPlatform() { |
| 530 | #if defined(OS_MACOSX) |
| 531 | return kOsMac; |
| 532 | #elif defined(OS_WIN) |
| 533 | return kOsWin; |
| 534 | #elif defined(OS_CHROMEOS) // Needs to be before the OS_LINUX check. |
| 535 | return kOsCrOS; |
| 536 | #elif defined(OS_LINUX) |
| 537 | return kOsLinux; |
| 538 | #else |
| 539 | #error Unknown platform |
| 540 | #endif |
| 541 | } |
| 542 | |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 543 | void RecordUMAStatistics(const PrefService* prefs) { |
| 544 | std::set<std::string> flags; |
| 545 | GetEnabledFlags(prefs, &flags); |
| 546 | for (std::set<std::string>::iterator it = flags.begin(); it != flags.end(); |
| 547 | ++it) { |
| 548 | std::string action("AboutFlags_"); |
| 549 | action += *it; |
| 550 | UserMetrics::RecordComputedAction(action); |
| 551 | } |
| 552 | // Since flag metrics are recorded every startup, add a tick so that the |
| 553 | // stats can be made meaningful. |
| 554 | if (flags.size()) |
| 555 | UserMetrics::RecordAction(UserMetricsAction("AboutFlags_StartupTick")); |
| 556 | } |
| 557 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 558 | ////////////////////////////////////////////////////////////////////////////// |
| 559 | // FlagsState implementation. |
| 560 | |
| 561 | namespace { |
| 562 | |
| 563 | void FlagsState::ConvertFlagsToSwitches( |
| 564 | PrefService* prefs, CommandLine* command_line) { |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 565 | if (command_line->HasSwitch(switches::kNoExperiments)) |
| 566 | return; |
| 567 | |
| 568 | std::set<std::string> enabled_experiments; |
[email protected] | ba816424 | 2010-11-16 21:31:00 | [diff] [blame] | 569 | |
| 570 | #if defined(OS_CHROMEOS) |
| 571 | // Some experiments were implemented via prefs on Chrome OS and we want to |
| 572 | // seamlessly migrate these prefs to about:flags for updated users. |
| 573 | MigrateChromeOSLabsPrefs(prefs, &enabled_experiments); |
| 574 | #endif |
| 575 | |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 576 | GetSanitizedEnabledFlagsForCurrentPlatform(prefs, &enabled_experiments); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 577 | |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame^] | 578 | typedef std::map<std::string, std::string> NameToSwitchMap; |
| 579 | NameToSwitchMap name_to_switch_map; |
| 580 | for (size_t i = 0; i < num_experiments; ++i) { |
| 581 | const Experiment& e = experiments[i]; |
| 582 | if (e.type == Experiment::SINGLE_VALUE) { |
| 583 | name_to_switch_map[e.internal_name] = e.command_line; |
| 584 | } else { |
| 585 | for (int j = 0; j < e.num_choices; ++j) |
| 586 | name_to_switch_map[NameForChoice(e, j)] = e.choices[j].command_line; |
| 587 | } |
| 588 | } |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 589 | |
| 590 | command_line->AppendSwitch(switches::kFlagSwitchesBegin); |
| 591 | flags_switches_.insert(switches::kFlagSwitchesBegin); |
| 592 | for (std::set<std::string>::iterator it = enabled_experiments.begin(); |
| 593 | it != enabled_experiments.end(); |
| 594 | ++it) { |
| 595 | const std::string& experiment_name = *it; |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame^] | 596 | NameToSwitchMap::const_iterator name_to_switch_it = |
| 597 | name_to_switch_map.find(experiment_name); |
| 598 | if (name_to_switch_it == name_to_switch_map.end()) { |
| 599 | NOTREACHED(); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 600 | continue; |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame^] | 601 | } |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 602 | |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame^] | 603 | command_line->AppendSwitch(name_to_switch_it->second); |
| 604 | flags_switches_.insert(name_to_switch_it->second); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 605 | } |
| 606 | command_line->AppendSwitch(switches::kFlagSwitchesEnd); |
| 607 | flags_switches_.insert(switches::kFlagSwitchesEnd); |
| 608 | } |
| 609 | |
| 610 | bool FlagsState::IsRestartNeededToCommitChanges() { |
| 611 | return needs_restart_; |
| 612 | } |
| 613 | |
| 614 | void FlagsState::SetExperimentEnabled( |
| 615 | PrefService* prefs, const std::string& internal_name, bool enable) { |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 616 | needs_restart_ = true; |
| 617 | |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame^] | 618 | size_t at_index = internal_name.find(about_flags::testing::kMultiSeparator); |
| 619 | if (at_index != std::string::npos) { |
| 620 | DCHECK(enable); |
| 621 | // We're being asked to enable a multi-choice experiment. Disable the |
| 622 | // currently selected choice. |
| 623 | DCHECK_NE(at_index, 0u); |
| 624 | SetExperimentEnabled(prefs, internal_name.substr(0, at_index), false); |
| 625 | |
| 626 | // And enable the new choice. |
| 627 | std::set<std::string> enabled_experiments; |
| 628 | GetSanitizedEnabledFlags(prefs, &enabled_experiments); |
| 629 | enabled_experiments.insert(internal_name); |
| 630 | SetEnabledFlags(prefs, enabled_experiments); |
| 631 | return; |
| 632 | } |
| 633 | |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 634 | std::set<std::string> enabled_experiments; |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 635 | GetSanitizedEnabledFlags(prefs, &enabled_experiments); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 636 | |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame^] | 637 | const Experiment* e = NULL; |
| 638 | for (size_t i = 0; i < num_experiments; ++i) { |
| 639 | if (experiments[i].internal_name == internal_name) { |
| 640 | e = experiments + i; |
| 641 | break; |
| 642 | } |
| 643 | } |
| 644 | DCHECK(e); |
| 645 | |
| 646 | if (e->type == Experiment::SINGLE_VALUE) { |
| 647 | if (enable) |
| 648 | enabled_experiments.insert(internal_name); |
| 649 | else |
| 650 | enabled_experiments.erase(internal_name); |
| 651 | } else { |
| 652 | if (enable) { |
| 653 | // Enable the first choice. |
| 654 | enabled_experiments.insert(NameForChoice(*e, 0)); |
| 655 | } else { |
| 656 | // Find the currently enabled choice and disable it. |
| 657 | for (int i = 0; i < e->num_choices; ++i) { |
| 658 | std::string choice_name = NameForChoice(*e, i); |
| 659 | if (enabled_experiments.find(choice_name) != |
| 660 | enabled_experiments.end()) { |
| 661 | enabled_experiments.erase(choice_name); |
| 662 | // Continue on just in case there's a bug and more than one |
| 663 | // experiment for this choice was enabled. |
| 664 | } |
| 665 | } |
| 666 | } |
| 667 | } |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 668 | |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 669 | SetEnabledFlags(prefs, enabled_experiments); |
[email protected] | ad2a3ded | 2010-08-27 13:19:05 | [diff] [blame] | 670 | } |
| 671 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 672 | void FlagsState::RemoveFlagsSwitches( |
| 673 | std::map<std::string, CommandLine::StringType>* switch_list) { |
| 674 | for (std::set<std::string>::const_iterator it = flags_switches_.begin(); |
| 675 | it != flags_switches_.end(); |
| 676 | ++it) { |
| 677 | switch_list->erase(*it); |
| 678 | } |
| 679 | } |
| 680 | |
| 681 | void FlagsState::reset() { |
| 682 | needs_restart_ = false; |
| 683 | flags_switches_.clear(); |
| 684 | } |
| 685 | |
| 686 | } // namespace |
| 687 | |
| 688 | namespace testing { |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame^] | 689 | |
| 690 | // WARNING: '@' is also used in the html file. If you update this constant you |
| 691 | // also need to update the html file. |
| 692 | const char kMultiSeparator[] = "@"; |
| 693 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 694 | void ClearState() { |
| 695 | FlagsState::instance()->reset(); |
| 696 | } |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 697 | |
| 698 | void SetExperiments(const Experiment* e, size_t count) { |
| 699 | if (!e) { |
| 700 | experiments = kExperiments; |
| 701 | num_experiments = arraysize(kExperiments); |
| 702 | } else { |
| 703 | experiments = e; |
| 704 | num_experiments = count; |
| 705 | } |
| 706 | } |
| 707 | |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame^] | 708 | const Experiment* GetExperiments(size_t* count) { |
| 709 | *count = num_experiments; |
| 710 | return experiments; |
| 711 | } |
| 712 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 713 | } // namespace testing |
| 714 | |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 715 | } // namespace about_flags |