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

Side by Side 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: 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 unified diff | Download patch
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/omnibox_controller.h" 5 #include "chrome/browser/ui/omnibox/omnibox_controller.h"
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "chrome/browser/autocomplete/autocomplete_classifier.h" 8 #include "chrome/browser/autocomplete/autocomplete_classifier.h"
9 #include "chrome/browser/autocomplete/autocomplete_match.h" 9 #include "chrome/browser/autocomplete/autocomplete_match.h"
10 #include "chrome/browser/autocomplete/search_provider.h" 10 #include "chrome/browser/autocomplete/search_provider.h"
(...skipping 12 matching lines...) Expand all
23 #include "extensions/common/constants.h" 23 #include "extensions/common/constants.h"
24 #include "ui/gfx/rect.h" 24 #include "ui/gfx/rect.h"
25 25
26 namespace { 26 namespace {
27 27
28 // Returns the AutocompleteMatch that the InstantController should prefetch, if 28 // Returns the AutocompleteMatch that the InstantController should prefetch, if
29 // any. 29 // any.
30 // 30 //
31 // The SearchProvider may mark some suggestions to be prefetched based on 31 // The SearchProvider may mark some suggestions to be prefetched based on
32 // instructions from the suggest server. If such a match ranks sufficiently 32 // instructions from the suggest server. If such a match ranks sufficiently
33 // highly, we'll return it. 33 // highly or if allow_prefetch_non_default_match field trial is enabled, we'll
34 // return it.
34 // 35 //
35 // We only care about matches that are the default or the very first entry in 36 // If the allow_prefetch_non_default_match field trial is enabled we return the
kmadhusu 2014/06/18 17:07:38 s/allow_prefetch_.../kAllowPrefetchNonDefaultMatch
sidharthms 2014/06/18 22:45:22 Done.
36 // the dropdown (which can happen for non-default matches only if we're hiding 37 // prefetch suggestion even if it is not the default match. Otherwise we only
37 // a top verbatim match) or the second entry in the dropdown (which can happen 38 // care about matches that are the default or the very first entry in the
38 // for non-default matches when a top verbatim match is shown); for other 39 // dropdown (which can happen for non-default matches only if we're hiding a top
39 // matches, we think the likelihood of the user selecting them is low enough 40 // verbatim match) or the second entry in the dropdown (which can happen for
40 // that prefetching isn't worth doing. 41 // non-default matches when a top verbatim match is shown); for other matches,
42 // we think the likelihood of the user selecting them is low enough that
43 // prefetching isn't worth doing.
41 const AutocompleteMatch* GetMatchToPrefetch(const AutocompleteResult& result) { 44 const AutocompleteMatch* GetMatchToPrefetch(const AutocompleteResult& result) {
42 // If the default match should be prefetched, do that. 45 if (chrome::ShouldAllowPrefetchNonDefaultMatch()) {
43 const AutocompleteResult::const_iterator default_match( 46 const AutocompleteResult::const_iterator prefetch_match = std::find_if(
44 result.default_match()); 47 result.begin(), result.end(), SearchProvider::ShouldPrefetch);
45 if ((default_match != result.end()) && 48 if (prefetch_match != result.end())
kmadhusu 2014/06/18 17:07:38 nit: You can use a ternary operator here and remov
sidharthms 2014/06/18 22:45:22 Done.
46 SearchProvider::ShouldPrefetch(*default_match)) 49 return &(*prefetch_match);
kmadhusu 2014/06/18 17:07:38 As you said yesterday, when we type "ya" we are su
sidharthms 2014/06/18 22:45:22 Done.
47 return &(*default_match); 50 } else {
51 // If the default match should be prefetched, do that.
52 const AutocompleteResult::const_iterator default_match(
53 result.default_match());
54 if ((default_match != result.end()) &&
55 SearchProvider::ShouldPrefetch(*default_match))
56 return &(*default_match);
48 57
49 // Otherwise, if the top match is a verbatim match and the very next match is 58 // Otherwise, if the top match is a verbatim match and the very next match
50 // prefetchable, fetch that. 59 // is prefetchable, fetch that.
51 if ((result.ShouldHideTopMatch() || 60 if ((result.ShouldHideTopMatch() ||
52 result.TopMatchIsStandaloneVerbatimMatch()) && 61 result.TopMatchIsStandaloneVerbatimMatch()) &&
53 (result.size() > 1) && 62 (result.size() > 1) &&
54 SearchProvider::ShouldPrefetch(result.match_at(1))) 63 SearchProvider::ShouldPrefetch(result.match_at(1)))
55 return &result.match_at(1); 64 return &result.match_at(1);
56 65 }
57 return NULL; 66 return NULL;
58 } 67 }
59 68
60 } // namespace 69 } // namespace
61 70
62 OmniboxController::OmniboxController(OmniboxEditModel* omnibox_edit_model, 71 OmniboxController::OmniboxController(OmniboxEditModel* omnibox_edit_model,
63 Profile* profile) 72 Profile* profile)
64 : omnibox_edit_model_(omnibox_edit_model), 73 : omnibox_edit_model_(omnibox_edit_model),
65 profile_(profile), 74 profile_(profile),
66 popup_(NULL), 75 popup_(NULL),
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 if (profile_->GetNetworkPredictor()) { 151 if (profile_->GetNetworkPredictor()) {
143 profile_->GetNetworkPredictor()->AnticipateOmniboxUrl( 152 profile_->GetNetworkPredictor()->AnticipateOmniboxUrl(
144 match.destination_url, 153 match.destination_url,
145 predictors::AutocompleteActionPredictor::IsPreconnectable(match)); 154 predictors::AutocompleteActionPredictor::IsPreconnectable(match));
146 } 155 }
147 // We could prefetch the alternate nav URL, if any, but because there 156 // We could prefetch the alternate nav URL, if any, but because there
148 // can be many of these as a user types an initial series of characters, 157 // can be many of these as a user types an initial series of characters,
149 // the OS DNS cache could suffer eviction problems for minimal gain. 158 // the OS DNS cache could suffer eviction problems for minimal gain.
150 } 159 }
151 } 160 }
OLDNEW
« chrome/browser/search/search_unittest.cc ('K') | « chrome/browser/search/search_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698