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