PSA: The New Two-Argument BASE_FEATURE Macro

122 views
Skip to first unread message

Xiaohan Wang (王消寒)

unread,
Aug 19, 2025, 7:18:11 PMAug 19
to chromium-dev, Alexei Svitkine, Daniel Cheng
Hello Chromium developers,

tl;dr:

Now you can write:

    BASE_FEATURE(MyFeature, base::FEATURE_ENABLED_BY_DEFAULT);

which is equivalent to:

    BASE_FEATURE(kMyFeature, "MyFeature", base::FEATURE_ENABLED_BY_DEFAULT);

Why?

In most cases, the feature name and string already match, so there's no need to type it twice. While there are legitimate reasons for them to differ, typos or mismatches can also cause confusion. The new two-argument macro simplifies feature definition and helps avoid unintended discrepancies. The existing three-argument macro will continue to be supported for cases where the name and string need to be different.

Migration

Over the next few days, I'll be running an automated script (with the help of AI) to migrate existing BASE_FEATURE definitions across the code base where the name and the string already match. Any features where the name and string do not match will not be migrated. These will be logged for further analysis as a follow-up.

If you encounter any issues related to this change or the new macro, please let me know!

The work is being tracked in https://issues.chromium.org/issues/436274260.

Thanks!
Xiaohan

Alesandro Ortiz

unread,
Aug 20, 2025, 12:02:48 AMAug 20
to Chromium-dev, Xiaohan Wang (王消寒), Alexei Svitkine, Daniel Cheng
Great idea, Xiaohan! I've wanted it to be like this for years, both from readability and writing perspective.

I left a comment on the issue regarding Code Search reference concerns which should be solvable. Ultimately want this to go forward! :)

Cheers,
Alesandro

Shezan Baig

unread,
Aug 27, 2025, 7:15:56 AM (10 days ago) Aug 27
to Chromium-dev, Alesandro Ortiz, Xiaohan Wang (王消寒), Alexei Svitkine, Daniel Cheng

Xiaohan Wang (王消寒)

unread,
Aug 27, 2025, 7:47:35 PM (9 days ago) Aug 27
to Shezan Baig, Chromium-dev, Alesandro Ortiz, Alexei Svitkine, Daniel Cheng
Thanks for the feedback and the discussions in the bug. Sorry for the inconvenience and confusion this migration caused!

I see the code search issue and we are proposing a small tweak to the API. We'll have

    BASE_FEATURE(kMyFeature, base::FEATURE_ENABLED_BY_DEFAULT);

Instead of

    BASE_FEATURE(MyFeature, base::FEATURE_ENABLED_BY_DEFAULT);

This should fix the code search issue automatically, while preserving the benefits of this change. It will also make BASE_DECLARE_FEATURE(kMyFeature) and BASE_FEATURE(kMyFeature, ...) more consistent.

I also replied with the same info (but more details) in the bug, and will start to work on this this week.

Best,
Xiaohan

Reply all
Reply to author
Forward
0 new messages