Bug 1300956. Part 9 - Implement ShutdownState. r=kaku
authorJW Wang <jwwang@mozilla.com>
Tue, 06 Sep 2016 11:37:46 +0800
changeset 354477 1d0bab504e28dc7ef37c8e8caa9f30683dc6a5ef
parent 354476 ce221b3846e69ef1990a9820d7e5e5a2a841ece6
child 354478 5c0e25ea512c72de6a462f4a0946fe9243cb04fe
push id6570
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:26:13 +0000
treeherdermozilla-beta@f455459b2ae5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskaku
bugs1300956
milestone51.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1300956. Part 9 - Implement ShutdownState. r=kaku MozReview-Commit-ID: LnbQeCPYy9f
dom/media/MediaDecoderStateMachine.cpp
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -368,16 +368,38 @@ public:
   }
 
   State GetState() const override
   {
     return DECODER_STATE_COMPLETED;
   }
 };
 
+class MediaDecoderStateMachine::ShutdownState
+  : public MediaDecoderStateMachine::StateObject
+{
+public:
+  explicit ShutdownState(Master* aPtr) : StateObject(aPtr) {}
+
+  void Enter() override
+  {
+    mMaster->mIsShutdown = true;
+  }
+
+  void Exit() override
+  {
+    MOZ_DIAGNOSTIC_ASSERT(false, "Shouldn't escape the SHUTDOWN state.");
+  }
+
+  State GetState() const override
+  {
+    return DECODER_STATE_SHUTDOWN;
+  }
+};
+
 #define INIT_WATCHABLE(name, val) \
   name(val, "MediaDecoderStateMachine::" #name)
 #define INIT_MIRROR(name, val) \
   name(mTaskQueue, val, "MediaDecoderStateMachine::" #name " (Mirror)")
 #define INIT_CANONICAL(name, val) \
   name(mTaskQueue, val, "MediaDecoderStateMachine::" #name " (Canonical)")
 
 MediaDecoderStateMachine::MediaDecoderStateMachine(MediaDecoder* aDecoder,
@@ -1256,16 +1278,19 @@ MediaDecoderStateMachine::SetState(State
       mStateObj = MakeUnique<SeekingState>(this);
       break;
     case DECODER_STATE_BUFFERING:
       mStateObj = MakeUnique<BufferingState>(this);
       break;
     case DECODER_STATE_COMPLETED:
       mStateObj = MakeUnique<CompletedState>(this);
       break;
+    case DECODER_STATE_SHUTDOWN:
+      mStateObj = MakeUnique<ShutdownState>(this);
+      break;
     default:
       mStateObj = nullptr;
       break;
   }
 
   EnterState();
 }
 
@@ -1274,44 +1299,28 @@ MediaDecoderStateMachine::ExitState()
 {
   MOZ_ASSERT(OnTaskQueue());
 
   if (mStateObj) {
     MOZ_ASSERT(mState == mStateObj->GetState());
     mStateObj->Exit();
     return;
   }
-
-  switch (mState) {
-    case DECODER_STATE_SHUTDOWN:
-      MOZ_DIAGNOSTIC_ASSERT(false, "Shouldn't escape the SHUTDOWN state.");
-      break;
-    default:
-      break;
-  }
 }
 
 void
 MediaDecoderStateMachine::EnterState()
 {
   MOZ_ASSERT(OnTaskQueue());
 
   if (mStateObj) {
     MOZ_ASSERT(mState == mStateObj->GetState());
     mStateObj->Enter();
     return;
   }
-
-  switch (mState) {
-    case DECODER_STATE_SHUTDOWN:
-      mIsShutdown = true;
-      break;
-    default:
-      break;
-  }
 }
 
 void MediaDecoderStateMachine::VolumeChanged()
 {
   MOZ_ASSERT(OnTaskQueue());
   mMediaSink->SetVolume(mVolume);
 }