diff options
Diffstat (limited to 'base')
-rw-r--r-- | base/timer.h | 3 | ||||
-rw-r--r-- | base/timer_unittest.cc | 31 |
2 files changed, 34 insertions, 0 deletions
diff --git a/base/timer.h b/base/timer.h index eb00486..706551f 100644 --- a/base/timer.h +++ b/base/timer.h @@ -206,6 +206,9 @@ class RepeatingTimer : public BaseTimer<Receiver, true> {}; // Once created, it is inactive until Reset is called. Once |delay| seconds have // passed since the last call to Reset, the callback is made. Once the callback // has been made, it's inactive until Reset is called again. +// +// If destroyed, the timeout is canceled and will not occur even if already +// inflight. template <class Receiver> class DelayTimer { public: diff --git a/base/timer_unittest.cc b/base/timer_unittest.cc index b48c774..4349245f 100644 --- a/base/timer_unittest.cc +++ b/base/timer_unittest.cc @@ -243,6 +243,31 @@ void RunTest_DelayTimer_Reset(MessageLoop::Type message_loop_type) { ASSERT_TRUE(target.signaled()); } +class DelayTimerFatalTarget { + public: + void Signal() { + ASSERT_TRUE(false); + } +}; + + +void RunTest_DelayTimer_Deleted(MessageLoop::Type message_loop_type) { + MessageLoop loop(message_loop_type); + + DelayTimerFatalTarget target; + + { + base::DelayTimer<DelayTimerFatalTarget> timer( + TimeDelta::FromMilliseconds(50), &target, + &DelayTimerFatalTarget::Signal); + timer.Reset(); + } + + // When the timer is deleted, the DelayTimerFatalTarget should never be + // called. + PlatformThread::Sleep(100); +} + } // namespace //----------------------------------------------------------------------------- @@ -299,6 +324,12 @@ TEST(TimerTest, DelayTimer_Reset) { RunTest_DelayTimer_Reset(MessageLoop::TYPE_IO); } +TEST(TimerTest, DelayTimer_Deleted) { + RunTest_DelayTimer_Deleted(MessageLoop::TYPE_DEFAULT); + RunTest_DelayTimer_Deleted(MessageLoop::TYPE_UI); + RunTest_DelayTimer_Deleted(MessageLoop::TYPE_IO); +} + TEST(TimerTest, MessageLoopShutdown) { // This test is designed to verify that shutdown of the // message loop does not cause crashes if there were pending |