OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/autocomplete/zero_suggest_provider.h" | 5 #include "chrome/browser/autocomplete/zero_suggest_provider.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/i18n/case_conversion.h" | 8 #include "base/i18n/case_conversion.h" |
9 #include "base/json/json_string_value_serializer.h" | 9 #include "base/json/json_string_value_serializer.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 done_ = true; | 144 done_ = true; |
145 | 145 |
146 if (have_results) { | 146 if (have_results) { |
147 ConvertResultsToAutocompleteMatches(); | 147 ConvertResultsToAutocompleteMatches(); |
148 listener_->OnProviderUpdate(true); | 148 listener_->OnProviderUpdate(true); |
149 } | 149 } |
150 } | 150 } |
151 | 151 |
152 void ZeroSuggestProvider::StartZeroSuggest( | 152 void ZeroSuggestProvider::StartZeroSuggest( |
153 const GURL& url, | 153 const GURL& url, |
154 AutocompleteInput::PageClassification page_classification, | 154 AutocompleteInput::OmniboxContext omnibox_context, |
155 const string16& permanent_text) { | 155 const string16& permanent_text) { |
156 Stop(true); | 156 Stop(true); |
157 field_trial_triggered_ = false; | 157 field_trial_triggered_ = false; |
158 field_trial_triggered_in_session_ = false; | 158 field_trial_triggered_in_session_ = false; |
159 if (!ShouldRunZeroSuggest(url)) | 159 if (!ShouldRunZeroSuggest(url)) |
160 return; | 160 return; |
161 verbatim_relevance_ = kDefaultVerbatimZeroSuggestRelevance; | 161 verbatim_relevance_ = kDefaultVerbatimZeroSuggestRelevance; |
162 done_ = false; | 162 done_ = false; |
163 permanent_text_ = permanent_text; | 163 permanent_text_ = permanent_text; |
164 current_query_ = url.spec(); | 164 current_query_ = url.spec(); |
165 current_page_classification_ = page_classification; | 165 omnibox_context_ = omnibox_context; |
166 current_url_match_ = MatchForCurrentURL(); | 166 current_url_match_ = MatchForCurrentURL(); |
167 // TODO(jered): Consider adding locally-sourced zero-suggestions here too. | 167 // TODO(jered): Consider adding locally-sourced zero-suggestions here too. |
168 // These may be useful on the NTP or more relevant to the user than server | 168 // These may be useful on the NTP or more relevant to the user than server |
169 // suggestions, if based on local browsing history. | 169 // suggestions, if based on local browsing history. |
170 Run(); | 170 Run(); |
171 } | 171 } |
172 | 172 |
173 ZeroSuggestProvider::ZeroSuggestProvider( | 173 ZeroSuggestProvider::ZeroSuggestProvider( |
174 AutocompleteProviderListener* listener, | 174 AutocompleteProviderListener* listener, |
175 Profile* profile) | 175 Profile* profile) |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 it != query_matches_map_.end(); ++it) | 442 it != query_matches_map_.end(); ++it) |
443 matches_.push_back(it->second); | 443 matches_.push_back(it->second); |
444 | 444 |
445 for (SearchProvider::NavigationResults::const_iterator it( | 445 for (SearchProvider::NavigationResults::const_iterator it( |
446 navigation_results_.begin()); it != navigation_results_.end(); ++it) | 446 navigation_results_.begin()); it != navigation_results_.end(); ++it) |
447 matches_.push_back(NavigationToMatch(*it)); | 447 matches_.push_back(NavigationToMatch(*it)); |
448 } | 448 } |
449 | 449 |
450 AutocompleteMatch ZeroSuggestProvider::MatchForCurrentURL() { | 450 AutocompleteMatch ZeroSuggestProvider::MatchForCurrentURL() { |
451 AutocompleteInput input(permanent_text_, string16::npos, string16(), | 451 AutocompleteInput input(permanent_text_, string16::npos, string16(), |
452 GURL(current_query_), current_page_classification_, | 452 GURL(current_query_), omnibox_context_, |
453 false, false, true, AutocompleteInput::ALL_MATCHES); | 453 false, false, true, AutocompleteInput::ALL_MATCHES); |
454 | 454 |
455 AutocompleteMatch match( | 455 AutocompleteMatch match( |
456 HistoryURLProvider::SuggestExactInput(this, input, | 456 HistoryURLProvider::SuggestExactInput(this, input, |
457 !HasHTTPScheme(input.text()))); | 457 !HasHTTPScheme(input.text()))); |
458 match.is_history_what_you_typed_match = false; | 458 match.is_history_what_you_typed_match = false; |
459 | 459 |
460 // The placeholder suggestion for the current URL has high relevance so | 460 // The placeholder suggestion for the current URL has high relevance so |
461 // that it is in the first suggestion slot and inline autocompleted. It | 461 // that it is in the first suggestion slot and inline autocompleted. It |
462 // gets dropped as soon as the user types something. | 462 // gets dropped as soon as the user types something. |
463 match.relevance = verbatim_relevance_; | 463 match.relevance = verbatim_relevance_; |
464 | 464 |
465 return match; | 465 return match; |
466 } | 466 } |
OLD | NEW |