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 851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
862 keyword_fetcher_.reset(); | 862 keyword_fetcher_.reset(); |
863 default_fetcher_.reset(); | 863 default_fetcher_.reset(); |
864 } | 864 } |
865 | 865 |
866 void SearchProvider::ClearAllResults() { | 866 void SearchProvider::ClearAllResults() { |
867 keyword_results_.Clear(); | 867 keyword_results_.Clear(); |
868 default_results_.Clear(); | 868 default_results_.Clear(); |
869 } | 869 } |
870 | 870 |
871 void SearchProvider::RemoveAllStaleResults() { | 871 void SearchProvider::RemoveAllStaleResults() { |
872 // In theory it would be better to run an algorithm like that in | 872 // We only need to remove stale results (which ensures the top-scoring |
873 // match is inlineable) if the user is not in reorder mode. In reorder | |
874 // mode, the autocomplete system will reorder results to make sure the | |
875 // top result is inlineable. | |
876 const bool omnibox_will_reorder_for_legal_default_match = | |
877 OmniboxFieldTrial::ReorderForLegalDefaultMatch( | |
878 input_.current_page_classification()); | |
879 // In theory it would be better to run the removal algorithm like that in | |
Peter Kasting
2013/11/09 00:06:20
Nit: I think changing "an" to "the removal" here a
Mark P
2013/11/11 18:46:14
I thought "an algorithm" was vague (which algorith
| |
873 // RemoveStaleResults(...) below that uses all four results lists | 880 // RemoveStaleResults(...) below that uses all four results lists |
874 // and both verbatim scores at once. However, that will be much | 881 // and both verbatim scores at once. However, that will be much |
875 // more complicated for little obvious gain. For code simplicity | 882 // more complicated for little obvious gain. For code simplicity |
876 // and ease in reasoning about the invariants involved, this code | 883 // and ease in reasoning about the invariants involved, this code |
877 // removes stales results from the keyword provider and default | 884 // removes stales results from the keyword provider and default |
878 // provider independently. | 885 // provider independently. |
879 RemoveStaleResults(input_.text(), GetVerbatimRelevance(NULL), | 886 if (!omnibox_will_reorder_for_legal_default_match) { |
880 &default_results_.suggest_results, | 887 RemoveStaleResults(input_.text(), GetVerbatimRelevance(NULL), |
881 &default_results_.navigation_results); | 888 &default_results_.suggest_results, |
889 &default_results_.navigation_results); | |
890 } | |
882 if (!keyword_input_.text().empty()) { | 891 if (!keyword_input_.text().empty()) { |
883 RemoveStaleResults(keyword_input_.text(), GetKeywordVerbatimRelevance(NULL), | 892 if (!omnibox_will_reorder_for_legal_default_match) { |
884 &keyword_results_.suggest_results, | 893 RemoveStaleResults(keyword_input_.text(), |
885 &keyword_results_.navigation_results); | 894 GetKeywordVerbatimRelevance(NULL), |
886 } else { | 895 &keyword_results_.suggest_results, |
896 &keyword_results_.navigation_results); | |
897 } | |
898 } else { | |
887 // User is either in keyword mode with a blank input or out of | 899 // User is either in keyword mode with a blank input or out of |
888 // keyword mode entirely. | 900 // keyword mode entirely. |
889 keyword_results_.Clear(); | 901 keyword_results_.Clear(); |
890 } | 902 } |
Peter Kasting
2013/11/09 00:06:20
Tiny nit: Maybe this would match the comments bett
Mark P
2013/11/11 18:46:14
Sure, if you want. I considered both options and
| |
891 } | 903 } |
892 | 904 |
893 void SearchProvider::ApplyCalculatedRelevance() { | 905 void SearchProvider::ApplyCalculatedRelevance() { |
894 ApplyCalculatedSuggestRelevance(&keyword_results_.suggest_results); | 906 ApplyCalculatedSuggestRelevance(&keyword_results_.suggest_results); |
895 ApplyCalculatedSuggestRelevance(&default_results_.suggest_results); | 907 ApplyCalculatedSuggestRelevance(&default_results_.suggest_results); |
896 ApplyCalculatedNavigationRelevance(&keyword_results_.navigation_results); | 908 ApplyCalculatedNavigationRelevance(&keyword_results_.navigation_results); |
897 ApplyCalculatedNavigationRelevance(&default_results_.navigation_results); | 909 ApplyCalculatedNavigationRelevance(&default_results_.navigation_results); |
898 default_results_.verbatim_relevance = -1; | 910 default_results_.verbatim_relevance = -1; |
899 keyword_results_.verbatim_relevance = -1; | 911 keyword_results_.verbatim_relevance = -1; |
900 } | 912 } |
(...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1780 it->set_relevance(max_query_relevance); | 1792 it->set_relevance(max_query_relevance); |
1781 it->set_relevance_from_server(relevance_from_server); | 1793 it->set_relevance_from_server(relevance_from_server); |
1782 } | 1794 } |
1783 } | 1795 } |
1784 | 1796 |
1785 void SearchProvider::UpdateDone() { | 1797 void SearchProvider::UpdateDone() { |
1786 // We're done when the timer isn't running, there are no suggest queries | 1798 // We're done when the timer isn't running, there are no suggest queries |
1787 // pending, and we're not waiting on Instant. | 1799 // pending, and we're not waiting on Instant. |
1788 done_ = !timer_.IsRunning() && (suggest_results_pending_ == 0); | 1800 done_ = !timer_.IsRunning() && (suggest_results_pending_ == 0); |
1789 } | 1801 } |
OLD | NEW |