Chromium Code Reviews| 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(), SuggestionAnswer(), std::string(), |
| 115 from_keyword_provider, 0, false, false, base::string16()); | 115 std::string(), 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()) { |
| 125 deletion_handlers_.push_back(new SuggestionDeletionHandler( | 125 deletion_handlers_.push_back(new SuggestionDeletionHandler( |
| (...skipping 75 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 = suggestion.answer(); | |
| 211 if (suggestion.type() == AutocompleteMatchType::SEARCH_SUGGEST_INFINITE) { | 212 if (suggestion.type() == AutocompleteMatchType::SEARCH_SUGGEST_INFINITE) { |
| 212 match.RecordAdditionalInfo( | 213 match.RecordAdditionalInfo( |
| 213 kACMatchPropertyInputText, base::UTF16ToUTF8(input.text())); | 214 kACMatchPropertyInputText, base::UTF16ToUTF8(input.text())); |
| 214 match.RecordAdditionalInfo( | 215 match.RecordAdditionalInfo( |
| 215 kACMatchPropertyContentsPrefix, | 216 kACMatchPropertyContentsPrefix, |
| 216 base::UTF16ToUTF8(suggestion.match_contents_prefix())); | 217 base::UTF16ToUTF8(suggestion.match_contents_prefix())); |
| 217 match.RecordAdditionalInfo( | 218 match.RecordAdditionalInfo( |
| 218 kACMatchPropertyContentsStartIndex, | 219 kACMatchPropertyContentsStartIndex, |
| 219 static_cast<int>( | 220 static_cast<int>( |
| 220 suggestion.suggestion().length() - match.contents.length())); | 221 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. | 424 // Copy over answer data from lower-ranking item, if necessary. |
| 424 // This depends on the lower-ranking item always being added last - see | 425 // This depends on the lower-ranking item always being added last - see |
| 425 // use of push_back above. | 426 // use of push_back above. |
| 426 AutocompleteMatch& more_relevant_match = i.first->second; | 427 AutocompleteMatch& more_relevant_match = i.first->second; |
| 427 const AutocompleteMatch& less_relevant_match = | 428 const AutocompleteMatch& less_relevant_match = |
| 428 more_relevant_match.duplicate_matches.back(); | 429 more_relevant_match.duplicate_matches.back(); |
| 429 if (!less_relevant_match.answer_type.empty() && | 430 if (!less_relevant_match.answer_type.empty() && |
| 430 more_relevant_match.answer_type.empty()) { | 431 more_relevant_match.answer_type.empty()) { |
| 431 more_relevant_match.answer_type = less_relevant_match.answer_type; | 432 more_relevant_match.answer_type = less_relevant_match.answer_type; |
| 432 more_relevant_match.answer_contents = less_relevant_match.answer_contents; | 433 more_relevant_match.answer_contents = less_relevant_match.answer_contents; |
| 434 more_relevant_match.answer = less_relevant_match.answer; | |
| 433 } | 435 } |
| 434 } | 436 } |
| 435 } | 437 } |
| 436 | 438 |
| 437 bool BaseSearchProvider::ParseSuggestResults( | 439 bool BaseSearchProvider::ParseSuggestResults( |
| 438 const base::Value& root_val, | 440 const base::Value& root_val, |
| 439 int default_result_relevance, | 441 int default_result_relevance, |
| 440 bool is_keyword_result, | 442 bool is_keyword_result, |
| 441 SearchSuggestionParser::Results* results) { | 443 SearchSuggestionParser::Results* results) { |
| 442 if (!SearchSuggestionParser::ParseSuggestResults( | 444 if (!SearchSuggestionParser::ParseSuggestResults( |
| 443 root_val, GetInput(is_keyword_result), | 445 root_val, GetInput(is_keyword_result), |
| 444 client_->SchemeClassifier(), default_result_relevance, | 446 client_->SchemeClassifier(), default_result_relevance, |
| 445 client_->AcceptLanguages(), is_keyword_result, results)) | 447 client_->AcceptLanguages(), is_keyword_result, results)) |
| 446 return false; | 448 return false; |
| 447 | 449 |
| 448 for (std::vector<GURL>::const_iterator it = | 450 for (SuggestionAnswer::URLs::const_iterator it = |
|
groby-ooo-7-16
2014/10/28 00:50:02
Since we're touching this anyways, let's go C++11
Justin Donnelly
2014/10/28 15:20:55
Done. (I can't properly express how much I love ra
| |
| 449 results->answers_image_urls.begin(); | 451 results->answers_image_urls.begin(); |
| 450 it != results->answers_image_urls.end(); ++it) | 452 it != results->answers_image_urls.end(); ++it) |
| 451 client_->PrefetchImage(*it); | 453 client_->PrefetchImage(*it); |
| 452 | 454 |
| 453 field_trial_triggered_ |= results->field_trial_triggered; | 455 field_trial_triggered_ |= results->field_trial_triggered; |
| 454 field_trial_triggered_in_session_ |= results->field_trial_triggered; | 456 field_trial_triggered_in_session_ |= results->field_trial_triggered; |
| 455 return true; | 457 return true; |
| 456 } | 458 } |
| 457 | 459 |
| 458 void BaseSearchProvider::DeleteMatchFromMatches( | 460 void BaseSearchProvider::DeleteMatchFromMatches( |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 471 } | 473 } |
| 472 | 474 |
| 473 void BaseSearchProvider::OnDeletionComplete( | 475 void BaseSearchProvider::OnDeletionComplete( |
| 474 bool success, SuggestionDeletionHandler* handler) { | 476 bool success, SuggestionDeletionHandler* handler) { |
| 475 RecordDeletionResult(success); | 477 RecordDeletionResult(success); |
| 476 SuggestionDeletionHandlers::iterator it = std::find( | 478 SuggestionDeletionHandlers::iterator it = std::find( |
| 477 deletion_handlers_.begin(), deletion_handlers_.end(), handler); | 479 deletion_handlers_.begin(), deletion_handlers_.end(), handler); |
| 478 DCHECK(it != deletion_handlers_.end()); | 480 DCHECK(it != deletion_handlers_.end()); |
| 479 deletion_handlers_.erase(it); | 481 deletion_handlers_.erase(it); |
| 480 } | 482 } |
| OLD | NEW |