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 855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
866 keyword_fetcher_.reset(); | 866 keyword_fetcher_.reset(); |
867 default_fetcher_.reset(); | 867 default_fetcher_.reset(); |
868 } | 868 } |
869 | 869 |
870 void SearchProvider::ClearAllResults() { | 870 void SearchProvider::ClearAllResults() { |
871 keyword_results_.Clear(); | 871 keyword_results_.Clear(); |
872 default_results_.Clear(); | 872 default_results_.Clear(); |
873 } | 873 } |
874 | 874 |
875 void SearchProvider::RemoveAllStaleResults() { | 875 void SearchProvider::RemoveAllStaleResults() { |
| 876 // We only need to remove stale results (which ensures the top-scoring |
| 877 // match is inlineable) if the user is not in reorder mode. In reorder |
| 878 // mode, the autocomplete system will reorder results to make sure the |
| 879 // top result is inlineable. |
| 880 const bool omnibox_will_reorder_for_legal_default_match = |
| 881 OmniboxFieldTrial::ReorderForLegalDefaultMatch( |
| 882 input_.current_page_classification()); |
876 // In theory it would be better to run an algorithm like that in | 883 // In theory it would be better to run an algorithm like that in |
877 // RemoveStaleResults(...) below that uses all four results lists | 884 // RemoveStaleResults(...) below that uses all four results lists |
878 // and both verbatim scores at once. However, that will be much | 885 // and both verbatim scores at once. However, that will be much |
879 // more complicated for little obvious gain. For code simplicity | 886 // more complicated for little obvious gain. For code simplicity |
880 // and ease in reasoning about the invariants involved, this code | 887 // and ease in reasoning about the invariants involved, this code |
881 // removes stales results from the keyword provider and default | 888 // removes stales results from the keyword provider and default |
882 // provider independently. | 889 // provider independently. |
883 RemoveStaleResults(input_.text(), GetVerbatimRelevance(NULL), | 890 if (!omnibox_will_reorder_for_legal_default_match) { |
884 &default_results_.suggest_results, | 891 RemoveStaleResults(input_.text(), GetVerbatimRelevance(NULL), |
885 &default_results_.navigation_results); | 892 &default_results_.suggest_results, |
886 if (!keyword_input_.text().empty()) { | 893 &default_results_.navigation_results); |
887 RemoveStaleResults(keyword_input_.text(), GetKeywordVerbatimRelevance(NULL), | 894 if (!keyword_input_.text().empty()) { |
888 &keyword_results_.suggest_results, | 895 RemoveStaleResults(keyword_input_.text(), |
889 &keyword_results_.navigation_results); | 896 GetKeywordVerbatimRelevance(NULL), |
890 } else { | 897 &keyword_results_.suggest_results, |
| 898 &keyword_results_.navigation_results); |
| 899 } |
| 900 } |
| 901 if (keyword_input_.text().empty()) { |
891 // User is either in keyword mode with a blank input or out of | 902 // User is either in keyword mode with a blank input or out of |
892 // keyword mode entirely. | 903 // keyword mode entirely. |
893 keyword_results_.Clear(); | 904 keyword_results_.Clear(); |
894 } | 905 } |
895 } | 906 } |
896 | 907 |
897 void SearchProvider::ApplyCalculatedRelevance() { | 908 void SearchProvider::ApplyCalculatedRelevance() { |
898 ApplyCalculatedSuggestRelevance(&keyword_results_.suggest_results); | 909 ApplyCalculatedSuggestRelevance(&keyword_results_.suggest_results); |
899 ApplyCalculatedSuggestRelevance(&default_results_.suggest_results); | 910 ApplyCalculatedSuggestRelevance(&default_results_.suggest_results); |
900 ApplyCalculatedNavigationRelevance(&keyword_results_.navigation_results); | 911 ApplyCalculatedNavigationRelevance(&keyword_results_.navigation_results); |
(...skipping 959 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1860 it->set_relevance(max_query_relevance); | 1871 it->set_relevance(max_query_relevance); |
1861 it->set_relevance_from_server(relevance_from_server); | 1872 it->set_relevance_from_server(relevance_from_server); |
1862 } | 1873 } |
1863 } | 1874 } |
1864 | 1875 |
1865 void SearchProvider::UpdateDone() { | 1876 void SearchProvider::UpdateDone() { |
1866 // We're done when the timer isn't running, there are no suggest queries | 1877 // We're done when the timer isn't running, there are no suggest queries |
1867 // pending, and we're not waiting on Instant. | 1878 // pending, and we're not waiting on Instant. |
1868 done_ = !timer_.IsRunning() && (suggest_results_pending_ == 0); | 1879 done_ = !timer_.IsRunning() && (suggest_results_pending_ == 0); |
1869 } | 1880 } |
OLD | NEW |