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 "components/omnibox/base_search_provider.h" | 5 #include "components/omnibox/base_search_provider.h" |
6 | 6 |
7 #include "base/i18n/case_conversion.h" | 7 #include "base/i18n/case_conversion.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "components/metrics/proto/omnibox_event.pb.h" | 10 #include "components/metrics/proto/omnibox_event.pb.h" |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 AutocompleteMatchType::Type type, | 104 AutocompleteMatchType::Type type, |
105 bool from_keyword_provider, | 105 bool from_keyword_provider, |
106 const TemplateURL* template_url, | 106 const TemplateURL* template_url, |
107 const SearchTermsData& search_terms_data) { | 107 const SearchTermsData& search_terms_data) { |
108 // These calls use a number of default values. For instance, they assume | 108 // These calls use a number of default values. For instance, they assume |
109 // that if this match is from a keyword provider, then the user is in keyword | 109 // that if this match is from a keyword provider, then the user is in keyword |
110 // mode. They also assume the caller knows what it's doing and we set | 110 // mode. They also assume the caller knows what it's doing and we set |
111 // this match to look as if it was received/created synchronously. | 111 // this match to look as if it was received/created synchronously. |
112 SearchSuggestionParser::SuggestResult suggest_result( | 112 SearchSuggestionParser::SuggestResult suggest_result( |
113 suggestion, type, suggestion, base::string16(), base::string16(), | 113 suggestion, type, suggestion, base::string16(), base::string16(), |
114 base::string16(), base::string16(), std::string(), std::string(), | 114 base::string16(), base::string16(), nullptr, std::string(), std::string(), |
115 from_keyword_provider, 0, false, false, base::string16()); | 115 from_keyword_provider, 0, false, false, base::string16()); |
116 suggest_result.set_received_after_last_keystroke(false); | 116 suggest_result.set_received_after_last_keystroke(false); |
117 return CreateSearchSuggestion( | 117 return CreateSearchSuggestion( |
118 NULL, AutocompleteInput(), from_keyword_provider, suggest_result, | 118 NULL, AutocompleteInput(), from_keyword_provider, suggest_result, |
119 template_url, search_terms_data, 0, false); | 119 template_url, search_terms_data, 0, false); |
120 } | 120 } |
121 | 121 |
122 void BaseSearchProvider::DeleteMatch(const AutocompleteMatch& match) { | 122 void BaseSearchProvider::DeleteMatch(const AutocompleteMatch& match) { |
123 DCHECK(match.deletable); | 123 DCHECK(match.deletable); |
124 if (!match.GetAdditionalInfo(BaseSearchProvider::kDeletionUrlKey).empty()) { | 124 if (!match.GetAdditionalInfo(BaseSearchProvider::kDeletionUrlKey).empty()) { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
201 AutocompleteMatch match(autocomplete_provider, suggestion.relevance(), false, | 201 AutocompleteMatch match(autocomplete_provider, suggestion.relevance(), false, |
202 suggestion.type()); | 202 suggestion.type()); |
203 | 203 |
204 if (!template_url) | 204 if (!template_url) |
205 return match; | 205 return match; |
206 match.keyword = template_url->keyword(); | 206 match.keyword = template_url->keyword(); |
207 match.contents = suggestion.match_contents(); | 207 match.contents = suggestion.match_contents(); |
208 match.contents_class = suggestion.match_contents_class(); | 208 match.contents_class = suggestion.match_contents_class(); |
209 match.answer_contents = suggestion.answer_contents(); | 209 match.answer_contents = suggestion.answer_contents(); |
210 match.answer_type = suggestion.answer_type(); | 210 match.answer_type = suggestion.answer_type(); |
211 match.answer.reset( | |
212 suggestion.answer() ? new SuggestionAnswer(*suggestion.answer()) : NULL); | |
211 if (suggestion.type() == AutocompleteMatchType::SEARCH_SUGGEST_INFINITE) { | 213 if (suggestion.type() == AutocompleteMatchType::SEARCH_SUGGEST_INFINITE) { |
212 match.RecordAdditionalInfo( | 214 match.RecordAdditionalInfo( |
213 kACMatchPropertyInputText, base::UTF16ToUTF8(input.text())); | 215 kACMatchPropertyInputText, base::UTF16ToUTF8(input.text())); |
214 match.RecordAdditionalInfo( | 216 match.RecordAdditionalInfo( |
215 kACMatchPropertyContentsPrefix, | 217 kACMatchPropertyContentsPrefix, |
216 base::UTF16ToUTF8(suggestion.match_contents_prefix())); | 218 base::UTF16ToUTF8(suggestion.match_contents_prefix())); |
217 match.RecordAdditionalInfo( | 219 match.RecordAdditionalInfo( |
218 kACMatchPropertyContentsStartIndex, | 220 kACMatchPropertyContentsStartIndex, |
219 static_cast<int>( | 221 static_cast<int>( |
220 suggestion.suggestion().length() - match.contents.length())); | 222 suggestion.suggestion().length() - match.contents.length())); |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
423 // Copy over answer data from lower-ranking item, if necessary. | 425 // Copy over answer data from lower-ranking item, if necessary. |
424 // This depends on the lower-ranking item always being added last - see | 426 // This depends on the lower-ranking item always being added last - see |
425 // use of push_back above. | 427 // use of push_back above. |
426 AutocompleteMatch& more_relevant_match = i.first->second; | 428 AutocompleteMatch& more_relevant_match = i.first->second; |
427 const AutocompleteMatch& less_relevant_match = | 429 const AutocompleteMatch& less_relevant_match = |
428 more_relevant_match.duplicate_matches.back(); | 430 more_relevant_match.duplicate_matches.back(); |
429 if (!less_relevant_match.answer_type.empty() && | 431 if (!less_relevant_match.answer_type.empty() && |
430 more_relevant_match.answer_type.empty()) { | 432 more_relevant_match.answer_type.empty()) { |
431 more_relevant_match.answer_type = less_relevant_match.answer_type; | 433 more_relevant_match.answer_type = less_relevant_match.answer_type; |
432 more_relevant_match.answer_contents = less_relevant_match.answer_contents; | 434 more_relevant_match.answer_contents = less_relevant_match.answer_contents; |
435 more_relevant_match.answer.reset(less_relevant_match.answer.get() ? | |
groby-ooo-7-16
2014/10/21 00:35:54
Assuming that we don't care about the answer on th
Justin Donnelly
2014/10/21 21:43:54
No longer using the scoped_ptr.
| |
436 new SuggestionAnswer(*less_relevant_match.answer) : NULL); | |
433 } | 437 } |
434 } | 438 } |
435 } | 439 } |
436 | 440 |
437 bool BaseSearchProvider::ParseSuggestResults( | 441 bool BaseSearchProvider::ParseSuggestResults( |
438 const base::Value& root_val, | 442 const base::Value& root_val, |
439 int default_result_relevance, | 443 int default_result_relevance, |
440 bool is_keyword_result, | 444 bool is_keyword_result, |
441 SearchSuggestionParser::Results* results) { | 445 SearchSuggestionParser::Results* results) { |
442 if (!SearchSuggestionParser::ParseSuggestResults( | 446 if (!SearchSuggestionParser::ParseSuggestResults( |
(...skipping 28 matching lines...) Expand all Loading... | |
471 } | 475 } |
472 | 476 |
473 void BaseSearchProvider::OnDeletionComplete( | 477 void BaseSearchProvider::OnDeletionComplete( |
474 bool success, SuggestionDeletionHandler* handler) { | 478 bool success, SuggestionDeletionHandler* handler) { |
475 RecordDeletionResult(success); | 479 RecordDeletionResult(success); |
476 SuggestionDeletionHandlers::iterator it = std::find( | 480 SuggestionDeletionHandlers::iterator it = std::find( |
477 deletion_handlers_.begin(), deletion_handlers_.end(), handler); | 481 deletion_handlers_.begin(), deletion_handlers_.end(), handler); |
478 DCHECK(it != deletion_handlers_.end()); | 482 DCHECK(it != deletion_handlers_.end()); |
479 deletion_handlers_.erase(it); | 483 deletion_handlers_.erase(it); |
480 } | 484 } |
OLD | NEW |