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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 const int BaseSearchProvider::kDeletionURLFetcherID = 3; | 128 const int BaseSearchProvider::kDeletionURLFetcherID = 3; |
129 | 129 |
130 BaseSearchProvider::BaseSearchProvider(AutocompleteProviderListener* listener, | 130 BaseSearchProvider::BaseSearchProvider(AutocompleteProviderListener* listener, |
131 Profile* profile, | 131 Profile* profile, |
132 AutocompleteProvider::Type type) | 132 AutocompleteProvider::Type type) |
133 : AutocompleteProvider(type), | 133 : AutocompleteProvider(type), |
134 listener_(listener), | 134 listener_(listener), |
135 profile_(profile), | 135 profile_(profile), |
136 field_trial_triggered_(false), | 136 field_trial_triggered_(false), |
137 field_trial_triggered_in_session_(false), | 137 field_trial_triggered_in_session_(false), |
138 suggest_results_pending_(0), | 138 suggest_results_pending_(0) { |
139 in_app_list_(false) { | |
140 } | 139 } |
141 | 140 |
142 // static | 141 // static |
143 bool BaseSearchProvider::ShouldPrefetch(const AutocompleteMatch& match) { | 142 bool BaseSearchProvider::ShouldPrefetch(const AutocompleteMatch& match) { |
144 return match.GetAdditionalInfo(kShouldPrefetchKey) == kTrue; | 143 return match.GetAdditionalInfo(kShouldPrefetchKey) == kTrue; |
145 } | 144 } |
146 | 145 |
147 // static | 146 // static |
148 AutocompleteMatch BaseSearchProvider::CreateSearchSuggestion( | 147 AutocompleteMatch BaseSearchProvider::CreateSearchSuggestion( |
149 const base::string16& suggestion, | 148 const base::string16& suggestion, |
150 AutocompleteMatchType::Type type, | 149 AutocompleteMatchType::Type type, |
151 bool from_keyword_provider, | 150 bool from_keyword_provider, |
152 const TemplateURL* template_url, | 151 const TemplateURL* template_url, |
153 const SearchTermsData& search_terms_data) { | 152 const SearchTermsData& search_terms_data) { |
154 return CreateSearchSuggestion( | 153 return CreateSearchSuggestion( |
155 NULL, AutocompleteInput(), BaseSearchProvider::SuggestResult( | 154 NULL, AutocompleteInput(), BaseSearchProvider::SuggestResult( |
156 suggestion, type, suggestion, base::string16(), base::string16(), | 155 suggestion, type, suggestion, base::string16(), base::string16(), |
157 base::string16(), base::string16(), std::string(), std::string(), | 156 base::string16(), base::string16(), std::string(), std::string(), |
158 from_keyword_provider, 0, false, false, base::string16()), | 157 from_keyword_provider, 0, false, false, base::string16()), |
159 template_url, search_terms_data, 0, 0, false, false); | 158 template_url, search_terms_data, 0, 0, false); |
160 } | 159 } |
161 | 160 |
162 void BaseSearchProvider::Stop(bool clear_cached_results) { | 161 void BaseSearchProvider::Stop(bool clear_cached_results) { |
163 StopSuggest(); | 162 StopSuggest(); |
164 done_ = true; | 163 done_ = true; |
165 | 164 |
166 if (clear_cached_results) | 165 if (clear_cached_results) |
167 ClearAllResults(); | 166 ClearAllResults(); |
168 } | 167 } |
169 | 168 |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 | 477 |
479 // static | 478 // static |
480 AutocompleteMatch BaseSearchProvider::CreateSearchSuggestion( | 479 AutocompleteMatch BaseSearchProvider::CreateSearchSuggestion( |
481 AutocompleteProvider* autocomplete_provider, | 480 AutocompleteProvider* autocomplete_provider, |
482 const AutocompleteInput& input, | 481 const AutocompleteInput& input, |
483 const SuggestResult& suggestion, | 482 const SuggestResult& suggestion, |
484 const TemplateURL* template_url, | 483 const TemplateURL* template_url, |
485 const SearchTermsData& search_terms_data, | 484 const SearchTermsData& search_terms_data, |
486 int accepted_suggestion, | 485 int accepted_suggestion, |
487 int omnibox_start_margin, | 486 int omnibox_start_margin, |
488 bool append_extra_query_params, | 487 bool append_extra_query_params) { |
489 bool from_app_list) { | |
490 AutocompleteMatch match(autocomplete_provider, suggestion.relevance(), false, | 488 AutocompleteMatch match(autocomplete_provider, suggestion.relevance(), false, |
491 suggestion.type()); | 489 suggestion.type()); |
492 | 490 |
493 if (!template_url) | 491 if (!template_url) |
494 return match; | 492 return match; |
495 match.keyword = template_url->keyword(); | 493 match.keyword = template_url->keyword(); |
496 match.contents = suggestion.match_contents(); | 494 match.contents = suggestion.match_contents(); |
497 match.contents_class = suggestion.match_contents_class(); | 495 match.contents_class = suggestion.match_contents_class(); |
498 match.answer_contents = suggestion.answer_contents(); | 496 match.answer_contents = suggestion.answer_contents(); |
499 match.answer_type = suggestion.answer_type(); | 497 match.answer_type = suggestion.answer_type(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 DCHECK(search_url.SupportsReplacement(search_terms_data)); | 534 DCHECK(search_url.SupportsReplacement(search_terms_data)); |
537 match.search_terms_args.reset( | 535 match.search_terms_args.reset( |
538 new TemplateURLRef::SearchTermsArgs(suggestion.suggestion())); | 536 new TemplateURLRef::SearchTermsArgs(suggestion.suggestion())); |
539 match.search_terms_args->original_query = input.text(); | 537 match.search_terms_args->original_query = input.text(); |
540 match.search_terms_args->accepted_suggestion = accepted_suggestion; | 538 match.search_terms_args->accepted_suggestion = accepted_suggestion; |
541 match.search_terms_args->omnibox_start_margin = omnibox_start_margin; | 539 match.search_terms_args->omnibox_start_margin = omnibox_start_margin; |
542 match.search_terms_args->suggest_query_params = | 540 match.search_terms_args->suggest_query_params = |
543 suggestion.suggest_query_params(); | 541 suggestion.suggest_query_params(); |
544 match.search_terms_args->append_extra_query_params = | 542 match.search_terms_args->append_extra_query_params = |
545 append_extra_query_params; | 543 append_extra_query_params; |
546 match.search_terms_args->from_app_list = from_app_list; | |
547 // This is the destination URL sans assisted query stats. This must be set | 544 // This is the destination URL sans assisted query stats. This must be set |
548 // so the AutocompleteController can properly de-dupe; the controller will | 545 // so the AutocompleteController can properly de-dupe; the controller will |
549 // eventually overwrite it before it reaches the user. | 546 // eventually overwrite it before it reaches the user. |
550 match.destination_url = | 547 match.destination_url = |
551 GURL(search_url.ReplaceSearchTerms(*match.search_terms_args.get(), | 548 GURL(search_url.ReplaceSearchTerms(*match.search_terms_args.get(), |
552 search_terms_data)); | 549 search_terms_data)); |
553 | 550 |
554 // Search results don't look like URLs. | 551 // Search results don't look like URLs. |
555 match.transition = suggestion.from_keyword_provider() ? | 552 match.transition = suggestion.from_keyword_provider() ? |
556 content::PAGE_TRANSITION_KEYWORD : content::PAGE_TRANSITION_GENERATED; | 553 content::PAGE_TRANSITION_KEYWORD : content::PAGE_TRANSITION_GENERATED; |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
718 InstantService* instant_service = | 715 InstantService* instant_service = |
719 InstantServiceFactory::GetForProfile(profile_); | 716 InstantServiceFactory::GetForProfile(profile_); |
720 // Android and iOS have no InstantService. | 717 // Android and iOS have no InstantService. |
721 const int omnibox_start_margin = instant_service ? | 718 const int omnibox_start_margin = instant_service ? |
722 instant_service->omnibox_start_margin() : chrome::kDisableStartMargin; | 719 instant_service->omnibox_start_margin() : chrome::kDisableStartMargin; |
723 | 720 |
724 AutocompleteMatch match = CreateSearchSuggestion( | 721 AutocompleteMatch match = CreateSearchSuggestion( |
725 this, GetInput(result.from_keyword_provider()), result, | 722 this, GetInput(result.from_keyword_provider()), result, |
726 GetTemplateURL(result.from_keyword_provider()), | 723 GetTemplateURL(result.from_keyword_provider()), |
727 UIThreadSearchTermsData(profile_), accepted_suggestion, | 724 UIThreadSearchTermsData(profile_), accepted_suggestion, |
728 omnibox_start_margin, ShouldAppendExtraParams(result), | 725 omnibox_start_margin, ShouldAppendExtraParams(result)); |
729 in_app_list_); | |
730 if (!match.destination_url.is_valid()) | 726 if (!match.destination_url.is_valid()) |
731 return; | 727 return; |
732 match.search_terms_args->bookmark_bar_pinned = | 728 match.search_terms_args->bookmark_bar_pinned = |
733 profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar); | 729 profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar); |
734 match.RecordAdditionalInfo(kRelevanceFromServerKey, | 730 match.RecordAdditionalInfo(kRelevanceFromServerKey, |
735 result.relevance_from_server() ? kTrue : kFalse); | 731 result.relevance_from_server() ? kTrue : kFalse); |
736 match.RecordAdditionalInfo(kShouldPrefetchKey, | 732 match.RecordAdditionalInfo(kShouldPrefetchKey, |
737 result.should_prefetch() ? kTrue : kFalse); | 733 result.should_prefetch() ? kTrue : kFalse); |
738 SetDeletionURL(result.deletion_url(), &match); | 734 SetDeletionURL(result.deletion_url(), &match); |
739 if (mark_as_deletable) | 735 if (mark_as_deletable) |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1003 } | 999 } |
1004 | 1000 |
1005 void BaseSearchProvider::OnDeletionComplete( | 1001 void BaseSearchProvider::OnDeletionComplete( |
1006 bool success, SuggestionDeletionHandler* handler) { | 1002 bool success, SuggestionDeletionHandler* handler) { |
1007 RecordDeletionResult(success); | 1003 RecordDeletionResult(success); |
1008 SuggestionDeletionHandlers::iterator it = std::find( | 1004 SuggestionDeletionHandlers::iterator it = std::find( |
1009 deletion_handlers_.begin(), deletion_handlers_.end(), handler); | 1005 deletion_handlers_.begin(), deletion_handlers_.end(), handler); |
1010 DCHECK(it != deletion_handlers_.end()); | 1006 DCHECK(it != deletion_handlers_.end()); |
1011 deletion_handlers_.erase(it); | 1007 deletion_handlers_.erase(it); |
1012 } | 1008 } |
OLD | NEW |