Chromium Code Reviews| Index: Source/platform/Timer.h |
| diff --git a/Source/platform/Timer.h b/Source/platform/Timer.h |
| index 1f03cf11dc894643c79ec0b2ed0eda911cebf9fb..2ca6cce94d8d4144d9c023f9099896de2cc67624 100644 |
| --- a/Source/platform/Timer.h |
| +++ b/Source/platform/Timer.h |
| @@ -105,8 +105,12 @@ private: |
| friend class TimerHeapReference; |
| }; |
| +template <typename TimerFiredClass> class MockableTimer; |
| + |
| template <typename TimerFiredClass> |
| class Timer : public TimerBase { |
| + friend class MockableTimer<TimerFiredClass>; |
| + |
| public: |
| typedef void (TimerFiredClass::*TimerFiredFunction)(Timer*); |
| @@ -120,6 +124,37 @@ private: |
| TimerFiredFunction m_function; |
| }; |
| +// Just derive from TimerBase and skip the template-fu? |
|
Zeeshan Qureshi
2013/12/13 02:05:58
Deriving from TimerBase might just be cleaner.
Rick Byers
2013/12/13 22:52:25
I like that you don't have to duplicate anything h
|
| +template <typename TimerFiredClass> |
| +class MockableTimer : public Timer<TimerFiredClass> { |
| +public: |
| + typedef typename Timer<TimerFiredClass>::TimerFiredFunction TimerFiredFunction; |
| + |
| + MockableTimer(TimerFiredClass* o, TimerFiredFunction f) |
| + : Timer<TimerFiredClass>(o, f) |
| + , m_suspended(false) |
| + { |
| + } |
| + |
| + bool isSuspended() { return m_suspended; } |
| + |
| + void suspend() { m_suspended = true; } |
|
Rick Byers
2013/12/13 22:52:25
I wonder if we should make these a little scarrier
Zeeshan Qureshi
2014/01/07 19:35:09
Yes!
|
| + |
| + void resume() { m_suspended = false; } |
| + |
| + // Should this only work when timer is suspended? |
|
Zeeshan Qureshi
2013/12/13 02:05:58
Not sure, maybe only allow this when m_suspended?
Rick Byers
2013/12/13 22:52:25
Yeah, probably a good idea to ASSERT(m_suspended)
Zeeshan Qureshi
2014/01/07 19:35:09
Done, it's a little tricky to reason about pending
|
| + void fire() { Timer<TimerFiredClass>::fired(); } |
| + |
| +private: |
| + bool m_suspended; |
| + |
| + virtual void fired() |
| + { |
| + if (!m_suspended) |
| + Timer<TimerFiredClass>::fired(); |
| + } |
| +}; |
| + |
| inline bool TimerBase::isActive() const |
| { |
| ASSERT(m_thread == currentThread()); |