the Chromium logo

The Chromium Projects

C++ Prefs

Prefs is a system for storing configuration data keyed to the user session (i.e. the sorts of data that would be stored in config files in most other software projects). Although originally designed for storing Chrome's user preferences, it now sees use more generally to store all sorts of feature data. It is capable of representing any JSON data structure (strings, numbers, booleans, lists, mappings -- see base::Value).

Prefs are not meant to store large collections of data, which could result in a large memory overhead. See more here.

All prefs need to be registered by a PrefRegistry, which is often triggered by BrowserContextKeyedServiceFactory::RegisterProfilePrefs().

For prefs to be recognized in the ChromeOS UI, the pref name must be added to GetAllowlistedKeys() in

Active prefs can be viewed on Chromebooks by entering chrome://prefs-internals and chrome://local-state into the Chrome tab search bar to view active Profile Prefs and Local State Prefs, respectively.

To learn more about using Prefs to write code, see go/chromium-cookbook-policy-prefs. If you'd like to understand prefs more deeply, read "User Sessions".