blob: fb24e4f2ff20e3a1b6925111094dac0c5ec375f6 [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
4via chrome://flag UI.
5
6*** note
7**NOTE:** It's NOT required if you don't intend to make your feature appear in
8chrome://flag UI.
9***
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
Ming-Ying Chungc23505d62022-09-22 10:07:3363Googlers: Read also [Chrome Feature Flag in chrome://flags](http/go/finch-feature-api#chrome-feature-flag-in-chromeflags).
64***
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
109## Related Documents
110
111* [Chromium Feature API & Finch (Googler-only)](http://go/finch-feature-api)
112* [Configuration: Prefs, Settings, Features, Switches & Flags](configuration.md)
113* [Runtime Enabled Features](../third_party/blink/renderer/platform/RuntimeEnabledFeatures.md)
114* [Initialization of Blink runtime features in content layer](initialize_blink_features.md)