blob: 8642fd3f867480c1b6aef18e5872ff3b9eaf33e9 [file] [log] [blame] [view]
Makoto Shimazu9f0bd3a2017-08-08 01:54:241# Adding a new feature flag in chrome://flags
2
3This document describes how to add your new feature behind a flag.
4
5## Step 1: Adding a new `base::Feature`
6This step would be different between where you want to use the flag.
7For example, if you want to use the flag in src/content, you should add a base::Feature to the following files:
8
9* [content/public/common/content_features.cc](https://cs.chromium.org/chromium/src/content/public/common/content_features.cc)
10* [content/public/common/content_features.h](https://cs.chromium.org/chromium/src/content/public/common/content_features.h)
11
12If you want to use the flag in blink, you should also read
13[Runtime Enable Features](https://www.chromium.org/blink/runtime-enabled-features).
14
15You can refer to [this CL](https://chromium-review.googlesource.com/c/554510/)
16to see
17
181. where to add the base::Feature
19[[1](https://chromium-review.googlesource.com/c/554510/8/content/public/common/content_features.cc#253)]
20[[2](https://chromium-review.googlesource.com/c/554510/8/content/public/common/content_features.h)]
212. how to use it
22[[1](https://chromium-review.googlesource.com/c/554510/8/content/common/service_worker/service_worker_utils.cc#153)]
233. how to wire the base::Feature to WebRuntimeFeatures
24[[1](https://chromium-review.googlesource.com/c/554510/8/content/child/runtime_features.cc)]
Kent Tamura6943cf792018-04-09 05:24:5425[[2](https://chromium-review.googlesource.com/c/554510/8/third_party/blink/public/platform/web_runtime_features.h)]
26[[3](https://chromium-review.googlesource.com/c/554510/third_party/blink/Source/platform/exported/web_runtime_features.cc)]
27[[4](https://chromium-review.googlesource.com/c/554510/8/third_party/blink/renderer/platform/runtime_enabled_features.json5)]
Makoto Shimazu9f0bd3a2017-08-08 01:54:24284. how to use it in blink
Kent Tamura6943cf792018-04-09 05:24:5429[[1](https://chromium-review.googlesource.com/c/554510/8/third_party/blnk/renderere/core/workers/worker_thread.cc)]
Makoto Shimazu9f0bd3a2017-08-08 01:54:2430
31Also, this patch added a virtual test for running layout tests with the flag.
32When you add a flag, you can consider to use that.
33
34## Step 2: Adding the feature flag to the chrome://flags UI.
35You have to modify these four files in total.
36
37* [chrome/browser/about_flags.cc](https://cs.chromium.org/chromium/src/chrome/browser/about_flags.cc)
38* [chrome/browser/flag_descriptions.cc](https://cs.chromium.org/chromium/src/chrome/browser/flag_descriptions.cc)
39* [chrome/browser/flag_descriptions.h](https://cs.chromium.org/chromium/src/chrome/browser/flag_descriptions.h)
40* [tools/metrics/histograms/enums.xml](https://cs.chromium.org/chromium/src/tools/metrics/histograms/enums.xml)
41
42At first you need to add an entry to __about_flags.cc__,
43__flag_descriptions.cc__ and __flag_descriptions.h__. After that, try running the following test.
44
45```bash
46# Build unit_tests
Max Morozf5b31fcd2018-08-10 21:55:4847autoninja -C out/Default unit_tests
Makoto Shimazu9f0bd3a2017-08-08 01:54:2448# Run AboutFlagsHistogramTest.CheckHistograms
49./out/Default/unit_tests --gtest_filter=AboutFlagsHistogramTest.CheckHistograms
50```
51
52That test will ask you to add several entries to enums.xml.
53You can refer to [this CL](https://chromium-review.googlesource.com/c/593707) as an example.