| 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 19 matching lines...) Expand all Loading... |
| 30 #include "chrome/browser/history/history_service.h" | 30 #include "chrome/browser/history/history_service.h" |
| 31 #include "chrome/browser/history/history_service_factory.h" | 31 #include "chrome/browser/history/history_service_factory.h" |
| 32 #include "chrome/browser/history/in_memory_database.h" | 32 #include "chrome/browser/history/in_memory_database.h" |
| 33 #include "chrome/browser/metrics/variations/variations_http_header_provider.h" | 33 #include "chrome/browser/metrics/variations/variations_http_header_provider.h" |
| 34 #include "chrome/browser/net/url_fixer_upper.h" | 34 #include "chrome/browser/net/url_fixer_upper.h" |
| 35 #include "chrome/browser/profiles/profile.h" | 35 #include "chrome/browser/profiles/profile.h" |
| 36 #include "chrome/browser/search_engines/search_engine_type.h" | 36 #include "chrome/browser/search_engines/search_engine_type.h" |
| 37 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" | 37 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" |
| 38 #include "chrome/browser/search_engines/template_url_service.h" | 38 #include "chrome/browser/search_engines/template_url_service.h" |
| 39 #include "chrome/browser/search_engines/template_url_service_factory.h" | 39 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 40 #include "chrome/browser/ui/browser_instant_controller.h" | |
| 41 #include "chrome/browser/ui/search/search.h" | 40 #include "chrome/browser/ui/search/search.h" |
| 42 #include "chrome/common/pref_names.h" | 41 #include "chrome/common/pref_names.h" |
| 43 #include "chrome/common/url_constants.h" | 42 #include "chrome/common/url_constants.h" |
| 44 #include "googleurl/src/url_util.h" | 43 #include "googleurl/src/url_util.h" |
| 45 #include "grit/generated_resources.h" | 44 #include "grit/generated_resources.h" |
| 46 #include "net/base/escape.h" | 45 #include "net/base/escape.h" |
| 47 #include "net/base/load_flags.h" | 46 #include "net/base/load_flags.h" |
| 48 #include "net/base/net_util.h" | 47 #include "net/base/net_util.h" |
| 49 #include "net/http/http_request_headers.h" | 48 #include "net/http/http_request_headers.h" |
| 50 #include "net/http/http_response_headers.h" | 49 #include "net/http/http_response_headers.h" |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 if (((i->type == AutocompleteMatch::SEARCH_HISTORY) || | 166 if (((i->type == AutocompleteMatch::SEARCH_HISTORY) || |
| 168 (i->type == AutocompleteMatch::SEARCH_SUGGEST)) && | 167 (i->type == AutocompleteMatch::SEARCH_SUGGEST)) && |
| 169 (i->fill_into_edit == text)) { | 168 (i->fill_into_edit == text)) { |
| 170 i = matches_.erase(i); | 169 i = matches_.erase(i); |
| 171 results_updated = true; | 170 results_updated = true; |
| 172 } else { | 171 } else { |
| 173 ++i; | 172 ++i; |
| 174 } | 173 } |
| 175 } | 174 } |
| 176 | 175 |
| 177 // Add the new instant suggest result. | 176 // Add the new Instant suggest result. |
| 178 if (suggestion.type == INSTANT_SUGGESTION_SEARCH) { | 177 if (!suggestion.is_url) { |
| 179 // Instant has a query suggestion. Rank it higher than SEARCH_WHAT_YOU_TYPED | 178 // Instant has a query suggestion. Rank it higher than SEARCH_WHAT_YOU_TYPED |
| 180 // so that it gets autocompleted. | 179 // so that it gets autocompleted. |
| 181 const int verbatim_relevance = GetVerbatimRelevance(); | 180 const int verbatim_relevance = GetVerbatimRelevance(); |
| 182 int did_not_accept_default_suggestion = default_suggest_results_.empty() ? | 181 int did_not_accept_default_suggestion = default_suggest_results_.empty() ? |
| 183 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE : | 182 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE : |
| 184 TemplateURLRef::NO_SUGGESTION_CHOSEN; | 183 TemplateURLRef::NO_SUGGESTION_CHOSEN; |
| 185 MatchMap match_map; | 184 MatchMap match_map; |
| 186 AddMatchToMap(text, adjusted_input_text, verbatim_relevance + 1, | 185 AddMatchToMap(text, adjusted_input_text, verbatim_relevance + 1, |
| 187 AutocompleteMatch::SEARCH_SUGGEST, | 186 AutocompleteMatch::SEARCH_SUGGEST, |
| 188 did_not_accept_default_suggestion, false, &match_map); | 187 did_not_accept_default_suggestion, false, &match_map); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 ACMatchClassification(0, ACMatchClassification::NONE)); | 275 ACMatchClassification(0, ACMatchClassification::NONE)); |
| 277 match.keyword = providers_.default_provider(); | 276 match.keyword = providers_.default_provider(); |
| 278 matches_.push_back(match); | 277 matches_.push_back(match); |
| 279 } | 278 } |
| 280 Stop(false); | 279 Stop(false); |
| 281 return; | 280 return; |
| 282 } | 281 } |
| 283 | 282 |
| 284 input_ = input; | 283 input_ = input; |
| 285 | 284 |
| 286 // Don't run the normal provider flow when the Instant Extended API is | 285 // When Instant is enabled in the extended mode, the embedded page will handle |
| 287 // enabled. (When the Extended API is enabled, the embedded page will handle | 286 // all search suggestions itself, so don't run the normal provider flow. |
| 288 // all search suggestions itself.) | 287 // TODO(dcblack): Once we are done refactoring the omnibox so we don't need to |
| 289 // TODO(dcblack): once we are done refactoring the omnibox so we don't need to | |
| 290 // use FinalizeInstantQuery anymore, we can take out this check and remove | 288 // use FinalizeInstantQuery anymore, we can take out this check and remove |
| 291 // this provider from kInstantExtendedOmniboxProviders. | 289 // this provider from kInstantExtendedOmniboxProviders. |
| 292 if (!chrome::search::IsInstantExtendedAPIEnabled(profile_)) { | 290 if (!chrome::search::IsInstantExtendedAPIEnabled(profile_) || |
| 291 !chrome::search::IsInstantEnabled(profile_)) { |
| 293 DoHistoryQuery(minimal_changes); | 292 DoHistoryQuery(minimal_changes); |
| 294 StartOrStopSuggestQuery(minimal_changes); | 293 StartOrStopSuggestQuery(minimal_changes); |
| 295 } | 294 } |
| 296 UpdateMatches(); | 295 UpdateMatches(); |
| 297 } | 296 } |
| 298 | 297 |
| 299 SearchProvider::Result::Result(int relevance) : relevance_(relevance) {} | 298 SearchProvider::Result::Result(int relevance) : relevance_(relevance) {} |
| 300 SearchProvider::Result::~Result() {} | 299 SearchProvider::Result::~Result() {} |
| 301 | 300 |
| 302 SearchProvider::SuggestResult::SuggestResult(const string16& suggestion, | 301 SearchProvider::SuggestResult::SuggestResult(const string16& suggestion, |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 706 } | 705 } |
| 707 | 706 |
| 708 // 5th element: Optional key-value pairs from the Suggest server. | 707 // 5th element: Optional key-value pairs from the Suggest server. |
| 709 ListValue* types = NULL; | 708 ListValue* types = NULL; |
| 710 ListValue* relevances = NULL; | 709 ListValue* relevances = NULL; |
| 711 DictionaryValue* extras = NULL; | 710 DictionaryValue* extras = NULL; |
| 712 if (root_list->GetDictionary(4, &extras)) { | 711 if (root_list->GetDictionary(4, &extras)) { |
| 713 extras->GetList("google:suggesttype", &types); | 712 extras->GetList("google:suggesttype", &types); |
| 714 | 713 |
| 715 // Only accept relevance suggestions if Instant is disabled. | 714 // Only accept relevance suggestions if Instant is disabled. |
| 716 if (!is_keyword && | 715 if (!is_keyword && !chrome::search::IsInstantEnabled(profile_)) { |
| 717 !chrome::BrowserInstantController::IsInstantEnabled(profile_)) { | |
| 718 // Discard this list if its size does not match that of the suggestions. | 716 // Discard this list if its size does not match that of the suggestions. |
| 719 if (extras->GetList("google:suggestrelevance", &relevances) && | 717 if (extras->GetList("google:suggestrelevance", &relevances) && |
| 720 relevances->GetSize() != results->GetSize()) | 718 relevances->GetSize() != results->GetSize()) |
| 721 relevances = NULL; | 719 relevances = NULL; |
| 722 | 720 |
| 723 extras->GetInteger("google:verbatimrelevance", &verbatim_relevance_); | 721 extras->GetInteger("google:verbatimrelevance", &verbatim_relevance_); |
| 724 } | 722 } |
| 725 | 723 |
| 726 // Check if the active suggest field trial (if any) has triggered either | 724 // Check if the active suggest field trial (if any) has triggered either |
| 727 // for the default provider or keyword provider. | 725 // for the default provider or keyword provider. |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 807 if (keyword_url && !keyword_url->IsExtensionKeyword()) { | 805 if (keyword_url && !keyword_url->IsExtensionKeyword()) { |
| 808 AddMatchToMap(keyword_input_.text(), keyword_input_.text(), | 806 AddMatchToMap(keyword_input_.text(), keyword_input_.text(), |
| 809 CalculateRelevanceForKeywordVerbatim( | 807 CalculateRelevanceForKeywordVerbatim( |
| 810 input_.type(), input_.prefer_keyword()), | 808 input_.type(), input_.prefer_keyword()), |
| 811 AutocompleteMatch::SEARCH_OTHER_ENGINE, | 809 AutocompleteMatch::SEARCH_OTHER_ENGINE, |
| 812 did_not_accept_keyword_suggestion, true, &map); | 810 did_not_accept_keyword_suggestion, true, &map); |
| 813 } | 811 } |
| 814 } | 812 } |
| 815 const size_t verbatim_matches_size = map.size(); | 813 const size_t verbatim_matches_size = map.size(); |
| 816 if (!default_provider_suggestion_.text.empty() && | 814 if (!default_provider_suggestion_.text.empty() && |
| 817 default_provider_suggestion_.type == INSTANT_SUGGESTION_SEARCH && | 815 !default_provider_suggestion_.is_url && |
| 818 !input_.prevent_inline_autocomplete()) | 816 !input_.prevent_inline_autocomplete()) |
| 819 AddMatchToMap(input_.text() + default_provider_suggestion_.text, | 817 AddMatchToMap(input_.text() + default_provider_suggestion_.text, |
| 820 input_.text(), verbatim_relevance + 1, | 818 input_.text(), verbatim_relevance + 1, |
| 821 AutocompleteMatch::SEARCH_SUGGEST, | 819 AutocompleteMatch::SEARCH_SUGGEST, |
| 822 did_not_accept_default_suggestion, false, &map); | 820 did_not_accept_default_suggestion, false, &map); |
| 823 | 821 |
| 824 AddHistoryResultsToMap(keyword_history_results_, true, | 822 AddHistoryResultsToMap(keyword_history_results_, true, |
| 825 did_not_accept_keyword_suggestion, &map); | 823 did_not_accept_keyword_suggestion, &map); |
| 826 AddHistoryResultsToMap(default_history_results_, false, | 824 AddHistoryResultsToMap(default_history_results_, false, |
| 827 did_not_accept_default_suggestion, &map); | 825 did_not_accept_default_suggestion, &map); |
| 828 | 826 |
| 829 AddSuggestResultsToMap(keyword_suggest_results_, true, &map); | 827 AddSuggestResultsToMap(keyword_suggest_results_, true, &map); |
| 830 AddSuggestResultsToMap(default_suggest_results_, false, &map); | 828 AddSuggestResultsToMap(default_suggest_results_, false, &map); |
| 831 | 829 |
| 832 // Now add the most relevant matches from the map to |matches_|. | 830 // Now add the most relevant matches from the map to |matches_|. |
| 833 matches_.clear(); | 831 matches_.clear(); |
| 834 for (MatchMap::const_iterator i(map.begin()); i != map.end(); ++i) | 832 for (MatchMap::const_iterator i(map.begin()); i != map.end(); ++i) |
| 835 matches_.push_back(i->second); | 833 matches_.push_back(i->second); |
| 836 | 834 |
| 837 if (!default_provider_suggestion_.text.empty() && | 835 if (!default_provider_suggestion_.text.empty() && |
| 838 default_provider_suggestion_.type == INSTANT_SUGGESTION_URL && | 836 default_provider_suggestion_.is_url && |
| 839 !input_.prevent_inline_autocomplete()) { | 837 !input_.prevent_inline_autocomplete()) { |
| 840 // See comment in FinalizeInstantQuery() for why we don't use | 838 // See comment in FinalizeInstantQuery() for why we don't use |
| 841 // |verbatim_relevance| here. | 839 // |verbatim_relevance| here. |
| 842 matches_.push_back(NavigationToMatch( | 840 matches_.push_back(NavigationToMatch( |
| 843 NavigationResult(GURL(UTF16ToUTF8(default_provider_suggestion_.text)), | 841 NavigationResult(GURL(UTF16ToUTF8(default_provider_suggestion_.text)), |
| 844 string16(), | 842 string16(), |
| 845 kNonURLVerbatimRelevance + 1), | 843 kNonURLVerbatimRelevance + 1), |
| 846 false)); | 844 false)); |
| 847 } | 845 } |
| 848 AddNavigationResultsToMatches(keyword_navigation_results_, true); | 846 AddNavigationResultsToMatches(keyword_navigation_results_, true); |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1340 &match.contents_class); | 1338 &match.contents_class); |
| 1341 | 1339 |
| 1342 match.description = navigation.description(); | 1340 match.description = navigation.description(); |
| 1343 AutocompleteMatch::ClassifyMatchInString(input, match.description, | 1341 AutocompleteMatch::ClassifyMatchInString(input, match.description, |
| 1344 ACMatchClassification::NONE, &match.description_class); | 1342 ACMatchClassification::NONE, &match.description_class); |
| 1345 return match; | 1343 return match; |
| 1346 } | 1344 } |
| 1347 | 1345 |
| 1348 void SearchProvider::UpdateDone() { | 1346 void SearchProvider::UpdateDone() { |
| 1349 // We're done when the timer isn't running, there are no suggest queries | 1347 // We're done when the timer isn't running, there are no suggest queries |
| 1350 // pending, and we're not waiting on instant. | 1348 // pending, and we're not waiting on Instant. |
| 1351 done_ = (!timer_.IsRunning() && (suggest_results_pending_ == 0) && | 1349 done_ = (!timer_.IsRunning() && (suggest_results_pending_ == 0) && |
| 1352 (instant_finalized_ || | 1350 (instant_finalized_ || !chrome::search::IsInstantEnabled(profile_))); |
| 1353 (!chrome::BrowserInstantController::IsInstantEnabled(profile_) && | |
| 1354 !chrome::search::IsInstantExtendedAPIEnabled(profile_)))); | |
| 1355 } | 1351 } |
| OLD | NEW |