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

Unified Diff: components/omnibox/search_provider.cc

Issue 645303003: Parametrize Suggest polling strategy and delay. Also add a parameter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed two comments. Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/omnibox/search_provider.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/omnibox/search_provider.cc
diff --git a/components/omnibox/search_provider.cc b/components/omnibox/search_provider.cc
index a9cd7b7fe3eef8168757e0ea582ee84243161d40..4cd192fa4b5f29bc663ff286d0cc575dae457156 100644
--- a/components/omnibox/search_provider.cc
+++ b/components/omnibox/search_provider.cc
@@ -116,9 +116,6 @@ class SearchProvider::CompareScoredResults {
// SearchProvider -------------------------------------------------------------
-// static
-int SearchProvider::kMinimumTimeBetweenSuggestQueriesMs = 100;
-
SearchProvider::SearchProvider(
AutocompleteProviderListener* listener,
TemplateURLService* template_url_service,
@@ -579,6 +576,21 @@ void SearchProvider::DoHistoryQuery(bool minimal_changes) {
}
}
+base::TimeDelta SearchProvider::GetSuggestQueryDelay() const {
+ bool from_last_keystroke;
+ int polling_delay_ms;
+ OmniboxFieldTrial::GetSuggestPollingStrategy(&from_last_keystroke,
+ &polling_delay_ms);
+
+ base::TimeDelta delay(base::TimeDelta::FromMilliseconds(polling_delay_ms));
+ if (from_last_keystroke)
+ 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);
+}
+
void SearchProvider::StartOrStopSuggestQuery(bool minimal_changes) {
if (!IsQuerySuitableForSuggest()) {
StopSuggest();
@@ -586,6 +598,9 @@ void SearchProvider::StartOrStopSuggestQuery(bool minimal_changes) {
return;
}
+ if (OmniboxFieldTrial::DisableResultsCaching())
+ ClearAllResults();
+
// 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 +627,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 {
« 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