Commit d93bb086 authored by tzik's avatar tzik Committed by Commit Bot

Rename base::Timer to base::TimerBase

This CL updates all remaining user of base::Timer to use its subclasses,
and renames base::Timer to base::TimerBase to ensure there's no user
anymore.

Bug: 850247
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:ios-simulator-full-configs;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:linux_vr;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: I73d70cbbe338e17f5d7de34acd1c961ce05c4305
Reviewed-on: https://chromium-review.googlesource.com/1124200
Commit-Queue: Taiju Tsuiki <tzik@chromium.org>
Reviewed-by: default avatarGabriel Charette <gab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#576447}
parent 08752cc7
...@@ -308,7 +308,7 @@ void ImportantFileWriter::ClearPendingWrite() { ...@@ -308,7 +308,7 @@ void ImportantFileWriter::ClearPendingWrite() {
serializer_ = nullptr; serializer_ = nullptr;
} }
void ImportantFileWriter::SetTimerForTesting(Timer* timer_override) { void ImportantFileWriter::SetTimerForTesting(OneShotTimer* timer_override) {
timer_override_ = timer_override; timer_override_ = timer_override;
} }
......
...@@ -114,14 +114,13 @@ class BASE_EXPORT ImportantFileWriter { ...@@ -114,14 +114,13 @@ class BASE_EXPORT ImportantFileWriter {
} }
// Overrides the timer to use for scheduling writes with |timer_override|. // Overrides the timer to use for scheduling writes with |timer_override|.
void SetTimerForTesting(Timer* timer_override); void SetTimerForTesting(OneShotTimer* timer_override);
private: private:
const Timer& timer() const { const OneShotTimer& timer() const {
return timer_override_ ? const_cast<const Timer&>(*timer_override_) return timer_override_ ? *timer_override_ : timer_;
: timer_;
} }
Timer& timer() { return timer_override_ ? *timer_override_ : timer_; } OneShotTimer& timer() { return timer_override_ ? *timer_override_ : timer_; }
void ClearPendingWrite(); void ClearPendingWrite();
...@@ -139,7 +138,7 @@ class BASE_EXPORT ImportantFileWriter { ...@@ -139,7 +138,7 @@ class BASE_EXPORT ImportantFileWriter {
OneShotTimer timer_; OneShotTimer timer_;
// An override for |timer_| used for testing. // An override for |timer_| used for testing.
Timer* timer_override_ = nullptr; OneShotTimer* timer_override_ = nullptr;
// Serializer which will provide the data to be saved. // Serializer which will provide the data to be saved.
DataSerializer* serializer_; DataSerializer* serializer_;
......
...@@ -12,7 +12,7 @@ namespace base { ...@@ -12,7 +12,7 @@ namespace base {
class TestSimpleTaskRunner; class TestSimpleTaskRunner;
// A mock implementation of base::Timer which requires being explicitly // A mock implementation of base::OneShotTimer which requires being explicitly
// Fire()'d. // Fire()'d.
// Prefer using ScopedTaskEnvironment::MOCK_TIME + FastForward*() to this when // Prefer using ScopedTaskEnvironment::MOCK_TIME + FastForward*() to this when
// possible. // possible.
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "base/time/tick_clock.h" #include "base/time/tick_clock.h"
namespace base { namespace base {
namespace internal {
// BaseTimerTaskInternal is a simple delegate for scheduling a callback to Timer // BaseTimerTaskInternal is a simple delegate for scheduling a callback to Timer
// on the current sequence. It also handles the following edge cases: // on the current sequence. It also handles the following edge cases:
...@@ -23,9 +24,7 @@ namespace base { ...@@ -23,9 +24,7 @@ namespace base {
// - abandoned (orphaned) by Timer. // - abandoned (orphaned) by Timer.
class BaseTimerTaskInternal { class BaseTimerTaskInternal {
public: public:
explicit BaseTimerTaskInternal(Timer* timer) explicit BaseTimerTaskInternal(TimerBase* timer) : timer_(timer) {}
: timer_(timer) {
}
~BaseTimerTaskInternal() { ~BaseTimerTaskInternal() {
// This task may be getting cleared because the task runner has been // This task may be getting cleared because the task runner has been
...@@ -45,7 +44,7 @@ class BaseTimerTaskInternal { ...@@ -45,7 +44,7 @@ class BaseTimerTaskInternal {
// Although Timer should not call back into |this|, let's clear |timer_| // Although Timer should not call back into |this|, let's clear |timer_|
// first to be pedantic. // first to be pedantic.
Timer* timer = timer_; TimerBase* timer = timer_;
timer_ = nullptr; timer_ = nullptr;
timer->RunScheduledTask(); timer->RunScheduledTask();
} }
...@@ -54,17 +53,17 @@ class BaseTimerTaskInternal { ...@@ -54,17 +53,17 @@ class BaseTimerTaskInternal {
void Abandon() { timer_ = nullptr; } void Abandon() { timer_ = nullptr; }
private: private:
Timer* timer_; TimerBase* timer_;
DISALLOW_COPY_AND_ASSIGN(BaseTimerTaskInternal); DISALLOW_COPY_AND_ASSIGN(BaseTimerTaskInternal);
}; };
Timer::Timer(bool retain_user_task, bool is_repeating) TimerBase::TimerBase(bool retain_user_task, bool is_repeating)
: Timer(retain_user_task, is_repeating, nullptr) {} : TimerBase(retain_user_task, is_repeating, nullptr) {}
Timer::Timer(bool retain_user_task, TimerBase::TimerBase(bool retain_user_task,
bool is_repeating, bool is_repeating,
const TickClock* tick_clock) const TickClock* tick_clock)
: scheduled_task_(nullptr), : scheduled_task_(nullptr),
is_repeating_(is_repeating), is_repeating_(is_repeating),
retain_user_task_(retain_user_task), retain_user_task_(retain_user_task),
...@@ -77,17 +76,17 @@ Timer::Timer(bool retain_user_task, ...@@ -77,17 +76,17 @@ Timer::Timer(bool retain_user_task,
origin_sequence_checker_.DetachFromSequence(); origin_sequence_checker_.DetachFromSequence();
} }
Timer::Timer(const Location& posted_from, TimerBase::TimerBase(const Location& posted_from,
TimeDelta delay, TimeDelta delay,
const base::Closure& user_task, const base::Closure& user_task,
bool is_repeating) bool is_repeating)
: Timer(posted_from, delay, user_task, is_repeating, nullptr) {} : TimerBase(posted_from, delay, user_task, is_repeating, nullptr) {}
Timer::Timer(const Location& posted_from, TimerBase::TimerBase(const Location& posted_from,
TimeDelta delay, TimeDelta delay,
const base::Closure& user_task, const base::Closure& user_task,
bool is_repeating, bool is_repeating,
const TickClock* tick_clock) const TickClock* tick_clock)
: scheduled_task_(nullptr), : scheduled_task_(nullptr),
posted_from_(posted_from), posted_from_(posted_from),
delay_(delay), delay_(delay),
...@@ -100,22 +99,22 @@ Timer::Timer(const Location& posted_from, ...@@ -100,22 +99,22 @@ Timer::Timer(const Location& posted_from,
origin_sequence_checker_.DetachFromSequence(); origin_sequence_checker_.DetachFromSequence();
} }
Timer::~Timer() { TimerBase::~TimerBase() {
DCHECK(origin_sequence_checker_.CalledOnValidSequence()); DCHECK(origin_sequence_checker_.CalledOnValidSequence());
AbandonAndStop(); AbandonAndStop();
} }
bool Timer::IsRunning() const { bool TimerBase::IsRunning() const {
DCHECK(origin_sequence_checker_.CalledOnValidSequence()); DCHECK(origin_sequence_checker_.CalledOnValidSequence());
return is_running_; return is_running_;
} }
TimeDelta Timer::GetCurrentDelay() const { TimeDelta TimerBase::GetCurrentDelay() const {
DCHECK(origin_sequence_checker_.CalledOnValidSequence()); DCHECK(origin_sequence_checker_.CalledOnValidSequence());
return delay_; return delay_;
} }
void Timer::SetTaskRunner(scoped_refptr<SequencedTaskRunner> task_runner) { void TimerBase::SetTaskRunner(scoped_refptr<SequencedTaskRunner> task_runner) {
// Do not allow changing the task runner when the Timer is running. // Do not allow changing the task runner when the Timer is running.
// Don't check for |origin_sequence_checker_.CalledOnValidSequence()| here to // Don't check for |origin_sequence_checker_.CalledOnValidSequence()| here to
// allow the use case of constructing the Timer and immediatetly invoking // allow the use case of constructing the Timer and immediatetly invoking
...@@ -127,9 +126,9 @@ void Timer::SetTaskRunner(scoped_refptr<SequencedTaskRunner> task_runner) { ...@@ -127,9 +126,9 @@ void Timer::SetTaskRunner(scoped_refptr<SequencedTaskRunner> task_runner) {
task_runner_.swap(task_runner); task_runner_.swap(task_runner);
} }
void Timer::Start(const Location& posted_from, void TimerBase::Start(const Location& posted_from,
TimeDelta delay, TimeDelta delay,
const base::Closure& user_task) { const base::Closure& user_task) {
DCHECK(origin_sequence_checker_.CalledOnValidSequence()); DCHECK(origin_sequence_checker_.CalledOnValidSequence());
posted_from_ = posted_from; posted_from_ = posted_from;
...@@ -139,7 +138,7 @@ void Timer::Start(const Location& posted_from, ...@@ -139,7 +138,7 @@ void Timer::Start(const Location& posted_from,
Reset(); Reset();
} }
void Timer::Stop() { void TimerBase::Stop() {
// TODO(gab): Enable this when it's no longer called racily from // TODO(gab): Enable this when it's no longer called racily from
// RunScheduledTask(): https://crbug.com/587199. // RunScheduledTask(): https://crbug.com/587199.
// DCHECK(origin_sequence_checker_.CalledOnValidSequence()); // DCHECK(origin_sequence_checker_.CalledOnValidSequence());
...@@ -155,7 +154,7 @@ void Timer::Stop() { ...@@ -155,7 +154,7 @@ void Timer::Stop() {
// |user_task_|. // |user_task_|.
} }
void Timer::Reset() { void TimerBase::Reset() {
DCHECK(origin_sequence_checker_.CalledOnValidSequence()); DCHECK(origin_sequence_checker_.CalledOnValidSequence());
DCHECK(!user_task_.is_null()); DCHECK(!user_task_.is_null());
...@@ -183,14 +182,14 @@ void Timer::Reset() { ...@@ -183,14 +182,14 @@ void Timer::Reset() {
PostNewScheduledTask(delay_); PostNewScheduledTask(delay_);
} }
TimeTicks Timer::Now() const { TimeTicks TimerBase::Now() const {
// TODO(gab): Enable this when it's no longer called racily from // TODO(gab): Enable this when it's no longer called racily from
// RunScheduledTask(): https://crbug.com/587199. // RunScheduledTask(): https://crbug.com/587199.
// DCHECK(origin_sequence_checker_.CalledOnValidSequence()); // DCHECK(origin_sequence_checker_.CalledOnValidSequence());
return tick_clock_ ? tick_clock_->NowTicks() : TimeTicks::Now(); return tick_clock_ ? tick_clock_->NowTicks() : TimeTicks::Now();
} }
void Timer::PostNewScheduledTask(TimeDelta delay) { void TimerBase::PostNewScheduledTask(TimeDelta delay) {
// TODO(gab): Enable this when it's no longer called racily from // TODO(gab): Enable this when it's no longer called racily from
// RunScheduledTask(): https://crbug.com/587199. // RunScheduledTask(): https://crbug.com/587199.
// DCHECK(origin_sequence_checker_.CalledOnValidSequence()); // DCHECK(origin_sequence_checker_.CalledOnValidSequence());
...@@ -214,11 +213,11 @@ void Timer::PostNewScheduledTask(TimeDelta delay) { ...@@ -214,11 +213,11 @@ void Timer::PostNewScheduledTask(TimeDelta delay) {
} }
} }
scoped_refptr<SequencedTaskRunner> Timer::GetTaskRunner() { scoped_refptr<SequencedTaskRunner> TimerBase::GetTaskRunner() {
return task_runner_.get() ? task_runner_ : SequencedTaskRunnerHandle::Get(); return task_runner_.get() ? task_runner_ : SequencedTaskRunnerHandle::Get();
} }
void Timer::AbandonScheduledTask() { void TimerBase::AbandonScheduledTask() {
// TODO(gab): Enable this when it's no longer called racily from // TODO(gab): Enable this when it's no longer called racily from
// RunScheduledTask() -> Stop(): https://crbug.com/587199. // RunScheduledTask() -> Stop(): https://crbug.com/587199.
// DCHECK(origin_sequence_checker_.CalledOnValidSequence()); // DCHECK(origin_sequence_checker_.CalledOnValidSequence());
...@@ -228,7 +227,7 @@ void Timer::AbandonScheduledTask() { ...@@ -228,7 +227,7 @@ void Timer::AbandonScheduledTask() {
} }
} }
void Timer::RunScheduledTask() { void TimerBase::RunScheduledTask() {
// TODO(gab): Enable this when it's no longer called racily: // TODO(gab): Enable this when it's no longer called racily:
// https://crbug.com/587199. // https://crbug.com/587199.
// DCHECK(origin_sequence_checker_.CalledOnValidSequence()); // DCHECK(origin_sequence_checker_.CalledOnValidSequence());
...@@ -265,6 +264,8 @@ void Timer::RunScheduledTask() { ...@@ -265,6 +264,8 @@ void Timer::RunScheduledTask() {
// No more member accesses here: |this| could be deleted at this point. // No more member accesses here: |this| could be deleted at this point.
} }
} // namespace internal
void OneShotTimer::FireNow() { void OneShotTimer::FireNow() {
DCHECK(origin_sequence_checker_.CalledOnValidSequence()); DCHECK(origin_sequence_checker_.CalledOnValidSequence());
DCHECK(!task_runner_) << "FireNow() is incompatible with SetTaskRunner()"; DCHECK(!task_runner_) << "FireNow() is incompatible with SetTaskRunner()";
......
...@@ -2,16 +2,20 @@ ...@@ -2,16 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// OneShotTimer and RepeatingTimer provide a simple timer API. As the names // OneShotTimer, RepeatingTimer and RetainingOneShotTimer provide a simple timer
// suggest, OneShotTimer calls you back once after a time delay expires. // API. As the names suggest, OneShotTimer calls you back once after a time
// delay expires.
// RepeatingTimer on the other hand calls you back periodically with the // RepeatingTimer on the other hand calls you back periodically with the
// prescribed time interval. // prescribed time interval.
// RetainingOneShotTimer doesn't repeat the task itself like OneShotTimer, but
// retains the given task after the time out. You can restart it with Reset
// again without giving new task to Start.
// //
// OneShotTimer and RepeatingTimer both cancel the timer when they go out of // All of OneShotTimer, RepeatingTimer and RetainingOneShotTimer cancel the
// scope, which makes it easy to ensure that you do not get called when your // timer when they go out of scope, which makes it easy to ensure that you do
// object has gone out of scope. Just instantiate a OneShotTimer or // not get called when your object has gone out of scope. Just instantiate a
// RepeatingTimer as a member variable of the class for which you wish to // timer as a member variable of the class for which you wish to receive timer
// receive timer events. // events.
// //
// Sample RepeatingTimer usage: // Sample RepeatingTimer usage:
// //
...@@ -32,12 +36,11 @@ ...@@ -32,12 +36,11 @@
// base::RepeatingTimer timer_; // base::RepeatingTimer timer_;
// }; // };
// //
// Both OneShotTimer and RepeatingTimer also support a Reset method, which // Timers also support a Reset method, which allows you to easily defer the
// allows you to easily defer the timer event until the timer delay passes once // timer event until the timer delay passes once again. So, in the above
// again. So, in the above example, if 0.5 seconds have already passed, // example, if 0.5 seconds have already passed, calling Reset on |timer_|
// calling Reset on |timer_| would postpone DoStuff by another 1 second. In // would postpone DoStuff by another 1 second. In other words, Reset is
// other words, Reset is shorthand for calling Stop and then Start again with // shorthand for calling Stop and then Start again with the same arguments.
// the same arguments.
// //
// These APIs are not thread safe. All methods must be called from the same // These APIs are not thread safe. All methods must be called from the same
// sequence (not necessarily the construction sequence), except for the // sequence (not necessarily the construction sequence), except for the
...@@ -75,35 +78,42 @@ ...@@ -75,35 +78,42 @@
namespace base { namespace base {
class BaseTimerTaskInternal;
class TickClock; class TickClock;
namespace internal {
class BaseTimerTaskInternal;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// This class wraps TaskRunner::PostDelayedTask to manage delayed and repeating // This class wraps TaskRunner::PostDelayedTask to manage delayed and repeating
// tasks. See meta comment above for thread-safety requirements. // tasks. See meta comment above for thread-safety requirements.
// Do not use this class directly. Use one of OneShotTimer, RepeatingTimer or
// RetainingOneShotTimer.
// //
class BASE_EXPORT Timer { class BASE_EXPORT TimerBase {
public: public:
// Construct a timer in repeating or one-shot mode. Start must be called later // Construct a timer in repeating or one-shot mode. Start must be called later
// to set task info. |retain_user_task| determines whether the user_task is // to set task info. |retain_user_task| determines whether the user_task is
// retained or reset when it runs or stops. If |tick_clock| is provided, it is // retained or reset when it runs or stops. If |tick_clock| is provided, it is
// used instead of TimeTicks::Now() to get TimeTicks when scheduling tasks. // used instead of TimeTicks::Now() to get TimeTicks when scheduling tasks.
Timer(bool retain_user_task, bool is_repeating); TimerBase(bool retain_user_task, bool is_repeating);
Timer(bool retain_user_task, bool is_repeating, const TickClock* tick_clock); TimerBase(bool retain_user_task,
bool is_repeating,
const TickClock* tick_clock);
// Construct a timer with retained task info. If |tick_clock| is provided, it // Construct a timer with retained task info. If |tick_clock| is provided, it
// is used instead of TimeTicks::Now() to get TimeTicks when scheduling tasks. // is used instead of TimeTicks::Now() to get TimeTicks when scheduling tasks.
Timer(const Location& posted_from, TimerBase(const Location& posted_from,
TimeDelta delay, TimeDelta delay,
const base::Closure& user_task, const base::Closure& user_task,
bool is_repeating); bool is_repeating);
Timer(const Location& posted_from, TimerBase(const Location& posted_from,
TimeDelta delay, TimeDelta delay,
const base::Closure& user_task, const base::Closure& user_task,
bool is_repeating, bool is_repeating,
const TickClock* tick_clock); const TickClock* tick_clock);
virtual ~Timer(); virtual ~TimerBase();
// Returns true if the timer is running (i.e., not stopped). // Returns true if the timer is running (i.e., not stopped).
bool IsRunning() const; bool IsRunning() const;
...@@ -231,16 +241,18 @@ class BASE_EXPORT Timer { ...@@ -231,16 +241,18 @@ class BASE_EXPORT Timer {
// If true, |user_task_| is scheduled to run sometime in the future. // If true, |user_task_| is scheduled to run sometime in the future.
bool is_running_; bool is_running_;
DISALLOW_COPY_AND_ASSIGN(Timer); DISALLOW_COPY_AND_ASSIGN(TimerBase);
}; };
} // namespace internal
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// A simple, one-shot timer. See usage notes at the top of the file. // A simple, one-shot timer. See usage notes at the top of the file.
class BASE_EXPORT OneShotTimer : public Timer { class BASE_EXPORT OneShotTimer : public internal::TimerBase {
public: public:
OneShotTimer() : OneShotTimer(nullptr) {} OneShotTimer() : OneShotTimer(nullptr) {}
explicit OneShotTimer(const TickClock* tick_clock) explicit OneShotTimer(const TickClock* tick_clock)
: Timer(false, false, tick_clock) {} : internal::TimerBase(false, false, tick_clock) {}
// Run the scheduled task immediately, and stop the timer. The timer needs to // Run the scheduled task immediately, and stop the timer. The timer needs to
// be running. // be running.
...@@ -249,41 +261,49 @@ class BASE_EXPORT OneShotTimer : public Timer { ...@@ -249,41 +261,49 @@ class BASE_EXPORT OneShotTimer : public Timer {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// A simple, repeating timer. See usage notes at the top of the file. // A simple, repeating timer. See usage notes at the top of the file.
class RepeatingTimer : public Timer { class RepeatingTimer : public internal::TimerBase {
public: public:
RepeatingTimer() : RepeatingTimer(nullptr) {} RepeatingTimer() : RepeatingTimer(nullptr) {}
explicit RepeatingTimer(const TickClock* tick_clock) explicit RepeatingTimer(const TickClock* tick_clock)
: Timer(true, true, tick_clock) {} : internal::TimerBase(true, true, tick_clock) {}
RepeatingTimer(const Location& posted_from, RepeatingTimer(const Location& posted_from,
TimeDelta delay, TimeDelta delay,
RepeatingClosure user_task) RepeatingClosure user_task)
: Timer(posted_from, delay, std::move(user_task), true) {} : internal::TimerBase(posted_from, delay, std::move(user_task), true) {}
RepeatingTimer(const Location& posted_from, RepeatingTimer(const Location& posted_from,
TimeDelta delay, TimeDelta delay,
RepeatingClosure user_task, RepeatingClosure user_task,
const TickClock* tick_clock) const TickClock* tick_clock)
: Timer(posted_from, delay, std::move(user_task), true, tick_clock) {} : internal::TimerBase(posted_from,
delay,
std::move(user_task),
true,
tick_clock) {}
}; };
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// A simple, one-shot timer with the retained user task. See usage notes at the // A simple, one-shot timer with the retained user task. See usage notes at the
// top of the file. // top of the file.
class RetainingOneShotTimer : public Timer { class RetainingOneShotTimer : public internal::TimerBase {
public: public:
RetainingOneShotTimer() : RetainingOneShotTimer(nullptr) {} RetainingOneShotTimer() : RetainingOneShotTimer(nullptr) {}
explicit RetainingOneShotTimer(const TickClock* tick_clock) explicit RetainingOneShotTimer(const TickClock* tick_clock)
: Timer(true, false, tick_clock) {} : internal::TimerBase(true, false, tick_clock) {}
RetainingOneShotTimer(const Location& posted_from, RetainingOneShotTimer(const Location& posted_from,
TimeDelta delay, TimeDelta delay,
RepeatingClosure user_task) RepeatingClosure user_task)
: Timer(posted_from, delay, std::move(user_task), false) {} : internal::TimerBase(posted_from, delay, std::move(user_task), false) {}
RetainingOneShotTimer(const Location& posted_from, RetainingOneShotTimer(const Location& posted_from,
TimeDelta delay, TimeDelta delay,
RepeatingClosure user_task, RepeatingClosure user_task,
const TickClock* tick_clock) const TickClock* tick_clock)
: Timer(posted_from, delay, std::move(user_task), false, tick_clock) {} : internal::TimerBase(posted_from,
delay,
std::move(user_task),
false,
tick_clock) {}
}; };
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
......
...@@ -603,7 +603,7 @@ void TimerTestCallback() { ...@@ -603,7 +603,7 @@ void TimerTestCallback() {
TEST(TimerTest, NonRepeatIsRunning) { TEST(TimerTest, NonRepeatIsRunning) {
{ {
MessageLoop loop; MessageLoop loop;
Timer timer(false, false); OneShotTimer timer;
EXPECT_FALSE(timer.IsRunning()); EXPECT_FALSE(timer.IsRunning());
timer.Start(FROM_HERE, TimeDelta::FromDays(1), Bind(&TimerTestCallback)); timer.Start(FROM_HERE, TimeDelta::FromDays(1), Bind(&TimerTestCallback));
EXPECT_TRUE(timer.IsRunning()); EXPECT_TRUE(timer.IsRunning());
...@@ -613,7 +613,7 @@ TEST(TimerTest, NonRepeatIsRunning) { ...@@ -613,7 +613,7 @@ TEST(TimerTest, NonRepeatIsRunning) {
} }
{ {
Timer timer(true, false); RetainingOneShotTimer timer;
MessageLoop loop; MessageLoop loop;
EXPECT_FALSE(timer.IsRunning()); EXPECT_FALSE(timer.IsRunning());
timer.Start(FROM_HERE, TimeDelta::FromDays(1), Bind(&TimerTestCallback)); timer.Start(FROM_HERE, TimeDelta::FromDays(1), Bind(&TimerTestCallback));
...@@ -627,7 +627,7 @@ TEST(TimerTest, NonRepeatIsRunning) { ...@@ -627,7 +627,7 @@ TEST(TimerTest, NonRepeatIsRunning) {
} }
TEST(TimerTest, NonRepeatMessageLoopDeath) { TEST(TimerTest, NonRepeatMessageLoopDeath) {
Timer timer(false, false); OneShotTimer timer;
{ {
MessageLoop loop; MessageLoop loop;
EXPECT_FALSE(timer.IsRunning()); EXPECT_FALSE(timer.IsRunning());
...@@ -640,8 +640,8 @@ TEST(TimerTest, NonRepeatMessageLoopDeath) { ...@@ -640,8 +640,8 @@ TEST(TimerTest, NonRepeatMessageLoopDeath) {
TEST(TimerTest, RetainRepeatIsRunning) { TEST(TimerTest, RetainRepeatIsRunning) {
MessageLoop loop; MessageLoop loop;
Timer timer(FROM_HERE, TimeDelta::FromDays(1), Bind(&TimerTestCallback), RepeatingTimer timer(FROM_HERE, TimeDelta::FromDays(1),
true); Bind(&TimerTestCallback));
EXPECT_FALSE(timer.IsRunning()); EXPECT_FALSE(timer.IsRunning());
timer.Reset(); timer.Reset();
EXPECT_TRUE(timer.IsRunning()); EXPECT_TRUE(timer.IsRunning());
...@@ -653,8 +653,8 @@ TEST(TimerTest, RetainRepeatIsRunning) { ...@@ -653,8 +653,8 @@ TEST(TimerTest, RetainRepeatIsRunning) {
TEST(TimerTest, RetainNonRepeatIsRunning) { TEST(TimerTest, RetainNonRepeatIsRunning) {
MessageLoop loop; MessageLoop loop;
Timer timer(FROM_HERE, TimeDelta::FromDays(1), Bind(&TimerTestCallback), RetainingOneShotTimer timer(FROM_HERE, TimeDelta::FromDays(1),
false); Bind(&TimerTestCallback));
EXPECT_FALSE(timer.IsRunning()); EXPECT_FALSE(timer.IsRunning());
timer.Reset(); timer.Reset();
EXPECT_TRUE(timer.IsRunning()); EXPECT_TRUE(timer.IsRunning());
...@@ -692,7 +692,7 @@ TEST(TimerTest, ContinuationStopStart) { ...@@ -692,7 +692,7 @@ TEST(TimerTest, ContinuationStopStart) {
{ {
ClearAllCallbackHappened(); ClearAllCallbackHappened();
MessageLoop loop; MessageLoop loop;
Timer timer(false, false); OneShotTimer timer;
timer.Start(FROM_HERE, TimeDelta::FromMilliseconds(10), timer.Start(FROM_HERE, TimeDelta::FromMilliseconds(10),
Bind(&SetCallbackHappened1)); Bind(&SetCallbackHappened1));
timer.Stop(); timer.Stop();
...@@ -708,7 +708,7 @@ TEST(TimerTest, ContinuationReset) { ...@@ -708,7 +708,7 @@ TEST(TimerTest, ContinuationReset) {
{ {
ClearAllCallbackHappened(); ClearAllCallbackHappened();
MessageLoop loop; MessageLoop loop;
Timer timer(false, false); OneShotTimer timer;
timer.Start(FROM_HERE, TimeDelta::FromMilliseconds(10), timer.Start(FROM_HERE, TimeDelta::FromMilliseconds(10),
Bind(&SetCallbackHappened1)); Bind(&SetCallbackHappened1));
timer.Reset(); timer.Reset();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment