Chromium Code Reviews| Index: components/omnibox/search_provider.cc |
| diff --git a/components/omnibox/search_provider.cc b/components/omnibox/search_provider.cc |
| index a9cd7b7fe3eef8168757e0ea582ee84243161d40..6bfbfc4698349fa25aee2467d3008e0022d00109 100644 |
| --- a/components/omnibox/search_provider.cc |
| +++ b/components/omnibox/search_provider.cc |
| @@ -579,6 +579,21 @@ void SearchProvider::DoHistoryQuery(bool minimal_changes) { |
| } |
| } |
| +base::TimeDelta SearchProvider::GetSuggestQueryDelay() { |
| + bool since_the_last_request = true; |
|
Mark P
2014/10/21 21:28:22
I suggest you don't initialize these two variables
Bart N.
2014/10/22 01:19:08
Done.
|
| + int polling_delay_ms = 100; |
| + OmniboxFieldTrial::GetSuggestPollingStrategy(&since_the_last_request, |
| + &polling_delay_ms); |
| + |
| + base::TimeDelta delay(base::TimeDelta::FromMilliseconds(polling_delay_ms)); |
| + if (!since_the_last_request) |
| + return delay; |
| + |
| + base::TimeDelta time_since_last_suggest_request = |
| + base::TimeTicks::Now() - time_suggest_request_sent_; |
| + return std::max(base::TimeDelta(), delay - time_since_last_suggest_request); |
|
Mark P
2014/10/21 21:28:22
You shouldn't need this max. TimeTicks is suppose
Bart N.
2014/10/22 01:19:08
What if time_since_last_suggest_request is more th
Mark P
2014/10/22 20:33:06
Well, negative delays shouldn't wait in any case.
Bart N.
2014/10/22 22:04:56
Acknowledged.
|
| +} |
| + |
| void SearchProvider::StartOrStopSuggestQuery(bool minimal_changes) { |
| if (!IsQuerySuitableForSuggest()) { |
| StopSuggest(); |
| @@ -586,6 +601,9 @@ void SearchProvider::StartOrStopSuggestQuery(bool minimal_changes) { |
| return; |
| } |
| + if (OmniboxFieldTrial::DisableResultsCaching()) |
| + ClearAllResults(); |
|
Mark P
2014/10/21 21:28:22
For your experiment, do you also want to clear cac
Bart N.
2014/10/22 01:19:08
I think so. Do you know why it is not cleared alre
Mark P
2014/10/22 20:33:06
Well, my understanding of how answers work is that
Bart N.
2014/10/22 22:04:56
Acknowledged.
|
| + |
| // For the minimal_changes case, if we finished the previous query and still |
| // have its results, or are allowed to keep running it, just do that, rather |
| // than starting a new query. |
| @@ -612,16 +630,16 @@ void SearchProvider::StartOrStopSuggestQuery(bool minimal_changes) { |
| if (!input_.want_asynchronous_matches()) |
| return; |
| - // To avoid flooding the suggest server, don't send a query until at |
| - // least 100 ms since the last query. |
| - base::TimeTicks next_suggest_time(time_suggest_request_sent_ + |
| - base::TimeDelta::FromMilliseconds(kMinimumTimeBetweenSuggestQueriesMs)); |
| - base::TimeTicks now(base::TimeTicks::Now()); |
| - if (now >= next_suggest_time) { |
| + // Kick off a timer that will start the URL fetch if it completes before |
| + // the user types another character. Requests may be delayed to avoid |
| + // flooding the server with requests that are likely to be thrown away later |
| + // anyway. |
| + const base::TimeDelta delay = GetSuggestQueryDelay(); |
| + if (delay <= base::TimeDelta()) { |
| Run(); |
| return; |
| } |
| - timer_.Start(FROM_HERE, next_suggest_time - now, this, &SearchProvider::Run); |
| + timer_.Start(FROM_HERE, delay, this, &SearchProvider::Run); |
| } |
| bool SearchProvider::IsQuerySuitableForSuggest() const { |