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/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 const int BaseSearchProvider::kDefaultProviderURLFetcherID = 1; | 109 const int BaseSearchProvider::kDefaultProviderURLFetcherID = 1; |
110 const int BaseSearchProvider::kKeywordProviderURLFetcherID = 2; | 110 const int BaseSearchProvider::kKeywordProviderURLFetcherID = 2; |
111 const int BaseSearchProvider::kDeletionURLFetcherID = 3; | 111 const int BaseSearchProvider::kDeletionURLFetcherID = 3; |
112 | 112 |
113 BaseSearchProvider::BaseSearchProvider(AutocompleteProviderListener* listener, | 113 BaseSearchProvider::BaseSearchProvider(AutocompleteProviderListener* listener, |
114 Profile* profile, | 114 Profile* profile, |
115 AutocompleteProvider::Type type) | 115 AutocompleteProvider::Type type) |
116 : AutocompleteProvider(listener, profile, type), | 116 : AutocompleteProvider(listener, profile, type), |
117 field_trial_triggered_(false), | 117 field_trial_triggered_(false), |
118 field_trial_triggered_in_session_(false), | 118 field_trial_triggered_in_session_(false), |
119 suggest_results_pending_(0) { | 119 suggest_results_pending_(0), |
| 120 in_app_list_(false) { |
120 } | 121 } |
121 | 122 |
122 // static | 123 // static |
123 bool BaseSearchProvider::ShouldPrefetch(const AutocompleteMatch& match) { | 124 bool BaseSearchProvider::ShouldPrefetch(const AutocompleteMatch& match) { |
124 return match.GetAdditionalInfo(kShouldPrefetchKey) == kTrue; | 125 return match.GetAdditionalInfo(kShouldPrefetchKey) == kTrue; |
125 } | 126 } |
126 | 127 |
127 // static | 128 // static |
128 AutocompleteMatch BaseSearchProvider::CreateSearchSuggestion( | 129 AutocompleteMatch BaseSearchProvider::CreateSearchSuggestion( |
129 const base::string16& suggestion, | 130 const base::string16& suggestion, |
130 AutocompleteMatchType::Type type, | 131 AutocompleteMatchType::Type type, |
131 bool from_keyword_provider, | 132 bool from_keyword_provider, |
132 const TemplateURL* template_url) { | 133 const TemplateURL* template_url) { |
133 return CreateSearchSuggestion( | 134 return CreateSearchSuggestion( |
134 NULL, AutocompleteInput(), BaseSearchProvider::SuggestResult( | 135 NULL, AutocompleteInput(), BaseSearchProvider::SuggestResult( |
135 suggestion, type, suggestion, base::string16(), base::string16(), | 136 suggestion, type, suggestion, base::string16(), base::string16(), |
136 std::string(), std::string(), from_keyword_provider, 0, false, false, | 137 std::string(), std::string(), from_keyword_provider, 0, false, false, |
137 base::string16()), | 138 base::string16()), |
138 template_url, 0, 0, false); | 139 template_url, 0, 0, false, false); |
139 } | 140 } |
140 | 141 |
141 void BaseSearchProvider::Stop(bool clear_cached_results) { | 142 void BaseSearchProvider::Stop(bool clear_cached_results) { |
142 StopSuggest(); | 143 StopSuggest(); |
143 done_ = true; | 144 done_ = true; |
144 | 145 |
145 if (clear_cached_results) | 146 if (clear_cached_results) |
146 ClearAllResults(); | 147 ClearAllResults(); |
147 } | 148 } |
148 | 149 |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 // BaseSearchProvider --------------------------------------------------------- | 433 // BaseSearchProvider --------------------------------------------------------- |
433 | 434 |
434 // static | 435 // static |
435 AutocompleteMatch BaseSearchProvider::CreateSearchSuggestion( | 436 AutocompleteMatch BaseSearchProvider::CreateSearchSuggestion( |
436 AutocompleteProvider* autocomplete_provider, | 437 AutocompleteProvider* autocomplete_provider, |
437 const AutocompleteInput& input, | 438 const AutocompleteInput& input, |
438 const SuggestResult& suggestion, | 439 const SuggestResult& suggestion, |
439 const TemplateURL* template_url, | 440 const TemplateURL* template_url, |
440 int accepted_suggestion, | 441 int accepted_suggestion, |
441 int omnibox_start_margin, | 442 int omnibox_start_margin, |
442 bool append_extra_query_params) { | 443 bool append_extra_query_params, |
| 444 bool from_app_list) { |
443 AutocompleteMatch match(autocomplete_provider, suggestion.relevance(), false, | 445 AutocompleteMatch match(autocomplete_provider, suggestion.relevance(), false, |
444 suggestion.type()); | 446 suggestion.type()); |
445 | 447 |
446 if (!template_url) | 448 if (!template_url) |
447 return match; | 449 return match; |
448 match.keyword = template_url->keyword(); | 450 match.keyword = template_url->keyword(); |
449 match.contents = suggestion.match_contents(); | 451 match.contents = suggestion.match_contents(); |
450 match.contents_class = suggestion.match_contents_class(); | 452 match.contents_class = suggestion.match_contents_class(); |
451 if (suggestion.type() == AutocompleteMatchType::SEARCH_SUGGEST_INFINITE) { | 453 if (suggestion.type() == AutocompleteMatchType::SEARCH_SUGGEST_INFINITE) { |
452 match.RecordAdditionalInfo( | 454 match.RecordAdditionalInfo( |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 DCHECK(search_url.SupportsReplacement()); | 489 DCHECK(search_url.SupportsReplacement()); |
488 match.search_terms_args.reset( | 490 match.search_terms_args.reset( |
489 new TemplateURLRef::SearchTermsArgs(suggestion.suggestion())); | 491 new TemplateURLRef::SearchTermsArgs(suggestion.suggestion())); |
490 match.search_terms_args->original_query = input.text(); | 492 match.search_terms_args->original_query = input.text(); |
491 match.search_terms_args->accepted_suggestion = accepted_suggestion; | 493 match.search_terms_args->accepted_suggestion = accepted_suggestion; |
492 match.search_terms_args->omnibox_start_margin = omnibox_start_margin; | 494 match.search_terms_args->omnibox_start_margin = omnibox_start_margin; |
493 match.search_terms_args->suggest_query_params = | 495 match.search_terms_args->suggest_query_params = |
494 suggestion.suggest_query_params(); | 496 suggestion.suggest_query_params(); |
495 match.search_terms_args->append_extra_query_params = | 497 match.search_terms_args->append_extra_query_params = |
496 append_extra_query_params; | 498 append_extra_query_params; |
| 499 match.search_terms_args->from_app_list = from_app_list; |
497 // This is the destination URL sans assisted query stats. This must be set | 500 // This is the destination URL sans assisted query stats. This must be set |
498 // so the AutocompleteController can properly de-dupe; the controller will | 501 // so the AutocompleteController can properly de-dupe; the controller will |
499 // eventually overwrite it before it reaches the user. | 502 // eventually overwrite it before it reaches the user. |
500 match.destination_url = | 503 match.destination_url = |
501 GURL(search_url.ReplaceSearchTerms(*match.search_terms_args.get())); | 504 GURL(search_url.ReplaceSearchTerms(*match.search_terms_args.get())); |
502 | 505 |
503 // Search results don't look like URLs. | 506 // Search results don't look like URLs. |
504 match.transition = suggestion.from_keyword_provider() ? | 507 match.transition = suggestion.from_keyword_provider() ? |
505 content::PAGE_TRANSITION_KEYWORD : content::PAGE_TRANSITION_GENERATED; | 508 content::PAGE_TRANSITION_KEYWORD : content::PAGE_TRANSITION_GENERATED; |
506 | 509 |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 MatchMap* map) { | 664 MatchMap* map) { |
662 InstantService* instant_service = | 665 InstantService* instant_service = |
663 InstantServiceFactory::GetForProfile(profile_); | 666 InstantServiceFactory::GetForProfile(profile_); |
664 // Android and iOS have no InstantService. | 667 // Android and iOS have no InstantService. |
665 const int omnibox_start_margin = instant_service ? | 668 const int omnibox_start_margin = instant_service ? |
666 instant_service->omnibox_start_margin() : chrome::kDisableStartMargin; | 669 instant_service->omnibox_start_margin() : chrome::kDisableStartMargin; |
667 | 670 |
668 AutocompleteMatch match = CreateSearchSuggestion( | 671 AutocompleteMatch match = CreateSearchSuggestion( |
669 this, GetInput(result.from_keyword_provider()), result, | 672 this, GetInput(result.from_keyword_provider()), result, |
670 GetTemplateURL(result.from_keyword_provider()), accepted_suggestion, | 673 GetTemplateURL(result.from_keyword_provider()), accepted_suggestion, |
671 omnibox_start_margin, ShouldAppendExtraParams(result)); | 674 omnibox_start_margin, ShouldAppendExtraParams(result), |
| 675 in_app_list_); |
672 if (!match.destination_url.is_valid()) | 676 if (!match.destination_url.is_valid()) |
673 return; | 677 return; |
674 match.search_terms_args->bookmark_bar_pinned = | 678 match.search_terms_args->bookmark_bar_pinned = |
675 profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar); | 679 profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar); |
676 match.RecordAdditionalInfo(kRelevanceFromServerKey, | 680 match.RecordAdditionalInfo(kRelevanceFromServerKey, |
677 result.relevance_from_server() ? kTrue : kFalse); | 681 result.relevance_from_server() ? kTrue : kFalse); |
678 match.RecordAdditionalInfo(kShouldPrefetchKey, | 682 match.RecordAdditionalInfo(kShouldPrefetchKey, |
679 result.should_prefetch() ? kTrue : kFalse); | 683 result.should_prefetch() ? kTrue : kFalse); |
680 | 684 |
681 if (!result.deletion_url().empty()) { | 685 if (!result.deletion_url().empty()) { |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
894 } | 898 } |
895 | 899 |
896 void BaseSearchProvider::OnDeletionComplete( | 900 void BaseSearchProvider::OnDeletionComplete( |
897 bool success, SuggestionDeletionHandler* handler) { | 901 bool success, SuggestionDeletionHandler* handler) { |
898 RecordDeletionResult(success); | 902 RecordDeletionResult(success); |
899 SuggestionDeletionHandlers::iterator it = std::find( | 903 SuggestionDeletionHandlers::iterator it = std::find( |
900 deletion_handlers_.begin(), deletion_handlers_.end(), handler); | 904 deletion_handlers_.begin(), deletion_handlers_.end(), handler); |
901 DCHECK(it != deletion_handlers_.end()); | 905 DCHECK(it != deletion_handlers_.end()); |
902 deletion_handlers_.erase(it); | 906 deletion_handlers_.erase(it); |
903 } | 907 } |
OLD | NEW |