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

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: Autocomplete result check added 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..95acac4de0200322d880b92585532c38f4b0e119 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 {
Peter Kasting 2014/06/19 23:03:09 Nit: No else after return.
sidharthms 2014/06/20 00:30:49 Done.
+ // 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
@@ -83,30 +92,16 @@ void OmniboxController::StartAutocomplete(
void OmniboxController::OnResultChanged(bool default_match_changed) {
const bool was_open = popup_->IsOpen();
+ const AutocompleteResult& result = this->result();
Peter Kasting 2014/06/19 23:03:09 Nit: I think it would be better to remove this and
sidharthms 2014/06/20 00:30:49 Done.
if (default_match_changed) {
// The default match has changed, we need to let the OmniboxEditModel know
// about new inline autocomplete text (blue highlight).
- const AutocompleteResult& result = this->result();
const AutocompleteResult::const_iterator match(result.default_match());
if (match != result.end()) {
current_match_ = *match;
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();
@@ -122,6 +117,23 @@ void OmniboxController::OnResultChanged(bool default_match_changed) {
// to have temporary text when the popup is closed.
omnibox_edit_model_->AcceptTemporaryTextAsUserText();
}
+
+ if (!chrome::IsInstantExtendedAPIEnabled())
Peter Kasting 2014/06/19 23:03:08 Nit: Why not include this in the next conditional
sidharthms 2014/06/20 00:30:49 Done.
+ return;
+ if ((default_match_changed && result.default_match() != result.end()) ||
+ (chrome::ShouldAllowPrefetchNonDefaultMatch() && !result.empty())) {
+ 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);
+ }
}
void OmniboxController::InvalidateCurrentMatch() {
« 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