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/i18n/icu_string_conversions.h" | 8 #include "base/i18n/icu_string_conversions.h" |
9 #include "base/json/json_string_value_serializer.h" | 9 #include "base/json/json_string_value_serializer.h" |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 const int BaseSearchProvider::kDeletionURLFetcherID = 3; | 126 const int BaseSearchProvider::kDeletionURLFetcherID = 3; |
127 | 127 |
128 BaseSearchProvider::BaseSearchProvider(AutocompleteProviderListener* listener, | 128 BaseSearchProvider::BaseSearchProvider(AutocompleteProviderListener* listener, |
129 Profile* profile, | 129 Profile* profile, |
130 AutocompleteProvider::Type type) | 130 AutocompleteProvider::Type type) |
131 : AutocompleteProvider(type), | 131 : AutocompleteProvider(type), |
132 listener_(listener), | 132 listener_(listener), |
133 profile_(profile), | 133 profile_(profile), |
134 field_trial_triggered_(false), | 134 field_trial_triggered_(false), |
135 field_trial_triggered_in_session_(false), | 135 field_trial_triggered_in_session_(false), |
136 suggest_results_pending_(0), | 136 suggest_results_pending_(0) { |
137 in_app_list_(false) { | |
138 } | 137 } |
139 | 138 |
140 // static | 139 // static |
141 bool BaseSearchProvider::ShouldPrefetch(const AutocompleteMatch& match) { | 140 bool BaseSearchProvider::ShouldPrefetch(const AutocompleteMatch& match) { |
142 return match.GetAdditionalInfo(kShouldPrefetchKey) == kTrue; | 141 return match.GetAdditionalInfo(kShouldPrefetchKey) == kTrue; |
143 } | 142 } |
144 | 143 |
145 // static | 144 // static |
146 AutocompleteMatch BaseSearchProvider::CreateSearchSuggestion( | 145 AutocompleteMatch BaseSearchProvider::CreateSearchSuggestion( |
147 const base::string16& suggestion, | 146 const base::string16& suggestion, |
148 AutocompleteMatchType::Type type, | 147 AutocompleteMatchType::Type type, |
149 bool from_keyword_provider, | 148 bool from_keyword_provider, |
150 const TemplateURL* template_url, | 149 const TemplateURL* template_url, |
151 const SearchTermsData& search_terms_data) { | 150 const SearchTermsData& search_terms_data) { |
152 return CreateSearchSuggestion( | 151 return CreateSearchSuggestion( |
153 NULL, AutocompleteInput(), BaseSearchProvider::SuggestResult( | 152 NULL, AutocompleteInput(), BaseSearchProvider::SuggestResult( |
154 suggestion, type, suggestion, base::string16(), base::string16(), | 153 suggestion, type, suggestion, base::string16(), base::string16(), |
155 base::string16(), base::string16(), std::string(), std::string(), | 154 base::string16(), base::string16(), std::string(), std::string(), |
156 from_keyword_provider, 0, false, false, base::string16()), | 155 from_keyword_provider, 0, false, false, base::string16()), |
157 template_url, search_terms_data, 0, false, false); | 156 template_url, search_terms_data, 0, false); |
158 } | 157 } |
159 | 158 |
160 void BaseSearchProvider::Stop(bool clear_cached_results) { | 159 void BaseSearchProvider::Stop(bool clear_cached_results) { |
161 StopSuggest(); | 160 StopSuggest(); |
162 done_ = true; | 161 done_ = true; |
163 | 162 |
164 if (clear_cached_results) | 163 if (clear_cached_results) |
165 ClearAllResults(); | 164 ClearAllResults(); |
166 } | 165 } |
167 | 166 |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 // BaseSearchProvider --------------------------------------------------------- | 474 // BaseSearchProvider --------------------------------------------------------- |
476 | 475 |
477 // static | 476 // static |
478 AutocompleteMatch BaseSearchProvider::CreateSearchSuggestion( | 477 AutocompleteMatch BaseSearchProvider::CreateSearchSuggestion( |
479 AutocompleteProvider* autocomplete_provider, | 478 AutocompleteProvider* autocomplete_provider, |
480 const AutocompleteInput& input, | 479 const AutocompleteInput& input, |
481 const SuggestResult& suggestion, | 480 const SuggestResult& suggestion, |
482 const TemplateURL* template_url, | 481 const TemplateURL* template_url, |
483 const SearchTermsData& search_terms_data, | 482 const SearchTermsData& search_terms_data, |
484 int accepted_suggestion, | 483 int accepted_suggestion, |
485 bool append_extra_query_params, | 484 bool append_extra_query_params) { |
486 bool from_app_list) { | |
487 AutocompleteMatch match(autocomplete_provider, suggestion.relevance(), false, | 485 AutocompleteMatch match(autocomplete_provider, suggestion.relevance(), false, |
488 suggestion.type()); | 486 suggestion.type()); |
489 | 487 |
490 if (!template_url) | 488 if (!template_url) |
491 return match; | 489 return match; |
492 match.keyword = template_url->keyword(); | 490 match.keyword = template_url->keyword(); |
493 match.contents = suggestion.match_contents(); | 491 match.contents = suggestion.match_contents(); |
494 match.contents_class = suggestion.match_contents_class(); | 492 match.contents_class = suggestion.match_contents_class(); |
495 match.answer_contents = suggestion.answer_contents(); | 493 match.answer_contents = suggestion.answer_contents(); |
496 match.answer_type = suggestion.answer_type(); | 494 match.answer_type = suggestion.answer_type(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 DCHECK(search_url.SupportsReplacement(search_terms_data)); | 531 DCHECK(search_url.SupportsReplacement(search_terms_data)); |
534 match.search_terms_args.reset( | 532 match.search_terms_args.reset( |
535 new TemplateURLRef::SearchTermsArgs(suggestion.suggestion())); | 533 new TemplateURLRef::SearchTermsArgs(suggestion.suggestion())); |
536 match.search_terms_args->original_query = input.text(); | 534 match.search_terms_args->original_query = input.text(); |
537 match.search_terms_args->accepted_suggestion = accepted_suggestion; | 535 match.search_terms_args->accepted_suggestion = accepted_suggestion; |
538 match.search_terms_args->enable_omnibox_start_margin = true; | 536 match.search_terms_args->enable_omnibox_start_margin = true; |
539 match.search_terms_args->suggest_query_params = | 537 match.search_terms_args->suggest_query_params = |
540 suggestion.suggest_query_params(); | 538 suggestion.suggest_query_params(); |
541 match.search_terms_args->append_extra_query_params = | 539 match.search_terms_args->append_extra_query_params = |
542 append_extra_query_params; | 540 append_extra_query_params; |
543 match.search_terms_args->from_app_list = from_app_list; | |
544 // This is the destination URL sans assisted query stats. This must be set | 541 // This is the destination URL sans assisted query stats. This must be set |
545 // so the AutocompleteController can properly de-dupe; the controller will | 542 // so the AutocompleteController can properly de-dupe; the controller will |
546 // eventually overwrite it before it reaches the user. | 543 // eventually overwrite it before it reaches the user. |
547 match.destination_url = | 544 match.destination_url = |
548 GURL(search_url.ReplaceSearchTerms(*match.search_terms_args.get(), | 545 GURL(search_url.ReplaceSearchTerms(*match.search_terms_args.get(), |
549 search_terms_data)); | 546 search_terms_data)); |
550 | 547 |
551 // Search results don't look like URLs. | 548 // Search results don't look like URLs. |
552 match.transition = suggestion.from_keyword_provider() ? | 549 match.transition = suggestion.from_keyword_provider() ? |
553 content::PAGE_TRANSITION_KEYWORD : content::PAGE_TRANSITION_GENERATED; | 550 content::PAGE_TRANSITION_KEYWORD : content::PAGE_TRANSITION_GENERATED; |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
709 | 706 |
710 void BaseSearchProvider::AddMatchToMap(const SuggestResult& result, | 707 void BaseSearchProvider::AddMatchToMap(const SuggestResult& result, |
711 const std::string& metadata, | 708 const std::string& metadata, |
712 int accepted_suggestion, | 709 int accepted_suggestion, |
713 bool mark_as_deletable, | 710 bool mark_as_deletable, |
714 MatchMap* map) { | 711 MatchMap* map) { |
715 AutocompleteMatch match = CreateSearchSuggestion( | 712 AutocompleteMatch match = CreateSearchSuggestion( |
716 this, GetInput(result.from_keyword_provider()), result, | 713 this, GetInput(result.from_keyword_provider()), result, |
717 GetTemplateURL(result.from_keyword_provider()), | 714 GetTemplateURL(result.from_keyword_provider()), |
718 UIThreadSearchTermsData(profile_), accepted_suggestion, | 715 UIThreadSearchTermsData(profile_), accepted_suggestion, |
719 ShouldAppendExtraParams(result), in_app_list_); | 716 ShouldAppendExtraParams(result)); |
720 if (!match.destination_url.is_valid()) | 717 if (!match.destination_url.is_valid()) |
721 return; | 718 return; |
722 match.search_terms_args->bookmark_bar_pinned = | 719 match.search_terms_args->bookmark_bar_pinned = |
723 profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar); | 720 profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar); |
724 match.RecordAdditionalInfo(kRelevanceFromServerKey, | 721 match.RecordAdditionalInfo(kRelevanceFromServerKey, |
725 result.relevance_from_server() ? kTrue : kFalse); | 722 result.relevance_from_server() ? kTrue : kFalse); |
726 match.RecordAdditionalInfo(kShouldPrefetchKey, | 723 match.RecordAdditionalInfo(kShouldPrefetchKey, |
727 result.should_prefetch() ? kTrue : kFalse); | 724 result.should_prefetch() ? kTrue : kFalse); |
728 SetDeletionURL(result.deletion_url(), &match); | 725 SetDeletionURL(result.deletion_url(), &match); |
729 if (mark_as_deletable) | 726 if (mark_as_deletable) |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
993 } | 990 } |
994 | 991 |
995 void BaseSearchProvider::OnDeletionComplete( | 992 void BaseSearchProvider::OnDeletionComplete( |
996 bool success, SuggestionDeletionHandler* handler) { | 993 bool success, SuggestionDeletionHandler* handler) { |
997 RecordDeletionResult(success); | 994 RecordDeletionResult(success); |
998 SuggestionDeletionHandlers::iterator it = std::find( | 995 SuggestionDeletionHandlers::iterator it = std::find( |
999 deletion_handlers_.begin(), deletion_handlers_.end(), handler); | 996 deletion_handlers_.begin(), deletion_handlers_.end(), handler); |
1000 DCHECK(it != deletion_handlers_.end()); | 997 DCHECK(it != deletion_handlers_.end()); |
1001 deletion_handlers_.erase(it); | 998 deletion_handlers_.erase(it); |
1002 } | 999 } |
OLD | NEW |