| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/base_search_provider.h" | 5 #include "chrome/browser/autocomplete/base_search_provider.h" |
| 6 | 6 |
| 7 #include "base/i18n/case_conversion.h" | 7 #include "base/i18n/case_conversion.h" |
| 8 #include "base/prefs/pref_registry_simple.h" | 8 #include "base/prefs/pref_registry_simple.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 return match.GetAdditionalInfo(kShouldPrefetchKey) == kTrue; | 109 return match.GetAdditionalInfo(kShouldPrefetchKey) == kTrue; |
| 110 } | 110 } |
| 111 | 111 |
| 112 // static | 112 // static |
| 113 AutocompleteMatch BaseSearchProvider::CreateSearchSuggestion( | 113 AutocompleteMatch BaseSearchProvider::CreateSearchSuggestion( |
| 114 const base::string16& suggestion, | 114 const base::string16& suggestion, |
| 115 AutocompleteMatchType::Type type, | 115 AutocompleteMatchType::Type type, |
| 116 bool from_keyword_provider, | 116 bool from_keyword_provider, |
| 117 const TemplateURL* template_url, | 117 const TemplateURL* template_url, |
| 118 const SearchTermsData& search_terms_data) { | 118 const SearchTermsData& search_terms_data) { |
| 119 // These calls use a number of default values. For instance, they assume | 119 // This call uses a number of default values. For instance, it assumes that |
| 120 // that if this match is from a keyword provider, then the user is in keyword | 120 // if this match is from a keyword provider than the user is in keyword mode. |
| 121 // mode. They also assume the caller knows what it's doing and we set | |
| 122 // this match to look as if it was received/created synchronously. | |
| 123 SearchSuggestionParser::SuggestResult suggest_result( | |
| 124 suggestion, type, suggestion, base::string16(), base::string16(), | |
| 125 base::string16(), base::string16(), std::string(), std::string(), | |
| 126 from_keyword_provider, 0, false, false, base::string16()); | |
| 127 suggest_result.set_received_after_last_keystroke(false); | |
| 128 return CreateSearchSuggestion( | 121 return CreateSearchSuggestion( |
| 129 NULL, AutocompleteInput(), from_keyword_provider, suggest_result, | 122 NULL, AutocompleteInput(), from_keyword_provider, |
| 123 SearchSuggestionParser::SuggestResult( |
| 124 suggestion, type, suggestion, base::string16(), base::string16(), |
| 125 base::string16(), base::string16(), std::string(), std::string(), |
| 126 from_keyword_provider, 0, false, false, base::string16()), |
| 130 template_url, search_terms_data, 0, false); | 127 template_url, search_terms_data, 0, false); |
| 131 } | 128 } |
| 132 | 129 |
| 133 void BaseSearchProvider::Stop(bool clear_cached_results) { | 130 void BaseSearchProvider::Stop(bool clear_cached_results) { |
| 134 StopSuggest(); | 131 StopSuggest(); |
| 135 done_ = true; | 132 done_ = true; |
| 136 | 133 |
| 137 if (clear_cached_results) | 134 if (clear_cached_results) |
| 138 ClearAllResults(); | 135 ClearAllResults(); |
| 139 } | 136 } |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 (base::CollapseWhitespace(input.text(), false) == | 248 (base::CollapseWhitespace(input.text(), false) == |
| 252 suggestion.match_contents()); | 249 suggestion.match_contents()); |
| 253 | 250 |
| 254 // When the user forced a query, we need to make sure all the fill_into_edit | 251 // When the user forced a query, we need to make sure all the fill_into_edit |
| 255 // values preserve that property. Otherwise, if the user starts editing a | 252 // values preserve that property. Otherwise, if the user starts editing a |
| 256 // suggestion, non-Search results will suddenly appear. | 253 // suggestion, non-Search results will suddenly appear. |
| 257 if (input.type() == metrics::OmniboxInputType::FORCED_QUERY) | 254 if (input.type() == metrics::OmniboxInputType::FORCED_QUERY) |
| 258 match.fill_into_edit.assign(base::ASCIIToUTF16("?")); | 255 match.fill_into_edit.assign(base::ASCIIToUTF16("?")); |
| 259 if (suggestion.from_keyword_provider()) | 256 if (suggestion.from_keyword_provider()) |
| 260 match.fill_into_edit.append(match.keyword + base::char16(' ')); | 257 match.fill_into_edit.append(match.keyword + base::char16(' ')); |
| 261 // We only allow inlinable navsuggestions that were received before the | |
| 262 // last keystroke because we don't want asynchronous inline autocompletions. | |
| 263 if (!input.prevent_inline_autocomplete() && | 258 if (!input.prevent_inline_autocomplete() && |
| 264 !suggestion.received_after_last_keystroke() && | |
| 265 (!in_keyword_mode || suggestion.from_keyword_provider()) && | 259 (!in_keyword_mode || suggestion.from_keyword_provider()) && |
| 266 StartsWith(suggestion.suggestion(), input.text(), false)) { | 260 StartsWith(suggestion.suggestion(), input.text(), false)) { |
| 267 match.inline_autocompletion = | 261 match.inline_autocompletion = |
| 268 suggestion.suggestion().substr(input.text().length()); | 262 suggestion.suggestion().substr(input.text().length()); |
| 269 match.allowed_to_be_default_match = true; | 263 match.allowed_to_be_default_match = true; |
| 270 } | 264 } |
| 271 match.fill_into_edit.append(suggestion.suggestion()); | 265 match.fill_into_edit.append(suggestion.suggestion()); |
| 272 | 266 |
| 273 const TemplateURLRef& search_url = template_url->url_ref(); | 267 const TemplateURLRef& search_url = template_url->url_ref(); |
| 274 DCHECK(search_url.SupportsReplacement(search_terms_data)); | 268 DCHECK(search_url.SupportsReplacement(search_terms_data)); |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 } | 494 } |
| 501 | 495 |
| 502 void BaseSearchProvider::OnDeletionComplete( | 496 void BaseSearchProvider::OnDeletionComplete( |
| 503 bool success, SuggestionDeletionHandler* handler) { | 497 bool success, SuggestionDeletionHandler* handler) { |
| 504 RecordDeletionResult(success); | 498 RecordDeletionResult(success); |
| 505 SuggestionDeletionHandlers::iterator it = std::find( | 499 SuggestionDeletionHandlers::iterator it = std::find( |
| 506 deletion_handlers_.begin(), deletion_handlers_.end(), handler); | 500 deletion_handlers_.begin(), deletion_handlers_.end(), handler); |
| 507 DCHECK(it != deletion_handlers_.end()); | 501 DCHECK(it != deletion_handlers_.end()); |
| 508 deletion_handlers_.erase(it); | 502 deletion_handlers_.erase(it); |
| 509 } | 503 } |
| OLD | NEW |