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/callback.h" | 10 #include "base/callback.h" |
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
617 listener_->OnProviderUpdate(false); | 617 listener_->OnProviderUpdate(false); |
618 } | 618 } |
619 } | 619 } |
620 | 620 |
621 void SearchProvider::DoHistoryQuery(bool minimal_changes) { | 621 void SearchProvider::DoHistoryQuery(bool minimal_changes) { |
622 // The history query results are synchronous, so if minimal_changes is true, | 622 // The history query results are synchronous, so if minimal_changes is true, |
623 // we still have the last results and don't need to do anything. | 623 // we still have the last results and don't need to do anything. |
624 if (minimal_changes) | 624 if (minimal_changes) |
625 return; | 625 return; |
626 | 626 |
627 base::TimeTicks do_history_query_start_time(base::TimeTicks::Now()); | |
628 | |
627 keyword_history_results_.clear(); | 629 keyword_history_results_.clear(); |
628 default_history_results_.clear(); | 630 default_history_results_.clear(); |
629 | 631 |
630 if (OmniboxFieldTrial::SearchHistoryDisable( | 632 if (OmniboxFieldTrial::SearchHistoryDisable( |
631 input_.current_page_classification())) | 633 input_.current_page_classification())) |
632 return; | 634 return; |
633 | 635 |
636 base::TimeTicks start_time(base::TimeTicks::Now()); | |
634 HistoryService* const history_service = | 637 HistoryService* const history_service = |
635 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); | 638 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
639 base::TimeTicks now(base::TimeTicks::Now()); | |
msw
2013/08/29 17:32:24
eliminate |now|
| |
640 UMA_HISTOGRAM_TIMES("Omnibox.SearchProvider.GetHistoryServiceTime", | |
641 now - start_time); | |
642 start_time = now; | |
636 history::URLDatabase* url_db = history_service ? | 643 history::URLDatabase* url_db = history_service ? |
637 history_service->InMemoryDatabase() : NULL; | 644 history_service->InMemoryDatabase() : NULL; |
645 UMA_HISTOGRAM_TIMES("Omnibox.SearchProvider.InMemoryDatabaseTime", | |
msw
2013/08/29 17:32:24
Is it worthwhlie to dig in beyond the overall DoHi
| |
646 base::TimeTicks::Now() - start_time); | |
638 if (!url_db) | 647 if (!url_db) |
639 return; | 648 return; |
640 | 649 |
641 // Request history for both the keyword and default provider. We grab many | 650 // Request history for both the keyword and default provider. We grab many |
642 // more matches than we'll ultimately clamp to so that if there are several | 651 // more matches than we'll ultimately clamp to so that if there are several |
643 // recent multi-word matches who scores are lowered (see | 652 // recent multi-word matches who scores are lowered (see |
644 // AddHistoryResultsToMap()), they won't crowd out older, higher-scoring | 653 // AddHistoryResultsToMap()), they won't crowd out older, higher-scoring |
645 // matches. Note that this doesn't fix the problem entirely, but merely | 654 // matches. Note that this doesn't fix the problem entirely, but merely |
646 // limits it to cases with a very large number of such multi-word matches; for | 655 // limits it to cases with a very large number of such multi-word matches; for |
647 // now, this seems OK compared with the complexity of a real fix, which would | 656 // now, this seems OK compared with the complexity of a real fix, which would |
648 // require multiple searches and tracking of "single- vs. multi-word" in the | 657 // require multiple searches and tracking of "single- vs. multi-word" in the |
649 // database. | 658 // database. |
650 int num_matches = kMaxMatches * 5; | 659 int num_matches = kMaxMatches * 5; |
651 const TemplateURL* default_url = providers_.GetDefaultProviderURL(); | 660 const TemplateURL* default_url = providers_.GetDefaultProviderURL(); |
652 if (default_url) { | 661 if (default_url) { |
662 start_time = base::TimeTicks::Now(); | |
653 url_db->GetMostRecentKeywordSearchTerms(default_url->id(), input_.text(), | 663 url_db->GetMostRecentKeywordSearchTerms(default_url->id(), input_.text(), |
654 num_matches, &default_history_results_); | 664 num_matches, &default_history_results_); |
665 UMA_HISTOGRAM_TIMES( | |
666 "Omnibox.SearchProvider.GetMostRecentKeywordTermsDefaultProviderTime", | |
msw
2013/08/29 17:32:24
nit: RecentKeywordTermsTime? I guess names don't m
| |
667 base::TimeTicks::Now() - start_time); | |
655 } | 668 } |
656 const TemplateURL* keyword_url = providers_.GetKeywordProviderURL(); | 669 const TemplateURL* keyword_url = providers_.GetKeywordProviderURL(); |
657 if (keyword_url) { | 670 if (keyword_url) { |
658 url_db->GetMostRecentKeywordSearchTerms(keyword_url->id(), | 671 url_db->GetMostRecentKeywordSearchTerms(keyword_url->id(), |
659 keyword_input_.text(), num_matches, &keyword_history_results_); | 672 keyword_input_.text(), num_matches, &keyword_history_results_); |
660 } | 673 } |
674 UMA_HISTOGRAM_TIMES("Omnibox.SearchProvider.DoHistoryQueryTime", | |
675 base::TimeTicks::Now() - do_history_query_start_time); | |
661 } | 676 } |
662 | 677 |
663 void SearchProvider::StartOrStopSuggestQuery(bool minimal_changes) { | 678 void SearchProvider::StartOrStopSuggestQuery(bool minimal_changes) { |
664 if (!IsQuerySuitableForSuggest()) { | 679 if (!IsQuerySuitableForSuggest()) { |
665 StopSuggest(); | 680 StopSuggest(); |
666 ClearAllResults(); | 681 ClearAllResults(); |
667 return; | 682 return; |
668 } | 683 } |
669 | 684 |
670 // For the minimal_changes case, if we finished the previous query and still | 685 // For the minimal_changes case, if we finished the previous query and still |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
943 comparator); | 958 comparator); |
944 std::stable_sort(results->navigation_results.begin(), | 959 std::stable_sort(results->navigation_results.begin(), |
945 results->navigation_results.end(), | 960 results->navigation_results.end(), |
946 comparator); | 961 comparator); |
947 return true; | 962 return true; |
948 } | 963 } |
949 | 964 |
950 void SearchProvider::ConvertResultsToAutocompleteMatches() { | 965 void SearchProvider::ConvertResultsToAutocompleteMatches() { |
951 // Convert all the results to matches and add them to a map, so we can keep | 966 // Convert all the results to matches and add them to a map, so we can keep |
952 // the most relevant match for each result. | 967 // the most relevant match for each result. |
968 base::TimeTicks start_time(base::TimeTicks::Now()); | |
953 MatchMap map; | 969 MatchMap map; |
954 const base::Time no_time; | 970 const base::Time no_time; |
955 int did_not_accept_keyword_suggestion = | 971 int did_not_accept_keyword_suggestion = |
956 keyword_results_.suggest_results.empty() ? | 972 keyword_results_.suggest_results.empty() ? |
957 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE : | 973 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE : |
958 TemplateURLRef::NO_SUGGESTION_CHOSEN; | 974 TemplateURLRef::NO_SUGGESTION_CHOSEN; |
959 | 975 |
960 bool relevance_from_server; | 976 bool relevance_from_server; |
961 int verbatim_relevance = GetVerbatimRelevance(&relevance_from_server); | 977 int verbatim_relevance = GetVerbatimRelevance(&relevance_from_server); |
962 int did_not_accept_default_suggestion = | 978 int did_not_accept_default_suggestion = |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1007 // Now add the most relevant matches to |matches_|. We take up to kMaxMatches | 1023 // Now add the most relevant matches to |matches_|. We take up to kMaxMatches |
1008 // suggest/navsuggest matches, regardless of origin. If Instant Extended is | 1024 // suggest/navsuggest matches, regardless of origin. If Instant Extended is |
1009 // enabled and we have server-provided (and thus hopefully more accurate) | 1025 // enabled and we have server-provided (and thus hopefully more accurate) |
1010 // scores for some suggestions, we allow more of those, until we reach | 1026 // scores for some suggestions, we allow more of those, until we reach |
1011 // AutocompleteResult::kMaxMatches total matches (that is, enough to fill the | 1027 // AutocompleteResult::kMaxMatches total matches (that is, enough to fill the |
1012 // whole popup). | 1028 // whole popup). |
1013 // | 1029 // |
1014 // We will always return any verbatim matches, no matter how we obtained their | 1030 // We will always return any verbatim matches, no matter how we obtained their |
1015 // scores, unless we have already accepted AutocompleteResult::kMaxMatches | 1031 // scores, unless we have already accepted AutocompleteResult::kMaxMatches |
1016 // higher-scoring matches under the conditions above. | 1032 // higher-scoring matches under the conditions above. |
1033 UMA_HISTOGRAM_CUSTOM_COUNTS( | |
msw
2013/08/29 17:32:24
Ditto on the questionable necessity of this given
| |
1034 "Omnibox.SearchProvider.NumMatchesToSort", matches.size(), 1, 50, 20); | |
1017 std::sort(matches.begin(), matches.end(), &AutocompleteMatch::MoreRelevant); | 1035 std::sort(matches.begin(), matches.end(), &AutocompleteMatch::MoreRelevant); |
1018 matches_.clear(); | 1036 matches_.clear(); |
1019 | 1037 |
1020 size_t num_suggestions = 0; | 1038 size_t num_suggestions = 0; |
1021 for (ACMatches::const_iterator i(matches.begin()); | 1039 for (ACMatches::const_iterator i(matches.begin()); |
1022 (i != matches.end()) && | 1040 (i != matches.end()) && |
1023 (matches_.size() < AutocompleteResult::kMaxMatches); | 1041 (matches_.size() < AutocompleteResult::kMaxMatches); |
1024 ++i) { | 1042 ++i) { |
1025 // SEARCH_OTHER_ENGINE is only used in the SearchProvider for the keyword | 1043 // SEARCH_OTHER_ENGINE is only used in the SearchProvider for the keyword |
1026 // verbatim result, so this condition basically means "if this match is a | 1044 // verbatim result, so this condition basically means "if this match is a |
1027 // suggestion of some sort". | 1045 // suggestion of some sort". |
1028 if ((i->type != AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED) && | 1046 if ((i->type != AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED) && |
1029 (i->type != AutocompleteMatchType::SEARCH_OTHER_ENGINE)) { | 1047 (i->type != AutocompleteMatchType::SEARCH_OTHER_ENGINE)) { |
1030 // If we've already hit the limit on non-server-scored suggestions, and | 1048 // If we've already hit the limit on non-server-scored suggestions, and |
1031 // this isn't a server-scored suggestion we can add, skip it. | 1049 // this isn't a server-scored suggestion we can add, skip it. |
1032 if ((num_suggestions >= kMaxMatches) && | 1050 if ((num_suggestions >= kMaxMatches) && |
1033 (!chrome::IsInstantExtendedAPIEnabled() || | 1051 (!chrome::IsInstantExtendedAPIEnabled() || |
1034 (i->GetAdditionalInfo(kRelevanceFromServerKey) != kTrue))) { | 1052 (i->GetAdditionalInfo(kRelevanceFromServerKey) != kTrue))) { |
1035 continue; | 1053 continue; |
1036 } | 1054 } |
1037 | 1055 |
1038 ++num_suggestions; | 1056 ++num_suggestions; |
1039 } | 1057 } |
1040 | 1058 |
1041 matches_.push_back(*i); | 1059 matches_.push_back(*i); |
1042 } | 1060 } |
1061 UMA_HISTOGRAM_TIMES("Omnibox.SearchProvider.ConvertResultsTime", | |
1062 base::TimeTicks::Now() - start_time); | |
1043 } | 1063 } |
1044 | 1064 |
1045 bool SearchProvider::IsTopMatchNavigationInKeywordMode() const { | 1065 bool SearchProvider::IsTopMatchNavigationInKeywordMode() const { |
1046 return (!providers_.keyword_provider().empty() && | 1066 return (!providers_.keyword_provider().empty() && |
1047 (matches_.front().type == AutocompleteMatchType::NAVSUGGEST)); | 1067 (matches_.front().type == AutocompleteMatchType::NAVSUGGEST)); |
1048 } | 1068 } |
1049 | 1069 |
1050 bool SearchProvider::IsTopMatchScoreTooLow() const { | 1070 bool SearchProvider::IsTopMatchScoreTooLow() const { |
1051 // Here we use CalculateRelevanceForVerbatimIgnoringKeywordModeState() | 1071 // Here we use CalculateRelevanceForVerbatimIgnoringKeywordModeState() |
1052 // rather than CalculateRelevanceForVerbatim() because the latter returns | 1072 // rather than CalculateRelevanceForVerbatim() because the latter returns |
(...skipping 25 matching lines...) Expand all Loading... | |
1078 ++it) { | 1098 ++it) { |
1079 if (it->allowed_to_be_default_match) | 1099 if (it->allowed_to_be_default_match) |
1080 return true; | 1100 return true; |
1081 if (!autocomplete_result_will_reorder_for_default_match) | 1101 if (!autocomplete_result_will_reorder_for_default_match) |
1082 return false; | 1102 return false; |
1083 } | 1103 } |
1084 return false; | 1104 return false; |
1085 } | 1105 } |
1086 | 1106 |
1087 void SearchProvider::UpdateMatches() { | 1107 void SearchProvider::UpdateMatches() { |
1108 base::TimeTicks update_matches_start_time(base::TimeTicks::Now()); | |
1088 ConvertResultsToAutocompleteMatches(); | 1109 ConvertResultsToAutocompleteMatches(); |
1089 | 1110 |
1090 // Check constraints that may be violated by suggested relevances. | 1111 // Check constraints that may be violated by suggested relevances. |
1091 if (!matches_.empty() && | 1112 if (!matches_.empty() && |
1092 (default_results_.HasServerProvidedScores() || | 1113 (default_results_.HasServerProvidedScores() || |
1093 keyword_results_.HasServerProvidedScores())) { | 1114 keyword_results_.HasServerProvidedScores())) { |
1094 // These blocks attempt to repair undesirable behavior by suggested | 1115 // These blocks attempt to repair undesirable behavior by suggested |
1095 // relevances with minimal impact, preserving other suggested relevances. | 1116 // relevances with minimal impact, preserving other suggested relevances. |
1096 if (IsTopMatchNavigationInKeywordMode()) { | 1117 if (IsTopMatchNavigationInKeywordMode()) { |
1097 // Correct the suggested relevance scores if the top match is a | 1118 // Correct the suggested relevance scores if the top match is a |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1149 ApplyCalculatedRelevance(); | 1170 ApplyCalculatedRelevance(); |
1150 ConvertResultsToAutocompleteMatches(); | 1171 ConvertResultsToAutocompleteMatches(); |
1151 } | 1172 } |
1152 DCHECK(!IsTopMatchNavigationInKeywordMode()); | 1173 DCHECK(!IsTopMatchNavigationInKeywordMode()); |
1153 DCHECK(omnibox_will_reorder_for_legal_default_match || | 1174 DCHECK(omnibox_will_reorder_for_legal_default_match || |
1154 !IsTopMatchScoreTooLow()); | 1175 !IsTopMatchScoreTooLow()); |
1155 DCHECK(!IsTopMatchSearchWithURLInput()); | 1176 DCHECK(!IsTopMatchSearchWithURLInput()); |
1156 DCHECK(HasValidDefaultMatch(omnibox_will_reorder_for_legal_default_match)); | 1177 DCHECK(HasValidDefaultMatch(omnibox_will_reorder_for_legal_default_match)); |
1157 } | 1178 } |
1158 | 1179 |
1180 base::TimeTicks update_starred_start_time(base::TimeTicks::Now()); | |
1159 UpdateStarredStateOfMatches(); | 1181 UpdateStarredStateOfMatches(); |
1182 UMA_HISTOGRAM_TIMES("Omnibox.SearchProvider.UpdateStarredTime", | |
msw
2013/08/29 17:32:24
ditto
| |
1183 base::TimeTicks::Now() - update_starred_start_time); | |
1160 UpdateDone(); | 1184 UpdateDone(); |
1185 UMA_HISTOGRAM_TIMES("Omnibox.SearchProvider.UpdateMatchesTime", | |
1186 base::TimeTicks::Now() - update_matches_start_time); | |
1161 } | 1187 } |
1162 | 1188 |
1163 void SearchProvider::AddNavigationResultsToMatches( | 1189 void SearchProvider::AddNavigationResultsToMatches( |
1164 const NavigationResults& navigation_results, | 1190 const NavigationResults& navigation_results, |
1165 ACMatches* matches) { | 1191 ACMatches* matches) { |
1166 for (NavigationResults::const_iterator it = navigation_results.begin(); | 1192 for (NavigationResults::const_iterator it = navigation_results.begin(); |
1167 it != navigation_results.end(); ++it) { | 1193 it != navigation_results.end(); ++it) { |
1168 matches->push_back(NavigationToMatch(*it)); | 1194 matches->push_back(NavigationToMatch(*it)); |
1169 // In the absence of suggested relevance scores, use only the single | 1195 // In the absence of suggested relevance scores, use only the single |
1170 // highest-scoring result. (The results are already sorted by relevance.) | 1196 // highest-scoring result. (The results are already sorted by relevance.) |
1171 if (!it->relevance_from_server()) | 1197 if (!it->relevance_from_server()) |
1172 return; | 1198 return; |
1173 } | 1199 } |
1174 } | 1200 } |
1175 | 1201 |
1176 void SearchProvider::AddHistoryResultsToMap(const HistoryResults& results, | 1202 void SearchProvider::AddHistoryResultsToMap(const HistoryResults& results, |
1177 bool is_keyword, | 1203 bool is_keyword, |
1178 int did_not_accept_suggestion, | 1204 int did_not_accept_suggestion, |
1179 MatchMap* map) { | 1205 MatchMap* map) { |
1180 if (results.empty()) | 1206 if (results.empty()) |
1181 return; | 1207 return; |
1182 | 1208 |
1209 base::TimeTicks start_time(base::TimeTicks::Now()); | |
1183 bool prevent_inline_autocomplete = input_.prevent_inline_autocomplete() || | 1210 bool prevent_inline_autocomplete = input_.prevent_inline_autocomplete() || |
1184 (input_.type() == AutocompleteInput::URL); | 1211 (input_.type() == AutocompleteInput::URL); |
1185 const string16& input_text = | 1212 const string16& input_text = |
1186 is_keyword ? keyword_input_.text() : input_.text(); | 1213 is_keyword ? keyword_input_.text() : input_.text(); |
1187 bool input_multiple_words = HasMultipleWords(input_text); | 1214 bool input_multiple_words = HasMultipleWords(input_text); |
1188 | 1215 |
1189 SuggestResults scored_results; | 1216 SuggestResults scored_results; |
1190 if (!prevent_inline_autocomplete && input_multiple_words) { | 1217 if (!prevent_inline_autocomplete && input_multiple_words) { |
1191 // ScoreHistoryResults() allows autocompletion of multi-word, 1-visit | 1218 // ScoreHistoryResults() allows autocompletion of multi-word, 1-visit |
1192 // queries if the input also has multiple words. But if we were already | 1219 // queries if the input also has multiple words. But if we were already |
(...skipping 13 matching lines...) Expand all Loading... | |
1206 scored_results = ScoreHistoryResults(results, prevent_inline_autocomplete, | 1233 scored_results = ScoreHistoryResults(results, prevent_inline_autocomplete, |
1207 input_multiple_words, input_text, | 1234 input_multiple_words, input_text, |
1208 is_keyword); | 1235 is_keyword); |
1209 for (SuggestResults::const_iterator i(scored_results.begin()); | 1236 for (SuggestResults::const_iterator i(scored_results.begin()); |
1210 i != scored_results.end(); ++i) { | 1237 i != scored_results.end(); ++i) { |
1211 AddMatchToMap(i->suggestion(), input_text, i->relevance(), false, | 1238 AddMatchToMap(i->suggestion(), input_text, i->relevance(), false, |
1212 AutocompleteMatchType::SEARCH_HISTORY, | 1239 AutocompleteMatchType::SEARCH_HISTORY, |
1213 did_not_accept_suggestion, | 1240 did_not_accept_suggestion, |
1214 is_keyword, map); | 1241 is_keyword, map); |
1215 } | 1242 } |
1243 UMA_HISTOGRAM_TIMES("Omnibox.SearchProvider.AddHistoryResultsTime", | |
1244 base::TimeTicks::Now() - start_time); | |
1216 } | 1245 } |
1217 | 1246 |
1218 SearchProvider::SuggestResults SearchProvider::ScoreHistoryResults( | 1247 SearchProvider::SuggestResults SearchProvider::ScoreHistoryResults( |
1219 const HistoryResults& results, | 1248 const HistoryResults& results, |
1220 bool base_prevent_inline_autocomplete, | 1249 bool base_prevent_inline_autocomplete, |
1221 bool input_multiple_words, | 1250 bool input_multiple_words, |
1222 const string16& input_text, | 1251 const string16& input_text, |
1223 bool is_keyword) { | 1252 bool is_keyword) { |
1224 AutocompleteClassifier* classifier = | 1253 AutocompleteClassifier* classifier = |
1225 AutocompleteClassifierFactory::GetForProfile(profile_); | 1254 AutocompleteClassifierFactory::GetForProfile(profile_); |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1556 it->set_relevance(max_query_relevance); | 1585 it->set_relevance(max_query_relevance); |
1557 it->set_relevance_from_server(relevance_from_server); | 1586 it->set_relevance_from_server(relevance_from_server); |
1558 } | 1587 } |
1559 } | 1588 } |
1560 | 1589 |
1561 void SearchProvider::UpdateDone() { | 1590 void SearchProvider::UpdateDone() { |
1562 // We're done when the timer isn't running, there are no suggest queries | 1591 // We're done when the timer isn't running, there are no suggest queries |
1563 // pending, and we're not waiting on Instant. | 1592 // pending, and we're not waiting on Instant. |
1564 done_ = !timer_.IsRunning() && (suggest_results_pending_ == 0); | 1593 done_ = !timer_.IsRunning() && (suggest_results_pending_ == 0); |
1565 } | 1594 } |
OLD | NEW |