Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Unified Diff: chrome/browser/ui/omnibox/omnibox_controller.cc

Issue 324273004: Allow non default prefetch suggestions to be prefetched (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments addressed Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/search/search_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/omnibox/omnibox_controller.cc
diff --git a/chrome/browser/ui/omnibox/omnibox_controller.cc b/chrome/browser/ui/omnibox/omnibox_controller.cc
index 29d27d7e01d42b142f9e723ed68754e68b31e732..496a65eac111ee8677d68ce0f358b9fc42f6b95a 100644
--- a/chrome/browser/ui/omnibox/omnibox_controller.cc
+++ b/chrome/browser/ui/omnibox/omnibox_controller.cc
@@ -30,31 +30,40 @@ namespace {
//
// The SearchProvider may mark some suggestions to be prefetched based on
// instructions from the suggest server. If such a match ranks sufficiently
-// highly, we'll return it.
+// highly or if kAllowPrefetchNonDefaultMatch field trial is enabled, we'll
+// return it.
//
-// We only care about matches that are the default or the very first entry in
-// the dropdown (which can happen for non-default matches only if we're hiding
-// a top verbatim match) or the second entry in the dropdown (which can happen
-// for non-default matches when a top verbatim match is shown); for other
-// matches, we think the likelihood of the user selecting them is low enough
-// that prefetching isn't worth doing.
+// If the kAllowPrefetchNonDefaultMatch field trial is enabled we return the
+// prefetch suggestion even if it is not the default match. Otherwise we only
+// care about matches that are the default or the very first entry in the
+// dropdown (which can happen for non-default matches only if we're hiding a top
+// verbatim match) or the second entry in the dropdown (which can happen for
+// non-default matches when a top verbatim match is shown); for other matches,
+// we think the likelihood of the user selecting them is low enough that
+// prefetching isn't worth doing.
const AutocompleteMatch* GetMatchToPrefetch(const AutocompleteResult& result) {
- // If the default match should be prefetched, do that.
- const AutocompleteResult::const_iterator default_match(
- result.default_match());
- if ((default_match != result.end()) &&
- SearchProvider::ShouldPrefetch(*default_match))
- return &(*default_match);
-
- // Otherwise, if the top match is a verbatim match and the very next match is
- // prefetchable, fetch that.
- if ((result.ShouldHideTopMatch() ||
- result.TopMatchIsStandaloneVerbatimMatch()) &&
- (result.size() > 1) &&
- SearchProvider::ShouldPrefetch(result.match_at(1)))
- return &result.match_at(1);
-
- return NULL;
+ if (chrome::ShouldAllowPrefetchNonDefaultMatch()) {
+ const AutocompleteResult::const_iterator prefetch_match = std::find_if(
+ result.begin(), result.end(), SearchProvider::ShouldPrefetch);
+ return prefetch_match != result.end() ? &(*prefetch_match) : NULL;
+ } else {
+ // If the default match should be prefetched, do that.
+ const AutocompleteResult::const_iterator default_match(
+ result.default_match());
+ if ((default_match != result.end()) &&
+ SearchProvider::ShouldPrefetch(*default_match))
+ return &(*default_match);
+
+ // Otherwise, if the top match is a verbatim match and the very next match
+ // is prefetchable, fetch that.
+ if ((result.ShouldHideTopMatch() ||
+ result.TopMatchIsStandaloneVerbatimMatch()) &&
+ (result.size() > 1) &&
+ SearchProvider::ShouldPrefetch(result.match_at(1)))
+ return &result.match_at(1);
+
+ return NULL;
+ }
}
} // namespace
@@ -93,20 +102,6 @@ void OmniboxController::OnResultChanged(bool default_match_changed) {
if (!prerender::IsOmniboxEnabled(profile_))
DoPreconnect(*match);
omnibox_edit_model_->OnCurrentMatchChanged();
-
- if (chrome::IsInstantExtendedAPIEnabled()) {
- InstantSuggestion prefetch_suggestion;
- const AutocompleteMatch* match_to_prefetch = GetMatchToPrefetch(result);
- if (match_to_prefetch) {
- prefetch_suggestion.text = match_to_prefetch->contents;
- prefetch_suggestion.metadata =
- SearchProvider::GetSuggestMetadata(*match_to_prefetch);
- }
- // Send the prefetch suggestion unconditionally to the InstantPage. If
- // there is no suggestion to prefetch, we need to send a blank query to
- // clear the prefetched results.
- omnibox_edit_model_->SetSuggestionToPrefetch(prefetch_suggestion);
- }
} else {
InvalidateCurrentMatch();
popup_->OnResultChanged();
@@ -117,6 +112,21 @@ void OmniboxController::OnResultChanged(bool default_match_changed) {
popup_->OnResultChanged();
}
+ if ((default_match_changed || chrome::ShouldAllowPrefetchNonDefaultMatch()) &&
+ chrome::IsInstantExtendedAPIEnabled()) {
kmadhusu 2014/06/19 19:56:31 Previously, AutocompleteController::OnResultChange
sidharthms 2014/06/19 20:52:58 Done.
+ InstantSuggestion prefetch_suggestion;
+ const AutocompleteMatch* match_to_prefetch = GetMatchToPrefetch(result());
+ if (match_to_prefetch) {
+ prefetch_suggestion.text = match_to_prefetch->contents;
+ prefetch_suggestion.metadata =
+ SearchProvider::GetSuggestMetadata(*match_to_prefetch);
+ }
+ // Send the prefetch suggestion unconditionally to the InstantPage. If
+ // there is no suggestion to prefetch, we need to send a blank query to
+ // clear the prefetched results.
+ omnibox_edit_model_->SetSuggestionToPrefetch(prefetch_suggestion);
+ }
+
if (!popup_->IsOpen() && was_open) {
// Accept the temporary text as the user text, because it makes little sense
// to have temporary text when the popup is closed.
« no previous file with comments | « chrome/browser/search/search_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698