| 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 "components/omnibox/browser/search_provider.h" | 5 #include "components/omnibox/browser/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 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 Stop(true, false); | 305 Stop(true, false); |
| 306 return; | 306 return; |
| 307 } | 307 } |
| 308 | 308 |
| 309 input_ = input; | 309 input_ = input; |
| 310 | 310 |
| 311 DoHistoryQuery(minimal_changes); | 311 DoHistoryQuery(minimal_changes); |
| 312 // Answers needs scored history results before any suggest query has been | 312 // Answers needs scored history results before any suggest query has been |
| 313 // started, since the query for answer-bearing results needs additional | 313 // started, since the query for answer-bearing results needs additional |
| 314 // prefetch information based on the highest-scored local history result. | 314 // prefetch information based on the highest-scored local history result. |
| 315 if (OmniboxFieldTrial::EnableAnswersInSuggest()) { | 315 ScoreHistoryResults(raw_default_history_results_, |
| 316 ScoreHistoryResults(raw_default_history_results_, | 316 false, |
| 317 false, | 317 &transformed_default_history_results_); |
| 318 &transformed_default_history_results_); | 318 ScoreHistoryResults(raw_keyword_history_results_, |
| 319 ScoreHistoryResults(raw_keyword_history_results_, | 319 true, |
| 320 true, | 320 &transformed_keyword_history_results_); |
| 321 &transformed_keyword_history_results_); | 321 prefetch_data_ = FindAnswersPrefetchData(); |
| 322 prefetch_data_ = FindAnswersPrefetchData(); | |
| 323 | 322 |
| 324 // Raw results are not needed any more. | 323 // Raw results are not needed any more. |
| 325 raw_default_history_results_.clear(); | 324 raw_default_history_results_.clear(); |
| 326 raw_keyword_history_results_.clear(); | 325 raw_keyword_history_results_.clear(); |
| 327 } | |
| 328 | 326 |
| 329 StartOrStopSuggestQuery(minimal_changes); | 327 StartOrStopSuggestQuery(minimal_changes); |
| 330 UpdateMatches(); | 328 UpdateMatches(); |
| 331 } | 329 } |
| 332 | 330 |
| 333 void SearchProvider::Stop(bool clear_cached_results, | 331 void SearchProvider::Stop(bool clear_cached_results, |
| 334 bool due_to_user_inactivity) { | 332 bool due_to_user_inactivity) { |
| 335 StopSuggest(); | 333 StopSuggest(); |
| 336 done_ = true; | 334 done_ = true; |
| 337 | 335 |
| (...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 827 const TemplateURL* template_url, | 825 const TemplateURL* template_url, |
| 828 const AutocompleteInput& input) { | 826 const AutocompleteInput& input) { |
| 829 if (!template_url || template_url->suggestions_url().empty()) | 827 if (!template_url || template_url->suggestions_url().empty()) |
| 830 return NULL; | 828 return NULL; |
| 831 | 829 |
| 832 // Bail if the suggestion URL is invalid with the given replacements. | 830 // Bail if the suggestion URL is invalid with the given replacements. |
| 833 TemplateURLRef::SearchTermsArgs search_term_args(input.text()); | 831 TemplateURLRef::SearchTermsArgs search_term_args(input.text()); |
| 834 search_term_args.input_type = input.type(); | 832 search_term_args.input_type = input.type(); |
| 835 search_term_args.cursor_position = input.cursor_position(); | 833 search_term_args.cursor_position = input.cursor_position(); |
| 836 search_term_args.page_classification = input.current_page_classification(); | 834 search_term_args.page_classification = input.current_page_classification(); |
| 837 if (OmniboxFieldTrial::EnableAnswersInSuggest()) { | 835 // Session token and prefetch data required for answers. |
| 838 search_term_args.session_token = GetSessionToken(); | 836 search_term_args.session_token = GetSessionToken(); |
| 839 if (!prefetch_data_.full_query_text.empty()) { | 837 if (!prefetch_data_.full_query_text.empty()) { |
| 840 search_term_args.prefetch_query = | 838 search_term_args.prefetch_query = |
| 841 base::UTF16ToUTF8(prefetch_data_.full_query_text); | 839 base::UTF16ToUTF8(prefetch_data_.full_query_text); |
| 842 search_term_args.prefetch_query_type = | 840 search_term_args.prefetch_query_type = |
| 843 base::UTF16ToUTF8(prefetch_data_.query_type); | 841 base::UTF16ToUTF8(prefetch_data_.query_type); |
| 844 } | |
| 845 } | 842 } |
| 846 GURL suggest_url(template_url->suggestions_url_ref().ReplaceSearchTerms( | 843 GURL suggest_url(template_url->suggestions_url_ref().ReplaceSearchTerms( |
| 847 search_term_args, | 844 search_term_args, |
| 848 client()->GetTemplateURLService()->search_terms_data())); | 845 client()->GetTemplateURLService()->search_terms_data())); |
| 849 if (!suggest_url.is_valid()) | 846 if (!suggest_url.is_valid()) |
| 850 return NULL; | 847 return NULL; |
| 848 |
| 851 // Send the current page URL if user setting and URL requirements are met and | 849 // Send the current page URL if user setting and URL requirements are met and |
| 852 // the user is in the field trial. | 850 // the user is in the field trial. |
| 853 TemplateURLService* template_url_service = client()->GetTemplateURLService(); | 851 TemplateURLService* template_url_service = client()->GetTemplateURLService(); |
| 854 if (CanSendURL(input.current_url(), suggest_url, template_url, | 852 if (CanSendURL(input.current_url(), suggest_url, template_url, |
| 855 input.current_page_classification(), | 853 input.current_page_classification(), |
| 856 template_url_service->search_terms_data(), client()) && | 854 template_url_service->search_terms_data(), client()) && |
| 857 OmniboxFieldTrial::InZeroSuggestAfterTypingFieldTrial()) { | 855 OmniboxFieldTrial::InZeroSuggestAfterTypingFieldTrial()) { |
| 858 search_term_args.current_page_url = input.current_url().spec(); | 856 search_term_args.current_page_url = input.current_url().spec(); |
| 859 // Create the suggest URL again with the current page URL. | 857 // Create the suggest URL again with the current page URL. |
| 860 suggest_url = GURL(template_url->suggestions_url_ref().ReplaceSearchTerms( | 858 suggest_url = GURL(template_url->suggestions_url_ref().ReplaceSearchTerms( |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1059 // In the absence of suggested relevance scores, use only the single | 1057 // In the absence of suggested relevance scores, use only the single |
| 1060 // highest-scoring result. (The results are already sorted by relevance.) | 1058 // highest-scoring result. (The results are already sorted by relevance.) |
| 1061 if (!it->relevance_from_server()) | 1059 if (!it->relevance_from_server()) |
| 1062 return; | 1060 return; |
| 1063 } | 1061 } |
| 1064 } | 1062 } |
| 1065 | 1063 |
| 1066 void SearchProvider::AddRawHistoryResultsToMap(bool is_keyword, | 1064 void SearchProvider::AddRawHistoryResultsToMap(bool is_keyword, |
| 1067 int did_not_accept_suggestion, | 1065 int did_not_accept_suggestion, |
| 1068 MatchMap* map) { | 1066 MatchMap* map) { |
| 1069 const HistoryResults& raw_results = | |
| 1070 is_keyword ? raw_keyword_history_results_ : raw_default_history_results_; | |
| 1071 if (!OmniboxFieldTrial::EnableAnswersInSuggest() && raw_results.empty()) | |
| 1072 return; | |
| 1073 | |
| 1074 base::TimeTicks start_time(base::TimeTicks::Now()); | 1067 base::TimeTicks start_time(base::TimeTicks::Now()); |
| 1075 | 1068 |
| 1076 // Until Answers becomes default, scoring of history results will still happen | 1069 const SearchSuggestionParser::SuggestResults* transformed_results = |
| 1077 // here for non-Answers Chrome, to prevent scoring performance regressions | 1070 is_keyword ? &transformed_keyword_history_results_ |
| 1078 // resulting from moving the scoring code before the suggest request is sent. | 1071 : &transformed_default_history_results_; |
| 1079 // For users with Answers enabled, the history results have already been | |
| 1080 // scored earlier, right after calling DoHistoryQuery(). | |
| 1081 SearchSuggestionParser::SuggestResults local_transformed_results; | |
| 1082 const SearchSuggestionParser::SuggestResults* transformed_results = NULL; | |
| 1083 if (!OmniboxFieldTrial::EnableAnswersInSuggest()) { | |
| 1084 ScoreHistoryResults(raw_results, is_keyword, &local_transformed_results); | |
| 1085 transformed_results = &local_transformed_results; | |
| 1086 } else { | |
| 1087 transformed_results = is_keyword ? &transformed_keyword_history_results_ | |
| 1088 : &transformed_default_history_results_; | |
| 1089 } | |
| 1090 DCHECK(transformed_results); | 1072 DCHECK(transformed_results); |
| 1091 AddTransformedHistoryResultsToMap( | 1073 AddTransformedHistoryResultsToMap( |
| 1092 *transformed_results, did_not_accept_suggestion, map); | 1074 *transformed_results, did_not_accept_suggestion, map); |
| 1093 UMA_HISTOGRAM_TIMES("Omnibox.SearchProvider.AddHistoryResultsTime", | 1075 UMA_HISTOGRAM_TIMES("Omnibox.SearchProvider.AddHistoryResultsTime", |
| 1094 base::TimeTicks::Now() - start_time); | 1076 base::TimeTicks::Now() - start_time); |
| 1095 } | 1077 } |
| 1096 | 1078 |
| 1097 void SearchProvider::AddTransformedHistoryResultsToMap( | 1079 void SearchProvider::AddTransformedHistoryResultsToMap( |
| 1098 const SearchSuggestionParser::SuggestResults& transformed_results, | 1080 const SearchSuggestionParser::SuggestResults& transformed_results, |
| 1099 int did_not_accept_suggestion, | 1081 int did_not_accept_suggestion, |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1514 for (MatchMap::const_iterator i(map.begin()); i != map.end(); ++i) | 1496 for (MatchMap::const_iterator i(map.begin()); i != map.end(); ++i) |
| 1515 matches.push_back(i->second); | 1497 matches.push_back(i->second); |
| 1516 std::sort(matches.begin(), matches.end(), &AutocompleteMatch::MoreRelevant); | 1498 std::sort(matches.begin(), matches.end(), &AutocompleteMatch::MoreRelevant); |
| 1517 | 1499 |
| 1518 // If there is a top scoring entry, find the corresponding answer. | 1500 // If there is a top scoring entry, find the corresponding answer. |
| 1519 if (!matches.empty()) | 1501 if (!matches.empty()) |
| 1520 return answers_cache_.GetTopAnswerEntry(matches[0].contents); | 1502 return answers_cache_.GetTopAnswerEntry(matches[0].contents); |
| 1521 | 1503 |
| 1522 return AnswersQueryData(); | 1504 return AnswersQueryData(); |
| 1523 } | 1505 } |
| OLD | NEW |