Remove unused AlarmTimer, OneShotAlarmTimer, RepeatingAlarmTimer

All AlarmTimer variants but SimpleAlarmTimer have no user in Chromium
and ChromeOS repositories, and base::Timer is being refactored.
As a preparation for the refactoring, this CL removes unused
OneShotAlarmTimer and RepeatingAlarmTimer, and merge SimpleAlarmTimer
into the AlarmTimer.

Bug: 850247
Change-Id: I78b7b7fea7a20edb51e3ad708d2fccceae85bd9d
Reviewed-on: https://chromium-review.googlesource.com/1095201
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Taiju Tsuiki <tzik@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#566303}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 3b99c6385b5bd9895856812fe94dd2125a6459ae
diff --git a/alarm_timer_chromeos.cc b/alarm_timer_chromeos.cc
index 1718038..da5c9b6 100644
--- a/alarm_timer_chromeos.cc
+++ b/alarm_timer_chromeos.cc
@@ -20,17 +20,17 @@
 
 namespace timers {
 
-AlarmTimer::AlarmTimer(bool retain_user_task, bool is_repeating)
-    : base::Timer(retain_user_task, is_repeating),
+SimpleAlarmTimer::SimpleAlarmTimer()
+    : base::Timer(true, false),
       alarm_fd_(timerfd_create(CLOCK_REALTIME_ALARM, 0)),
       weak_factory_(this) {}
 
-AlarmTimer::~AlarmTimer() {
+SimpleAlarmTimer::~SimpleAlarmTimer() {
   DCHECK(origin_task_runner_->RunsTasksInCurrentSequence());
   Stop();
 }
 
-void AlarmTimer::Stop() {
+void SimpleAlarmTimer::Stop() {
   DCHECK(origin_task_runner_->RunsTasksInCurrentSequence());
 
   if (!base::Timer::is_running())
@@ -47,12 +47,9 @@
   base::Timer::set_is_running(false);
   alarm_fd_watcher_.reset();
   pending_task_.reset();
-
-  if (!base::Timer::retain_user_task())
-    base::Timer::set_user_task(base::Closure());
 }
 
-void AlarmTimer::Reset() {
+void SimpleAlarmTimer::Reset() {
   DCHECK(origin_task_runner_->RunsTasksInCurrentSequence());
   DCHECK(!base::Timer::user_task().is_null());
 
@@ -93,20 +90,21 @@
   // If the delay is zero, post the task now.
   if (delay.is_zero()) {
     origin_task_runner_->PostTask(
-        FROM_HERE,
-        base::Bind(&AlarmTimer::OnTimerFired, weak_factory_.GetWeakPtr()));
+        FROM_HERE, base::BindOnce(&SimpleAlarmTimer::OnTimerFired,
+                                  weak_factory_.GetWeakPtr()));
   } else {
     // Otherwise, if the delay is not zero, generate a tracing event to indicate
     // that the task was posted and watch |alarm_fd_|.
-    base::debug::TaskAnnotator().DidQueueTask("AlarmTimer::Reset",
+    base::debug::TaskAnnotator().DidQueueTask("SimpleAlarmTimer::Reset",
                                               *pending_task_);
     alarm_fd_watcher_ = base::FileDescriptorWatcher::WatchReadable(
-        alarm_fd_, base::Bind(&AlarmTimer::OnAlarmFdReadableWithoutBlocking,
-                              weak_factory_.GetWeakPtr()));
+        alarm_fd_,
+        base::BindRepeating(&SimpleAlarmTimer::OnAlarmFdReadableWithoutBlocking,
+                            weak_factory_.GetWeakPtr()));
   }
 }
 
-void AlarmTimer::OnAlarmFdReadableWithoutBlocking() {
+void SimpleAlarmTimer::OnAlarmFdReadableWithoutBlocking() {
   DCHECK(origin_task_runner_->RunsTasksInCurrentSequence());
   DCHECK(base::Timer::IsRunning());
 
@@ -118,52 +116,29 @@
   OnTimerFired();
 }
 
-void AlarmTimer::OnTimerFired() {
+void SimpleAlarmTimer::OnTimerFired() {
   DCHECK(origin_task_runner_->RunsTasksInCurrentSequence());
   DCHECK(base::Timer::IsRunning());
   DCHECK(pending_task_.get());
 
   // Take ownership of the PendingTask to prevent it from being deleted if the
-  // AlarmTimer is deleted.
+  // SimpleAlarmTimer is deleted.
   const auto pending_user_task = std::move(pending_task_);
 
-  base::WeakPtr<AlarmTimer> weak_ptr = weak_factory_.GetWeakPtr();
+  base::WeakPtr<SimpleAlarmTimer> weak_ptr = weak_factory_.GetWeakPtr();
 
   // Run the task.
-  TRACE_TASK_EXECUTION("AlarmTimer::OnTimerFired", *pending_user_task);
-  base::debug::TaskAnnotator().RunTask("AlarmTimer::Reset",
+  TRACE_TASK_EXECUTION("SimpleAlarmTimer::OnTimerFired", *pending_user_task);
+  base::debug::TaskAnnotator().RunTask("SimpleAlarmTimer::Reset",
                                        pending_user_task.get());
 
-  // If the timer wasn't deleted, stopped or reset by the callback, reset or
-  // stop it.
-  if (weak_ptr.get()) {
-    if (base::Timer::is_repeating())
-      Reset();
-    else
-      Stop();
-  }
+  // If the timer wasn't deleted, stopped or reset by the callback, stop it.
+  if (weak_ptr)
+    Stop();
 }
 
-bool AlarmTimer::CanWakeFromSuspend() const {
+bool SimpleAlarmTimer::CanWakeFromSuspend() const {
   return alarm_fd_ != -1;
 }
 
-OneShotAlarmTimer::OneShotAlarmTimer() : AlarmTimer(false, false) {
-}
-
-OneShotAlarmTimer::~OneShotAlarmTimer() {
-}
-
-RepeatingAlarmTimer::RepeatingAlarmTimer() : AlarmTimer(true, true) {
-}
-
-RepeatingAlarmTimer::~RepeatingAlarmTimer() {
-}
-
-SimpleAlarmTimer::SimpleAlarmTimer() : AlarmTimer(true, false) {
-}
-
-SimpleAlarmTimer::~SimpleAlarmTimer() {
-}
-
 }  // namespace timers
diff --git a/alarm_timer_chromeos.h b/alarm_timer_chromeos.h
index d861aee..c7140ec 100644
--- a/alarm_timer_chromeos.h
+++ b/alarm_timer_chromeos.h
@@ -9,7 +9,7 @@
 
 #include "base/files/file_descriptor_watcher_posix.h"
 #include "base/macros.h"
-#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_refptr.h"
 #include "base/memory/weak_ptr.h"
 #include "base/threading/sequenced_task_runner_handle.h"
 #include "base/time/time.h"
@@ -24,23 +24,25 @@
 // suspended state. For example, this is useful for running tasks that are
 // needed for maintaining network connectivity, like sending heartbeat messages.
 // Currently, this feature is only available on Chrome OS systems running linux
-// version 3.11 or higher. On all other platforms, the AlarmTimer behaves
+// version 3.11 or higher. On all other platforms, the SimpleAlarmTimer behaves
 // exactly the same way as a regular Timer.
 //
-// An AlarmTimer instance can only be used from the sequence on which it was
-// instantiated. Start() and Stop() must be called from a thread that supports
-// FileDescriptorWatcher.
-class AlarmTimer : public base::Timer {
+// A SimpleAlarmTimer instance can only be used from the sequence on which it
+// was instantiated. Start() and Stop() must be called from a thread that
+// supports FileDescriptorWatcher.
+//
+// A SimpleAlarmTimer only fires once but remembers the task that it was given
+// even after it has fired.  Useful if you want to run the same task multiple
+// times but not at a regular interval.
+class SimpleAlarmTimer : public base::Timer {
  public:
-  ~AlarmTimer() override;
+  SimpleAlarmTimer();
+  ~SimpleAlarmTimer() override;
 
   // Timer overrides.
   void Stop() override;
   void Reset() override;
 
- protected:
-  AlarmTimer(bool retain_user_task, bool is_repeating);
-
  private:
   // Called when |alarm_fd_| is readable without blocking. Reads data from
   // |alarm_fd_| and calls OnTimerFired().
@@ -70,37 +72,9 @@
   std::unique_ptr<base::PendingTask> pending_task_;
 
   // Used to invalidate pending callbacks.
-  base::WeakPtrFactory<AlarmTimer> weak_factory_;
+  base::WeakPtrFactory<SimpleAlarmTimer> weak_factory_;
 
-  DISALLOW_COPY_AND_ASSIGN(AlarmTimer);
-};
-
-// As its name suggests, a OneShotAlarmTimer runs a given task once.  It does
-// not remember the task that was given to it after it has fired and does not
-// repeat.  Useful for fire-and-forget tasks.
-class OneShotAlarmTimer : public AlarmTimer {
- public:
-  OneShotAlarmTimer();
-  ~OneShotAlarmTimer() override;
-};
-
-// A RepeatingAlarmTimer takes a task and delay and repeatedly runs the task
-// using the specified delay as an interval between the runs until it is
-// explicitly stopped.  It remembers both the task and the delay it was given
-// after it fires.
-class RepeatingAlarmTimer : public AlarmTimer {
- public:
-  RepeatingAlarmTimer();
-  ~RepeatingAlarmTimer() override;
-};
-
-// A SimpleAlarmTimer only fires once but remembers the task that it was given
-// even after it has fired.  Useful if you want to run the same task multiple
-// times but not at a regular interval.
-class SimpleAlarmTimer : public AlarmTimer {
- public:
-  SimpleAlarmTimer();
-  ~SimpleAlarmTimer() override;
+  DISALLOW_COPY_AND_ASSIGN(SimpleAlarmTimer);
 };
 
 }  // namespace timers
diff --git a/alarm_timer_unittest.cc b/alarm_timer_unittest.cc
index ec82237..868eb78 100644
--- a/alarm_timer_unittest.cc
+++ b/alarm_timer_unittest.cc
@@ -27,42 +27,49 @@
 namespace {
 const base::TimeDelta kTenMilliseconds = base::TimeDelta::FromMilliseconds(10);
 
-class OneShotAlarmTimerTester {
+class AlarmTimerTester {
  public:
-  OneShotAlarmTimerTester(bool* did_run, base::TimeDelta delay)
+  AlarmTimerTester(bool* did_run,
+                   base::TimeDelta delay,
+                   base::OnceClosure quit_closure)
       : did_run_(did_run),
+        quit_closure_(std::move(quit_closure)),
         delay_(delay),
-        timer_(new timers::OneShotAlarmTimer()) {}
+        timer_(new timers::SimpleAlarmTimer()) {}
   void Start() {
-    timer_->Start(FROM_HERE, delay_, base::Bind(&OneShotAlarmTimerTester::Run,
-                                                base::Unretained(this)));
+    timer_->Start(
+        FROM_HERE, delay_,
+        base::BindRepeating(&AlarmTimerTester::Run, base::Unretained(this)));
   }
 
  private:
   void Run() {
     *did_run_ = true;
-
-    base::ThreadTaskRunnerHandle::Get()->PostTask(
-        FROM_HERE, base::RunLoop::QuitCurrentWhenIdleClosureDeprecated());
+    if (quit_closure_)
+      std::move(quit_closure_).Run();
   }
 
   bool* did_run_;
+  base::OnceClosure quit_closure_;
   const base::TimeDelta delay_;
-  std::unique_ptr<timers::OneShotAlarmTimer> timer_;
+  std::unique_ptr<timers::SimpleAlarmTimer> timer_;
 
-  DISALLOW_COPY_AND_ASSIGN(OneShotAlarmTimerTester);
+  DISALLOW_COPY_AND_ASSIGN(AlarmTimerTester);
 };
 
-class OneShotSelfDeletingAlarmTimerTester {
+class SelfDeletingAlarmTimerTester {
  public:
-  OneShotSelfDeletingAlarmTimerTester(bool* did_run, base::TimeDelta delay)
+  SelfDeletingAlarmTimerTester(bool* did_run,
+                               base::TimeDelta delay,
+                               base::OnceClosure quit_closure)
       : did_run_(did_run),
+        quit_closure_(std::move(quit_closure)),
         delay_(delay),
-        timer_(new timers::OneShotAlarmTimer()) {}
+        timer_(new timers::SimpleAlarmTimer()) {}
   void Start() {
     timer_->Start(FROM_HERE, delay_,
-                  base::Bind(&OneShotSelfDeletingAlarmTimerTester::Run,
-                             base::Unretained(this)));
+                  base::BindRepeating(&SelfDeletingAlarmTimerTester::Run,
+                                      base::Unretained(this)));
   }
 
  private:
@@ -70,46 +77,16 @@
     *did_run_ = true;
     timer_.reset();
 
-    base::ThreadTaskRunnerHandle::Get()->PostTask(
-        FROM_HERE, base::RunLoop::QuitCurrentWhenIdleClosureDeprecated());
+    if (quit_closure_)
+      std::move(quit_closure_).Run();
   }
 
   bool* did_run_;
+  base::OnceClosure quit_closure_;
   const base::TimeDelta delay_;
-  std::unique_ptr<timers::OneShotAlarmTimer> timer_;
+  std::unique_ptr<timers::SimpleAlarmTimer> timer_;
 
-  DISALLOW_COPY_AND_ASSIGN(OneShotSelfDeletingAlarmTimerTester);
-};
-
-class RepeatingAlarmTimerTester {
- public:
-  RepeatingAlarmTimerTester(bool* did_run, base::TimeDelta delay)
-      : did_run_(did_run),
-        delay_(delay),
-        counter_(10),
-        timer_(new timers::RepeatingAlarmTimer()) {}
-  void Start() {
-    timer_->Start(FROM_HERE, delay_, base::Bind(&RepeatingAlarmTimerTester::Run,
-                                                base::Unretained(this)));
-  }
-
- private:
-  void Run() {
-    if (--counter_ == 0) {
-      *did_run_ = true;
-      timer_->Stop();
-
-      base::ThreadTaskRunnerHandle::Get()->PostTask(
-          FROM_HERE, base::RunLoop::QuitCurrentWhenIdleClosureDeprecated());
-    }
-  }
-
-  bool* did_run_;
-  const base::TimeDelta delay_;
-  int counter_;
-  std::unique_ptr<timers::RepeatingAlarmTimer> timer_;
-
-  DISALLOW_COPY_AND_ASSIGN(RepeatingAlarmTimerTester);
+  DISALLOW_COPY_AND_ASSIGN(SelfDeletingAlarmTimerTester);
 };
 
 }  // namespace
@@ -118,26 +95,28 @@
 // Each test is run against each type of MessageLoop.  That way we are sure
 // that timers work properly in all configurations.
 
-TEST(AlarmTimerTest, OneShotAlarmTimer) {
+TEST(AlarmTimerTest, SimpleAlarmTimer) {
   base::MessageLoopForIO loop;
   base::FileDescriptorWatcher file_descriptor_watcher(&loop);
 
+  base::RunLoop run_loop;
   bool did_run = false;
-  OneShotAlarmTimerTester f(&did_run, kTenMilliseconds);
+  AlarmTimerTester f(&did_run, kTenMilliseconds,
+                     run_loop.QuitWhenIdleClosure());
   f.Start();
 
-  base::RunLoop().Run();
+  run_loop.Run();
 
   EXPECT_TRUE(did_run);
 }
 
-TEST(AlarmTimerTest, OneShotAlarmTimer_Cancel) {
+TEST(AlarmTimerTest, SimpleAlarmTimer_Cancel) {
   base::MessageLoopForIO loop;
   base::FileDescriptorWatcher file_descriptor_watcher(&loop);
 
   bool did_run_a = false;
-  OneShotAlarmTimerTester* a =
-      new OneShotAlarmTimerTester(&did_run_a, kTenMilliseconds);
+  AlarmTimerTester* a =
+      new AlarmTimerTester(&did_run_a, kTenMilliseconds, base::OnceClosure());
 
   // This should run before the timer expires.
   base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, a);
@@ -145,11 +124,13 @@
   // Now start the timer.
   a->Start();
 
+  base::RunLoop run_loop;
   bool did_run_b = false;
-  OneShotAlarmTimerTester b(&did_run_b, kTenMilliseconds);
+  AlarmTimerTester b(&did_run_b, kTenMilliseconds,
+                     run_loop.QuitWhenIdleClosure());
   b.Start();
 
-  base::RunLoop().Run();
+  run_loop.Run();
 
   EXPECT_FALSE(did_run_a);
   EXPECT_TRUE(did_run_b);
@@ -157,39 +138,43 @@
 
 // If underlying timer does not handle this properly, we will crash or fail
 // in full page heap environment.
-TEST(AlarmTimerTest, OneShotSelfDeletingAlarmTimer) {
+TEST(AlarmTimerTest, SelfDeletingAlarmTimer) {
   base::MessageLoopForIO loop;
   base::FileDescriptorWatcher file_descriptor_watcher(&loop);
 
+  base::RunLoop run_loop;
   bool did_run = false;
-  OneShotSelfDeletingAlarmTimerTester f(&did_run, kTenMilliseconds);
+  SelfDeletingAlarmTimerTester f(&did_run, kTenMilliseconds,
+                                 run_loop.QuitWhenIdleClosure());
   f.Start();
 
-  base::RunLoop().Run();
+  run_loop.Run();
 
   EXPECT_TRUE(did_run);
 }
 
-TEST(AlarmTimerTest, RepeatingAlarmTimer) {
+TEST(AlarmTimerTest, AlarmTimerZeroDelay) {
   base::MessageLoopForIO loop;
   base::FileDescriptorWatcher file_descriptor_watcher(&loop);
 
+  base::RunLoop run_loop;
   bool did_run = false;
-  RepeatingAlarmTimerTester f(&did_run, kTenMilliseconds);
+  AlarmTimerTester f(&did_run, base::TimeDelta(),
+                     run_loop.QuitWhenIdleClosure());
   f.Start();
 
-  base::RunLoop().Run();
+  run_loop.Run();
 
   EXPECT_TRUE(did_run);
 }
 
-TEST(AlarmTimerTest, RepeatingAlarmTimer_Cancel) {
+TEST(AlarmTimerTest, AlarmTimerZeroDelay_Cancel) {
   base::MessageLoopForIO loop;
   base::FileDescriptorWatcher file_descriptor_watcher(&loop);
 
   bool did_run_a = false;
-  RepeatingAlarmTimerTester* a =
-      new RepeatingAlarmTimerTester(&did_run_a, kTenMilliseconds);
+  AlarmTimerTester* a =
+      new AlarmTimerTester(&did_run_a, base::TimeDelta(), base::OnceClosure());
 
   // This should run before the timer expires.
   base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, a);
@@ -197,48 +182,13 @@
   // Now start the timer.
   a->Start();
 
+  base::RunLoop run_loop;
   bool did_run_b = false;
-  RepeatingAlarmTimerTester b(&did_run_b, kTenMilliseconds);
+  AlarmTimerTester b(&did_run_b, base::TimeDelta(),
+                     run_loop.QuitWhenIdleClosure());
   b.Start();
 
-  base::RunLoop().Run();
-
-  EXPECT_FALSE(did_run_a);
-  EXPECT_TRUE(did_run_b);
-}
-
-TEST(AlarmTimerTest, RepeatingAlarmTimerZeroDelay) {
-  base::MessageLoopForIO loop;
-  base::FileDescriptorWatcher file_descriptor_watcher(&loop);
-
-  bool did_run = false;
-  RepeatingAlarmTimerTester f(&did_run, base::TimeDelta());
-  f.Start();
-
-  base::RunLoop().Run();
-
-  EXPECT_TRUE(did_run);
-}
-
-TEST(AlarmTimerTest, RepeatingAlarmTimerZeroDelay_Cancel) {
-  base::MessageLoopForIO loop;
-  base::FileDescriptorWatcher file_descriptor_watcher(&loop);
-
-  bool did_run_a = false;
-  RepeatingAlarmTimerTester* a =
-      new RepeatingAlarmTimerTester(&did_run_a, base::TimeDelta());
-
-  // This should run before the timer expires.
-  base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, a);
-
-  // Now start the timer.
-  a->Start();
-
-  bool did_run_b = false;
-  RepeatingAlarmTimerTester b(&did_run_b, base::TimeDelta());
-  b.Start();
-
-  base::RunLoop().Run();
+  run_loop.Run();
 
   EXPECT_FALSE(did_run_a);
   EXPECT_TRUE(did_run_b);
@@ -254,10 +204,10 @@
     auto loop = std::make_unique<base::MessageLoopForIO>();
     auto file_descriptor_watcher =
         std::make_unique<base::FileDescriptorWatcher>(loop.get());
-    OneShotAlarmTimerTester a(&did_run, kTenMilliseconds);
-    OneShotAlarmTimerTester b(&did_run, kTenMilliseconds);
-    OneShotAlarmTimerTester c(&did_run, kTenMilliseconds);
-    OneShotAlarmTimerTester d(&did_run, kTenMilliseconds);
+    AlarmTimerTester a(&did_run, kTenMilliseconds, base::OnceClosure());
+    AlarmTimerTester b(&did_run, kTenMilliseconds, base::OnceClosure());
+    AlarmTimerTester c(&did_run, kTenMilliseconds, base::OnceClosure());
+    AlarmTimerTester d(&did_run, kTenMilliseconds, base::OnceClosure());
 
     a.Start();
     b.Start();
@@ -269,7 +219,7 @@
     // MessageLoop and FileDescriptorWatcher destruct.
     file_descriptor_watcher.reset();
     loop.reset();
-  }  // OneShotTimers destruct. SHOULD NOT CRASH, of course.
+  }  // SimpleAlarmTimers destruct. SHOULD NOT CRASH, of course.
 
   EXPECT_FALSE(did_run);
 }
@@ -278,23 +228,6 @@
   {
     base::MessageLoopForIO loop;
     base::FileDescriptorWatcher file_descriptor_watcher(&loop);
-    timers::OneShotAlarmTimer timer;
-    EXPECT_FALSE(timer.IsRunning());
-    timer.Start(FROM_HERE, base::TimeDelta::FromDays(1), base::DoNothing());
-
-    // Allow FileDescriptorWatcher to start watching the timer. Without this, a
-    // task posted by FileDescriptorWatcher::WatchReadable() is leaked.
-    base::RunLoop().RunUntilIdle();
-
-    EXPECT_TRUE(timer.IsRunning());
-    timer.Stop();
-    EXPECT_FALSE(timer.IsRunning());
-    EXPECT_TRUE(timer.user_task().is_null());
-  }
-
-  {
-    base::MessageLoopForIO loop;
-    base::FileDescriptorWatcher file_descriptor_watcher(&loop);
     timers::SimpleAlarmTimer timer;
     EXPECT_FALSE(timer.IsRunning());
     timer.Start(FROM_HERE, base::TimeDelta::FromDays(1), base::DoNothing());
@@ -313,28 +246,6 @@
   }
 }
 
-TEST(AlarmTimerTest, RetainRepeatIsRunning) {
-  base::MessageLoopForIO loop;
-  base::FileDescriptorWatcher file_descriptor_watcher(&loop);
-  timers::RepeatingAlarmTimer timer;
-  EXPECT_FALSE(timer.IsRunning());
-  timer.Start(FROM_HERE, base::TimeDelta::FromDays(1), base::DoNothing());
-
-  // Allow FileDescriptorWatcher to start watching the timer. Without this, a
-  // task posted by FileDescriptorWatcher::WatchReadable() is leaked.
-  base::RunLoop().RunUntilIdle();
-
-  EXPECT_TRUE(timer.IsRunning());
-  timer.Reset();
-  base::RunLoop().RunUntilIdle();
-  EXPECT_TRUE(timer.IsRunning());
-  timer.Stop();
-  EXPECT_FALSE(timer.IsRunning());
-  timer.Reset();
-  base::RunLoop().RunUntilIdle();
-  EXPECT_TRUE(timer.IsRunning());
-}
-
 TEST(AlarmTimerTest, RetainNonRepeatIsRunning) {
   base::MessageLoopForIO loop;
   base::FileDescriptorWatcher file_descriptor_watcher(&loop);
@@ -367,29 +278,34 @@
   g_callback_happened2 = false;
 }
 
-void SetCallbackHappened1() {
+void SetCallbackHappened1(base::OnceClosure quit_closure) {
   g_callback_happened1 = true;
-  base::ThreadTaskRunnerHandle::Get()->PostTask(
-      FROM_HERE, base::RunLoop::QuitCurrentWhenIdleClosureDeprecated());
+  if (quit_closure)
+    std::move(quit_closure).Run();
 }
 
-void SetCallbackHappened2() {
+void SetCallbackHappened2(base::OnceClosure quit_closure) {
   g_callback_happened2 = true;
-  base::ThreadTaskRunnerHandle::Get()->PostTask(
-      FROM_HERE, base::RunLoop::QuitCurrentWhenIdleClosureDeprecated());
+  if (quit_closure)
+    std::move(quit_closure).Run();
 }
 
 TEST(AlarmTimerTest, ContinuationStopStart) {
   ClearAllCallbackHappened();
   base::MessageLoopForIO loop;
   base::FileDescriptorWatcher file_descriptor_watcher(&loop);
-  timers::OneShotAlarmTimer timer;
+  timers::SimpleAlarmTimer timer;
   timer.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(10),
-              base::Bind(&SetCallbackHappened1));
+              base::BindRepeating(&SetCallbackHappened1,
+                                  base::DoNothing().Repeatedly()));
   timer.Stop();
+
+  base::RunLoop run_loop;
   timer.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(40),
-              base::Bind(&SetCallbackHappened2));
-  base::RunLoop().Run();
+              base::BindRepeating(&SetCallbackHappened2,
+                                  run_loop.QuitWhenIdleClosure()));
+  run_loop.Run();
+
   EXPECT_FALSE(g_callback_happened1);
   EXPECT_TRUE(g_callback_happened2);
 }
@@ -398,13 +314,15 @@
   ClearAllCallbackHappened();
   base::MessageLoopForIO loop;
   base::FileDescriptorWatcher file_descriptor_watcher(&loop);
-  timers::OneShotAlarmTimer timer;
+
+  base::RunLoop run_loop;
+  timers::SimpleAlarmTimer timer;
   timer.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(10),
-              base::Bind(&SetCallbackHappened1));
+              base::BindRepeating(&SetCallbackHappened1,
+                                  run_loop.QuitWhenIdleClosure()));
   timer.Reset();
-  // Since Reset happened before task ran, the user_task must not be cleared:
   ASSERT_FALSE(timer.user_task().is_null());
-  base::RunLoop().Run();
+  run_loop.Run();
   EXPECT_TRUE(g_callback_happened1);
 }
 
@@ -416,12 +334,12 @@
   base::RunLoop run_loop;
 
   // Will be deleted by the callback.
-  timers::OneShotAlarmTimer* timer = new timers::OneShotAlarmTimer;
+  timers::SimpleAlarmTimer* timer = new timers::SimpleAlarmTimer;
 
   timer->Start(
       FROM_HERE, base::TimeDelta::FromMilliseconds(10),
-      base::Bind(
-          [](timers::OneShotAlarmTimer* timer, base::RunLoop* run_loop) {
+      base::BindRepeating(
+          [](timers::SimpleAlarmTimer* timer, base::RunLoop* run_loop) {
             delete timer;
             run_loop->Quit();
           },
@@ -437,12 +355,12 @@
   base::RunLoop run_loop;
 
   // Will be deleted by the callback.
-  timers::OneShotAlarmTimer* timer = new timers::OneShotAlarmTimer;
+  timers::SimpleAlarmTimer* timer = new timers::SimpleAlarmTimer;
 
   timer->Start(
       FROM_HERE, base::TimeDelta(),
-      base::Bind(
-          [](timers::OneShotAlarmTimer* timer, base::RunLoop* run_loop) {
+      base::BindRepeating(
+          [](timers::SimpleAlarmTimer* timer, base::RunLoop* run_loop) {
             delete timer;
             run_loop->Quit();
           },