Elly Fong-Jones | bf59dbb | 2019-02-15 18:01:27 | [diff] [blame] | 1 | # Configuration: Prefs, Settings, Features, Switches & Flags |
| 2 | |
| 3 | This document outlines all the runtime configuration surfaces of Chromium, |
| 4 | and discusses appropriate uses and standard patterns for each of them. Some of |
| 5 | these are intended for use by users, some by developers, and some by system |
| 6 | administrators. |
| 7 | |
Ming-Ying Chung | c23505d6 | 2022-09-22 10:07:33 | [diff] [blame] | 8 | [TOC] |
| 9 | |
Elly Fong-Jones | bf59dbb | 2019-02-15 18:01:27 | [diff] [blame] | 10 | ## Prefs |
| 11 | |
| 12 | Example: prefs::kAllowDinosaurEasterEgg aka "allow_dinosaur_easter_egg" |
| 13 | |
| 14 | Prefs are implemented by registering them with a central pref service, usually |
| 15 | via [Profile::RegisterProfilePrefs][profile-register]. They store typed values, |
| 16 | which persist across restarts and may be synced between browser instances via |
| 17 | the Sync service. There are several pref stores, which are documented in detail |
| 18 | in the [prefs docs][prefs]. They can be directly configured via enterprise |
| 19 | policy. |
| 20 | |
| 21 | Prefs: |
| 22 | |
| 23 | * *Are not* directly surfaced to the user |
| 24 | * *Are not* localized into the user's language |
Christian Flach | 35ff4d4c | 2023-09-12 15:08:56 | [diff] [blame] | 25 | * *Are* configurable via enterprise policy if a policy exists for the pref |
| 26 | (there is no catch-all policy that allows setting arbitrary prefs) |
Elly Fong-Jones | bf59dbb | 2019-02-15 18:01:27 | [diff] [blame] | 27 | * *Are not* reported via UMA when in use |
| 28 | * *Are not* included in chrome://version |
| 29 | * *Are* automatically persistent across restarts (usually) |
| 30 | |
| 31 | ## Features |
| 32 | |
| 33 | Example: base::kDCheckIsFatalFeature |
| 34 | |
| 35 | These are implemented via creating a [base::Feature][base-feature] anywhere. |
| 36 | These can be enabled via server-side experimentation or via the command-line |
Owen Min | 3e52abb9 | 2021-04-16 19:55:02 | [diff] [blame] | 37 | using "--enable-features". Which features are in use is tracked by UMA metrics, |
Elly Fong-Jones | bf59dbb | 2019-02-15 18:01:27 | [diff] [blame] | 38 | and is visible in chrome://version as the "Variations" field. Do note that in |
| 39 | release builds, only a series of hashes show up in chrome://version rather than |
| 40 | the string names of the variations, but these hashes can be turned back into |
| 41 | string names if needed. This is done by consulting [the testing |
| 42 | config][fieldtrial-config] for Chromium builds, or a Google-internal tool for |
| 43 | Chrome builds. |
| 44 | |
| 45 | *Features are the best way to add runtime conditional behavior.* |
| 46 | |
| 47 | Features: |
| 48 | |
| 49 | * *Are not* directly surfaced to the user |
| 50 | * *Are not* localized into the user's language |
| 51 | * *Are not* configurable via enterprise policy |
| 52 | * *Are* reported via UMA/crash when in use |
| 53 | * *Are* included in chrome://version |
| 54 | * *Are not* automatically persistent across restarts |
| 55 | |
| 56 | ## Switches |
| 57 | |
| 58 | Example: switches::kIncognito aka "--incognito" |
| 59 | |
| 60 | These are implemented by testing anywhere in the codebase for the presence or |
| 61 | value of a switch in [base::CommandLine::ForCurrentProcess][base-commandline]. |
| 62 | There is no centralized registry of switches and they can be used for |
| 63 | essentially any purpose. |
| 64 | |
| 65 | Switches: |
| 66 | |
| 67 | * *Are not* directly surfaced to the user |
| 68 | * *Are not* localized into the user's language |
Elly Fong-Jones | 2af8c72 | 2023-05-12 14:47:14 | [diff] [blame] | 69 | * *Are not* configurable via enterprise policy (except on Chrome OS, via FeatureFlagsProto) |
Elly Fong-Jones | bf59dbb | 2019-02-15 18:01:27 | [diff] [blame] | 70 | * *Are not* reported via UMA when in use |
| 71 | * *Are* included in chrome://version |
| 72 | * *Are not* automatically persistent across restarts |
| 73 | |
| 74 | In general, switches are inferior to use of base::Feature, which has the same |
| 75 | capabilities and low engineering overhead but ties into UMA reporting. New code |
| 76 | should use base::Feature instead of switches. An exception to this is when the |
| 77 | configuration value is a string, since features can't take an arbitrary string |
| 78 | value. |
| 79 | |
| 80 | ## Flags |
| 81 | |
Corentin Wallez | e660b15 | 2020-07-15 16:07:54 | [diff] [blame] | 82 | Example: chrome://flags/#ignore-gpu-blocklist |
Elly Fong-Jones | bf59dbb | 2019-02-15 18:01:27 | [diff] [blame] | 83 | |
| 84 | These are implemented by adding an entry in [about_flags.cc][about-flags] |
| 85 | describing the flag, as well as metadata in [flag-metadata][flag-metadata]. |
| 86 | Flags have a name and description, and show up in chrome://flags. Flags also |
| 87 | have an expiration milestone, after which they will be hidden from that UI and |
| 88 | disabled, then later removed. Flags are backed by either a feature or a set of |
| 89 | switches, which they enable at browser startup depending on the value of the |
| 90 | flag. |
| 91 | |
| 92 | Flags should usually be temporary, to allow for pre-launch testing of a feature. |
| 93 | Permanent flags (those with expiration -1) should only be used when either: |
| 94 | |
| 95 | * The flag is regularly used for support/debugging purposes, by asking users to |
Corentin Wallez | e660b15 | 2020-07-15 16:07:54 | [diff] [blame] | 96 | flip it to eliminate a possible problem (such as ignore-gpu-blocklist) |
Elly Fong-Jones | bf59dbb | 2019-02-15 18:01:27 | [diff] [blame] | 97 | * The flag is used for ongoing QA/test purposes in environments where command-line |
| 98 | switches can't be used (e.g. on mobile) |
| 99 | |
| 100 | "Users might need to turn the feature on/off" is not a sufficient justification |
| 101 | for a permanent flag. If at all possible, we should design features such that |
| 102 | users don't want or need to turn them off, but if we need to retain that choice, |
| 103 | we should promote it to a full setting (see below) with translations and |
| 104 | support. "Developers/QA might need to turn the feature on/off", on the other |
| 105 | hand, is justification for a permanent flag. |
| 106 | |
| 107 | Flags: |
| 108 | |
| 109 | * *Are* directly surfaced to the user |
| 110 | * *Are not* localized into the user's language |
Owen Min | 4de6332 | 2023-07-17 19:11:57 | [diff] [blame] | 111 | * *Are not* configurable via enterprise policy |
Elly Fong-Jones | bf59dbb | 2019-02-15 18:01:27 | [diff] [blame] | 112 | * *Are* reported via UMA when in use (via Launch.FlagsAtStartup) |
| 113 | * *Are not* included in chrome://version |
| 114 | * *Are* automatically persistent across restarts |
| 115 | |
| 116 | ## Settings |
| 117 | |
| 118 | Example: "Show home button" |
| 119 | |
| 120 | Settings are implemented in WebUI, and show up in chrome://settings or one of |
| 121 | its subpages. They generally are bound to a pref which stores the value of that |
| 122 | setting. These are comparatively expensive to add, since they require |
| 123 | localization and some amount of UX involvement to figure out how to fit them |
| 124 | into chrome://settings, plus documentation and support material. Many settings |
| 125 | are implemented via prefs, but not all prefs correspond to settings; some are |
| 126 | used for tracking internal browser state across restarts. |
| 127 | |
| 128 | Settings: |
| 129 | |
| 130 | * *Are* directly surfaced to the user |
| 131 | * *Are* localized into the user's language |
| 132 | * *Are not* configurable via enterprise policy (but their backing prefs may be) |
| 133 | * *Are not* reported via UMA when in use |
| 134 | * *Are not* included in chrome://version |
| 135 | * *Are* automatically persistent across restarts (via their backing prefs) |
| 136 | |
| 137 | You should add a setting if end-users might want to change this behavior. A |
| 138 | decent litmus test for whether something should be a flag or a setting is: "will |
| 139 | someone who can't read or write code want to change this?" |
| 140 | |
Jan Kosiaty | b9f32ae | 2023-05-12 05:37:32 | [diff] [blame] | 141 | ## Summary Table |
| 142 | | | Prefs | Features | Switches | Flags | Settings | |
| 143 | | :- | :- | :- | :--: | :--: | :- | |
| 144 | | Directly surfaced to the user | ❌ | ❌ | ❌ | ✅ | ✅ | |
| 145 | | Localized into the user's language | ❌ | ❌ | ❌ | ❌ | ✅ | |
Christian Flach | 35ff4d4c | 2023-09-12 15:08:56 | [diff] [blame] | 146 | | Configurable via enterprise policy | ✅ if a policy<br>maps to the pref | ❌ | ❌ except on ChromeOS | ❌ | ❌ but their backing prefs may be | |
Jan Kosiaty | b9f32ae | 2023-05-12 05:37:32 | [diff] [blame] | 147 | | Reported when in use | ❌ | via UMA/crash | ❌ | via UMA<br> `Launch.FlagsAtStartup` | ❌ | |
| 148 | | Included in chrome://version | ❌ | ✅ | ✅ | ❌ | ❌ | |
| 149 | | Automatically persistent<br> across restarts | ✅ usually | ❌ | ❌ | ✅ | ✅ via backing prefs | |
| 150 | |
Ming-Ying Chung | c23505d6 | 2022-09-22 10:07:33 | [diff] [blame] | 151 | ## Related Documents |
| 152 | |
| 153 | * [Chromium Feature API & Finch (Googler-only)](http://go/finch-feature-api) |
| 154 | * [Adding a new feature flag in chrome://flags](how_to_add_your_feature_flag.md) |
| 155 | * [Runtime Enabled Features](../third_party/blink/renderer/platform/RuntimeEnabledFeatures.md) |
| 156 | * [Initialization of Blink runtime features in content layer](initialize_blink_features.md) |
| 157 | * [Integrating a feature with the origin trials framework](origin_trials_integration.md) |
| 158 | |
Elly Fong-Jones | bf59dbb | 2019-02-15 18:01:27 | [diff] [blame] | 159 | [base-commandline]: https://cs.chromium.org/chromium/src/base/command_line.h?type=cs&l=98 |
| 160 | [base-feature]: https://cs.chromium.org/chromium/src/base/feature_list.h?sq=package:chromium&g=0&l=53 |
| 161 | [about-flags]: https://cs.chromium.org/chromium/src/chrome/browser/about_flags.cc |
| 162 | [fieldtrial-config]: https://cs.chromium.org/chromium/src/testing/variations/fieldtrial_testing_config.json |
| 163 | [flag-metadata]: https://cs.chromium.org/chromium/src/chrome/browser/flag-metadata.json |
| 164 | [prefs]: https://www.chromium.org/developers/design-documents/preferences |
Ming-Ying Chung | c23505d6 | 2022-09-22 10:07:33 | [diff] [blame] | 165 | [profile-register]: https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/profiles/profile.h;l=189;drc=b0378e4b67a5dbdb15acf0341ccd51acda81c8e0 |