Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Unified Diff: base/timer/timer.h

Issue 1355063004: Template methods on Timer classes instead of the classes themselves. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: timer: . Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/timer/timer.h
diff --git a/base/timer/timer.h b/base/timer/timer.h
index 1ef58a3ea0b30a23dcd3fdc90a03675abea2fabf..cfdda67f519cb5a5a827d90721c5538c4b5ef9ac 100644
--- a/base/timer/timer.h
+++ b/base/timer/timer.h
@@ -29,7 +29,7 @@
// // This method is called every second to do stuff.
// ...
// }
-// base::RepeatingTimer<MyClass> timer_;
+// base::RepeatingTimer timer_;
// };
//
// Both OneShotTimer and RepeatingTimer also support a Reset method, which
@@ -200,11 +200,8 @@ class BASE_EXPORT Timer {
//-----------------------------------------------------------------------------
// This class is an implementation detail of OneShotTimer and RepeatingTimer.
// Please do not use this class directly.
-template <class Receiver, bool kIsRepeating>
class BaseTimerMethodPointer : public Timer {
public:
- typedef void (Receiver::*ReceiverMethod)();
-
// This is here to work around the fact that Timer::Start is "hidden" by the
// Start definition below, rather than being overloaded.
// TODO(tim): We should remove uses of BaseTimerMethodPointer::Start below
@@ -212,15 +209,16 @@ class BaseTimerMethodPointer : public Timer {
// see bug 148832.
using Timer::Start;
- BaseTimerMethodPointer() : Timer(kIsRepeating, kIsRepeating) {}
+ BaseTimerMethodPointer(bool repeats) : Timer(repeats, repeats) {}
Nico 2015/09/22 01:16:22 nit: enum RepeatMode { kOneShot, kRepeating };
danakj 2015/09/22 18:31:14 Done.
// Start the timer to run at the given |delay| from now. If the timer is
// already running, it will be replaced to call a task formed from
// |reviewer->*method|.
- virtual void Start(const tracked_objects::Location& posted_from,
- TimeDelta delay,
- Receiver* receiver,
- ReceiverMethod method) {
+ template <class Receiver>
+ void Start(const tracked_objects::Location& posted_from,
+ TimeDelta delay,
+ Receiver* receiver,
+ void (Receiver::*method)()) {
Timer::Start(posted_from, delay,
base::Bind(method, base::Unretained(receiver)));
}
@@ -228,13 +226,17 @@ class BaseTimerMethodPointer : public Timer {
//-----------------------------------------------------------------------------
// A simple, one-shot timer. See usage notes at the top of the file.
-template <class Receiver>
-class OneShotTimer : public BaseTimerMethodPointer<Receiver, false> {};
+class OneShotTimer : public BaseTimerMethodPointer {
+ public:
+ OneShotTimer() : BaseTimerMethodPointer(false) {}
+};
//-----------------------------------------------------------------------------
// A simple, repeating timer. See usage notes at the top of the file.
-template <class Receiver>
-class RepeatingTimer : public BaseTimerMethodPointer<Receiver, true> {};
+class RepeatingTimer : public BaseTimerMethodPointer {
+ public:
+ RepeatingTimer() : BaseTimerMethodPointer(true) {}
+};
//-----------------------------------------------------------------------------
// A Delay timer is like The Button from Lost. Once started, you have to keep
@@ -247,20 +249,19 @@ class RepeatingTimer : public BaseTimerMethodPointer<Receiver, true> {};
//
// If destroyed, the timeout is canceled and will not occur even if already
// inflight.
-template <class Receiver>
class DelayTimer : protected Timer {
public:
- typedef void (Receiver::*ReceiverMethod)();
-
+ template <class Receiver>
DelayTimer(const tracked_objects::Location& posted_from,
TimeDelta delay,
Receiver* receiver,
- ReceiverMethod method)
- : Timer(posted_from, delay,
+ void (Receiver::*method)())
+ : Timer(posted_from,
+ delay,
base::Bind(method, base::Unretained(receiver)),
false) {}
- void Reset() override { Timer::Reset(); }
+ void Reset() override;
};
} // namespace base

Powered by Google App Engine
This is Rietveld 408576698