| 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 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 : AutocompleteProvider(listener, profile, | 248 : AutocompleteProvider(listener, profile, |
| 249 AutocompleteProvider::TYPE_SEARCH), | 249 AutocompleteProvider::TYPE_SEARCH), |
| 250 providers_(TemplateURLServiceFactory::GetForProfile(profile)), | 250 providers_(TemplateURLServiceFactory::GetForProfile(profile)), |
| 251 suggest_results_pending_(0), | 251 suggest_results_pending_(0), |
| 252 field_trial_triggered_(false), | 252 field_trial_triggered_(false), |
| 253 field_trial_triggered_in_session_(false), | 253 field_trial_triggered_in_session_(false), |
| 254 omnibox_start_margin_(-1), | 254 omnibox_start_margin_(-1), |
| 255 prevent_search_history_inlining_( | 255 prevent_search_history_inlining_( |
| 256 OmniboxFieldTrial::SearchHistoryPreventInlining()), | 256 OmniboxFieldTrial::SearchHistoryPreventInlining()), |
| 257 disable_search_history_( | 257 disable_search_history_( |
| 258 OmniboxFieldTrial::SearchHistoryDisable()) { | 258 OmniboxFieldTrial::SearchHistoryDisable()), |
| 259 omnibox_will_reorder_for_inlining_( |
| 260 OmniboxFieldTrial::InReorderForInliningGroup()) { |
| 259 } | 261 } |
| 260 | 262 |
| 261 // static | 263 // static |
| 262 AutocompleteMatch SearchProvider::CreateSearchSuggestion( | 264 AutocompleteMatch SearchProvider::CreateSearchSuggestion( |
| 263 AutocompleteProvider* autocomplete_provider, | 265 AutocompleteProvider* autocomplete_provider, |
| 264 int relevance, | 266 int relevance, |
| 265 AutocompleteMatch::Type type, | 267 AutocompleteMatch::Type type, |
| 266 const TemplateURL* template_url, | 268 const TemplateURL* template_url, |
| 267 const string16& query_string, | 269 const string16& query_string, |
| 268 const string16& input_text, | 270 const string16& input_text, |
| (...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1118 // Disregard the suggested search and verbatim relevances if the input | 1120 // Disregard the suggested search and verbatim relevances if the input |
| 1119 // type is URL and the top match is a highly-ranked search suggestion. | 1121 // type is URL and the top match is a highly-ranked search suggestion. |
| 1120 // For example, prevent a search for "foo.com" from outranking another | 1122 // For example, prevent a search for "foo.com" from outranking another |
| 1121 // provider's navigation for "foo.com" or "foo.com/url_from_history". | 1123 // provider's navigation for "foo.com" or "foo.com/url_from_history". |
| 1122 ApplyCalculatedSuggestRelevance(&keyword_results_.suggest_results); | 1124 ApplyCalculatedSuggestRelevance(&keyword_results_.suggest_results); |
| 1123 ApplyCalculatedSuggestRelevance(&default_results_.suggest_results); | 1125 ApplyCalculatedSuggestRelevance(&default_results_.suggest_results); |
| 1124 default_results_.verbatim_relevance = -1; | 1126 default_results_.verbatim_relevance = -1; |
| 1125 keyword_results_.verbatim_relevance = -1; | 1127 keyword_results_.verbatim_relevance = -1; |
| 1126 ConvertResultsToAutocompleteMatches(); | 1128 ConvertResultsToAutocompleteMatches(); |
| 1127 } | 1129 } |
| 1128 if (IsTopMatchNotInlinable()) { | 1130 if (!omnibox_will_reorder_for_inlining_ && IsTopMatchNotInlinable()) { |
| 1129 // Disregard suggested relevances if the top match is not a verbatim match | 1131 // Disregard suggested relevances if the top match is not a verbatim match |
| 1130 // or inlinable. For example, input "foo" should not invoke a search for | 1132 // or inlinable. For example, input "foo" should not invoke a search for |
| 1131 // "bar", which would happen if the "bar" search match outranked all other | 1133 // "bar", which would happen if the "bar" search match outranked all other |
| 1132 // matches. | 1134 // matches. |
| 1133 ApplyCalculatedRelevance(); | 1135 ApplyCalculatedRelevance(); |
| 1134 ConvertResultsToAutocompleteMatches(); | 1136 ConvertResultsToAutocompleteMatches(); |
| 1135 } | 1137 } |
| 1136 DCHECK(!IsTopMatchNavigationInKeywordMode()); | 1138 DCHECK(!IsTopMatchNavigationInKeywordMode()); |
| 1137 DCHECK(!IsTopMatchScoreTooLow()); | 1139 DCHECK(!IsTopMatchScoreTooLow()); |
| 1138 DCHECK(!IsTopMatchHighRankSearchForURL()); | 1140 DCHECK(!IsTopMatchHighRankSearchForURL()); |
| 1139 DCHECK(!IsTopMatchNotInlinable()); | 1141 DCHECK(omnibox_will_reorder_for_inlining_ || !IsTopMatchNotInlinable()); |
| 1140 } | 1142 } |
| 1141 | 1143 |
| 1142 UpdateStarredStateOfMatches(); | 1144 UpdateStarredStateOfMatches(); |
| 1143 UpdateDone(); | 1145 UpdateDone(); |
| 1144 } | 1146 } |
| 1145 | 1147 |
| 1146 void SearchProvider::AddNavigationResultsToMatches( | 1148 void SearchProvider::AddNavigationResultsToMatches( |
| 1147 const NavigationResults& navigation_results, | 1149 const NavigationResults& navigation_results, |
| 1148 ACMatches* matches) { | 1150 ACMatches* matches) { |
| 1149 for (NavigationResults::const_iterator it = navigation_results.begin(); | 1151 for (NavigationResults::const_iterator it = navigation_results.begin(); |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1516 it->set_relevance(max_query_relevance); | 1518 it->set_relevance(max_query_relevance); |
| 1517 it->set_relevance_from_server(relevance_from_server); | 1519 it->set_relevance_from_server(relevance_from_server); |
| 1518 } | 1520 } |
| 1519 } | 1521 } |
| 1520 | 1522 |
| 1521 void SearchProvider::UpdateDone() { | 1523 void SearchProvider::UpdateDone() { |
| 1522 // We're done when the timer isn't running, there are no suggest queries | 1524 // We're done when the timer isn't running, there are no suggest queries |
| 1523 // pending, and we're not waiting on Instant. | 1525 // pending, and we're not waiting on Instant. |
| 1524 done_ = !timer_.IsRunning() && (suggest_results_pending_ == 0); | 1526 done_ = !timer_.IsRunning() && (suggest_results_pending_ == 0); |
| 1525 } | 1527 } |
| OLD | NEW |