summaryrefslogtreecommitdiffstats
path: root/chrome/common
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/common
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/common')
-rw-r--r--chrome/common/animation.cc33
-rw-r--r--chrome/common/animation.h11
2 files changed, 20 insertions, 24 deletions
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);
};