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 "components/omnibox/search_provider.h" | 5 #include "components/omnibox/search_provider.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 } | 548 } |
549 | 549 |
550 UpdateDone(); | 550 UpdateDone(); |
551 } | 551 } |
552 | 552 |
553 void SearchProvider::Run(bool query_is_private) { | 553 void SearchProvider::Run(bool query_is_private) { |
554 // Start a new request with the current input. | 554 // Start a new request with the current input. |
555 time_suggest_request_sent_ = base::TimeTicks::Now(); | 555 time_suggest_request_sent_ = base::TimeTicks::Now(); |
556 | 556 |
557 if (!query_is_private) { | 557 if (!query_is_private) { |
558 default_fetcher_.reset(CreateSuggestFetcher( | 558 default_fetcher_ = |
559 kDefaultProviderURLFetcherID, | 559 CreateSuggestFetcher(kDefaultProviderURLFetcherID, |
560 providers_.GetDefaultProviderURL(), | 560 providers_.GetDefaultProviderURL(), input_); |
561 input_)); | |
562 } | 561 } |
563 keyword_fetcher_.reset(CreateSuggestFetcher( | 562 keyword_fetcher_ = |
564 kKeywordProviderURLFetcherID, | 563 CreateSuggestFetcher(kKeywordProviderURLFetcherID, |
565 providers_.GetKeywordProviderURL(), | 564 providers_.GetKeywordProviderURL(), keyword_input_); |
566 keyword_input_)); | |
567 | 565 |
568 // Both the above can fail if the providers have been modified or deleted | 566 // Both the above can fail if the providers have been modified or deleted |
569 // since the query began. | 567 // since the query began. |
570 if (!default_fetcher_ && !keyword_fetcher_) { | 568 if (!default_fetcher_ && !keyword_fetcher_) { |
571 UpdateDone(); | 569 UpdateDone(); |
572 // We only need to update the listener if we're actually done. | 570 // We only need to update the listener if we're actually done. |
573 if (done_) | 571 if (done_) |
574 listener_->OnProviderUpdate(false); | 572 listener_->OnProviderUpdate(false); |
575 } else { | 573 } else { |
576 // Sent at least one request. | 574 // Sent at least one request. |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
815 SearchSuggestionParser::NavigationResults* list) { | 813 SearchSuggestionParser::NavigationResults* list) { |
816 for (size_t i = 0; i < list->size(); ++i) { | 814 for (size_t i = 0; i < list->size(); ++i) { |
817 SearchSuggestionParser::NavigationResult& result = (*list)[i]; | 815 SearchSuggestionParser::NavigationResult& result = (*list)[i]; |
818 result.set_relevance( | 816 result.set_relevance( |
819 result.CalculateRelevance(input_, providers_.has_keyword_provider()) + | 817 result.CalculateRelevance(input_, providers_.has_keyword_provider()) + |
820 (list->size() - i - 1)); | 818 (list->size() - i - 1)); |
821 result.set_relevance_from_server(false); | 819 result.set_relevance_from_server(false); |
822 } | 820 } |
823 } | 821 } |
824 | 822 |
825 net::URLFetcher* SearchProvider::CreateSuggestFetcher( | 823 scoped_ptr<net::URLFetcher> SearchProvider::CreateSuggestFetcher( |
826 int id, | 824 int id, |
827 const TemplateURL* template_url, | 825 const TemplateURL* template_url, |
828 const AutocompleteInput& input) { | 826 const AutocompleteInput& input) { |
829 if (!template_url || template_url->suggestions_url().empty()) | 827 if (!template_url || template_url->suggestions_url().empty()) |
830 return NULL; | 828 return NULL; |
831 | 829 |
832 // Bail if the suggestion URL is invalid with the given replacements. | 830 // Bail if the suggestion URL is invalid with the given replacements. |
833 TemplateURLRef::SearchTermsArgs search_term_args(input.text()); | 831 TemplateURLRef::SearchTermsArgs search_term_args(input.text()); |
834 search_term_args.input_type = input.type(); | 832 search_term_args.input_type = input.type(); |
835 search_term_args.cursor_position = input.cursor_position(); | 833 search_term_args.cursor_position = input.cursor_position(); |
(...skipping 20 matching lines...) Expand all Loading... |
856 OmniboxFieldTrial::InZeroSuggestAfterTypingFieldTrial()) { | 854 OmniboxFieldTrial::InZeroSuggestAfterTypingFieldTrial()) { |
857 search_term_args.current_page_url = current_page_url_.spec(); | 855 search_term_args.current_page_url = current_page_url_.spec(); |
858 // Create the suggest URL again with the current page URL. | 856 // Create the suggest URL again with the current page URL. |
859 suggest_url = GURL(template_url->suggestions_url_ref().ReplaceSearchTerms( | 857 suggest_url = GURL(template_url->suggestions_url_ref().ReplaceSearchTerms( |
860 search_term_args, | 858 search_term_args, |
861 providers_.template_url_service()->search_terms_data())); | 859 providers_.template_url_service()->search_terms_data())); |
862 } | 860 } |
863 | 861 |
864 LogOmniboxSuggestRequest(REQUEST_SENT); | 862 LogOmniboxSuggestRequest(REQUEST_SENT); |
865 | 863 |
866 net::URLFetcher* fetcher = | 864 scoped_ptr<net::URLFetcher> fetcher = |
867 net::URLFetcher::Create(id, suggest_url, net::URLFetcher::GET, this); | 865 net::URLFetcher::Create(id, suggest_url, net::URLFetcher::GET, this); |
868 fetcher->SetRequestContext(client_->RequestContext()); | 866 fetcher->SetRequestContext(client_->RequestContext()); |
869 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES); | 867 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES); |
870 // Add Chrome experiment state to the request headers. | 868 // Add Chrome experiment state to the request headers. |
871 net::HttpRequestHeaders headers; | 869 net::HttpRequestHeaders headers; |
872 variations::VariationsHttpHeaderProvider::GetInstance()->AppendHeaders( | 870 variations::VariationsHttpHeaderProvider::GetInstance()->AppendHeaders( |
873 fetcher->GetOriginalURL(), client_->IsOffTheRecord(), false, &headers); | 871 fetcher->GetOriginalURL(), client_->IsOffTheRecord(), false, &headers); |
874 fetcher->SetExtraRequestHeaders(headers.ToString()); | 872 fetcher->SetExtraRequestHeaders(headers.ToString()); |
875 fetcher->Start(); | 873 fetcher->Start(); |
876 return fetcher; | 874 return fetcher; |
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1514 for (MatchMap::const_iterator i(map.begin()); i != map.end(); ++i) | 1512 for (MatchMap::const_iterator i(map.begin()); i != map.end(); ++i) |
1515 matches.push_back(i->second); | 1513 matches.push_back(i->second); |
1516 std::sort(matches.begin(), matches.end(), &AutocompleteMatch::MoreRelevant); | 1514 std::sort(matches.begin(), matches.end(), &AutocompleteMatch::MoreRelevant); |
1517 | 1515 |
1518 // If there is a top scoring entry, find the corresponding answer. | 1516 // If there is a top scoring entry, find the corresponding answer. |
1519 if (!matches.empty()) | 1517 if (!matches.empty()) |
1520 return answers_cache_.GetTopAnswerEntry(matches[0].contents); | 1518 return answers_cache_.GetTopAnswerEntry(matches[0].contents); |
1521 | 1519 |
1522 return AnswersQueryData(); | 1520 return AnswersQueryData(); |
1523 } | 1521 } |
OLD | NEW |