Bug 1302006. Part 4 - Let StateObject handle dormant request. draft
authorJW Wang <jwwang@mozilla.com>
Mon, 12 Sep 2016 10:49:46 +0800
changeset 415269 24e5e66d2e67340d0dfc76693be01b1be878f6b3
parent 414780 774fdbb344e94fcb54c04ce40bd4a920fe6e0211
child 415273 d5e34b7cb30221c3e93e089b8db7f28cd7845987
push id29839
push userjwwang@mozilla.com
push dateTue, 20 Sep 2016 02:02:02 +0000
bugs1302006
milestone51.0a1
Bug 1302006. Part 4 - Let StateObject handle dormant request. MozReview-Commit-ID: FK3UwbYDexV
dom/media/MediaDecoderStateMachine.cpp
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -218,17 +218,33 @@ public:
   virtual ~StateObject() {}
   virtual void Enter() {}; // Entry action.
   virtual void Exit() {};  // Exit action.
   virtual void Step() {}   // Perform a 'cycle' of this state object.
   virtual State GetState() const = 0;
 
   // Event handlers for various events.
   // Return true if the event is handled by this state object.
-  virtual bool HandleDormant(bool aDormant) { return false; }
+  virtual bool HandleDormant(bool aDormant)
+  {
+    if (!aDormant) {
+      return true;
+    }
+    mMaster->mQueuedSeek.mTarget =
+      SeekTarget(mMaster->mCurrentPosition,
+                 SeekTarget::Accurate,
+                 MediaDecoderEventVisibility::Suppressed);
+    // SeekJob asserts |mTarget.IsValid() == !mPromise.IsEmpty()| so we
+    // need to create the promise even it is not used at all.
+    RefPtr<MediaDecoder::SeekPromise> unused =
+      mMaster->mQueuedSeek.mPromise.Ensure(__func__);
+    SetState(DECODER_STATE_DORMANT);
+    return true;
+  }
+
   virtual bool HandleCDMProxyReady() { return false; }
 
 protected:
   using Master = MediaDecoderStateMachine;
   explicit StateObject(Master* aPtr) : mMaster(aPtr) {}
   TaskQueue* OwnerThread() const { return mMaster->mTaskQueue; }
   MediaResource* Resource() const { return mMaster->mResource; }
   MediaDecoderReaderWrapper* Reader() const { return mMaster->mReader; }
@@ -1517,40 +1533,17 @@ MediaDecoderStateMachine::DispatchSetDor
     this, &MediaDecoderStateMachine::SetDormant, aDormant);
   OwnerThread()->Dispatch(r.forget());
 }
 
 void
 MediaDecoderStateMachine::SetDormant(bool aDormant)
 {
   MOZ_ASSERT(OnTaskQueue());
-
-  if (mStateObj->HandleDormant(aDormant)) {
-    return;
-  }
-
-  // These states are already handled by |mStateObj->HandleDormant| above.
-  MOZ_ASSERT(mState != DECODER_STATE_DORMANT &&
-             mState != DECODER_STATE_SEEKING);
-
-  // Nothing to do for we are not in dormant state.
-  if (!aDormant) {
-    return;
-  }
-
-  DECODER_LOG("Enter dormant state");
-
-  mQueuedSeek.mTarget = SeekTarget(mCurrentPosition,
-                                   SeekTarget::Accurate,
-                                   MediaDecoderEventVisibility::Suppressed);
-  // SeekJob asserts |mTarget.IsValid() == !mPromise.IsEmpty()| so we
-  // need to create the promise even it is not used at all.
-  RefPtr<MediaDecoder::SeekPromise> unused = mQueuedSeek.mPromise.Ensure(__func__);
-
-  SetState(DECODER_STATE_DORMANT);
+  mStateObj->HandleDormant(aDormant);
 }
 
 RefPtr<ShutdownPromise>
 MediaDecoderStateMachine::Shutdown()
 {
   MOZ_ASSERT(OnTaskQueue());
 
   SetState(DECODER_STATE_SHUTDOWN);