Bug 1302006. Part 4 - Let StateObject handle dormant request. r=kikuo
authorJW Wang <jwwang@mozilla.com>
Mon, 12 Sep 2016 10:49:46 +0800
changeset 314433 e1bf663363fd84b7c7c9f3c08bc22bce4874dede
parent 314432 c12f64bf259899d61108e556ac7bd437cd1d03d7
child 314434 2af2eaac5b485f3c88874439759bd1620deb3d80
push id20574
push usercbook@mozilla.com
push dateTue, 20 Sep 2016 10:05:16 +0000
treeherderfx-team@14705f779a46 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskikuo
bugs1302006
milestone52.0a1
Bug 1302006. Part 4 - Let StateObject handle dormant request. r=kikuo 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);