OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/omnibox/browser/verbatim_match.h" | 5 #include "components/omnibox/browser/verbatim_match.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "components/omnibox/browser/autocomplete_classifier.h" | 8 #include "components/omnibox/browser/autocomplete_classifier.h" |
9 #include "components/omnibox/browser/autocomplete_input.h" | 9 #include "components/omnibox/browser/autocomplete_input.h" |
10 #include "components/omnibox/browser/autocomplete_provider_client.h" | 10 #include "components/omnibox/browser/autocomplete_provider_client.h" |
11 #include "components/omnibox/browser/history_url_provider.h" | 11 #include "components/omnibox/browser/history_url_provider.h" |
12 #include "components/search/search.h" | |
13 #include "url/gurl.h" | 12 #include "url/gurl.h" |
14 | 13 |
15 AutocompleteMatch VerbatimMatchForURL( | 14 AutocompleteMatch VerbatimMatchForURL( |
16 AutocompleteProviderClient* client, | 15 AutocompleteProviderClient* client, |
17 const AutocompleteInput& input, | 16 const AutocompleteInput& input, |
18 const GURL& destination_url, | 17 const GURL& destination_url, |
19 HistoryURLProvider* history_url_provider, | 18 HistoryURLProvider* history_url_provider, |
20 int verbatim_relevance) { | 19 int verbatim_relevance) { |
21 DCHECK(!input.text().empty()); | 20 DCHECK(!input.text().empty()); |
22 AutocompleteMatch match; | 21 AutocompleteMatch match; |
23 // If query-in-the-omnibox is not enabled (and thus the verbatim match for | 22 // If the caller already knows where the verbatim match should go and has |
24 // a URL is guaranteed to be a URL) and the caller already knows where the | 23 // provided a HistoryURLProvider to aid in its construction, construct the |
25 // verbatim match should go and has provided a HistoryURLProvider to aid in | 24 // match directly, don't call Classify() on the input. Classify() runs all |
26 // its construction, construct the match directly, don't call Classify() on | 25 // providers' synchronous passes. Some providers such as HistoryQuick can |
27 // the input. Classify() runs all providers' synchronous passes. Some | 26 // have a slow synchronous pass on some inputs. |
28 // providers such as HistoryQuick can have a slow synchronous pass on some | 27 if (history_url_provider && destination_url.is_valid()) { |
29 // inputs. | |
30 if (history_url_provider && destination_url.is_valid() && | |
31 !search::IsQueryExtractionEnabled()) { | |
32 match = history_url_provider->SuggestExactInput( | 28 match = history_url_provider->SuggestExactInput( |
33 input, | 29 input, |
34 destination_url, | 30 destination_url, |
35 !AutocompleteInput::HasHTTPScheme(input.text())); | 31 !AutocompleteInput::HasHTTPScheme(input.text())); |
36 } else { | 32 } else { |
37 client->Classify(input.text(), false, true, | 33 client->Classify(input.text(), false, true, |
38 input.current_page_classification(), &match, nullptr); | 34 input.current_page_classification(), &match, nullptr); |
39 } | 35 } |
40 match.allowed_to_be_default_match = true; | 36 match.allowed_to_be_default_match = true; |
41 // The default relevance to use for relevance match. Should be greater than | 37 // The default relevance to use for relevance match. Should be greater than |
42 // all relevance matches returned by the ZeroSuggest server. | 38 // all relevance matches returned by the ZeroSuggest server. |
43 const int kDefaultVerbatimRelevance = 1300; | 39 const int kDefaultVerbatimRelevance = 1300; |
44 match.relevance = | 40 match.relevance = |
45 verbatim_relevance >= 0 ? verbatim_relevance : kDefaultVerbatimRelevance; | 41 verbatim_relevance >= 0 ? verbatim_relevance : kDefaultVerbatimRelevance; |
46 return match; | 42 return match; |
47 } | 43 } |
OLD | NEW |