diff options
Diffstat (limited to 'chrome/browser')
24 files changed, 114 insertions, 307 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_; diff --git a/chrome/browser/download_file.cc b/chrome/browser/download_file.cc index a7f796e..8b1da8c 100644 --- a/chrome/browser/download_file.cc +++ b/chrome/browser/download_file.cc @@ -12,7 +12,6 @@ #include "base/scoped_ptr.h" #include "base/string_util.h" #include "base/task.h" -#include "base/timer.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/download_manager.h" #include "chrome/browser/profile.h" @@ -137,8 +136,6 @@ bool DownloadFile::Open(const wchar_t* open_mode) { DownloadFileManager::DownloadFileManager(MessageLoop* ui_loop, ResourceDispatcherHost* rdh) : next_id_(0), - update_task_(NULL), - update_timer_(NULL), ui_loop_(ui_loop), resource_dispatcher_host_(rdh) { } @@ -146,7 +143,6 @@ DownloadFileManager::DownloadFileManager(MessageLoop* ui_loop, DownloadFileManager::~DownloadFileManager() { // Check for clean shutdown. DCHECK(downloads_.empty()); - DCHECK(!update_timer_ && !update_task_); ui_progress_.clear(); } @@ -197,22 +193,15 @@ void DownloadFileManager::RemoveDownloadFromUIProgress(int id) { // regularly controlled interval. void DownloadFileManager::StartUpdateTimer() { DCHECK(MessageLoop::current() == ui_loop_); - if (update_timer_ == NULL) { - update_task_ = new DownloadFileUpdateTask(this); - TimerManager* tm = ui_loop_->timer_manager(); - update_timer_ = tm->StartTimer(kUpdatePeriodMs, update_task_, true); + if (!update_timer_.IsRunning()) { + update_timer_.Start(TimeDelta::FromMilliseconds(kUpdatePeriodMs), this, + &DownloadFileManager::UpdateInProgressDownloads); } } void DownloadFileManager::StopUpdateTimer() { DCHECK(MessageLoop::current() == ui_loop_); - if (update_timer_ && update_task_) { - ui_loop_->timer_manager()->StopTimer(update_timer_); - delete update_timer_; - update_timer_ = NULL; - delete update_task_; - update_task_ = NULL; - } + update_timer_.Stop(); } // Called on the IO thread once the ResourceDispatcherHost has decided that a diff --git a/chrome/browser/download_file.h b/chrome/browser/download_file.h index f9c6e91..4b50c13 100644 --- a/chrome/browser/download_file.h +++ b/chrome/browser/download_file.h @@ -50,19 +50,15 @@ #include "base/lock.h" #include "base/ref_counted.h" #include "base/thread.h" +#include "base/timer.h" #include "chrome/browser/history/download_types.h" class DownloadManager; class GURL; class MessageLoop; class ResourceDispatcherHost; -class Task; class URLRequestContext; -namespace base { -class Timer; -} - // DownloadBuffer -------------------------------------------------------------- // This container is created and populated on the io_thread, and passed to the @@ -242,8 +238,7 @@ class DownloadFileManager DownloadFileMap downloads_; // Throttle updates to the UI thread. - Task* update_task_; - base::Timer* update_timer_; + base::RepeatingTimer<DownloadFileManager> update_timer_; // The MessageLoop that the DownloadManagers live on. MessageLoop* ui_loop_; diff --git a/chrome/browser/download_manager.cc b/chrome/browser/download_manager.cc index aef9b14..4f008d8 100644 --- a/chrome/browser/download_manager.cc +++ b/chrome/browser/download_manager.cc @@ -95,8 +95,6 @@ DownloadItem::DownloadItem(const DownloadCreateInfo& info) state_(static_cast<DownloadState>(info.state)), start_time_(info.start_time), db_handle_(info.db_handle), - update_task_(NULL), - timer_(NULL), manager_(NULL), is_paused_(false), open_when_complete_(false), @@ -124,8 +122,6 @@ DownloadItem::DownloadItem(int32 download_id, state_(IN_PROGRESS), start_time_(start_time), db_handle_(kUninitializedHandle), - update_task_(NULL), - timer_(NULL), manager_(NULL), is_paused_(false), open_when_complete_(false), @@ -141,7 +137,6 @@ void DownloadItem::Init(bool start_timer) { } DownloadItem::~DownloadItem() { - DCHECK(timer_ == NULL && update_task_ == NULL); state_ = REMOVING; UpdateObservers(); } @@ -205,20 +200,12 @@ void DownloadItem::Remove() { } void DownloadItem::StartProgressTimer() { - DCHECK(update_task_ == NULL && timer_ == NULL); - update_task_ = new DownloadItemUpdateTask(this); - TimerManager* tm = MessageLoop::current()->timer_manager(); - timer_ = tm->StartTimer(kUpdateTimeMs, update_task_, true); + update_timer_.Start(TimeDelta::FromMilliseconds(kUpdateTimeMs), this, + &DownloadItem::UpdateObservers); } void DownloadItem::StopProgressTimer() { - if (timer_) { - MessageLoop::current()->timer_manager()->StopTimer(timer_); - delete timer_; - timer_ = NULL; - delete update_task_; - update_task_ = NULL; - } + update_timer_.Stop(); } bool DownloadItem::TimeRemaining(TimeDelta* remaining) const { diff --git a/chrome/browser/download_manager.h b/chrome/browser/download_manager.h index 89773fe..a9ffc27 100644 --- a/chrome/browser/download_manager.h +++ b/chrome/browser/download_manager.h @@ -59,8 +59,6 @@ class MessageLoop; class PrefService; class Profile; class ResourceDispatcherHost; -class Task; -class Timer; class URLRequestContext; class WebContents; @@ -216,9 +214,8 @@ class DownloadItem { // Our persistent store handle int64 db_handle_; - // Timer & task for regularly updating our observers - Task* update_task_; - Timer* timer_; + // Timer for regularly updating our observers + base::RepeatingTimer<DownloadItem> update_timer_; // Our owning object DownloadManager* manager_; diff --git a/chrome/browser/download_tab_view.cc b/chrome/browser/download_tab_view.cc index ee74590..56b7c3e 100644 --- a/chrome/browser/download_tab_view.cc +++ b/chrome/browser/download_tab_view.cc @@ -663,8 +663,6 @@ void DownloadItemTabView::LinkActivated(ChromeViews::Link* source, DownloadTabView::DownloadTabView(DownloadManager* model) : model_(model), - progress_timer_(NULL), - progress_task_(NULL), start_angle_(download_util::kStartAngleDegrees), scroll_helper_(kSpacer, kProgressIconSize + kSpacer), selected_index_(-1) { @@ -688,25 +686,16 @@ void DownloadTabView::Initialize() { // Start progress animation timers when we get our first (in-progress) download. void DownloadTabView::StartDownloadProgress() { - if (progress_task_ || progress_timer_) + if (progress_timer_.IsRunning()) return; - progress_task_ = - new download_util::DownloadProgressTask<DownloadTabView>(this); - progress_timer_ = - MessageLoop::current()->timer_manager()-> - StartTimer(download_util::kProgressRateMs, progress_task_, true); + progress_timer_.Start( + TimeDelta::FromMilliseconds(download_util::kProgressRateMs), this, + &DownloadTabView::UpdateDownloadProgress); } // Stop progress animation when there are no more in-progress downloads. void DownloadTabView::StopDownloadProgress() { - if (progress_timer_) { - DCHECK(progress_task_); - MessageLoop::current()->timer_manager()->StopTimer(progress_timer_); - delete progress_timer_; - progress_timer_ = NULL; - delete progress_task_; - progress_task_ = NULL; - } + progress_timer_.Stop(); } // Update our animations. diff --git a/chrome/browser/download_tab_view.h b/chrome/browser/download_tab_view.h index 346a903..92ca343 100644 --- a/chrome/browser/download_tab_view.h +++ b/chrome/browser/download_tab_view.h @@ -173,8 +173,7 @@ class DownloadTabView : public ChromeViews::View, OrderedDownloads downloads_; // Progress animations - base::Timer* progress_timer_; - Task* progress_task_; + base::RepeatingTimer<DownloadTabView> progress_timer_; // Since this view manages the progress animation timers for all the floating // views, we need to track the current in progress downloads. This container diff --git a/chrome/browser/printing/print_job.cc b/chrome/browser/printing/print_job.cc index decd853..b1e2bdc 100644 --- a/chrome/browser/printing/print_job.cc +++ b/chrome/browser/printing/print_job.cc @@ -267,18 +267,14 @@ bool PrintJob::FlushJob(int timeout_ms) { // Make sure the object outlive this message loop. scoped_refptr<PrintJob> handle(this); - MessageLoop::QuitTask timeout_task; - scoped_ptr<Timer> timeout; - if (timeout_ms) { - timeout.reset(MessageLoop::current()->timer_manager()->StartTimer( - timeout_ms, - &timeout_task, - false)); - } - // Stop() will eventually be called, which will get out of the inner message // loop. But, don't take it for granted and set a timer in case something goes // wrong. + base::OneShotTimer<MessageLoop> quit_task; + if (timeout_ms) { + quit_task.Start(TimeDelta::FromMilliseconds(timeout_ms), + MessageLoop::current(), &MessageLoop::Quit); + } bool old_state = MessageLoop::current()->NestableTasksAllowed(); MessageLoop::current()->SetNestableTasksAllowed(true); @@ -286,9 +282,6 @@ bool PrintJob::FlushJob(int timeout_ms) { // Restore task state. MessageLoop::current()->SetNestableTasksAllowed(old_state); - if (timeout.get()) { - MessageLoop::current()->timer_manager()->StopTimer(timeout.get()); - } return true; } diff --git a/chrome/browser/printing/print_view_manager.cc b/chrome/browser/printing/print_view_manager.cc index 39e3bda..1157d64 100644 --- a/chrome/browser/printing/print_view_manager.cc +++ b/chrome/browser/printing/print_view_manager.cc @@ -492,12 +492,12 @@ bool PrintViewManager::RunInnerMessageLoop() { // be cpu bound, the page overly complex/large or the system just // memory-bound. static const int kPrinterSettingsTimeout = 60000; - MessageLoop::QuitTask timeout_task; - Timer* timeout = MessageLoop::current()->timer_manager()->StartTimer( - kPrinterSettingsTimeout, - &timeout_task, - false); + base::OneShotTimer<MessageLoop> quit_timer; + quit_timer.Start(TimeDelta::FromMilliseconds(kPrinterSettingsTimeout), + MessageLoop::current(), &MessageLoop::Quit); + inside_inner_message_loop_ = true; + // Need to enable recursive task. bool old_state = MessageLoop::current()->NestableTasksAllowed(); MessageLoop::current()->SetNestableTasksAllowed(true); @@ -512,11 +512,6 @@ bool PrintViewManager::RunInnerMessageLoop() { success = false; } - if (timeout) { - MessageLoop::current()->timer_manager()->StopTimer(timeout); - delete timeout; - timeout = NULL; - } return success; } diff --git a/chrome/browser/printing/printing_layout_uitest.cc b/chrome/browser/printing/printing_layout_uitest.cc index a55e246..943aeb6 100644 --- a/chrome/browser/printing/printing_layout_uitest.cc +++ b/chrome/browser/printing/printing_layout_uitest.cc @@ -399,23 +399,29 @@ class PrintingLayoutTextTest : public PrintingLayoutTest { // Dismiss the first dialog box child of owner_window by "executing" the // default button. -class DismissTheWindow : public Task { +class DismissTheWindow : public base::RefCountedThreadSafe<DismissTheWindow> { public: DismissTheWindow(DWORD owner_process) : owner_process_(owner_process), dialog_was_found_(false), dialog_window_(NULL), other_thread_(MessageLoop::current()), - timer_(NULL), start_time_(Time::Now()) { } - virtual void Run() { + + void Start() { + timer_.Start(TimeDelta::FromMilliseconds(250), this, + &DismissTheWindow::DoTimeout); + } + + private: + void DoTimeout() { // A bit twisted code that runs in 2 passes or more. First it tries to find // a dialog box, if it finds it, it will execute the default action. If it // still works, it will loop again but then it will try to *not* find the // window. Once this is right, it will stop the timer and unlock the // other_thread_ message loop. - if (!timer_) + if (!timer_.IsRunning()) return; if (!dialog_window_) { @@ -464,8 +470,7 @@ class DismissTheWindow : public Task { // Now verify that it indeed closed itself. if (!IsWindow(dialog_window_)) { - MessageLoop::current()->timer_manager()->StopTimer(timer_); - timer_ = NULL; + timer_.Stop(); // Unlock the other thread. other_thread_->PostTask(FROM_HERE, new MessageLoop::QuitTask()); } else { @@ -473,15 +478,12 @@ class DismissTheWindow : public Task { dialog_window_ = NULL; } } - void SetTimer(Timer* timer) { - timer_ = timer; - } - private: + DWORD owner_process_; bool dialog_was_found_; HWND dialog_window_; MessageLoop* other_thread_; - Timer* timer_; + base::RepeatingTimer<DismissTheWindow> timer_; Time start_time_; }; @@ -562,14 +564,13 @@ TEST_F(PrintingLayoutTest, DISABLED_Delayed) { scoped_ptr<base::Thread> worker( new base::Thread("PrintingLayoutTest_worker")); - DismissTheWindow dismiss_task(process_util::GetProcId(process())); + scoped_refptr<DismissTheWindow> dismiss_task = + new DismissTheWindow(process_util::GetProcId(process())); // We need to start the thread to be able to set the timer. worker->Start(); - scoped_ptr<Timer> timer(worker->message_loop()->timer_manager()->StartTimer( - 250, - &dismiss_task, - true)); - dismiss_task.SetTimer(timer.get()); + worker->message_loop()->PostTask(FROM_HERE, + NewRunnableMethod(dismiss_task.get(), &DismissTheWindow::Start)); + MessageLoop::current()->Run(); worker->Stop(); @@ -601,14 +602,13 @@ TEST_F(PrintingLayoutTest, DISABLED_IFrame) { scoped_ptr<base::Thread> worker( new base::Thread("PrintingLayoutTest_worker")); - DismissTheWindow dismiss_task(process_util::GetProcId(process())); + scoped_refptr<DismissTheWindow> dismiss_task = + new DismissTheWindow(process_util::GetProcId(process())); // We need to start the thread to be able to set the timer. worker->Start(); - scoped_ptr<Timer> timer(worker->message_loop()->timer_manager()->StartTimer( - 250, - &dismiss_task, - true)); - dismiss_task.SetTimer(timer.get()); + worker->message_loop()->PostTask(FROM_HERE, + NewRunnableMethod(dismiss_task.get(), &DismissTheWindow::Start)); + MessageLoop::current()->Run(); worker->Stop(); diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc index 9a64b40..b55a065 100644 --- a/chrome/browser/profile.cc +++ b/chrome/browser/profile.cc @@ -551,9 +551,6 @@ ProfileImpl::ProfileImpl(const std::wstring& path) created_web_data_service_(false), created_download_manager_(false), request_context_(NULL), -#pragma warning(suppress: 4355) // Okay to pass "this" here. - create_session_service_timer_(NULL), - create_session_service_task_(this), start_time_(Time::Now()), spellchecker_(NULL), #ifdef CHROME_PERSONALIZATION @@ -562,9 +559,9 @@ ProfileImpl::ProfileImpl(const std::wstring& path) shutdown_session_service_(false) { DCHECK(!path.empty()) << "Using an empty path will attempt to write " << "profile files to the root directory!"; - create_session_service_timer_ = - MessageLoop::current()->timer_manager()->StartTimer( - kCreateSessionServiceDelayMS, &create_session_service_task_, false); + create_session_service_timer_.Start( + TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this, + &ProfileImpl::EnsureSessionServiceCreated); } ProfileImpl::~ProfileImpl() { @@ -913,12 +910,7 @@ void ProfileImpl::MarkAsCleanShutdown() { } void ProfileImpl::StopCreateSessionServiceTimer() { - if (create_session_service_timer_) { - MessageLoop::current()->timer_manager()-> - StopTimer(create_session_service_timer_); - delete create_session_service_timer_; - create_session_service_timer_ = NULL; - } + create_session_service_timer_.Stop(); } #ifdef CHROME_PERSONALIZATION diff --git a/chrome/browser/profile.h b/chrome/browser/profile.h index e4057c6..238ce41 100644 --- a/chrome/browser/profile.h +++ b/chrome/browser/profile.h @@ -14,7 +14,7 @@ #include "base/ref_counted.h" #include "base/scoped_ptr.h" #include "base/task.h" -#include "base/time.h" +#include "base/timer.h" #ifdef CHROME_PERSONALIZATION #include "chrome/personalization/personalization.h" #endif @@ -33,10 +33,6 @@ class URLRequestContext; class VisitedLinkMaster; class WebDataService; -namespace base { -class Timer; -} - class Profile { public: @@ -291,23 +287,6 @@ class ProfileImpl : public Profile { private: class RequestContext; - // TODO(sky): replace this with a generic invokeLater that doesn't require - // arg to be ref counted. - class CreateSessionServiceTask : public Task { - public: - explicit CreateSessionServiceTask(ProfileImpl* profile) - : profile_(profile) { - } - void Run() { - profile_->GetSessionService(); - } - - private: - ProfileImpl* profile_; - - DISALLOW_EVIL_CONSTRUCTORS(CreateSessionServiceTask); - }; - friend class Profile; ProfileImpl(const std::wstring& path); @@ -316,6 +295,10 @@ class ProfileImpl : public Profile { std::wstring GetPrefFilePath(); void StopCreateSessionServiceTimer(); + + void EnsureSessionServiceCreated() { + GetSessionService(); + } std::wstring path_; bool off_the_record_; @@ -343,8 +326,7 @@ class ProfileImpl : public Profile { ProfileControllerSet controllers_; - base::Timer* create_session_service_timer_; - CreateSessionServiceTask create_session_service_task_; + base::OneShotTimer<ProfileImpl> create_session_service_timer_; scoped_ptr<OffTheRecordProfileImpl> off_the_record_profile_; diff --git a/chrome/browser/safe_browsing/protocol_manager.cc b/chrome/browser/safe_browsing/protocol_manager.cc index c1ed1b4..e66afc5 100644 --- a/chrome/browser/safe_browsing/protocol_manager.cc +++ b/chrome/browser/safe_browsing/protocol_manager.cc @@ -49,22 +49,6 @@ static const int kSbClientMinorVersion = 0; static const int kSbMaxBackOff = 8; -// Periodic update task -------------------------------------------------------- -class SafeBrowsingProtocolUpdateTask : public Task { - public: - explicit SafeBrowsingProtocolUpdateTask(SafeBrowsingProtocolManager* manager) - : manager_(manager) { - } - - void Run() { - manager_->GetNextUpdate(); - } - - private: - SafeBrowsingProtocolManager* manager_; -}; - - // SafeBrowsingProtocolManager implementation ---------------------------------- SafeBrowsingProtocolManager::SafeBrowsingProtocolManager( @@ -93,9 +77,6 @@ SafeBrowsingProtocolManager::SafeBrowsingProtocolManager( } SafeBrowsingProtocolManager::~SafeBrowsingProtocolManager() { - if (update_timer_.get()) - MessageLoop::current()->timer_manager()->StopTimer(update_timer_.get()); - // Delete in-progress SafeBrowsing requests. STLDeleteContainerPairFirstPointers(hash_requests_.begin(), hash_requests_.end()); @@ -399,17 +380,13 @@ void SafeBrowsingProtocolManager::Initialize() { void SafeBrowsingProtocolManager::ScheduleNextUpdate(bool back_off) { DCHECK(next_update_sec_ > 0); - if (!update_task_.get()) - update_task_.reset(new SafeBrowsingProtocolUpdateTask(this)); - - // Unschedule any current timer & task. - TimerManager* tm = MessageLoop::current()->timer_manager(); - if (update_timer_.get()) - tm->StopTimer(update_timer_.get()); + // Unschedule any current timer. + update_timer_.Stop(); // Reschedule with the new update. const int next_update = GetNextUpdateTime(back_off); - update_timer_.reset(tm->StartTimer(next_update, update_task_.get(), false)); + update_timer_.Start(TimeDelta::FromMilliseconds(next_update), this, + &SafeBrowsingProtocolManager::GetNextUpdate); } // According to section 5 of the SafeBrowsing protocol specification, we must diff --git a/chrome/browser/safe_browsing/protocol_manager.h b/chrome/browser/safe_browsing/protocol_manager.h index 1b12d5c6..c7276c6 100644 --- a/chrome/browser/safe_browsing/protocol_manager.h +++ b/chrome/browser/safe_browsing/protocol_manager.h @@ -159,8 +159,7 @@ class SafeBrowsingProtocolManager : public URLFetcher::Delegate { // For managing the next earliest time to query the SafeBrowsing servers for // updates. int next_update_sec_; - scoped_ptr<Task> update_task_; - scoped_ptr<Timer> update_timer_; + base::OneShotTimer<SafeBrowsingProtocolManager> update_timer_; // All chunk requests that need to be made, along with their MAC. std::deque<ChunkUrl> chunk_request_urls_; diff --git a/chrome/browser/tabs/tab_strip.cc b/chrome/browser/tabs/tab_strip.cc index d38be5a..03f6c2e 100644 --- a/chrome/browser/tabs/tab_strip.cc +++ b/chrome/browser/tabs/tab_strip.cc @@ -462,10 +462,6 @@ TabStrip::~TabStrip() { // TODO(beng): remove this if it doesn't work to fix the TabSelectedAt bug. drag_controller_.reset(NULL); - // Stop any existing Loading Animation timer. - MessageLoop::current()->timer_manager()->StopTimer( - loading_animation_timer_.get()); - // Make sure we unhook ourselves as a message loop observer so that we don't // crash in the case where the user closes the window after closing a tab // but before moving the mouse. @@ -849,18 +845,18 @@ void TabStrip::TabChangedAt(TabContents* contents, int index) { } void TabStrip::TabValidateAnimations() { - TimerManager* tm = MessageLoop::current()->timer_manager(); - Timer* timer = loading_animation_timer_.get(); if (model_->TabsAreLoading()) { - if (!tm->IsTimerRunning(timer)) { + if (!loading_animation_timer_.IsRunning()) { // Loads are happening, and the timer isn't running, so start it. - tm->ResetTimer(timer); + loading_animation_timer_.Start( + TimeDelta::FromMilliseconds(kLoadingAnimationFrameTimeMs), this, + &TabStrip::LoadingAnimationCallback); } } else { - if (tm->IsTimerRunning(timer)) { + if (loading_animation_timer_.IsRunning()) { + loading_animation_timer_.Stop(); // Loads are now complete, update the state if a task was scheduled. LoadingAnimationCallback(); - tm->StopTimer(timer); } } } @@ -1000,15 +996,6 @@ void TabStrip::ButtonPressed(ChromeViews::BaseButton* sender) { } /////////////////////////////////////////////////////////////////////////////// -// TabStrip, Task implementation: - -void TabStrip::Run() { - // Loading Animation frame advancement timer has fired, update all of the - // loading animations as applicable... - LoadingAnimationCallback(); -} - -/////////////////////////////////////////////////////////////////////////////// // TabStrip, MessageLoop::Observer implementation: void TabStrip::WillProcessMessage(const MSG& msg) { @@ -1085,11 +1072,6 @@ void TabStrip::Init() { newtab_button_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_NEWTAB)); AddChildView(newtab_button_); - // Creating the Timer directly instead of using StartTimer() ensures it won't - // actually start running until we use ResetTimer(); - loading_animation_timer_.reset( - new Timer(kLoadingAnimationFrameTimeMs, this, true)); - if (drop_indicator_width == 0) { // Direction doesn't matter, both images are the same size. SkBitmap* drop_image = GetDropArrowImage(true); diff --git a/chrome/browser/tabs/tab_strip.h b/chrome/browser/tabs/tab_strip.h index 9d2ed08..11f6f64 100644 --- a/chrome/browser/tabs/tab_strip.h +++ b/chrome/browser/tabs/tab_strip.h @@ -6,7 +6,6 @@ #define CHROME_BROWSER_TABS_TAB_STRIP_H__ #include "base/gfx/point.h" -#include "base/task.h" #include "chrome/browser/tabs/tab.h" #include "chrome/browser/tabs/tab_strip_model.h" #include "chrome/views/button.h" @@ -17,7 +16,6 @@ class DraggedTabController; class ScopedMouseCloseWidthCalculator; class TabStripModel; -class Timer; namespace ChromeViews { class ImageView; @@ -40,7 +38,6 @@ class TabStrip : public ChromeViews::View, public TabStripModelObserver, public Tab::TabDelegate, public ChromeViews::Button::ButtonListener, - public Task, public MessageLoopForUI::Observer { public: TabStrip(TabStripModel* model); @@ -153,9 +150,6 @@ class TabStrip : public ChromeViews::View, // ChromeViews::Button::ButtonListener implementation: virtual void ButtonPressed(ChromeViews::BaseButton* sender); - // Task implementation: - virtual void Run(); - // MessageLoop::Observer implementation: virtual void WillProcessMessage(const MSG& msg); virtual void DidProcessMessage(const MSG& msg); @@ -303,7 +297,7 @@ class TabStrip : public ChromeViews::View, bool resize_layout_scheduled_; // The timer used to update frames for the Loading Animation. - scoped_ptr<Timer> loading_animation_timer_; + base::RepeatingTimer<TabStrip> loading_animation_timer_; // The "New Tab" button. ChromeViews::Button* newtab_button_; diff --git a/chrome/browser/task_manager.cc b/chrome/browser/task_manager.cc index 06c7bbc..7cb75ff 100644 --- a/chrome/browser/task_manager.cc +++ b/chrome/browser/task_manager.cc @@ -7,7 +7,6 @@ #include "base/process_util.h" #include "base/stats_table.h" #include "base/string_util.h" -#include "base/timer.h" #include "chrome/browser/browser_list.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/render_process_host.h" @@ -44,26 +43,6 @@ static const int kGoatsTeleportedColumn = (94024 * kNuthMagicNumber) & kBitMask; //////////////////////////////////////////////////////////////////////////////// -// TaskManagerUpdateTask class. -// -// Used to periodically updates the task manager contents. -// -//////////////////////////////////////////////////////////////////////////////// - -class TaskManagerUpdateTask : public Task { - public: - explicit TaskManagerUpdateTask(TaskManagerTableModel* model) : model_(model) { - } - void Run() { - if (model_) model_->Refresh(); - } - - private: - TaskManagerTableModel* model_; - DISALLOW_EVIL_CONSTRUCTORS(TaskManagerUpdateTask); -}; - -//////////////////////////////////////////////////////////////////////////////// // TaskManagerTableModel class //////////////////////////////////////////////////////////////////////////////// @@ -72,7 +51,6 @@ int TaskManagerTableModel::goats_teleported_ = 0; TaskManagerTableModel::TaskManagerTableModel(TaskManager* task_manager) : observer_(NULL), - timer_(NULL), ui_loop_(MessageLoop::current()), is_updating_(false) { @@ -88,11 +66,9 @@ TaskManagerTableModel::TaskManagerTableModel(TaskManager* task_manager) new TaskManagerPluginProcessResourceProvider(task_manager); plugin_provider->AddRef(); providers_.push_back(plugin_provider); - update_task_.reset(new TaskManagerUpdateTask(this)); } TaskManagerTableModel::~TaskManagerTableModel() { - DCHECK(timer_ == NULL); for (ResourceProviderList::iterator iter = providers_.begin(); iter != providers_.end(); ++iter) { (*iter)->Release(); @@ -229,9 +205,8 @@ HANDLE TaskManagerTableModel::GetProcessAt(int index) { void TaskManagerTableModel::StartUpdating() { DCHECK(!is_updating_); is_updating_ = true; - DCHECK(timer_ == NULL); - TimerManager* tm = MessageLoop::current()->timer_manager(); - timer_ = tm->StartTimer(kUpdateTimeMs, update_task_.get(), true); + update_timer_.Start(TimeDelta::FromMilliseconds(kUpdateTimeMs), this, + &TaskManagerTableModel::Refresh); // Register jobs notifications so we can compute network usage (it must be // done from the IO thread). @@ -250,9 +225,7 @@ void TaskManagerTableModel::StartUpdating() { void TaskManagerTableModel::StopUpdating() { DCHECK(is_updating_); is_updating_ = false; - MessageLoop::current()->timer_manager()->StopTimer(timer_); - delete timer_; - timer_ = NULL; + update_timer_.Stop(); // Notify resource providers that we are done updating. for (ResourceProviderList::const_iterator iter = providers_.begin(); diff --git a/chrome/browser/task_manager.h b/chrome/browser/task_manager.h index a84917c..9b8687f 100644 --- a/chrome/browser/task_manager.h +++ b/chrome/browser/task_manager.h @@ -8,6 +8,7 @@ #include "base/lock.h" #include "base/singleton.h" #include "base/ref_counted.h" +#include "base/timer.h" #include "chrome/views/dialog_delegate.h" #include "chrome/views/group_table_view.h" #include "chrome/browser/cache_manager_host.h" @@ -25,10 +26,6 @@ class TaskManagerWindow; struct BytesReadParam; -namespace base { -class Timer; -} - namespace ChromeViews { class View; class Window; @@ -263,9 +260,8 @@ class TaskManagerTableModel : public ChromeViews::GroupTableModel, // The timer controlling the updates of the information. The timer is // allocated every time the task manager is shown and deleted when it is // hidden/closed. - base::Timer* timer_; + base::RepeatingTimer<TaskManagerTableModel> update_timer_; - scoped_ptr<Task> update_task_; MessageLoop* ui_loop_; // See design doc at http://go/at-teleporter for more information. diff --git a/chrome/browser/views/constrained_window_impl.cc b/chrome/browser/views/constrained_window_impl.cc index 8c66ad3..86f5677 100644 --- a/chrome/browser/views/constrained_window_impl.cc +++ b/chrome/browser/views/constrained_window_impl.cc @@ -208,8 +208,7 @@ ChromeFont OTRWindowResources::title_font_; class ConstrainedWindowNonClientView : public ChromeViews::NonClientView, public ChromeViews::BaseButton::ButtonListener, - public LocationBarView::Delegate, - public Task { + public LocationBarView::Delegate { public: ConstrainedWindowNonClientView(ConstrainedWindowImpl* container, TabContents* owner); @@ -256,9 +255,6 @@ class ConstrainedWindowNonClientView virtual TabContents* GetTabContents(); virtual void OnInputInProgress(bool in_progress); - // Overridden from Task: - virtual void Run(); - // Updates the current throbber animation frame; called from the // overloaded Run() and from SetShowThrobber(). void UpdateThrobber(); @@ -319,7 +315,7 @@ class ConstrainedWindowNonClientView bool show_throbber_; // The timer used to update frames for the throbber. - scoped_ptr<Timer> throbber_animation_timer_; + base::RepeatingTimer<ConstrainedWindowNonClientView> throbber_timer_; // The current index into the throbber image strip. int current_throbber_frame_; @@ -395,9 +391,6 @@ ConstrainedWindowNonClientView::ConstrainedWindowNonClientView( close_button_->SetListener(this, 0); AddChildView(close_button_); - throbber_animation_timer_.reset( - new Timer(kThrobberFrameTimeMs, this, true)); - // Note: we don't need for a controller because no input event will be ever // processed from a constrained window. location_bar_ = new LocationBarView(owner->profile(), @@ -409,8 +402,6 @@ ConstrainedWindowNonClientView::ConstrainedWindowNonClientView( } ConstrainedWindowNonClientView::~ConstrainedWindowNonClientView() { - MessageLoop::current()->timer_manager()->StopTimer( - throbber_animation_timer_.get()); } void ConstrainedWindowNonClientView::UpdateLocationBar() { @@ -483,25 +474,21 @@ void ConstrainedWindowNonClientView::UpdateWindowTitle() { void ConstrainedWindowNonClientView::SetShowThrobber(bool show_throbber) { show_throbber_ = show_throbber; - TimerManager* tm = MessageLoop::current()->timer_manager(); - Timer* timer = throbber_animation_timer_.get(); if (show_throbber) { - if (!tm->IsTimerRunning(timer)) - tm->ResetTimer(timer); + if (!throbber_timer_.IsRunning()) + throbber_timer_.Start( + TimeDelta::FromMilliseconds(kThrobberFrameTimeMs), this, + &ConstrainedWindowNonClientView::UpdateThrobber); } else { - if (tm->IsTimerRunning(timer)) { + if (throbber_timer_.IsRunning()) { + throbber_timer_.Stop(); UpdateThrobber(); - tm->StopTimer(timer); } } Layout(); } -void ConstrainedWindowNonClientView::Run() { - UpdateThrobber(); -} - //////////////////////////////////////////////////////////////////////////////// // ConstrainedWindowNonClientView, ChromeViews::NonClientView implementation: diff --git a/chrome/browser/views/download_item_view.cc b/chrome/browser/views/download_item_view.cc index 923752e..bde72f2 100644 --- a/chrome/browser/views/download_item_view.cc +++ b/chrome/browser/views/download_item_view.cc @@ -46,8 +46,6 @@ DownloadItemView::DownloadItemView(DownloadItem* download, parent_(parent), model_(model), progress_angle_(download_util::kStartAngleDegrees), - progress_timer_(NULL), - progress_task_(NULL), body_state_(NORMAL), drop_down_state_(NORMAL), drop_down_pressed_(false), @@ -175,24 +173,15 @@ void DownloadItemView::UpdateDownloadProgress() { } void DownloadItemView::StartDownloadProgress() { - if (progress_task_ || progress_timer_) + if (progress_timer_.IsRunning()) return; - progress_task_ = - new download_util::DownloadProgressTask<DownloadItemView>(this); - progress_timer_ = - MessageLoop::current()->timer_manager()-> - StartTimer(download_util::kProgressRateMs, progress_task_, true); + progress_timer_.Start( + TimeDelta::FromMilliseconds(download_util::kProgressRateMs), this, + &DownloadItemView::UpdateDownloadProgress); } void DownloadItemView::StopDownloadProgress() { - if (progress_timer_) { - DCHECK(progress_task_); - MessageLoop::current()->timer_manager()->StopTimer(progress_timer_); - delete progress_timer_; - progress_timer_ = NULL; - delete progress_task_; - progress_task_ = NULL; - } + progress_timer_.Stop(); } // DownloadObserver interface diff --git a/chrome/browser/views/download_item_view.h b/chrome/browser/views/download_item_view.h index 619c5ea..ab42fd5 100644 --- a/chrome/browser/views/download_item_view.h +++ b/chrome/browser/views/download_item_view.h @@ -20,6 +20,7 @@ #include "base/basictypes.h" #include "base/scoped_ptr.h" +#include "base/timer.h" #include "chrome/common/slide_animation.h" #include "chrome/browser/cancelable_request.h" #include "chrome/browser/download_manager.h" @@ -30,8 +31,6 @@ class DownloadShelfView; class SkBitmap; -class Task; -class Timer; class DownloadItemView : public ChromeViews::View, public DownloadItem::Observer, @@ -188,8 +187,7 @@ class DownloadItemView : public ChromeViews::View, scoped_ptr<SlideAnimation> complete_animation_; // Progress animation - Timer* progress_timer_; - Task* progress_task_; + base::RepeatingTimer<DownloadItemView> progress_timer_; DISALLOW_EVIL_CONSTRUCTORS(DownloadItemView); }; |