OLD | NEW |
---|---|
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 13 matching lines...) Expand all Loading... | |
24 #include "extensions/common/constants.h" | 24 #include "extensions/common/constants.h" |
25 #include "ui/gfx/rect.h" | 25 #include "ui/gfx/rect.h" |
26 | 26 |
27 namespace { | 27 namespace { |
28 | 28 |
29 // Returns the AutocompleteMatch that the InstantController should prefetch, if | 29 // Returns the AutocompleteMatch that the InstantController should prefetch, if |
30 // any. | 30 // any. |
31 // | 31 // |
32 // The SearchProvider may mark some suggestions to be prefetched based on | 32 // The SearchProvider may mark some suggestions to be prefetched based on |
33 // instructions from the suggest server. If such a match ranks sufficiently | 33 // instructions from the suggest server. If such a match ranks sufficiently |
34 // highly, we'll return it. We only care about matches that are the default or | 34 // highly, we'll return it. We only care about matches that are the default; for |
35 // else the very first entry in the dropdown (which can happen for non-default | 35 // other matches, we think the likelihood of the user selecting them is low |
36 // matches only if we're hiding a top verbatim match); for other matches, we | 36 // enough that prefetching isn't worth doing. |
37 // think the likelihood of the user selecting them is low enough that | |
38 // prefetching isn't worth doing. | |
39 const AutocompleteMatch* GetMatchToPrefetch(const AutocompleteResult& result) { | 37 const AutocompleteMatch* GetMatchToPrefetch(const AutocompleteResult& result) { |
40 const AutocompleteResult::const_iterator default_match( | 38 const AutocompleteResult::const_iterator default_match( |
41 result.default_match()); | 39 result.default_match()); |
42 if (default_match == result.end()) | 40 return ((default_match != result.end()) && |
samarth
2013/11/14 16:17:45
This isn't quite right. Let's say we have the fol
kmadhusu
2013/12/12 01:04:01
Fixed. Added a new function in AutocompleteResult.
| |
43 return NULL; | 41 SearchProvider::ShouldPrefetch(*default_match)) ? &(*default_match) : |
44 | 42 NULL; |
45 if (SearchProvider::ShouldPrefetch(*default_match)) | |
46 return &(*default_match); | |
47 | |
48 return (result.ShouldHideTopMatch() && (result.size() > 1) && | |
49 SearchProvider::ShouldPrefetch(result.match_at(1))) ? | |
50 &result.match_at(1) : NULL; | |
51 } | 43 } |
52 | 44 |
53 } // namespace | 45 } // namespace |
54 | 46 |
55 OmniboxController::OmniboxController(OmniboxEditModel* omnibox_edit_model, | 47 OmniboxController::OmniboxController(OmniboxEditModel* omnibox_edit_model, |
56 Profile* profile) | 48 Profile* profile) |
57 : omnibox_edit_model_(omnibox_edit_model), | 49 : omnibox_edit_model_(omnibox_edit_model), |
58 profile_(profile), | 50 profile_(profile), |
59 autocomplete_controller_(new AutocompleteController(profile, this, | 51 autocomplete_controller_(new AutocompleteController(profile, this, |
60 AutocompleteClassifier::kDefaultOmniboxProviders)) { | 52 AutocompleteClassifier::kDefaultOmniboxProviders)) { |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 if (profile_->GetNetworkPredictor()) { | 138 if (profile_->GetNetworkPredictor()) { |
147 profile_->GetNetworkPredictor()->AnticipateOmniboxUrl( | 139 profile_->GetNetworkPredictor()->AnticipateOmniboxUrl( |
148 match.destination_url, | 140 match.destination_url, |
149 predictors::AutocompleteActionPredictor::IsPreconnectable(match)); | 141 predictors::AutocompleteActionPredictor::IsPreconnectable(match)); |
150 } | 142 } |
151 // We could prefetch the alternate nav URL, if any, but because there | 143 // We could prefetch the alternate nav URL, if any, but because there |
152 // can be many of these as a user types an initial series of characters, | 144 // can be many of these as a user types an initial series of characters, |
153 // the OS DNS cache could suffer eviction problems for minimal gain. | 145 // the OS DNS cache could suffer eviction problems for minimal gain. |
154 } | 146 } |
155 } | 147 } |
OLD | NEW |