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" |
11 #include "base/prefs/pref_registry_simple.h" | 11 #include "base/prefs/pref_registry_simple.h" |
12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h" | 15 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h" |
16 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" | 16 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" |
17 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher_service.h" | 17 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher_service.h" |
18 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher_service_factory.h" | 18 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher_service_factory.h" |
19 #include "chrome/browser/history/history_service.h" | 19 #include "chrome/browser/history/history_service.h" |
20 #include "chrome/browser/history/history_service_factory.h" | 20 #include "chrome/browser/history/history_service_factory.h" |
21 #include "chrome/browser/omnibox/omnibox_field_trial.h" | 21 #include "chrome/browser/omnibox/omnibox_field_trial.h" |
22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/browser/search/instant_service.h" | |
24 #include "chrome/browser/search/instant_service_factory.h" | |
25 #include "chrome/browser/search/search.h" | 23 #include "chrome/browser/search/search.h" |
26 #include "chrome/browser/search_engines/template_url_service_factory.h" | 24 #include "chrome/browser/search_engines/template_url_service_factory.h" |
27 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" | 25 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" |
28 #include "chrome/browser/sync/profile_sync_service.h" | 26 #include "chrome/browser/sync/profile_sync_service.h" |
29 #include "chrome/browser/sync/profile_sync_service_factory.h" | 27 #include "chrome/browser/sync/profile_sync_service_factory.h" |
30 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
31 #include "components/autocomplete/url_prefix.h" | 29 #include "components/autocomplete/url_prefix.h" |
32 #include "components/metrics/proto/omnibox_event.pb.h" | 30 #include "components/metrics/proto/omnibox_event.pb.h" |
33 #include "components/metrics/proto/omnibox_input_type.pb.h" | 31 #include "components/metrics/proto/omnibox_input_type.pb.h" |
34 #include "components/search_engines/template_url.h" | 32 #include "components/search_engines/template_url.h" |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 const base::string16& suggestion, | 146 const base::string16& suggestion, |
149 AutocompleteMatchType::Type type, | 147 AutocompleteMatchType::Type type, |
150 bool from_keyword_provider, | 148 bool from_keyword_provider, |
151 const TemplateURL* template_url, | 149 const TemplateURL* template_url, |
152 const SearchTermsData& search_terms_data) { | 150 const SearchTermsData& search_terms_data) { |
153 return CreateSearchSuggestion( | 151 return CreateSearchSuggestion( |
154 NULL, AutocompleteInput(), BaseSearchProvider::SuggestResult( | 152 NULL, AutocompleteInput(), BaseSearchProvider::SuggestResult( |
155 suggestion, type, suggestion, base::string16(), base::string16(), | 153 suggestion, type, suggestion, base::string16(), base::string16(), |
156 base::string16(), base::string16(), std::string(), std::string(), | 154 base::string16(), base::string16(), std::string(), std::string(), |
157 from_keyword_provider, 0, false, false, base::string16()), | 155 from_keyword_provider, 0, false, false, base::string16()), |
158 template_url, search_terms_data, 0, 0, false, false); | 156 template_url, search_terms_data, 0, false, false); |
159 } | 157 } |
160 | 158 |
161 void BaseSearchProvider::Stop(bool clear_cached_results) { | 159 void BaseSearchProvider::Stop(bool clear_cached_results) { |
162 StopSuggest(); | 160 StopSuggest(); |
163 done_ = true; | 161 done_ = true; |
164 | 162 |
165 if (clear_cached_results) | 163 if (clear_cached_results) |
166 ClearAllResults(); | 164 ClearAllResults(); |
167 } | 165 } |
168 | 166 |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 // BaseSearchProvider --------------------------------------------------------- | 474 // BaseSearchProvider --------------------------------------------------------- |
477 | 475 |
478 // static | 476 // static |
479 AutocompleteMatch BaseSearchProvider::CreateSearchSuggestion( | 477 AutocompleteMatch BaseSearchProvider::CreateSearchSuggestion( |
480 AutocompleteProvider* autocomplete_provider, | 478 AutocompleteProvider* autocomplete_provider, |
481 const AutocompleteInput& input, | 479 const AutocompleteInput& input, |
482 const SuggestResult& suggestion, | 480 const SuggestResult& suggestion, |
483 const TemplateURL* template_url, | 481 const TemplateURL* template_url, |
484 const SearchTermsData& search_terms_data, | 482 const SearchTermsData& search_terms_data, |
485 int accepted_suggestion, | 483 int accepted_suggestion, |
486 int omnibox_start_margin, | |
487 bool append_extra_query_params, | 484 bool append_extra_query_params, |
488 bool from_app_list) { | 485 bool from_app_list) { |
489 AutocompleteMatch match(autocomplete_provider, suggestion.relevance(), false, | 486 AutocompleteMatch match(autocomplete_provider, suggestion.relevance(), false, |
490 suggestion.type()); | 487 suggestion.type()); |
491 | 488 |
492 if (!template_url) | 489 if (!template_url) |
493 return match; | 490 return match; |
494 match.keyword = template_url->keyword(); | 491 match.keyword = template_url->keyword(); |
495 match.contents = suggestion.match_contents(); | 492 match.contents = suggestion.match_contents(); |
496 match.contents_class = suggestion.match_contents_class(); | 493 match.contents_class = suggestion.match_contents_class(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 match.allowed_to_be_default_match = true; | 527 match.allowed_to_be_default_match = true; |
531 } | 528 } |
532 match.fill_into_edit.append(suggestion.suggestion()); | 529 match.fill_into_edit.append(suggestion.suggestion()); |
533 | 530 |
534 const TemplateURLRef& search_url = template_url->url_ref(); | 531 const TemplateURLRef& search_url = template_url->url_ref(); |
535 DCHECK(search_url.SupportsReplacement(search_terms_data)); | 532 DCHECK(search_url.SupportsReplacement(search_terms_data)); |
536 match.search_terms_args.reset( | 533 match.search_terms_args.reset( |
537 new TemplateURLRef::SearchTermsArgs(suggestion.suggestion())); | 534 new TemplateURLRef::SearchTermsArgs(suggestion.suggestion())); |
538 match.search_terms_args->original_query = input.text(); | 535 match.search_terms_args->original_query = input.text(); |
539 match.search_terms_args->accepted_suggestion = accepted_suggestion; | 536 match.search_terms_args->accepted_suggestion = accepted_suggestion; |
540 match.search_terms_args->omnibox_start_margin = omnibox_start_margin; | 537 match.search_terms_args->enable_omnibox_start_margin = true; |
541 match.search_terms_args->suggest_query_params = | 538 match.search_terms_args->suggest_query_params = |
542 suggestion.suggest_query_params(); | 539 suggestion.suggest_query_params(); |
543 match.search_terms_args->append_extra_query_params = | 540 match.search_terms_args->append_extra_query_params = |
544 append_extra_query_params; | 541 append_extra_query_params; |
545 match.search_terms_args->from_app_list = from_app_list; | 542 match.search_terms_args->from_app_list = from_app_list; |
546 // This is the destination URL sans assisted query stats. This must be set | 543 // This is the destination URL sans assisted query stats. This must be set |
547 // so the AutocompleteController can properly de-dupe; the controller will | 544 // so the AutocompleteController can properly de-dupe; the controller will |
548 // eventually overwrite it before it reaches the user. | 545 // eventually overwrite it before it reaches the user. |
549 match.destination_url = | 546 match.destination_url = |
550 GURL(search_url.ReplaceSearchTerms(*match.search_terms_args.get(), | 547 GURL(search_url.ReplaceSearchTerms(*match.search_terms_args.get(), |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 UpdateMatches(); | 704 UpdateMatches(); |
708 if (done_ || results_updated) | 705 if (done_ || results_updated) |
709 listener_->OnProviderUpdate(results_updated); | 706 listener_->OnProviderUpdate(results_updated); |
710 } | 707 } |
711 | 708 |
712 void BaseSearchProvider::AddMatchToMap(const SuggestResult& result, | 709 void BaseSearchProvider::AddMatchToMap(const SuggestResult& result, |
713 const std::string& metadata, | 710 const std::string& metadata, |
714 int accepted_suggestion, | 711 int accepted_suggestion, |
715 bool mark_as_deletable, | 712 bool mark_as_deletable, |
716 MatchMap* map) { | 713 MatchMap* map) { |
717 InstantService* instant_service = | |
718 InstantServiceFactory::GetForProfile(profile_); | |
719 // Android and iOS have no InstantService. | |
720 const int omnibox_start_margin = instant_service ? | |
721 instant_service->omnibox_start_margin() : chrome::kDisableStartMargin; | |
722 | |
723 AutocompleteMatch match = CreateSearchSuggestion( | 714 AutocompleteMatch match = CreateSearchSuggestion( |
724 this, GetInput(result.from_keyword_provider()), result, | 715 this, GetInput(result.from_keyword_provider()), result, |
725 GetTemplateURL(result.from_keyword_provider()), | 716 GetTemplateURL(result.from_keyword_provider()), |
726 UIThreadSearchTermsData(profile_), accepted_suggestion, | 717 UIThreadSearchTermsData(profile_), accepted_suggestion, |
727 omnibox_start_margin, ShouldAppendExtraParams(result), | 718 ShouldAppendExtraParams(result), in_app_list_); |
728 in_app_list_); | |
729 if (!match.destination_url.is_valid()) | 719 if (!match.destination_url.is_valid()) |
730 return; | 720 return; |
731 match.search_terms_args->bookmark_bar_pinned = | 721 match.search_terms_args->bookmark_bar_pinned = |
732 profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar); | 722 profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar); |
733 match.RecordAdditionalInfo(kRelevanceFromServerKey, | 723 match.RecordAdditionalInfo(kRelevanceFromServerKey, |
734 result.relevance_from_server() ? kTrue : kFalse); | 724 result.relevance_from_server() ? kTrue : kFalse); |
735 match.RecordAdditionalInfo(kShouldPrefetchKey, | 725 match.RecordAdditionalInfo(kShouldPrefetchKey, |
736 result.should_prefetch() ? kTrue : kFalse); | 726 result.should_prefetch() ? kTrue : kFalse); |
737 SetDeletionURL(result.deletion_url(), &match); | 727 SetDeletionURL(result.deletion_url(), &match); |
738 if (mark_as_deletable) | 728 if (mark_as_deletable) |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1002 } | 992 } |
1003 | 993 |
1004 void BaseSearchProvider::OnDeletionComplete( | 994 void BaseSearchProvider::OnDeletionComplete( |
1005 bool success, SuggestionDeletionHandler* handler) { | 995 bool success, SuggestionDeletionHandler* handler) { |
1006 RecordDeletionResult(success); | 996 RecordDeletionResult(success); |
1007 SuggestionDeletionHandlers::iterator it = std::find( | 997 SuggestionDeletionHandlers::iterator it = std::find( |
1008 deletion_handlers_.begin(), deletion_handlers_.end(), handler); | 998 deletion_handlers_.begin(), deletion_handlers_.end(), handler); |
1009 DCHECK(it != deletion_handlers_.end()); | 999 DCHECK(it != deletion_handlers_.end()); |
1010 deletion_handlers_.erase(it); | 1000 deletion_handlers_.erase(it); |
1011 } | 1001 } |
OLD | NEW |