// Copyright 2023 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef COMPONENTS_OMNIBOX_BROWSER_OMNIBOX_FEATURE_CONFIGS_H_ #define COMPONENTS_OMNIBOX_BROWSER_OMNIBOX_FEATURE_CONFIGS_H_ #include "base/feature_list.h" namespace omnibox_feature_configs { /* Finch params aren't cached. Reading the params 100's of times per omnibox input significantly impacts metrics. Configs cache the params to avoid regressions. 3 steps: (1) Declare/define the config: // omnibox_feature_configs.h struct MyFeature : Config<MyFeature> { DECLARE_FEATURE(kMyFeature); MyFeature(); bool enabled; int my_param; } // omnibox_feature_configs.cc // static BASE_FEATURE(MyFeature::kMyFeature, "OmniboxMyFeature", base::FEATURE_DISABLED_BY_DEFAULT); MyFeature::MyFeature() { enabled = base::FeatureList::IsEnabled(kMyFeature); my_param = base::FeatureParam<int>(&kMyFeature, "my_param", 0).Get(); } (2) Use the config: int x = omnibox_feature_configs::MyFeature::Get().my_param; (3) Override the config in tests: omnibox_feature_configs::ScopedConfigForTesting< omnibox_feature_configs::MyFeature> scoped_config; scoped_config.Get().enabled = true; scoped_config.Get().my_param = 1; scoped_config.Reset(); scoped_config.Get().enabled = true; scoped_config.Get().my_param = 2; instead of: base::test::ScopedFeatureList scoped_feature_list; scoped_feature_list_.InitAndEnableFeatureWithParameters( omnibox_feature_configs::MyFeature::kMyFeature, {{"my_param", "1"}}); scoped_feature_list.Reset(); scoped_feature_list_.InitAndEnableFeatureWithParameters( omnibox_feature_configs::MyFeature::kMyFeature, {{"my_param", "2"}}); */ // A substitute for `BASE_DECLARE_FEATURE` for nesting in structs. #define DECLARE_FEATURE … // Base class other configs should inherit from. template <class T> class Config { … }; // Util for overriding configs in tests. template <class T> class ScopedConfigForTesting : Config<T> { … }; // Add new configs below, ordered alphabetically. // If enabled, adds recent calc suggestions. struct CalcProvider : Config<CalcProvider> { … }; // If enabled, allow document provider requests when all other conditions are // met. struct DocumentProvider : Config<DocumentProvider> { … }; // If enabled, pretends all matches are allowed to be default. This is very // blunt, and needs refining before being launch ready. E.g. how does this // affect transferred matches? This might cause crashes. This can result in // misleading inline autocompletion; e.g. the bing.com favicon looks like the // search loupe, so inlined bing results will like DSE search suggestions. struct ForceAllowedToBeDefault : Config<ForceAllowedToBeDefault> { … }; // If enabled, only suggestions from the keyword mode provider and historical // keyword mode suggestions will be shown in keyword mode. struct LimitKeywordModeSuggestions : Config<LimitKeywordModeSuggestions> { … }; // If enabled, NTP Realbox second column will allow displaying contextual and // trending suggestions. struct RealboxContextualAndTrendingSuggestions : Config<RealboxContextualAndTrendingSuggestions> { … }; // If enabled, omnibox reports the number of zero-prefix suggestions shown in // the session which ends when autocomplete clears the set of results. The // current behavior incorrectly reports the number of zero-prefix suggestions in // the last set of results, which would be 0 for non-zps queries. struct ReportNumZPSInSession : Config<ReportNumZPSInSession> { … }; // If enabled, uses RichAnswerTemplate instead of SuggestionAnswer to display // answers. struct SuggestionAnswerMigration : Config<SuggestionAnswerMigration> { … }; // If enabled, the shortcut provider is more aggressive in scoring. struct ShortcutBoosting : Config<ShortcutBoosting> { … }; // If enabled, affects autocompleted keywords (e.g. input 'youtu Ispiryan' -> // match 'Ispiryan - Search YouTube'). // 1) These autocompleted keywords will be scored `score` instead of the default // 450. // 2) Autocompletes keyword even when the full keyword is typed ('youtube.com'). // Otherwise, only incomplete keywords ('youtube.co') are autocompleted. struct VitalizeAutocompletedKeywords : Config<VitalizeAutocompletedKeywords> { … }; // Do not add new configs here at the bottom by default. They should be ordered // alphabetically. #undef DECLARE_FEATURE } // namespace omnibox_feature_configs #endif // COMPONENTS_OMNIBOX_BROWSER_OMNIBOX_FEATURE_CONFIGS_H_