summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autocomplete
diff options
context:
space:
mode:
authordarin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-03 18:18:14 +0000
committerdarin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-03 18:18:14 +0000
commit2d31666a58e746b7a1d415c99e5f68ad9256d236 (patch)
tree144c99d4b80df0f0f9a3ded83f9d21a8b36f17cc /chrome/browser/autocomplete
parent90d6958fe2374a00d3c8583cf4d3b8a509ae8e90 (diff)
downloadchromium_src-2d31666a58e746b7a1d415c99e5f68ad9256d236.zip
chromium_src-2d31666a58e746b7a1d415c99e5f68ad9256d236.tar.gz
chromium_src-2d31666a58e746b7a1d415c99e5f68ad9256d236.tar.bz2
Minor cleanup to OneShotTimer and RepeatingTimer: moves more of the member variables into the Task subclass.
Also included in this change: deprecate MessageLoop::timer_manager(), and change consumers over to use OneShotTimer or RepeatingTimer. R=beng BUG=1346553 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1684 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autocomplete')
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup.cc23
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup.h7
-rw-r--r--chrome/browser/autocomplete/search_provider.cc7
-rw-r--r--chrome/browser/autocomplete/search_provider.h13
4 files changed, 22 insertions, 28 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_popup.cc b/chrome/browser/autocomplete/autocomplete_popup.cc
index b272143..ca2dcbc 100644
--- a/chrome/browser/autocomplete/autocomplete_popup.cc
+++ b/chrome/browser/autocomplete/autocomplete_popup.cc
@@ -721,10 +721,6 @@ AutocompletePopupModel::AutocompletePopupModel(const ChromeFont& font,
profile_(profile),
query_in_progress_(false),
update_pending_(false),
- // Creating the Timers directly instead of using StartTimer() ensures
- // they won't actually start running until we use ResetTimer().
- coalesce_timer_(new Timer(kPopupCoalesceMs, this, false)),
- max_delay_timer_(new Timer(kPopupUpdateMaxDelayMs, this, true)),
hovered_line_(kNoMatch),
selected_line_(kNoMatch) {
}
@@ -773,10 +769,9 @@ void AutocompletePopupModel::StartAutocomplete(
input_ = input;
// If we're starting a brand new query, stop caring about any old query.
- TimerManager* const tm = MessageLoop::current()->timer_manager();
if (!minimal_changes && query_in_progress_) {
update_pending_ = false;
- tm->StopTimer(coalesce_timer_.get());
+ coalesce_timer_.Stop();
}
// Start the new query.
@@ -785,8 +780,9 @@ void AutocompletePopupModel::StartAutocomplete(
// If we're not ready to show results and the max update interval timer isn't
// already running, start it now.
- if (query_in_progress_ && !tm->IsTimerRunning(max_delay_timer_.get()))
- tm->ResetTimer(max_delay_timer_.get());
+ if (query_in_progress_ && !max_delay_timer_.IsRunning())
+ max_delay_timer_.Start(TimeDelta::FromMilliseconds(kPopupUpdateMaxDelayMs),
+ this, &AutocompletePopupModel::Run);
SetDefaultMatchAndUpdate(!query_in_progress_);
}
@@ -1030,7 +1026,9 @@ void AutocompletePopupModel::SetDefaultMatchAndUpdate(bool immediately) {
} else if (!update_pending_) {
// Coalesce the results for the next kPopupCoalesceMs milliseconds.
update_pending_ = true;
- MessageLoop::current()->timer_manager()->ResetTimer(coalesce_timer_.get());
+ coalesce_timer_.Stop();
+ coalesce_timer_.Start(TimeDelta::FromMilliseconds(kPopupCoalesceMs), this,
+ &AutocompletePopupModel::Run);
}
// Update the edit with the possibly new data for this match.
@@ -1087,12 +1085,11 @@ void AutocompletePopupModel::CommitLatestResults(bool force) {
// The max update interval timer either needs to be reset (if more updates
// are to come) or stopped (when we're done with the query). The coalesce
// timer should always just be stopped.
- TimerManager* const tm = MessageLoop::current()->timer_manager();
- tm->StopTimer(coalesce_timer_.get());
+ coalesce_timer_.Stop();
if (query_in_progress_)
- tm->ResetTimer(max_delay_timer_.get());
+ max_delay_timer_.Reset();
else
- tm->StopTimer(max_delay_timer_.get());
+ max_delay_timer_.Stop();
}
bool AutocompletePopupModel::GetKeywordForMatch(const AutocompleteMatch& match,
diff --git a/chrome/browser/autocomplete/autocomplete_popup.h b/chrome/browser/autocomplete/autocomplete_popup.h
index 395f774..160c766 100644
--- a/chrome/browser/autocomplete/autocomplete_popup.h
+++ b/chrome/browser/autocomplete/autocomplete_popup.h
@@ -385,15 +385,12 @@ class AutocompletePopupModel : public ACControllerListener, public Task {
// Timer that tracks how long it's been since the last provider update we
// received. Instead of displaying each update immediately, we batch updates
// into groups, which reduces flicker.
- //
- // NOTE: Both coalesce_timer_ and max_delay_timer_ (below) are set up during
- // the constructor, and are guaranteed non-NULL for the life of the popup.
- scoped_ptr<Timer> coalesce_timer_;
+ base::OneShotTimer<AutocompletePopupModel> coalesce_timer_;
// Timer that tracks how long it's been since the last time we updated the
// onscreen results. This is used to ensure that the popup is somewhat
// responsive even when the user types continuously.
- scoped_ptr<Timer> max_delay_timer_;
+ base::RepeatingTimer<AutocompletePopupModel> max_delay_timer_;
// The line that's currently hovered. If we're not drawing a hover rect,
// this will be kNoMatch, even if the cursor is over the popup contents.
diff --git a/chrome/browser/autocomplete/search_provider.cc b/chrome/browser/autocomplete/search_provider.cc
index 23b6063..9126a35 100644
--- a/chrome/browser/autocomplete/search_provider.cc
+++ b/chrome/browser/autocomplete/search_provider.cc
@@ -180,7 +180,10 @@ void SearchProvider::StartOrStopSuggestQuery(bool minimal_changes,
// Kick off a timer that will start the URL fetch if it completes before
// the user types another character.
suggest_results_pending_ = true;
- MessageLoop::current()->timer_manager()->ResetTimer(timer_.get());
+
+ timer_.Stop();
+ timer_.Start(TimeDelta::FromMilliseconds(kQueryDelayMs), this,
+ &SearchProvider::Run);
}
void SearchProvider::StopHistory() {
@@ -192,7 +195,7 @@ void SearchProvider::StopHistory() {
void SearchProvider::StopSuggest() {
suggest_results_pending_ = false;
- MessageLoop::current()->timer_manager()->StopTimer(timer_.get());
+ timer_.Stop();
fetcher_.reset(); // Stop any in-progress URL fetch.
suggest_results_.clear();
have_suggest_results_ = false;
diff --git a/chrome/browser/autocomplete/search_provider.h b/chrome/browser/autocomplete/search_provider.h
index 9af8a53..4c509c5 100644
--- a/chrome/browser/autocomplete/search_provider.h
+++ b/chrome/browser/autocomplete/search_provider.h
@@ -34,14 +34,11 @@ class Value;
// comes back, the provider creates and returns matches for the best
// suggestions.
class SearchProvider : public AutocompleteProvider,
- public URLFetcher::Delegate,
- public Task {
+ public URLFetcher::Delegate {
public:
SearchProvider(ACProviderListener* listener, Profile* profile)
: AutocompleteProvider(listener, profile, "Search"),
last_default_provider_(NULL),
-#pragma warning(suppress: 4355) // Okay to pass "this" here.
- timer_(new Timer(kQueryDelayMs, this, false)),
fetcher_(NULL),
history_request_pending_(false),
have_history_results_(false),
@@ -63,9 +60,6 @@ class SearchProvider : public AutocompleteProvider,
const ResponseCookies& cookies,
const std::string& data);
- // Task
- void Run();
-
private:
struct NavigationResult {
NavigationResult(const std::wstring& url, const std::wstring& site_name)
@@ -85,6 +79,9 @@ class SearchProvider : public AutocompleteProvider,
typedef std::vector<history::KeywordSearchTermVisit> HistoryResults;
typedef std::map<std::wstring, AutocompleteMatch> MatchMap;
+ // Called when timer_ expires.
+ void Run();
+
// Determines whether an asynchronous subcomponent query should run for the
// current input. If so, starts it if necessary; otherwise stops it.
// NOTE: These functions do not update |done_|. Callers must do so.
@@ -173,7 +170,7 @@ class SearchProvider : public AutocompleteProvider,
// A timer to start a query to the suggest server after the user has stopped
// typing for long enough.
- scoped_ptr<Timer> timer_;
+ base::OneShotTimer<SearchProvider> timer_;
// The fetcher that retrieves suggest results from the server.
scoped_ptr<URLFetcher> fetcher_;