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

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: fixwindowslink+rebase 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
« no previous file with comments | « base/test/launcher/test_launcher.h ('k') | base/timer/timer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/timer/timer.h
diff --git a/base/timer/timer.h b/base/timer/timer.h
index 1ef58a3ea0b30a23dcd3fdc90a03675abea2fabf..e083bf5a253c3876d1c4a7c119de48afbf32da14 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,18 @@ class BaseTimerMethodPointer : public Timer {
// see bug 148832.
using Timer::Start;
- BaseTimerMethodPointer() : Timer(kIsRepeating, kIsRepeating) {}
+ enum RepeatMode { ONE_SHOT, REPEATING };
+ BaseTimerMethodPointer(RepeatMode mode)
+ : Timer(mode == REPEATING, mode == REPEATING) {}
// 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 +228,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(ONE_SHOT) {}
+};
//-----------------------------------------------------------------------------
// 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(REPEATING) {}
+};
//-----------------------------------------------------------------------------
// A Delay timer is like The Button from Lost. Once started, you have to keep
@@ -247,20 +251,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 {
+class BASE_EXPORT DelayTimer : protected Timer {
public:
- typedef void (Receiver::*ReceiverMethod)();
-
- DelayTimer(const tracked_objects::Location& posted_from,
- TimeDelta delay,
- Receiver* receiver,
- ReceiverMethod method)
- : Timer(posted_from, delay,
+ template <class Receiver>
+ BASE_EXPORT DelayTimer(const tracked_objects::Location& posted_from,
Nico 2015/09/23 00:21:25 Huh, that's really needed? Surprising, given that
danakj 2015/09/23 19:00:32 Ya.. compiler complains both with and without this
+ TimeDelta delay,
+ Receiver* receiver,
+ void (Receiver::*method)())
+ : Timer(posted_from,
+ delay,
base::Bind(method, base::Unretained(receiver)),
false) {}
- void Reset() override { Timer::Reset(); }
+ void Reset() override;
};
} // namespace base
« no previous file with comments | « base/test/launcher/test_launcher.h ('k') | base/timer/timer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698