blob: 560f2e8af74c21c265c4c32d2fb09bb7382926df [file] [log] [blame] [view]
Makoto Shimazu9f0bd3a2017-08-08 01:54:241# Adding a new feature flag in chrome://flags
2
Ming-Ying Chungc23505d62022-09-22 10:07:333This document describes how to add a new Chrome feature flag visible to users
Solomon Kinard584278e2023-02-22 04:35:294via `chrome://flags` UI.
Ming-Ying Chungc23505d62022-09-22 10:07:335
6*** note
7**NOTE:** It's NOT required if you don't intend to make your feature appear in
Solomon Kinard584278e2023-02-22 04:35:298`chrome://flags` UI.
Ming-Ying Chungc23505d62022-09-22 10:07:339***
10
11See also the following for definitions:
12* [Configuration: Features](configuration.md#features)
13* [Configuration: Flags](configuration.md#flags)
Makoto Shimazu9f0bd3a2017-08-08 01:54:2414
15## Step 1: Adding a new `base::Feature`
Ming-Ying Chungc23505d62022-09-22 10:07:3316
17This step would be different depending on where you want to use the flag:
18
19### To Use the Flag in `content/` Only
20
21Add a `base::Feature` to the following files:
Makoto Shimazu9f0bd3a2017-08-08 01:54:2422
23* [content/public/common/content_features.cc](https://cs.chromium.org/chromium/src/content/public/common/content_features.cc)
24* [content/public/common/content_features.h](https://cs.chromium.org/chromium/src/content/public/common/content_features.h)
25
Ming-Ying Chungc23505d62022-09-22 10:07:3326### To Use the Flag in `third_party/blink/` (and Possibly in `content/`)
Makoto Shimazu9f0bd3a2017-08-08 01:54:2427
Ming-Ying Chungc23505d62022-09-22 10:07:3328Add a `base::Feature` to the following files:
Makoto Shimazu9f0bd3a2017-08-08 01:54:2429
Ming-Ying Chungc23505d62022-09-22 10:07:3330* [third_party/blink/common/features.cc](https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/common/features.cc)
31* [third_party/blink/public/common/features.h](https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/public/common/features.h)
32
33Historically, Blink also has its own runtime feature mechanism. So if you
34feature needs to be runtime-enabled, read also Blink's
35[Runtime Enable Features][blink-rte] doc and
36[Initialization of Blink runtime features in content layer][blink-rte-init].
37
38[blink-rte]: ../third_party/blink/renderer/platform/RuntimeEnabledFeatures.md
39
40### Examples
41
42You can refer to [this CL](https://chromium-review.googlesource.com/c/554510/)
43and [this document](initialize_blink_features.md) to see
44
451. Where to add the `base::Feature`:
46 [[1](https://chromium-review.googlesource.com/c/554510/8/content/public/common/content_features.cc#253)]
47 [[2](https://chromium-review.googlesource.com/c/554510/8/content/public/common/content_features.h)]
482. How to use it:
49 [[1](https://chromium-review.googlesource.com/c/554510/8/content/common/service_worker/service_worker_utils.cc#153)]
503. How to wire your new `base::Feature` to a Blink runtime feature:
51 [[1][blink-rte-init]]
524. How to use it in Blink:
53 [[1](https://chromium-review.googlesource.com/c/554510/8/third_party/blnk/renderere/core/workers/worker_thread.cc)]
Makoto Shimazu9f0bd3a2017-08-08 01:54:2454
Kent Tamura59ffb022018-11-27 05:30:5655Also, this patch added a virtual test for running web tests with the flag.
Makoto Shimazu9f0bd3a2017-08-08 01:54:2456When you add a flag, you can consider to use that.
57
Ming-Ying Chungc23505d62022-09-22 10:07:3358[blink-rte-init]: initialize_blink_features.md
59
Makoto Shimazu9f0bd3a2017-08-08 01:54:2460## Step 2: Adding the feature flag to the chrome://flags UI.
Nate Fischer132c1712021-09-21 20:03:3261
62*** promo
Johann Koenigbac66bc2022-11-24 05:39:1863Googlers: Read also [Chrome Feature Flag in chrome://flags](http://go/finch-feature-api#chrome-feature-flag-in-chromeflags).
Ming-Ying Chungc23505d62022-09-22 10:07:3364***
65
66*** promo
Nate Fischer132c1712021-09-21 20:03:3267**Tip:** Android WebView has its own flag UI. The WebView team recommends adding
68your features there too if they are supported on WebView. Follow
69[these steps](/android_webview/docs/developer-ui.md#Adding-your-flags-and-features-to-the-UI)
70for WebView flags.
71***
72
Andrew Moylan9b2c3b02019-02-19 14:32:5173You have to modify these five files in total.
Makoto Shimazu9f0bd3a2017-08-08 01:54:2474
75* [chrome/browser/about_flags.cc](https://cs.chromium.org/chromium/src/chrome/browser/about_flags.cc)
76* [chrome/browser/flag_descriptions.cc](https://cs.chromium.org/chromium/src/chrome/browser/flag_descriptions.cc)
77* [chrome/browser/flag_descriptions.h](https://cs.chromium.org/chromium/src/chrome/browser/flag_descriptions.h)
78* [tools/metrics/histograms/enums.xml](https://cs.chromium.org/chromium/src/tools/metrics/histograms/enums.xml)
Andrew Moylan9b2c3b02019-02-19 14:32:5179* [chrome/browser/flag-metadata.json](https://cs.chromium.org/chromium/src/chrome/browser/flag-metadata.json)
Makoto Shimazu9f0bd3a2017-08-08 01:54:2480
81At first you need to add an entry to __about_flags.cc__,
Ming-Ying Chungc23505d62022-09-22 10:07:3382__flag_descriptions.cc__ and __flag_descriptions.h__. After that, try running
83the following test.
Makoto Shimazu9f0bd3a2017-08-08 01:54:2484
85```bash
86# Build unit_tests
Max Morozf5b31fcd2018-08-10 21:55:4887autoninja -C out/Default unit_tests
Makoto Shimazu9f0bd3a2017-08-08 01:54:2488# Run AboutFlagsHistogramTest.CheckHistograms
89./out/Default/unit_tests --gtest_filter=AboutFlagsHistogramTest.CheckHistograms
Becky Zhou273cd2d52019-01-08 22:46:5890# Run AboutFlagsHistogramTest.CheckHistograms on Android
91./out/Default/bin/run_unit_tests --gtest_filter=AboutFlagsHistogramTest.CheckHistograms
Makoto Shimazu9f0bd3a2017-08-08 01:54:2492```
93
Ming-Ying Chungc23505d62022-09-22 10:07:3394That test will ask you to add several entries to enums.xml. After doing so, run
95`git cl format` which will insert the entries in enums.xml in the correct order
96and run the tests again.
97You can refer to [this CL](https://chromium-review.googlesource.com/c/593707) as
98an example.
Andrew Moylan9b2c3b02019-02-19 14:32:5199
100Finally, run the following test.
101
102```bash
103./out/Default/unit_tests --gtest_filter=AboutFlagsTest.EveryFlagHasMetadata
104```
105
106That test will ask you to update the flag expiry metadata in
107[flag-metadata.json](https://cs.chromium.org/chromium/src/chrome/browser/flag-metadata.json).
Ming-Ying Chungc23505d62022-09-22 10:07:33108
Johann Koenigccd30e52022-11-21 06:05:39109## Removing the feature flag.
110
111When a feature flag is no longer used it should be removed. Once it has reached it's final state it
112can be removed in stages.
113
114First remove the flag from the UI:
115* [chrome/browser/about_flags.cc](https://cs.chromium.org/chromium/src/chrome/browser/about_flags.cc)
116* [chrome/browser/flag_descriptions.cc](https://cs.chromium.org/chromium/src/chrome/browser/flag_descriptions.cc)
117* [chrome/browser/flag_descriptions.h](https://cs.chromium.org/chromium/src/chrome/browser/flag_descriptions.h)
118* [chrome/browser/flag-metadata.json](https://cs.chromium.org/chromium/src/chrome/browser/flag-metadata.json)
119* Do not edit enums.xml. Keep the flag for archeological purposes.
120
Solomon Kinard9cecfcf2023-06-26 22:19:59121Once there is no way to change the flag value, it's usage can be removed from the code.
Johann Koenigccd30e52022-11-21 06:05:39122
123Finally, once the flag is no longer referenced, it can be removed from content/ and
124third_party/blink/
125
Ming-Ying Chungc23505d62022-09-22 10:07:33126## Related Documents
127
128* [Chromium Feature API & Finch (Googler-only)](http://go/finch-feature-api)
129* [Configuration: Prefs, Settings, Features, Switches & Flags](configuration.md)
130* [Runtime Enabled Features](../third_party/blink/renderer/platform/RuntimeEnabledFeatures.md)
131* [Initialization of Blink runtime features in content layer](initialize_blink_features.md)