diff options
author | darin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-28 20:50:12 +0000 |
---|---|---|
committer | darin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-28 20:50:12 +0000 |
commit | aeab57ea8560065d6c513fcd46bb43e1bfbfd7a6 (patch) | |
tree | a63f2d36e86361d5c27122a6d6ef4098b755d7d9 /chrome/browser | |
parent | e115558691eb08608fad56bb32f40265fdfa4ac5 (diff) | |
download | chromium_src-aeab57ea8560065d6c513fcd46bb43e1bfbfd7a6.zip chromium_src-aeab57ea8560065d6c513fcd46bb43e1bfbfd7a6.tar.gz chromium_src-aeab57ea8560065d6c513fcd46bb43e1bfbfd7a6.tar.bz2 |
Simplify OneShotTimer and RepeatingTimer. Fix up all consumers.
Major changes:
OneShotTimer and RepeatingTimer become template classes that no longer require
a Task or a Timer object. They just use PostDelayedTask. Under the hood that
still uses a Timer object.
The API is much simpler for consumers as they now no longer need to worry about
allocating a Task or managing the lifetime of the object pointer held by the
Task.
I added some new unit tests to timer_unittest.cc to cover the API.
I preserved the old TimerManager / Timer API for now, but I plan to soon kill
it.
R=brettw
BUG=1346553
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1502 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/browser.cc | 10 | ||||
-rw-r--r-- | chrome/browser/browser.h | 4 | ||||
-rw-r--r-- | chrome/browser/download_file.h | 7 | ||||
-rw-r--r-- | chrome/browser/download_tab_view.h | 5 | ||||
-rw-r--r-- | chrome/browser/profile.h | 7 | ||||
-rw-r--r-- | chrome/browser/resource_dispatcher_host.cc | 26 | ||||
-rw-r--r-- | chrome/browser/resource_dispatcher_host.h | 2 | ||||
-rw-r--r-- | chrome/browser/save_file_manager.h | 1 | ||||
-rw-r--r-- | chrome/browser/session_service.h | 1 | ||||
-rw-r--r-- | chrome/browser/task_manager.h | 7 |
10 files changed, 41 insertions, 29 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index 2be43a7..38fb2bb 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -89,11 +89,11 @@ class ReducePluginsWorkingSetTask : public Task { // A browser task to run when the user is not using the browser. // In our case, we're trying to be nice to the operating system and release // memory not in use. -class BrowserIdleTask : public IdleTimerTask { +class BrowserIdleTimer : public base::IdleTimer { public: - BrowserIdleTask() - : IdleTimerTask( - TimeDelta::FromSeconds(kBrowserReleaseMemoryInterval), false) { + BrowserIdleTimer() + : base::IdleTimer(TimeDelta::FromSeconds(kBrowserReleaseMemoryInterval), + false) { } virtual void OnIdle() { @@ -197,7 +197,7 @@ Browser::Browser(const gfx::Rect& initial_bounds, toolbar_model_(this), type_(type), app_name_(app_name), - idle_task_(new BrowserIdleTask()) { + idle_task_(new BrowserIdleTimer()) { tabstrip_model_.AddObserver(this); CommandLine parsed_command_line; diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h index 67c0938..f500972 100644 --- a/chrome/browser/browser.h +++ b/chrome/browser/browser.h @@ -17,7 +17,7 @@ #include "chrome/common/notification_service.h" #include "chrome/common/pref_member.h" -class BrowserIdleTask; +class BrowserIdleTimer; class BrowserWindow; class DebuggerWindow; class GoButton; @@ -617,7 +617,7 @@ class Browser : public TabStripModelDelegate, scoped_refptr<SelectFileDialog> select_file_dialog_; // The browser idle task helps cleanup unused memory resources when idle. - scoped_ptr<BrowserIdleTask> idle_task_; + scoped_ptr<BrowserIdleTimer> idle_task_; // Keep track of the encoding auto detect pref. BooleanPrefMember encoding_auto_detect_; diff --git a/chrome/browser/download_file.h b/chrome/browser/download_file.h index b995281..f9c6e91 100644 --- a/chrome/browser/download_file.h +++ b/chrome/browser/download_file.h @@ -57,9 +57,12 @@ class GURL; class MessageLoop; class ResourceDispatcherHost; class Task; -class Timer; class URLRequestContext; +namespace base { +class Timer; +} + // DownloadBuffer -------------------------------------------------------------- // This container is created and populated on the io_thread, and passed to the @@ -240,7 +243,7 @@ class DownloadFileManager // Throttle updates to the UI thread. Task* update_task_; - Timer* update_timer_; + base::Timer* update_timer_; // The MessageLoop that the DownloadManagers live on. MessageLoop* ui_loop_; diff --git a/chrome/browser/download_tab_view.h b/chrome/browser/download_tab_view.h index 59eebe5..346a903 100644 --- a/chrome/browser/download_tab_view.h +++ b/chrome/browser/download_tab_view.h @@ -21,7 +21,10 @@ class DownloadTabView; class SkBitmap; class Task; + +namespace base { class Timer; +} class DownloadItemTabView : public ChromeViews::View, public ChromeViews::LinkController { @@ -170,7 +173,7 @@ class DownloadTabView : public ChromeViews::View, OrderedDownloads downloads_; // Progress animations - Timer* progress_timer_; + base::Timer* progress_timer_; Task* progress_task_; // Since this view manages the progress animation timers for all the floating diff --git a/chrome/browser/profile.h b/chrome/browser/profile.h index 282354e..e4057c6 100644 --- a/chrome/browser/profile.h +++ b/chrome/browser/profile.h @@ -29,11 +29,14 @@ class SpellChecker; class TabRestoreService; class TemplateURLFetcher; class TemplateURLModel; -class Timer; class URLRequestContext; class VisitedLinkMaster; class WebDataService; +namespace base { +class Timer; +} + class Profile { public: @@ -340,7 +343,7 @@ class ProfileImpl : public Profile { ProfileControllerSet controllers_; - Timer* create_session_service_timer_; + base::Timer* create_session_service_timer_; CreateSessionServiceTask create_session_service_task_; scoped_ptr<OffTheRecordProfileImpl> off_the_record_profile_; diff --git a/chrome/browser/resource_dispatcher_host.cc b/chrome/browser/resource_dispatcher_host.cc index 4b3c5f0..ae3ef20 100644 --- a/chrome/browser/resource_dispatcher_host.cc +++ b/chrome/browser/resource_dispatcher_host.cc @@ -270,10 +270,7 @@ class ResourceDispatcherHost::DownloadEventHandler save_as_(save_as), buffer_(new DownloadBuffer), rdh_(rdh), - is_paused_(false), - pause_timer_(TimeDelta::FromMilliseconds(kThrottleTimeMs)) { - pause_timer_.set_task( - NewRunnableMethod(this, &DownloadEventHandler::CheckWriteProgress)); + is_paused_(false) { } // Not needed, as this event handler ought to be the final resource. @@ -344,7 +341,7 @@ class ResourceDispatcherHost::DownloadEventHandler // We schedule a pause outside of the read loop if there is too much file // writing work to do. if (buffer_->contents.size() > kLoadsToWrite) - pause_timer_.Start(); + StartPauseTimer(); return true; } @@ -389,7 +386,7 @@ class ResourceDispatcherHost::DownloadEventHandler // We'll come back later and see if it's okay to unpause the request. if (should_pause) - pause_timer_.Start(); + StartPauseTimer(); if (is_paused_ != should_pause) { rdh_->PauseRequest(global_id_.render_process_host_id, @@ -400,6 +397,11 @@ class ResourceDispatcherHost::DownloadEventHandler } private: + void StartPauseTimer() { + pause_timer_.Start(TimeDelta::FromMilliseconds(kThrottleTimeMs), this, + &DownloadEventHandler::CheckWriteProgress); + } + int download_id_; ResourceDispatcherHost::GlobalRequestID global_id_; int render_view_id_; @@ -413,7 +415,7 @@ class ResourceDispatcherHost::DownloadEventHandler DownloadBuffer* buffer_; ResourceDispatcherHost* rdh_; bool is_paused_; - OneShotTimer pause_timer_; + base::OneShotTimer<DownloadEventHandler> pause_timer_; static const int kReadBufSize = 32768; // bytes static const int kLoadsToWrite = 100; // number of data buffers queued @@ -1231,8 +1233,6 @@ class ResourceDispatcherHost::SaveFileEventHandler ResourceDispatcherHost::ResourceDispatcherHost(MessageLoop* io_loop) : ui_loop_(MessageLoop::current()), io_loop_(io_loop), - update_load_states_timer_( - TimeDelta::FromMilliseconds(kUpdateLoadStatesIntervalMsec)), download_file_manager_(new DownloadFileManager(ui_loop_, this)), save_file_manager_(new SaveFileManager(ui_loop_, io_loop, this)), safe_browsing_(new SafeBrowsingService), @@ -1240,8 +1240,6 @@ ResourceDispatcherHost::ResourceDispatcherHost(MessageLoop* io_loop) plugin_service_(PluginService::GetInstance()), method_runner_(this), is_shutdown_(false) { - update_load_states_timer_.set_task(method_runner_.NewRunnableMethod( - &ResourceDispatcherHost::UpdateLoadStates)); } ResourceDispatcherHost::~ResourceDispatcherHost() { @@ -1889,7 +1887,11 @@ void ResourceDispatcherHost::BeginRequestInternal(URLRequest* request, request->Start(); // Make sure we have the load state monitor running - update_load_states_timer_.Start(); + if (!update_load_states_timer_.IsRunning()) { + update_load_states_timer_.Start( + TimeDelta::FromMilliseconds(kUpdateLoadStatesIntervalMsec), + this, &ResourceDispatcherHost::UpdateLoadStates); + } } // This test mirrors the decision that WebKit makes in diff --git a/chrome/browser/resource_dispatcher_host.h b/chrome/browser/resource_dispatcher_host.h index 2205ff6..db94fcd 100644 --- a/chrome/browser/resource_dispatcher_host.h +++ b/chrome/browser/resource_dispatcher_host.h @@ -444,7 +444,7 @@ class ResourceDispatcherHost : public URLRequest::Delegate { // A timer that periodically calls UpdateLoadStates while pending_requests_ // is not empty. - RepeatingTimer update_load_states_timer_; + base::RepeatingTimer<ResourceDispatcherHost> update_load_states_timer_; // We own the download file writing thread and manager scoped_refptr<DownloadFileManager> download_file_manager_; diff --git a/chrome/browser/save_file_manager.h b/chrome/browser/save_file_manager.h index 84397b9..23631e0 100644 --- a/chrome/browser/save_file_manager.h +++ b/chrome/browser/save_file_manager.h @@ -73,7 +73,6 @@ class SavePackage; class MessageLoop; class ResourceDispatcherHost; class Task; -class Timer; class URLRequestContext; class SaveFileManager diff --git a/chrome/browser/session_service.h b/chrome/browser/session_service.h index 3f7548f..9d75707 100644 --- a/chrome/browser/session_service.h +++ b/chrome/browser/session_service.h @@ -24,7 +24,6 @@ class NavigationController; class NavigationEntry; class Profile; class TabContents; -class Timer; class SessionBackend; class SessionCommand; diff --git a/chrome/browser/task_manager.h b/chrome/browser/task_manager.h index f7ab4f4..a84917c 100644 --- a/chrome/browser/task_manager.h +++ b/chrome/browser/task_manager.h @@ -22,10 +22,13 @@ class TaskManager; class TaskManagerContents; class TaskManagerTableModel; class TaskManagerWindow; -class Timer; struct BytesReadParam; +namespace base { +class Timer; +} + namespace ChromeViews { class View; class Window; @@ -260,7 +263,7 @@ 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. - Timer* timer_; + base::Timer* timer_; scoped_ptr<Task> update_task_; MessageLoop* ui_loop_; |