Created
December 8, 2024 08:46
-
-
Save mushoku-ningen/e5da3288239580b11d8868a195124667 to your computer and use it in GitHub Desktop.
change omnibox (the suggestions in the search bar) max matches to 40 (change 40 if needed) in chromium source code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/components/omnibox/browser/autocomplete_result.cc b/components/omnibox/browser/autocomplete_result.cc | |
index db1188aed745e..9e51a1bcf8f9a 100644 | |
--- a/components/omnibox/browser/autocomplete_result.cc | |
+++ b/components/omnibox/browser/autocomplete_result.cc | |
@@ -89,75 +89,80 @@ constexpr size_t kMaxPedalMatchIndex = | |
// static | |
size_t AutocompleteResult::GetMaxMatches(bool is_zero_suggest) { | |
- constexpr size_t kDefaultMaxAutocompleteMatches = | |
- is_android ? 10 : (is_ios ? 10 : 8); | |
- constexpr size_t kDefaultMaxZeroSuggestMatches = | |
- is_android ? 15 : (is_ios ? 20 : 8); | |
-#if BUILDFLAG(IS_IOS) | |
- // By default, iPad has the same max as iPhone. | |
- // `kDefaultMaxAutocompleteMatches` defines a hard limit on the number of | |
- // autocomplete suggestions on iPad, so if an experiment defines | |
- // MaxZeroSuggestMatches to 15, it would be 15 on iPhone and 10 on iPad. | |
- constexpr size_t kMaxAutocompleteMatchesOnIPad = 10; | |
- // By default, iPad has the same max as iPhone. `kMaxZeroSuggestMatchesOnIPad` | |
- // defines a hard limit on the number of ZPS suggestions on iPad, so if an | |
- // experiment defines MaxZeroSuggestMatches to 15, it would be 15 on iPhone | |
- // and 10 on iPad. | |
- constexpr size_t kMaxZeroSuggestMatchesOnIPad = 10; | |
-#endif | |
- static_assert(kMaxAutocompletePositionValue > kDefaultMaxAutocompleteMatches, | |
- "kMaxAutocompletePositionValue must be larger than the largest " | |
- "possible autocomplete result size."); | |
- static_assert(kMaxAutocompletePositionValue > kDefaultMaxZeroSuggestMatches, | |
- "kMaxAutocompletePositionValue must be larger than the largest " | |
- "possible zero suggest autocomplete result size."); | |
- static_assert(kDefaultMaxAutocompleteMatches != 0, | |
- "Default number of suggestions must be non-zero"); | |
- static_assert(kDefaultMaxZeroSuggestMatches != 0, | |
- "Default number of zero-prefix suggestions must be non-zero"); | |
- | |
- // If we're interested in the zero suggest match limit, and one has been | |
- // specified, return it. | |
- if (is_zero_suggest) { | |
- size_t field_trial_value = base::GetFieldTrialParamByFeatureAsInt( | |
- omnibox::kMaxZeroSuggestMatches, | |
- OmniboxFieldTrial::kMaxZeroSuggestMatchesParam, | |
- kDefaultMaxZeroSuggestMatches); | |
- DCHECK(kMaxAutocompletePositionValue > field_trial_value); | |
-#if BUILDFLAG(IS_IOS) | |
- if (ui::GetDeviceFormFactor() == ui::DEVICE_FORM_FACTOR_TABLET) { | |
- field_trial_value = | |
- std::min(field_trial_value, kMaxZeroSuggestMatchesOnIPad); | |
- } | |
-#endif | |
- return field_trial_value; | |
- } | |
- | |
- // Otherwise, i.e. if no zero suggest specific limit has been specified or | |
- // the input is not from omnibox focus, return the general max matches limit. | |
- size_t field_trial_value = base::GetFieldTrialParamByFeatureAsInt( | |
- omnibox::kUIExperimentMaxAutocompleteMatches, | |
- OmniboxFieldTrial::kUIMaxAutocompleteMatchesParam, | |
- kDefaultMaxAutocompleteMatches); | |
- DCHECK(kMaxAutocompletePositionValue > field_trial_value); | |
-#if BUILDFLAG(IS_IOS) | |
- if (ui::GetDeviceFormFactor() == ui::DEVICE_FORM_FACTOR_TABLET) { | |
- field_trial_value = | |
- std::min(field_trial_value, kMaxAutocompleteMatchesOnIPad); | |
- } | |
-#endif | |
- return field_trial_value; | |
+ return 40; | |
+ | |
+// constexpr size_t kDefaultMaxAutocompleteMatches = | |
+// is_android ? 10 : (is_ios ? 10 : 8); | |
+// constexpr size_t kDefaultMaxZeroSuggestMatches = | |
+// is_android ? 15 : (is_ios ? 20 : 8); | |
+//#if BUILDFLAG(IS_IOS) | |
+// // By default, iPad has the same max as iPhone. | |
+// // `kDefaultMaxAutocompleteMatches` defines a hard limit on the number of | |
+// // autocomplete suggestions on iPad, so if an experiment defines | |
+// // MaxZeroSuggestMatches to 15, it would be 15 on iPhone and 10 on iPad. | |
+// constexpr size_t kMaxAutocompleteMatchesOnIPad = 10; | |
+// // By default, iPad has the same max as iPhone. `kMaxZeroSuggestMatchesOnIPad` | |
+// // defines a hard limit on the number of ZPS suggestions on iPad, so if an | |
+// // experiment defines MaxZeroSuggestMatches to 15, it would be 15 on iPhone | |
+// // and 10 on iPad. | |
+// constexpr size_t kMaxZeroSuggestMatchesOnIPad = 10; | |
+//#endif | |
+// static_assert(kMaxAutocompletePositionValue > kDefaultMaxAutocompleteMatches, | |
+// "kMaxAutocompletePositionValue must be larger than the largest " | |
+// "possible autocomplete result size."); | |
+// static_assert(kMaxAutocompletePositionValue > kDefaultMaxZeroSuggestMatches, | |
+// "kMaxAutocompletePositionValue must be larger than the largest " | |
+// "possible zero suggest autocomplete result size."); | |
+// static_assert(kDefaultMaxAutocompleteMatches != 0, | |
+// "Default number of suggestions must be non-zero"); | |
+// static_assert(kDefaultMaxZeroSuggestMatches != 0, | |
+// "Default number of zero-prefix suggestions must be non-zero"); | |
+// | |
+// // If we're interested in the zero suggest match limit, and one has been | |
+// // specified, return it. | |
+// if (is_zero_suggest) { | |
+// size_t field_trial_value = base::GetFieldTrialParamByFeatureAsInt( | |
+// omnibox::kMaxZeroSuggestMatches, | |
+// OmniboxFieldTrial::kMaxZeroSuggestMatchesParam, | |
+// kDefaultMaxZeroSuggestMatches); | |
+// DCHECK(kMaxAutocompletePositionValue > field_trial_value); | |
+//#if BUILDFLAG(IS_IOS) | |
+// if (ui::GetDeviceFormFactor() == ui::DEVICE_FORM_FACTOR_TABLET) { | |
+// field_trial_value = | |
+// std::min(field_trial_value, kMaxZeroSuggestMatchesOnIPad); | |
+// } | |
+//#endif | |
+// printf("log1 %zu\n",field_trial_value); | |
+// return field_trial_value; | |
+// } | |
+// | |
+// // Otherwise, i.e. if no zero suggest specific limit has been specified or | |
+// // the input is not from omnibox focus, return the general max matches limit. | |
+// size_t field_trial_value = base::GetFieldTrialParamByFeatureAsInt( | |
+// omnibox::kUIExperimentMaxAutocompleteMatches, | |
+// OmniboxFieldTrial::kUIMaxAutocompleteMatchesParam, | |
+// kDefaultMaxAutocompleteMatches); | |
+// DCHECK(kMaxAutocompletePositionValue > field_trial_value); | |
+//#if BUILDFLAG(IS_IOS) | |
+// if (ui::GetDeviceFormFactor() == ui::DEVICE_FORM_FACTOR_TABLET) { | |
+// field_trial_value = | |
+// std::min(field_trial_value, kMaxAutocompleteMatchesOnIPad); | |
+// } | |
+//#endif | |
+// printf("log %zu\n",field_trial_value); | |
+// return field_trial_value; | |
} | |
// static | |
size_t AutocompleteResult::GetDynamicMaxMatches() { | |
- constexpr const int kDynamicMaxMatchesLimit = is_android ? 15 : 10; | |
- if (!base::FeatureList::IsEnabled(omnibox::kDynamicMaxAutocomplete)) | |
- return AutocompleteResult::GetMaxMatches(); | |
- return base::GetFieldTrialParamByFeatureAsInt( | |
- omnibox::kDynamicMaxAutocomplete, | |
- OmniboxFieldTrial::kDynamicMaxAutocompleteIncreasedLimitParam, | |
- kDynamicMaxMatchesLimit); | |
+ return 40; | |
+// constexpr const int kDynamicMaxMatchesLimit = is_android ? 15 : 10; | |
+// if (!base::FeatureList::IsEnabled(omnibox::kDynamicMaxAutocomplete)) | |
+// return AutocompleteResult::GetMaxMatches(); | |
+// return base::GetFieldTrialParamByFeatureAsInt( | |
+// omnibox::kDynamicMaxAutocomplete, | |
+// OmniboxFieldTrial::kDynamicMaxAutocompleteIncreasedLimitParam, | |
+// kDynamicMaxMatchesLimit); | |
} | |
AutocompleteResult::AutocompleteResult() { | |
diff --git a/components/omnibox/browser/search_provider.cc b/components/omnibox/browser/search_provider.cc | |
index 3e5401f386e35..eaf4e8c754cc0 100644 | |
--- a/components/omnibox/browser/search_provider.cc | |
+++ b/components/omnibox/browser/search_provider.cc | |
@@ -1070,7 +1070,7 @@ void SearchProvider::ConvertResultsToAutocompleteMatches() { | |
size_t num_suggestions = 0; | |
for (ACMatches::const_iterator i(matches.begin()); | |
(i != matches.end()) && | |
- (matches_.size() < AutocompleteResult::GetDynamicMaxMatches()); | |
+ (matches_.size() < 40); | |
++i) { | |
// SEARCH_OTHER_ENGINE is only used in the SearchProvider for the keyword | |
// verbatim result, so this condition basically means "if this match is a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment