Bug 1300497. Part 5 - run MDSM cycles immediately in the callback of mDelayedScheduler. draft
authorJW Wang <jwwang@mozilla.com>
Mon, 05 Sep 2016 17:51:54 +0800
changeset 410899 81779a695c1add37463a1b612c8cdbaad9bed39d
parent 410898 519590a1a8a14e46d5b2060fd208c19fcb90c307
child 410900 585fdb36e56deb46b2bc87a2b021c917d7296653
child 411418 6724fb8e33263e539cba8ce108577e86b3a83b2e
push id28782
push userjwwang@mozilla.com
push dateWed, 07 Sep 2016 03:31:14 +0000
bugs1300497
milestone51.0a1
Bug 1300497. Part 5 - run MDSM cycles immediately in the callback of mDelayedScheduler. There is no point in scheduling an addition cycle to do that. Also remove the annoying debugging message which is not helpful. MozReview-Commit-ID: BMjeTNg6HCY
dom/media/MediaDecoderStateMachine.cpp
dom/media/MediaDecoderStateMachine.h
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -2614,23 +2614,23 @@ MediaDecoderStateMachine::ScheduleStateM
   MOZ_ASSERT(aMicroseconds > 0);
   if (mDispatchedStateMachine) {
     return;
   }
 
   TimeStamp now = TimeStamp::Now();
   TimeStamp target = now + TimeDuration::FromMicroseconds(aMicroseconds);
 
-  SAMPLE_LOG("Scheduling state machine for %lf ms from now", (target - now).ToMilliseconds());
-
-  RefPtr<MediaDecoderStateMachine> self = this;
-  mDelayedScheduler.Ensure(target, [self] () {
-    self->OnDelayedSchedule();
-  }, [self] () {
-    self->NotReached();
+  // It is OK to capture 'this' without causing UAF because the callback
+  // always happens before shutdown.
+  mDelayedScheduler.Ensure(target, [this] () {
+    mDelayedScheduler.CompleteRequest();
+    RunStateMachine();
+  }, [] () {
+    MOZ_DIAGNOSTIC_ASSERT(false);
   });
 }
 
 bool MediaDecoderStateMachine::OnTaskQueue() const
 {
   return OwnerThread()->IsCurrentThreadIn();
 }
 
--- a/dom/media/MediaDecoderStateMachine.h
+++ b/dom/media/MediaDecoderStateMachine.h
@@ -314,25 +314,16 @@ private:
   // Schedules the shared state machine thread to run the state machine.
   void ScheduleStateMachine();
 
   // Invokes ScheduleStateMachine to run in |aMicroseconds| microseconds,
   // unless it's already scheduled to run earlier, in which case the
   // request is discarded.
   void ScheduleStateMachineIn(int64_t aMicroseconds);
 
-  void OnDelayedSchedule()
-  {
-    MOZ_ASSERT(OnTaskQueue());
-    mDelayedScheduler.CompleteRequest();
-    ScheduleStateMachine();
-  }
-
-  void NotReached() { MOZ_DIAGNOSTIC_ASSERT(false); }
-
   // Discard audio/video data that are already played by MSG.
   void DiscardStreamData();
   bool HaveEnoughDecodedAudio();
   bool HaveEnoughDecodedVideo();
 
   // True if shutdown process has begun.
   bool IsShutdown() const;