| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/search_provider.h" | 5 #include "chrome/browser/autocomplete/search_provider.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "base/base64.h" | 10 #include "base/base64.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
| 22 #include "chrome/browser/autocomplete/autocomplete_classifier.h" | 22 #include "chrome/browser/autocomplete/autocomplete_classifier.h" |
| 23 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" | 23 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" |
| 24 #include "chrome/browser/autocomplete/autocomplete_result.h" | 24 #include "chrome/browser/autocomplete/autocomplete_result.h" |
| 25 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" | 25 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" |
| 26 #include "chrome/browser/autocomplete/keyword_provider.h" | 26 #include "chrome/browser/autocomplete/keyword_provider.h" |
| 27 #include "chrome/browser/history/history_service.h" | 27 #include "chrome/browser/history/history_service.h" |
| 28 #include "chrome/browser/history/history_service_factory.h" | 28 #include "chrome/browser/history/history_service_factory.h" |
| 29 #include "chrome/browser/omnibox/omnibox_field_trial.h" | 29 #include "chrome/browser/omnibox/omnibox_field_trial.h" |
| 30 #include "chrome/browser/profiles/profile.h" | 30 #include "chrome/browser/profiles/profile.h" |
| 31 #include "chrome/browser/search_engines/template_url_service_factory.h" | |
| 32 #include "chrome/browser/ui/search/instant_controller.h" | |
| 33 #include "chrome/common/chrome_switches.h" | |
| 34 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
| 35 #include "components/autocomplete/autocomplete_provider_listener.h" | 32 #include "components/autocomplete/autocomplete_provider_listener.h" |
| 36 #include "components/autocomplete/url_prefix.h" | 33 #include "components/autocomplete/url_prefix.h" |
| 37 #include "components/google/core/browser/google_util.h" | 34 #include "components/google/core/browser/google_util.h" |
| 38 #include "components/history/core/browser/in_memory_database.h" | 35 #include "components/history/core/browser/in_memory_database.h" |
| 39 #include "components/history/core/browser/keyword_search_term.h" | 36 #include "components/history/core/browser/keyword_search_term.h" |
| 40 #include "components/metrics/proto/omnibox_input_type.pb.h" | 37 #include "components/metrics/proto/omnibox_input_type.pb.h" |
| 41 #include "components/search/search.h" | 38 #include "components/search/search.h" |
| 42 #include "components/search_engines/template_url_prepopulate_data.h" | 39 #include "components/search_engines/template_url_prepopulate_data.h" |
| 43 #include "components/search_engines/template_url_service.h" | 40 #include "components/search_engines/template_url_service.h" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 } | 123 } |
| 127 }; | 124 }; |
| 128 | 125 |
| 129 | 126 |
| 130 // SearchProvider ------------------------------------------------------------- | 127 // SearchProvider ------------------------------------------------------------- |
| 131 | 128 |
| 132 // static | 129 // static |
| 133 int SearchProvider::kMinimumTimeBetweenSuggestQueriesMs = 100; | 130 int SearchProvider::kMinimumTimeBetweenSuggestQueriesMs = 100; |
| 134 | 131 |
| 135 SearchProvider::SearchProvider(AutocompleteProviderListener* listener, | 132 SearchProvider::SearchProvider(AutocompleteProviderListener* listener, |
| 133 TemplateURLService* template_url_service, |
| 136 Profile* profile) | 134 Profile* profile) |
| 137 : BaseSearchProvider(listener, profile, AutocompleteProvider::TYPE_SEARCH), | 135 : BaseSearchProvider(listener, template_url_service, profile, |
| 138 providers_(TemplateURLServiceFactory::GetForProfile(profile)) { | 136 AutocompleteProvider::TYPE_SEARCH), |
| 137 providers_(template_url_service) { |
| 139 } | 138 } |
| 140 | 139 |
| 141 // static | 140 // static |
| 142 std::string SearchProvider::GetSuggestMetadata(const AutocompleteMatch& match) { | 141 std::string SearchProvider::GetSuggestMetadata(const AutocompleteMatch& match) { |
| 143 return match.GetAdditionalInfo(kSuggestMetadataKey); | 142 return match.GetAdditionalInfo(kSuggestMetadataKey); |
| 144 } | 143 } |
| 145 | 144 |
| 146 void SearchProvider::ResetSession() { | 145 void SearchProvider::ResetSession() { |
| 147 field_trial_triggered_in_session_ = false; | 146 field_trial_triggered_in_session_ = false; |
| 148 } | 147 } |
| (...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 } | 659 } |
| 661 } | 660 } |
| 662 GURL suggest_url(template_url->suggestions_url_ref().ReplaceSearchTerms( | 661 GURL suggest_url(template_url->suggestions_url_ref().ReplaceSearchTerms( |
| 663 search_term_args, | 662 search_term_args, |
| 664 providers_.template_url_service()->search_terms_data())); | 663 providers_.template_url_service()->search_terms_data())); |
| 665 if (!suggest_url.is_valid()) | 664 if (!suggest_url.is_valid()) |
| 666 return NULL; | 665 return NULL; |
| 667 // Send the current page URL if user setting and URL requirements are met and | 666 // Send the current page URL if user setting and URL requirements are met and |
| 668 // the user is in the field trial. | 667 // the user is in the field trial. |
| 669 if (CanSendURL(current_page_url_, suggest_url, template_url, | 668 if (CanSendURL(current_page_url_, suggest_url, template_url, |
| 670 input.current_page_classification(), profile_) && | 669 input.current_page_classification(), |
| 670 template_url_service_->search_terms_data(), profile_) && |
| 671 OmniboxFieldTrial::InZeroSuggestAfterTypingFieldTrial()) { | 671 OmniboxFieldTrial::InZeroSuggestAfterTypingFieldTrial()) { |
| 672 search_term_args.current_page_url = current_page_url_.spec(); | 672 search_term_args.current_page_url = current_page_url_.spec(); |
| 673 // Create the suggest URL again with the current page URL. | 673 // Create the suggest URL again with the current page URL. |
| 674 suggest_url = GURL(template_url->suggestions_url_ref().ReplaceSearchTerms( | 674 suggest_url = GURL(template_url->suggestions_url_ref().ReplaceSearchTerms( |
| 675 search_term_args, | 675 search_term_args, |
| 676 providers_.template_url_service()->search_terms_data())); | 676 providers_.template_url_service()->search_terms_data())); |
| 677 } | 677 } |
| 678 | 678 |
| 679 suggest_results_pending_++; | 679 suggest_results_pending_++; |
| 680 LogOmniboxSuggestRequest(REQUEST_SENT); | 680 LogOmniboxSuggestRequest(REQUEST_SENT); |
| (...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1241 last_answer_seen_.query_type = match->answer_type; | 1241 last_answer_seen_.query_type = match->answer_type; |
| 1242 } | 1242 } |
| 1243 | 1243 |
| 1244 void SearchProvider::DoAnswersQuery(const AutocompleteInput& input) { | 1244 void SearchProvider::DoAnswersQuery(const AutocompleteInput& input) { |
| 1245 // If the query text starts with trimmed input, this is valid prefetch data. | 1245 // If the query text starts with trimmed input, this is valid prefetch data. |
| 1246 prefetch_data_ = StartsWith(last_answer_seen_.full_query_text, | 1246 prefetch_data_ = StartsWith(last_answer_seen_.full_query_text, |
| 1247 base::CollapseWhitespace(input.text(), false), | 1247 base::CollapseWhitespace(input.text(), false), |
| 1248 false) ? | 1248 false) ? |
| 1249 last_answer_seen_ : AnswersQueryData(); | 1249 last_answer_seen_ : AnswersQueryData(); |
| 1250 } | 1250 } |
| OLD | NEW |