Makoto Shimazu | 9f0bd3a | 2017-08-08 01:54:24 | [diff] [blame] | 1 | # Adding a new feature flag in chrome://flags |
| 2 | |
| 3 | This document describes how to add your new feature behind a flag. |
| 4 | |
| 5 | ## Step 1: Adding a new `base::Feature` |
| 6 | This step would be different between where you want to use the flag. |
| 7 | For 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 | |
| 12 | If 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 | |
| 15 | You can refer to [this CL](https://chromium-review.googlesource.com/c/554510/) |
| 16 | to see |
| 17 | |
| 18 | 1. 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)] |
| 21 | 2. how to use it |
| 22 | [[1](https://chromium-review.googlesource.com/c/554510/8/content/common/service_worker/service_worker_utils.cc#153)] |
| 23 | 3. how to wire the base::Feature to WebRuntimeFeatures |
| 24 | [[1](https://chromium-review.googlesource.com/c/554510/8/content/child/runtime_features.cc)] |
Kent Tamura | 6943cf79 | 2018-04-09 05:24:54 | [diff] [blame] | 25 | [[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 Shimazu | 9f0bd3a | 2017-08-08 01:54:24 | [diff] [blame] | 28 | 4. how to use it in blink |
Kent Tamura | 6943cf79 | 2018-04-09 05:24:54 | [diff] [blame] | 29 | [[1](https://chromium-review.googlesource.com/c/554510/8/third_party/blnk/renderere/core/workers/worker_thread.cc)] |
Makoto Shimazu | 9f0bd3a | 2017-08-08 01:54:24 | [diff] [blame] | 30 | |
| 31 | Also, this patch added a virtual test for running layout tests with the flag. |
| 32 | When you add a flag, you can consider to use that. |
| 33 | |
| 34 | ## Step 2: Adding the feature flag to the chrome://flags UI. |
| 35 | You 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 | |
| 42 | At 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 Moroz | f5b31fcd | 2018-08-10 21:55:48 | [diff] [blame] | 47 | autoninja -C out/Default unit_tests |
Makoto Shimazu | 9f0bd3a | 2017-08-08 01:54:24 | [diff] [blame] | 48 | # Run AboutFlagsHistogramTest.CheckHistograms |
| 49 | ./out/Default/unit_tests --gtest_filter=AboutFlagsHistogramTest.CheckHistograms |
| 50 | ``` |
| 51 | |
| 52 | That test will ask you to add several entries to enums.xml. |
| 53 | You can refer to [this CL](https://chromium-review.googlesource.com/c/593707) as an example. |