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

Side by Side Diff: chrome/browser/ui/omnibox/chrome_omnibox_client.cc

Issue 2196393006: Remove search::ShouldAllowPrefetchNonDefaultMatch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove_prerender_omnibox
Patch Set: Created 4 years, 4 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 unified diff | Download patch
« no previous file with comments | « no previous file | components/search/search.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/omnibox/chrome_omnibox_client.h" 5 #include "chrome/browser/ui/omnibox/chrome_omnibox_client.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 53
54 using predictors::AutocompleteActionPredictor; 54 using predictors::AutocompleteActionPredictor;
55 55
56 namespace { 56 namespace {
57 57
58 // Returns the AutocompleteMatch that the InstantController should prefetch, if 58 // Returns the AutocompleteMatch that the InstantController should prefetch, if
59 // any. 59 // any.
60 // 60 //
61 // The SearchProvider may mark some suggestions to be prefetched based on 61 // The SearchProvider may mark some suggestions to be prefetched based on
62 // instructions from the suggest server. If such a match ranks sufficiently 62 // instructions from the suggest server. If such a match ranks sufficiently
63 // highly or if kAllowPrefetchNonDefaultMatch field trial is enabled, we'll 63 // highly, we'll return it.
64 // return it.
65 // 64 //
66 // If the kAllowPrefetchNonDefaultMatch field trial is enabled we return the 65 // We only care about matches that are the default or the second entry in the
67 // prefetch suggestion even if it is not the default match. Otherwise we only 66 // dropdown (which can happen for non-default matches when a top verbatim match
68 // care about matches that are the default or the second entry in the dropdown 67 // is shown); for other matches, we think the likelihood of the user selecting
69 // (which can happen for non-default matches when a top verbatim match is
70 // shown); for other matches, we think the likelihood of the user selecting
71 // them is low enough that prefetching isn't worth doing. 68 // them is low enough that prefetching isn't worth doing.
72 const AutocompleteMatch* GetMatchToPrefetch(const AutocompleteResult& result) { 69 const AutocompleteMatch* GetMatchToPrefetch(const AutocompleteResult& result) {
73 if (search::ShouldAllowPrefetchNonDefaultMatch()) {
74 const AutocompleteResult::const_iterator prefetch_match = std::find_if(
75 result.begin(), result.end(), SearchProvider::ShouldPrefetch);
76 return prefetch_match != result.end() ? &(*prefetch_match) : NULL;
77 }
78
79 // If the default match should be prefetched, do that. 70 // If the default match should be prefetched, do that.
80 const auto default_match = result.default_match(); 71 const auto default_match = result.default_match();
81 if ((default_match != result.end()) && 72 if ((default_match != result.end()) &&
82 SearchProvider::ShouldPrefetch(*default_match)) 73 SearchProvider::ShouldPrefetch(*default_match))
83 return &(*default_match); 74 return &(*default_match);
84 75
85 // Otherwise, if the top match is a verbatim match and the very next match 76 // Otherwise, if the top match is a verbatim match and the very next match
86 // is prefetchable, fetch that. 77 // is prefetchable, fetch that.
87 if (result.TopMatchIsStandaloneVerbatimMatch() && (result.size() > 1) && 78 if (result.TopMatchIsStandaloneVerbatimMatch() && (result.size() > 1) &&
88 SearchProvider::ShouldPrefetch(result.match_at(1))) 79 SearchProvider::ShouldPrefetch(result.match_at(1)))
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 return; 258 return;
268 SearchTabHelper::FromWebContents( 259 SearchTabHelper::FromWebContents(
269 controller_->GetWebContents())->OmniboxFocusChanged(state, reason); 260 controller_->GetWebContents())->OmniboxFocusChanged(state, reason);
270 } 261 }
271 262
272 void ChromeOmniboxClient::OnResultChanged( 263 void ChromeOmniboxClient::OnResultChanged(
273 const AutocompleteResult& result, 264 const AutocompleteResult& result,
274 bool default_match_changed, 265 bool default_match_changed,
275 const base::Callback<void(const SkBitmap& bitmap)>& on_bitmap_fetched) { 266 const base::Callback<void(const SkBitmap& bitmap)>& on_bitmap_fetched) {
276 if (search::IsInstantExtendedAPIEnabled() && 267 if (search::IsInstantExtendedAPIEnabled() &&
277 ((default_match_changed && result.default_match() != result.end()) || 268 (default_match_changed && result.default_match() != result.end())) {
278 (search::ShouldAllowPrefetchNonDefaultMatch() && !result.empty()))) {
279 InstantSuggestion prefetch_suggestion; 269 InstantSuggestion prefetch_suggestion;
280 const AutocompleteMatch* match_to_prefetch = GetMatchToPrefetch(result); 270 const AutocompleteMatch* match_to_prefetch = GetMatchToPrefetch(result);
281 if (match_to_prefetch) { 271 if (match_to_prefetch) {
282 prefetch_suggestion.text = match_to_prefetch->contents; 272 prefetch_suggestion.text = match_to_prefetch->contents;
283 prefetch_suggestion.metadata = 273 prefetch_suggestion.metadata =
284 SearchProvider::GetSuggestMetadata(*match_to_prefetch); 274 SearchProvider::GetSuggestMetadata(*match_to_prefetch);
285 } 275 }
286 // Send the prefetch suggestion unconditionally to the InstantPage. If 276 // Send the prefetch suggestion unconditionally to the InstantPage. If
287 // there is no suggestion to prefetch, we need to send a blank query to 277 // there is no suggestion to prefetch, we need to send a blank query to
288 // clear the prefetched results. 278 // clear the prefetched results.
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 if (prerenderer) 458 if (prerenderer)
469 prerenderer->Prerender(suggestion); 459 prerenderer->Prerender(suggestion);
470 } 460 }
471 } 461 }
472 462
473 void ChromeOmniboxClient::OnBitmapFetched(const BitmapFetchedCallback& callback, 463 void ChromeOmniboxClient::OnBitmapFetched(const BitmapFetchedCallback& callback,
474 const SkBitmap& bitmap) { 464 const SkBitmap& bitmap) {
475 request_id_ = BitmapFetcherService::REQUEST_ID_INVALID; 465 request_id_ = BitmapFetcherService::REQUEST_ID_INVALID;
476 callback.Run(bitmap); 466 callback.Run(bitmap);
477 } 467 }
OLDNEW
« no previous file with comments | « no previous file | components/search/search.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698