summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authordarin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-28 20:50:12 +0000
committerdarin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-28 20:50:12 +0000
commitaeab57ea8560065d6c513fcd46bb43e1bfbfd7a6 (patch)
treea63f2d36e86361d5c27122a6d6ef4098b755d7d9 /chrome
parente115558691eb08608fad56bb32f40265fdfa4ac5 (diff)
downloadchromium_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')
-rw-r--r--chrome/browser/browser.cc10
-rw-r--r--chrome/browser/browser.h4
-rw-r--r--chrome/browser/download_file.h7
-rw-r--r--chrome/browser/download_tab_view.h5
-rw-r--r--chrome/browser/profile.h7
-rw-r--r--chrome/browser/resource_dispatcher_host.cc26
-rw-r--r--chrome/browser/resource_dispatcher_host.h2
-rw-r--r--chrome/browser/save_file_manager.h1
-rw-r--r--chrome/browser/session_service.h1
-rw-r--r--chrome/browser/task_manager.h7
-rw-r--r--chrome/common/animation.cc33
-rw-r--r--chrome/common/animation.h11
-rw-r--r--chrome/renderer/render_view.cc7
-rw-r--r--chrome/renderer/render_view.h2
-rw-r--r--chrome/views/throbber.h5
15 files changed, 69 insertions, 59 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_;
diff --git a/chrome/common/animation.cc b/chrome/common/animation.cc
index b4b4ba6..d407ccc 100644
--- a/chrome/common/animation.cc
+++ b/chrome/common/animation.cc
@@ -14,9 +14,7 @@ Animation::Animation(int frame_rate,
iteration_count_(0),
current_iteration_(0),
state_(0.0),
- delegate_(delegate),
- timer_(TimeDelta::FromMilliseconds(timer_interval_)) {
- timer_.set_unowned_task(this);
+ delegate_(delegate) {
}
Animation::Animation(int duration,
@@ -29,9 +27,7 @@ Animation::Animation(int duration,
iteration_count_(0),
current_iteration_(0),
state_(0.0),
- delegate_(delegate),
- timer_(TimeDelta::FromMilliseconds(timer_interval_)) {
- timer_.set_unowned_task(this);
+ delegate_(delegate) {
SetDuration(duration);
}
@@ -50,7 +46,8 @@ double Animation::GetCurrentValue() const {
void Animation::Start() {
if (!animating_) {
- timer_.Start();
+ timer_.Start(TimeDelta::FromMilliseconds(timer_interval_), this,
+ &Animation::Run);
animating_ = true;
if (delegate_)
@@ -87,6 +84,17 @@ bool Animation::IsAnimating() {
return animating_;
}
+void Animation::SetDuration(int duration) {
+ duration_ = duration;
+ if (duration_ < timer_interval_)
+ duration_ = timer_interval_;
+ iteration_count_ = duration_ / timer_interval_;
+
+ // Changing the number of iterations forces us to reset the
+ // animation to the first iteration.
+ current_iteration_ = 0;
+}
+
void Animation::Run() {
state_ = static_cast<double>(++current_iteration_) / iteration_count_;
@@ -101,17 +109,6 @@ void Animation::Run() {
Stop();
}
-void Animation::SetDuration(int duration) {
- duration_ = duration;
- if (duration_ < timer_interval_)
- duration_ = timer_interval_;
- iteration_count_ = duration_ / timer_interval_;
-
- // Changing the number of iterations forces us to reset the
- // animation to the first iteration.
- current_iteration_ = 0;
-}
-
int Animation::CalculateInterval(int frame_rate) {
int timer_interval = 1000 / frame_rate;
if (timer_interval < 10)
diff --git a/chrome/common/animation.h b/chrome/common/animation.h
index 3505fe6..657512a 100644
--- a/chrome/common/animation.h
+++ b/chrome/common/animation.h
@@ -6,7 +6,6 @@
#ifndef CHROME_COMMON_ANIMATION_H__
#define CHROME_COMMON_ANIMATION_H__
-#include "base/task.h"
#include "base/timer.h"
class Animation;
@@ -48,7 +47,7 @@ class AnimationDelegate {
// initialization specific to the subclass, and then call |Start|. The
// animation uses the current thread's message loop.
//
-class Animation : public Task {
+class Animation {
public:
// Initializes everything except the duration.
//
@@ -86,14 +85,14 @@ class Animation : public Task {
// Return whether this animation is animating.
bool IsAnimating();
- // The animation's Task::Run implementation
- virtual void Run();
-
// Changes the length of the animation. This resets the current
// state of the animation to the beginning.
void SetDuration(int duration);
protected:
+ // Called when the animation's timer expires.
+ void Run();
+
// Calculates the timer interval from the constructor list.
int CalculateInterval(int frame_rate);
@@ -111,7 +110,7 @@ class Animation : public Task {
AnimationDelegate* delegate_;
- RepeatingTimer timer_;
+ base::RepeatingTimer<Animation> timer_;
DISALLOW_EVIL_CONSTRUCTORS(Animation);
};
diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc
index af11413..8d91e58 100644
--- a/chrome/renderer/render_view.cc
+++ b/chrome/renderer/render_view.cc
@@ -140,7 +140,6 @@ RenderView::RenderView()
last_page_id_sent_to_browser_(-1),
last_indexed_page_id_(-1),
method_factory_(this),
- nav_state_sync_timer_(kDelayForNavigationSync),
opened_by_user_gesture_(true),
enable_dom_automation_(false),
enable_dom_ui_bindings_(false),
@@ -153,8 +152,6 @@ RenderView::RenderView()
disable_popup_blocking_(false),
has_unload_listener_(false) {
resource_dispatcher_ = new ResourceDispatcher(this);
- nav_state_sync_timer_.set_task(
- method_factory_.NewRunnableMethod(&RenderView::SyncNavigationState));
#ifdef CHROME_PERSONALIZATION
personalization_ = Personalization::CreateRendererPersonalization();
#endif
@@ -2190,7 +2187,9 @@ int RenderView::GetHistoryForwardListCount() {
}
void RenderView::OnNavStateChanged(WebView* webview) {
- nav_state_sync_timer_.Start();
+ if (!nav_state_sync_timer_.IsRunning())
+ nav_state_sync_timer_.Start(kDelayForNavigationSync, this,
+ &RenderView::SyncNavigationState);
}
void RenderView::SetTooltipText(WebView* webview,
diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h
index 6ac8f0c..f4afb8f 100644
--- a/chrome/renderer/render_view.h
+++ b/chrome/renderer/render_view.h
@@ -574,7 +574,7 @@ class RenderView : public RenderWidget, public WebViewDelegate,
ScopedRunnableMethodFactory<RenderView> method_factory_;
// Timer used to delay the updating of nav state (see SyncNavigationState).
- OneShotTimer nav_state_sync_timer_;
+ base::OneShotTimer<RenderView> nav_state_sync_timer_;
typedef std::vector<WebPluginDelegateProxy*> PluginDelegateList;
PluginDelegateList plugin_delegates_;
diff --git a/chrome/views/throbber.h b/chrome/views/throbber.h
index d7e298c..812cae1 100644
--- a/chrome/views/throbber.h
+++ b/chrome/views/throbber.h
@@ -12,7 +12,10 @@
#include "chrome/views/view.h"
class SkBitmap;
+
+namespace base {
class Timer;
+}
namespace ChromeViews {
@@ -49,7 +52,7 @@ class Throbber : public ChromeViews::View,
DWORD last_time_recorded_;
SkBitmap* frames_;
int frame_time_ms_;
- Timer* timer_;
+ base::Timer* timer_;
DISALLOW_EVIL_CONSTRUCTORS(Throbber);
};