| Index: chrome/browser/autocomplete/search_provider.cc
|
| diff --git a/chrome/browser/autocomplete/search_provider.cc b/chrome/browser/autocomplete/search_provider.cc
|
| index 6a486b9dfb584a41a71106566f9e3f6fdcbf1271..04b37a5a6092bfdf1c01e92a91d7a21963d3a863 100644
|
| --- a/chrome/browser/autocomplete/search_provider.cc
|
| +++ b/chrome/browser/autocomplete/search_provider.cc
|
| @@ -132,8 +132,10 @@ int SearchProvider::kMinimumTimeBetweenSuggestQueriesMs = 100;
|
| SearchProvider::SearchProvider(AutocompleteProviderListener* listener,
|
| TemplateURLService* template_url_service,
|
| Profile* profile)
|
| - : BaseSearchProvider(listener, template_url_service, profile,
|
| + : BaseSearchProvider(template_url_service, profile,
|
| AutocompleteProvider::TYPE_SEARCH),
|
| + listener_(listener),
|
| + suggest_results_pending_(0),
|
| providers_(template_url_service) {
|
| }
|
|
|
| @@ -149,23 +151,6 @@ void SearchProvider::ResetSession() {
|
| SearchProvider::~SearchProvider() {
|
| }
|
|
|
| -void SearchProvider::UpdateMatchContentsClass(
|
| - const base::string16& input_text,
|
| - SearchSuggestionParser::Results* results) {
|
| - for (SearchSuggestionParser::SuggestResults::iterator sug_it =
|
| - results->suggest_results.begin();
|
| - sug_it != results->suggest_results.end(); ++sug_it) {
|
| - sug_it->ClassifyMatchContents(false, input_text);
|
| - }
|
| - const std::string languages(
|
| - profile_->GetPrefs()->GetString(prefs::kAcceptLanguages));
|
| - for (SearchSuggestionParser::NavigationResults::iterator nav_it =
|
| - results->navigation_results.begin();
|
| - nav_it != results->navigation_results.end(); ++nav_it) {
|
| - nav_it->CalculateAndClassifyMatchContents(false, input_text, languages);
|
| - }
|
| -}
|
| -
|
| // static
|
| int SearchProvider::CalculateRelevanceForKeywordVerbatim(
|
| metrics::OmniboxInputType::Type type,
|
| @@ -265,33 +250,6 @@ void SearchProvider::Start(const AutocompleteInput& input,
|
| UpdateMatches();
|
| }
|
|
|
| -void SearchProvider::SortResults(bool is_keyword,
|
| - SearchSuggestionParser::Results* results) {
|
| - // Ignore suggested scores for non-keyword matches in keyword mode; if the
|
| - // server is allowed to score these, it could interfere with the user's
|
| - // ability to get good keyword results.
|
| - const bool abandon_suggested_scores =
|
| - !is_keyword && !providers_.keyword_provider().empty();
|
| - // Apply calculated relevance scores to suggestions if valid relevances were
|
| - // not provided or we're abandoning suggested scores entirely.
|
| - if (!results->relevances_from_server || abandon_suggested_scores) {
|
| - ApplyCalculatedSuggestRelevance(&results->suggest_results);
|
| - ApplyCalculatedNavigationRelevance(&results->navigation_results);
|
| - // If abandoning scores entirely, also abandon the verbatim score.
|
| - if (abandon_suggested_scores)
|
| - results->verbatim_relevance = -1;
|
| - }
|
| -
|
| - // Keep the result lists sorted.
|
| - const CompareScoredResults comparator = CompareScoredResults();
|
| - std::stable_sort(results->suggest_results.begin(),
|
| - results->suggest_results.end(),
|
| - comparator);
|
| - std::stable_sort(results->navigation_results.begin(),
|
| - results->navigation_results.end(),
|
| - comparator);
|
| -}
|
| -
|
| const TemplateURL* SearchProvider::GetTemplateURL(bool is_keyword) const {
|
| return is_keyword ? providers_.GetKeywordProviderURL()
|
| : providers_.GetDefaultProviderURL();
|
| @@ -301,11 +259,6 @@ const AutocompleteInput SearchProvider::GetInput(bool is_keyword) const {
|
| return is_keyword ? keyword_input_ : input_;
|
| }
|
|
|
| -SearchSuggestionParser::Results* SearchProvider::GetResultsToFill(
|
| - bool is_keyword) {
|
| - return is_keyword ? &keyword_results_ : &default_results_;
|
| -}
|
| -
|
| bool SearchProvider::ShouldAppendExtraParams(
|
| const SearchSuggestionParser::SuggestResult& result) const {
|
| return !result.from_keyword_provider() ||
|
| @@ -329,10 +282,6 @@ void SearchProvider::ClearAllResults() {
|
| default_results_.Clear();
|
| }
|
|
|
| -int SearchProvider::GetDefaultResultRelevance() const {
|
| - return -1;
|
| -}
|
| -
|
| void SearchProvider::RecordDeletionResult(bool success) {
|
| if (success) {
|
| base::RecordAction(
|
| @@ -343,6 +292,82 @@ void SearchProvider::RecordDeletionResult(bool success) {
|
| }
|
| }
|
|
|
| +void SearchProvider::OnURLFetchComplete(const net::URLFetcher* source) {
|
| + DCHECK(!done_);
|
| + --suggest_results_pending_;
|
| + DCHECK_GE(suggest_results_pending_, 0); // Should never go negative.
|
| +
|
| + const bool is_keyword = source == keyword_fetcher_.get();
|
| +
|
| + // Ensure the request succeeded and that the provider used is still available.
|
| + // A verbatim match cannot be generated without this provider, causing errors.
|
| + const bool request_succeeded =
|
| + source->GetStatus().is_success() && (source->GetResponseCode() == 200) &&
|
| + GetTemplateURL(is_keyword);
|
| +
|
| + LogFetchComplete(request_succeeded, is_keyword);
|
| +
|
| + bool results_updated = false;
|
| + if (request_succeeded) {
|
| + scoped_ptr<base::Value> data(SearchSuggestionParser::DeserializeJsonData(
|
| + SearchSuggestionParser::ExtractJsonData(source)));
|
| + if (data) {
|
| + SearchSuggestionParser::Results* results =
|
| + is_keyword ? &keyword_results_ : &default_results_;
|
| + results_updated = ParseSuggestResults(*data, -1, is_keyword, results);
|
| + if (results_updated)
|
| + SortResults(is_keyword, results);
|
| + }
|
| + }
|
| + UpdateMatches();
|
| + if (done_ || results_updated)
|
| + listener_->OnProviderUpdate(results_updated);
|
| +}
|
| +
|
| +void SearchProvider::UpdateMatchContentsClass(
|
| + const base::string16& input_text,
|
| + SearchSuggestionParser::Results* results) {
|
| + for (SearchSuggestionParser::SuggestResults::iterator sug_it =
|
| + results->suggest_results.begin();
|
| + sug_it != results->suggest_results.end(); ++sug_it) {
|
| + sug_it->ClassifyMatchContents(false, input_text);
|
| + }
|
| + const std::string languages(
|
| + profile_->GetPrefs()->GetString(prefs::kAcceptLanguages));
|
| + for (SearchSuggestionParser::NavigationResults::iterator nav_it =
|
| + results->navigation_results.begin();
|
| + nav_it != results->navigation_results.end(); ++nav_it) {
|
| + nav_it->CalculateAndClassifyMatchContents(false, input_text, languages);
|
| + }
|
| +}
|
| +
|
| +void SearchProvider::SortResults(bool is_keyword,
|
| + SearchSuggestionParser::Results* results) {
|
| + // Ignore suggested scores for non-keyword matches in keyword mode; if the
|
| + // server is allowed to score these, it could interfere with the user's
|
| + // ability to get good keyword results.
|
| + const bool abandon_suggested_scores =
|
| + !is_keyword && !providers_.keyword_provider().empty();
|
| + // Apply calculated relevance scores to suggestions if valid relevances were
|
| + // not provided or we're abandoning suggested scores entirely.
|
| + if (!results->relevances_from_server || abandon_suggested_scores) {
|
| + ApplyCalculatedSuggestRelevance(&results->suggest_results);
|
| + ApplyCalculatedNavigationRelevance(&results->navigation_results);
|
| + // If abandoning scores entirely, also abandon the verbatim score.
|
| + if (abandon_suggested_scores)
|
| + results->verbatim_relevance = -1;
|
| + }
|
| +
|
| + // Keep the result lists sorted.
|
| + const CompareScoredResults comparator = CompareScoredResults();
|
| + std::stable_sort(results->suggest_results.begin(),
|
| + results->suggest_results.end(),
|
| + comparator);
|
| + std::stable_sort(results->navigation_results.begin(),
|
| + results->navigation_results.end(),
|
| + comparator);
|
| +}
|
| +
|
| void SearchProvider::LogFetchComplete(bool success, bool is_keyword) {
|
| LogOmniboxSuggestRequest(REPLY_RECEIVED);
|
| // Record response time for suggest requests sent to Google. We care
|
| @@ -366,10 +391,6 @@ void SearchProvider::LogFetchComplete(bool success, bool is_keyword) {
|
| }
|
| }
|
|
|
| -bool SearchProvider::IsKeywordFetcher(const net::URLFetcher* fetcher) const {
|
| - return fetcher == keyword_fetcher_.get();
|
| -}
|
| -
|
| void SearchProvider::UpdateMatches() {
|
| ConvertResultsToAutocompleteMatches();
|
|
|
|
|