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

Side by Side Diff: chrome/browser/autocomplete/search_provider.cc

Issue 10860068: Fix Omnibox search provider's confusing internal variable semantics (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 const int SearchProvider::kDefaultProviderURLFetcherID = 1; 115 const int SearchProvider::kDefaultProviderURLFetcherID = 1;
116 // static 116 // static
117 const int SearchProvider::kKeywordProviderURLFetcherID = 2; 117 const int SearchProvider::kKeywordProviderURLFetcherID = 2;
118 // static 118 // static
119 bool SearchProvider::query_suggest_immediately_ = false; 119 bool SearchProvider::query_suggest_immediately_ = false;
120 120
121 SearchProvider::SearchProvider(AutocompleteProviderListener* listener, 121 SearchProvider::SearchProvider(AutocompleteProviderListener* listener,
122 Profile* profile) 122 Profile* profile)
123 : AutocompleteProvider(listener, profile, "Search"), 123 : AutocompleteProvider(listener, profile, "Search"),
124 providers_(TemplateURLServiceFactory::GetForProfile(profile)), 124 providers_(TemplateURLServiceFactory::GetForProfile(profile)),
125 in_timer_phase_(false),
125 suggest_results_pending_(0), 126 suggest_results_pending_(0),
126 suggest_field_trial_group_number_( 127 suggest_field_trial_group_number_(
127 AutocompleteFieldTrial::GetSuggestNumberOfGroups()), 128 AutocompleteFieldTrial::GetSuggestNumberOfGroups()),
128 has_suggested_relevance_(false), 129 has_suggested_relevance_(false),
129 verbatim_relevance_(-1), 130 verbatim_relevance_(-1),
130 have_suggest_results_(false), 131 have_suggest_results_(false),
131 instant_finalized_(false) { 132 instant_finalized_(false) {
132 // Above, we default |suggest_field_trial_group_number_| to the number of 133 // Above, we default |suggest_field_trial_group_number_| to the number of
133 // groups to mean "not in field trial." Field trial groups run from 0 to 134 // groups to mean "not in field trial." Field trial groups run from 0 to
134 // GetSuggestNumberOfGroups() - 1 (inclusive). 135 // GetSuggestNumberOfGroups() - 1 (inclusive).
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 public: 303 public:
303 bool operator()(const Result& a, const Result& b) { 304 bool operator()(const Result& a, const Result& b) {
304 // Sort in descending relevance order. 305 // Sort in descending relevance order.
305 return a.relevance() > b.relevance(); 306 return a.relevance() > b.relevance();
306 } 307 }
307 }; 308 };
308 309
309 void SearchProvider::Run() { 310 void SearchProvider::Run() {
310 // Start a new request with the current input. 311 // Start a new request with the current input.
311 DCHECK(!done_); 312 DCHECK(!done_);
313 DCHECK(in_timer_phase_);
314 in_timer_phase_ = false;
312 suggest_results_pending_ = 0; 315 suggest_results_pending_ = 0;
313 time_suggest_request_sent_ = base::TimeTicks::Now(); 316 time_suggest_request_sent_ = base::TimeTicks::Now();
314 const TemplateURL* default_url = providers_.GetDefaultProviderURL(); 317 const TemplateURL* default_url = providers_.GetDefaultProviderURL();
315 if (default_url && !default_url->suggestions_url().empty()) { 318 if (default_url && !default_url->suggestions_url().empty()) {
316 suggest_results_pending_++; 319 suggest_results_pending_++;
317 LogOmniboxSuggestRequest(REQUEST_SENT); 320 LogOmniboxSuggestRequest(REQUEST_SENT);
318 default_fetcher_.reset(CreateSuggestFetcher(kDefaultProviderURLFetcherID, 321 default_fetcher_.reset(CreateSuggestFetcher(kDefaultProviderURLFetcherID,
319 default_url->suggestions_url_ref(), input_.text())); 322 default_url->suggestions_url_ref(), input_.text()));
320 } 323 }
321 const TemplateURL* keyword_url = providers_.GetKeywordProviderURL(); 324 const TemplateURL* keyword_url = providers_.GetKeywordProviderURL();
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 // We can't keep running any previous query, so halt it. 500 // We can't keep running any previous query, so halt it.
498 StopSuggest(); 501 StopSuggest();
499 502
500 // Remove existing results that cannot inline autocomplete the new input. 503 // Remove existing results that cannot inline autocomplete the new input.
501 RemoveStaleResults(); 504 RemoveStaleResults();
502 505
503 // We can't start a new query if we're only allowed synchronous results. 506 // We can't start a new query if we're only allowed synchronous results.
504 if (input_.matches_requested() != AutocompleteInput::ALL_MATCHES) 507 if (input_.matches_requested() != AutocompleteInput::ALL_MATCHES)
505 return; 508 return;
506 509
507 // We'll have at least one pending fetch. Set it to 1 now, but the value is
508 // correctly set in Run. As Run isn't invoked immediately we need to set this
509 // now, else we won't think we're waiting on results from the server when we
510 // really are.
511 suggest_results_pending_ = 1;
512
513 // Kick off a timer that will start the URL fetch if it completes before 510 // Kick off a timer that will start the URL fetch if it completes before
514 // the user types another character. Requests may be delayed to avoid 511 // the user types another character. Requests may be delayed to avoid
515 // flooding the server with requests that are likely to be thrown away later 512 // flooding the server with requests that are likely to be thrown away later
516 // anyway. 513 // anyway.
514 in_timer_phase_ = true;
517 timer_.Start(FROM_HERE, GetSuggestQueryDelay(), this, &SearchProvider::Run); 515 timer_.Start(FROM_HERE, GetSuggestQueryDelay(), this, &SearchProvider::Run);
518 } 516 }
519 517
520 bool SearchProvider::IsQuerySuitableForSuggest() const { 518 bool SearchProvider::IsQuerySuitableForSuggest() const {
521 // Don't run Suggest in incognito mode, if the engine doesn't support it, or 519 // Don't run Suggest in incognito mode, if the engine doesn't support it, or
522 // if the user has disabled it. 520 // if the user has disabled it.
523 const TemplateURL* default_url = providers_.GetDefaultProviderURL(); 521 const TemplateURL* default_url = providers_.GetDefaultProviderURL();
524 const TemplateURL* keyword_url = providers_.GetKeywordProviderURL(); 522 const TemplateURL* keyword_url = providers_.GetKeywordProviderURL();
525 if (profile_->IsOffTheRecord() || 523 if (profile_->IsOffTheRecord() ||
526 ((!default_url || default_url->suggestions_url().empty()) && 524 ((!default_url || default_url->suggestions_url().empty()) &&
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 return true; 570 return true;
573 } 571 }
574 572
575 void SearchProvider::StopSuggest() { 573 void SearchProvider::StopSuggest() {
576 // Increment the appropriate field in the histogram by the number of 574 // Increment the appropriate field in the histogram by the number of
577 // pending requests that were invalidated. 575 // pending requests that were invalidated.
578 for (int i = 0; i < suggest_results_pending_; i++) 576 for (int i = 0; i < suggest_results_pending_; i++)
579 LogOmniboxSuggestRequest(REQUEST_INVALIDATED); 577 LogOmniboxSuggestRequest(REQUEST_INVALIDATED);
580 suggest_results_pending_ = 0; 578 suggest_results_pending_ = 0;
581 timer_.Stop(); 579 timer_.Stop();
580 in_timer_phase_ = false;
582 // Stop any in-progress URL fetches. 581 // Stop any in-progress URL fetches.
583 keyword_fetcher_.reset(); 582 keyword_fetcher_.reset();
584 default_fetcher_.reset(); 583 default_fetcher_.reset();
585 } 584 }
586 585
587 void SearchProvider::ClearResults() { 586 void SearchProvider::ClearResults() {
588 keyword_suggest_results_.clear(); 587 keyword_suggest_results_.clear();
589 default_suggest_results_.clear(); 588 default_suggest_results_.clear();
590 keyword_navigation_results_.clear(); 589 keyword_navigation_results_.clear();
591 default_navigation_results_.clear(); 590 default_navigation_results_.clear();
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
1237 1236
1238 match.description = navigation.description(); 1237 match.description = navigation.description();
1239 AutocompleteMatch::ClassifyMatchInString(input, match.description, 1238 AutocompleteMatch::ClassifyMatchInString(input, match.description,
1240 ACMatchClassification::NONE, &match.description_class); 1239 ACMatchClassification::NONE, &match.description_class);
1241 return match; 1240 return match;
1242 } 1241 }
1243 1242
1244 void SearchProvider::UpdateDone() { 1243 void SearchProvider::UpdateDone() {
1245 // We're done when there are no more suggest queries pending (this is set to 1 1244 // We're done when there are no more suggest queries pending (this is set to 1
1246 // when the timer is started) and we're not waiting on instant. 1245 // when the timer is started) and we're not waiting on instant.
1247 done_ = ((suggest_results_pending_ == 0) && 1246 done_ = (!in_timer_phase_ && (suggest_results_pending_ == 0) &&
1248 (instant_finalized_ || !InstantController::IsEnabled(profile_))); 1247 (instant_finalized_ || !InstantController::IsEnabled(profile_)));
1249 } 1248 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698