This document describes how to add your new feature behind a flag. See also Configuration, which gives more explanation about flags and other options for configuring Chrome.
This step would be different between where you want to use the flag. For example, if you want to use the flag in src/content, you should add a base::Feature to the following files:
If you want to use the flag in blink, you should also read Runtime Enable Features.
You can refer to this CL and this document to see
- where to add the base::Feature [1] [2]
- how to use it [1]
- how to wire your new base::Feature to a blink runtime feature[1]
- how to use it in blink [1]
Also, this patch added a virtual test for running web tests with the flag. When you add a flag, you can consider to use that.
*** promo Tip: Android WebView has its own flag UI. The WebView team recommends adding your features there too if they are supported on WebView. Follow these steps for WebView flags.
You have to modify these five files in total.
- chrome/browser/about_flags.cc
- chrome/browser/flag_descriptions.cc
- chrome/browser/flag_descriptions.h
- tools/metrics/histograms/enums.xml
- chrome/browser/flag-metadata.json
At first you need to add an entry to about_flags.cc, flag_descriptions.cc and flag_descriptions.h. After that, try running the following test.
# Build unit_tests
autoninja -C out/Default unit_tests
# Run AboutFlagsHistogramTest.CheckHistograms
./out/Default/unit_tests --gtest_filter=AboutFlagsHistogramTest.CheckHistograms
# Run AboutFlagsHistogramTest.CheckHistograms on Android
./out/Default/bin/run_unit_tests --gtest_filter=AboutFlagsHistogramTest.CheckHistograms
That test will ask you to add several entries to enums.xml. After doing so, run git cl format
which will insert the entries in enums.xml in the correct order and run the tests again.
You can refer to this CL as an example.
Finally, run the following test.
./out/Default/unit_tests --gtest_filter=AboutFlagsTest.EveryFlagHasMetadata
That test will ask you to update the flag expiry metadata in flag-metadata.json.