Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: components/omnibox/search_provider.cc

Issue 1185723002: Prepare HistoryProvider for componentization (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Response to review Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/omnibox/search_provider.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 bool operator()(const SearchSuggestionParser::Result& a, 111 bool operator()(const SearchSuggestionParser::Result& a,
112 const SearchSuggestionParser::Result& b) { 112 const SearchSuggestionParser::Result& b) {
113 // Sort in descending relevance order. 113 // Sort in descending relevance order.
114 return a.relevance() > b.relevance(); 114 return a.relevance() > b.relevance();
115 } 115 }
116 }; 116 };
117 117
118 118
119 // SearchProvider ------------------------------------------------------------- 119 // SearchProvider -------------------------------------------------------------
120 120
121 SearchProvider::SearchProvider( 121 SearchProvider::SearchProvider(AutocompleteProviderClient* client,
122 AutocompleteProviderListener* listener, 122 AutocompleteProviderListener* listener,
123 TemplateURLService* template_url_service, 123 TemplateURLService* template_url_service)
124 scoped_ptr<AutocompleteProviderClient> client) 124 : BaseSearchProvider(AutocompleteProvider::TYPE_SEARCH,
125 : BaseSearchProvider(template_url_service, client.Pass(), 125 client,
126 AutocompleteProvider::TYPE_SEARCH), 126 template_url_service),
127 listener_(listener), 127 listener_(listener),
128 providers_(template_url_service), 128 providers_(template_url_service),
129 answers_cache_(10) { 129 answers_cache_(10) {
130 // |template_url_service_| can be null in tests. 130 // |template_url_service_| can be null in tests.
131 if (template_url_service_) 131 if (template_url_service_)
132 template_url_service_->AddObserver(this); 132 template_url_service_->AddObserver(this);
133 } 133 }
134 134
135 // static 135 // static
136 std::string SearchProvider::GetSuggestMetadata(const AutocompleteMatch& match) { 136 std::string SearchProvider::GetSuggestMetadata(const AutocompleteMatch& match) {
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 } 843 }
844 GURL suggest_url(template_url->suggestions_url_ref().ReplaceSearchTerms( 844 GURL suggest_url(template_url->suggestions_url_ref().ReplaceSearchTerms(
845 search_term_args, 845 search_term_args,
846 providers_.template_url_service()->search_terms_data())); 846 providers_.template_url_service()->search_terms_data()));
847 if (!suggest_url.is_valid()) 847 if (!suggest_url.is_valid())
848 return NULL; 848 return NULL;
849 // Send the current page URL if user setting and URL requirements are met and 849 // Send the current page URL if user setting and URL requirements are met and
850 // the user is in the field trial. 850 // the user is in the field trial.
851 if (CanSendURL(current_page_url_, suggest_url, template_url, 851 if (CanSendURL(current_page_url_, suggest_url, template_url,
852 input.current_page_classification(), 852 input.current_page_classification(),
853 template_url_service_->search_terms_data(), client_.get()) && 853 template_url_service_->search_terms_data(), client_) &&
854 OmniboxFieldTrial::InZeroSuggestAfterTypingFieldTrial()) { 854 OmniboxFieldTrial::InZeroSuggestAfterTypingFieldTrial()) {
855 search_term_args.current_page_url = current_page_url_.spec(); 855 search_term_args.current_page_url = current_page_url_.spec();
856 // Create the suggest URL again with the current page URL. 856 // Create the suggest URL again with the current page URL.
857 suggest_url = GURL(template_url->suggestions_url_ref().ReplaceSearchTerms( 857 suggest_url = GURL(template_url->suggestions_url_ref().ReplaceSearchTerms(
858 search_term_args, 858 search_term_args,
859 providers_.template_url_service()->search_terms_data())); 859 providers_.template_url_service()->search_terms_data()));
860 } 860 }
861 861
862 LogOmniboxSuggestRequest(REQUEST_SENT); 862 LogOmniboxSuggestRequest(REQUEST_SENT);
863 863
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after
1512 for (MatchMap::const_iterator i(map.begin()); i != map.end(); ++i) 1512 for (MatchMap::const_iterator i(map.begin()); i != map.end(); ++i)
1513 matches.push_back(i->second); 1513 matches.push_back(i->second);
1514 std::sort(matches.begin(), matches.end(), &AutocompleteMatch::MoreRelevant); 1514 std::sort(matches.begin(), matches.end(), &AutocompleteMatch::MoreRelevant);
1515 1515
1516 // If there is a top scoring entry, find the corresponding answer. 1516 // If there is a top scoring entry, find the corresponding answer.
1517 if (!matches.empty()) 1517 if (!matches.empty())
1518 return answers_cache_.GetTopAnswerEntry(matches[0].contents); 1518 return answers_cache_.GetTopAnswerEntry(matches[0].contents);
1519 1519
1520 return AnswersQueryData(); 1520 return AnswersQueryData();
1521 } 1521 }
OLDNEW
« no previous file with comments | « components/omnibox/search_provider.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698