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