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/auto_reset.h" | 10 #include "base/auto_reset.h" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 template_url_service_->GetTemplateURLForKeyword(keyword_provider_); | 114 template_url_service_->GetTemplateURLForKeyword(keyword_provider_); |
115 } | 115 } |
116 | 116 |
117 | 117 |
118 // SearchProvider ------------------------------------------------------------- | 118 // SearchProvider ------------------------------------------------------------- |
119 | 119 |
120 // static | 120 // static |
121 const int SearchProvider::kDefaultProviderURLFetcherID = 1; | 121 const int SearchProvider::kDefaultProviderURLFetcherID = 1; |
122 // static | 122 // static |
123 const int SearchProvider::kKeywordProviderURLFetcherID = 2; | 123 const int SearchProvider::kKeywordProviderURLFetcherID = 2; |
124 // static | |
125 // To avoid flooding the suggest server, don't send a query until at least 100 | |
msw
2013/04/03 21:46:08
nit: keep this comment with its use in StartOrStop
Mark P
2013/04/03 22:51:40
Done. Moved back to old location.
| |
126 // ms since the last query. | |
127 int SearchProvider::kMinimumTimeBetweenSuggestQueriesMs = 100; | |
124 | 128 |
125 SearchProvider::SearchProvider(AutocompleteProviderListener* listener, | 129 SearchProvider::SearchProvider(AutocompleteProviderListener* listener, |
126 Profile* profile) | 130 Profile* profile) |
127 : AutocompleteProvider(listener, profile, | 131 : AutocompleteProvider(listener, profile, |
128 AutocompleteProvider::TYPE_SEARCH), | 132 AutocompleteProvider::TYPE_SEARCH), |
129 providers_(TemplateURLServiceFactory::GetForProfile(profile)), | 133 providers_(TemplateURLServiceFactory::GetForProfile(profile)), |
130 suggest_results_pending_(0), | 134 suggest_results_pending_(0), |
131 has_default_suggested_relevance_(false), | 135 has_default_suggested_relevance_(false), |
132 has_keyword_suggested_relevance_(false), | 136 has_keyword_suggested_relevance_(false), |
133 default_verbatim_relevance_(-1), | 137 default_verbatim_relevance_(-1), |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
555 // We can't keep running any previous query, so halt it. | 559 // We can't keep running any previous query, so halt it. |
556 StopSuggest(); | 560 StopSuggest(); |
557 | 561 |
558 // Remove existing results that cannot inline autocomplete the new input. | 562 // Remove existing results that cannot inline autocomplete the new input. |
559 RemoveStaleResults(); | 563 RemoveStaleResults(); |
560 | 564 |
561 // We can't start a new query if we're only allowed synchronous results. | 565 // We can't start a new query if we're only allowed synchronous results. |
562 if (input_.matches_requested() != AutocompleteInput::ALL_MATCHES) | 566 if (input_.matches_requested() != AutocompleteInput::ALL_MATCHES) |
563 return; | 567 return; |
564 | 568 |
565 // To avoid flooding the suggest server, don't send a query until at least 100 | |
566 // ms since the last query. | |
567 const int kMinimumTimeBetweenSuggestQueriesMs = 100; | |
568 base::TimeTicks next_suggest_time(time_suggest_request_sent_ + | 569 base::TimeTicks next_suggest_time(time_suggest_request_sent_ + |
569 TimeDelta::FromMilliseconds(kMinimumTimeBetweenSuggestQueriesMs)); | 570 TimeDelta::FromMilliseconds(kMinimumTimeBetweenSuggestQueriesMs)); |
570 base::TimeTicks now(base::TimeTicks::Now()); | 571 base::TimeTicks now(base::TimeTicks::Now()); |
571 if (now >= next_suggest_time) { | 572 if (now >= next_suggest_time) { |
572 Run(); | 573 Run(); |
573 return; | 574 return; |
574 } | 575 } |
575 timer_.Start(FROM_HERE, next_suggest_time - now, this, &SearchProvider::Run); | 576 timer_.Start(FROM_HERE, next_suggest_time - now, this, &SearchProvider::Run); |
576 } | 577 } |
577 | 578 |
(...skipping 932 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1510 } | 1511 } |
1511 return true; | 1512 return true; |
1512 } | 1513 } |
1513 | 1514 |
1514 void SearchProvider::UpdateDone() { | 1515 void SearchProvider::UpdateDone() { |
1515 // We're done when the timer isn't running, there are no suggest queries | 1516 // We're done when the timer isn't running, there are no suggest queries |
1516 // pending, and we're not waiting on Instant. | 1517 // pending, and we're not waiting on Instant. |
1517 done_ = (!timer_.IsRunning() && (suggest_results_pending_ == 0) && | 1518 done_ = (!timer_.IsRunning() && (suggest_results_pending_ == 0) && |
1518 (instant_finalized_ || !chrome::IsInstantEnabled(profile_))); | 1519 (instant_finalized_ || !chrome::IsInstantEnabled(profile_))); |
1519 } | 1520 } |
OLD | NEW |