Migrate CallStats and RtpStreamsSynchronizer timers over to RepeatingTask

Bug: none
Change-Id: Ib49a3de74c6d3a6d4ea158383a5e4b69a1e58ab9
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/175000
Reviewed-by: Sebastian Jansson <srte@webrtc.org>
Commit-Queue: Tommi <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31252}
diff --git a/rtc_base/task_utils/repeating_task.h b/rtc_base/task_utils/repeating_task.h
index 1545d6f..75d03bf 100644
--- a/rtc_base/task_utils/repeating_task.h
+++ b/rtc_base/task_utils/repeating_task.h
@@ -20,7 +20,6 @@
 #include "api/units/time_delta.h"
 #include "api/units/timestamp.h"
 #include "rtc_base/synchronization/sequence_checker.h"
-#include "rtc_base/thread_checker.h"
 
 namespace webrtc {
 
@@ -31,18 +30,25 @@
  public:
   RepeatingTaskBase(TaskQueueBase* task_queue, TimeDelta first_delay);
   ~RepeatingTaskBase() override;
-  virtual TimeDelta RunClosure() = 0;
+
+  void Stop();
 
  private:
-  friend class ::webrtc::RepeatingTaskHandle;
+  virtual TimeDelta RunClosure() = 0;
 
   bool Run() final;
-  void Stop() RTC_RUN_ON(task_queue_);
 
   TaskQueueBase* const task_queue_;
   // This is always finite, except for the special case where it's PlusInfinity
   // to signal that the task should stop.
-  Timestamp next_run_time_ RTC_GUARDED_BY(task_queue_);
+  Timestamp next_run_time_ RTC_GUARDED_BY(sequence_checker_);
+  // We use a SequenceChecker to check for correct usage instead of using
+  // RTC_DCHECK_RUN_ON(task_queue_). This is to work around a compatibility
+  // issue with some TQ implementations such as rtc::Thread that don't
+  // consistently set themselves as the 'current' TQ when running tasks.
+  // The SequenceChecker detects those implementations differently but gives
+  // the same effect as far as thread safety goes.
+  SequenceChecker sequence_checker_;
 };
 
 // The template closure pattern is based on rtc::ClosureTask.
@@ -61,9 +67,9 @@
         "");
   }
 
+ private:
   TimeDelta RunClosure() override { return closure_(); }
 
- private:
   typename std::remove_const<
       typename std::remove_reference<Closure>::type>::type closure_;
 };