Bug 990356 - Part 1: Remove lazy init of |mTimer| since we need one for most of the case. r=cpearce
authorJW Wang <jwwang@mozilla.com>
Wed, 02 Apr 2014 08:51:46 -0400
changeset 188794 6c27d78bc562b5cb51dc990161e1a6f9a6ec1706
parent 188793 9bf6ffacf4f6c320af344588cd54598dac176c9f
child 188795 166f661850a61341c8bedb25204b674416594f33
push idunknown
push userunknown
push dateunknown
reviewerscpearce
bugs990356
milestone31.0a1
Bug 990356 - Part 1: Remove lazy init of |mTimer| since we need one for most of the case. r=cpearce
content/media/MediaDecoderStateMachine.cpp
--- a/content/media/MediaDecoderStateMachine.cpp
+++ b/content/media/MediaDecoderStateMachine.cpp
@@ -1042,16 +1042,22 @@ nsresult MediaDecoderStateMachine::Init(
 
   MediaDecoderReader* cloneReader = nullptr;
   if (aCloneDonor) {
     cloneReader = static_cast<MediaDecoderStateMachine*>(aCloneDonor)->mReader;
   }
 
   mStateMachineThreadPool = stateMachinePool;
 
+  nsresult rv;
+  mTimer = do_CreateInstance("@mozilla.org/timer;1", &rv);
+  NS_ENSURE_SUCCESS(rv, rv);
+  rv = mTimer->SetTarget(GetStateMachineThread());
+  NS_ENSURE_SUCCESS(rv, rv);
+
   return mReader->Init(cloneReader);
 }
 
 void MediaDecoderStateMachine::StopPlayback()
 {
   DECODER_LOG(PR_LOG_DEBUG, ("%p StopPlayback()", mDecoder.get()));
 
   AssertCurrentThreadInMonitor();
@@ -2780,21 +2786,19 @@ nsresult MediaDecoderStateMachine::Sched
 
   TimeStamp timeout = TimeStamp::Now() + UsecsToDuration(aUsecs);
   if (!mTimeout.IsNull()) {
     if (timeout >= mTimeout) {
       // We've already scheduled a timer set to expire at or before this time,
       // or have an event dispatched to run the state machine.
       return NS_OK;
     }
-    if (mTimer) {
-      // We've been asked to schedule a timer to run before an existing timer.
-      // Cancel the existing timer.
-      mTimer->Cancel();
-    }
+    // We've been asked to schedule a timer to run before an existing timer.
+    // Cancel the existing timer.
+    mTimer->Cancel();
   }
 
   uint32_t ms = static_cast<uint32_t>((aUsecs / USECS_PER_MS) & 0xFFFFFFFF);
   if (mRealTime && ms > 40)
     ms = 40;
   if (ms == 0) {
     if (mIsRunning) {
       // We're currently running this state machine on the state machine
@@ -2816,28 +2820,22 @@ nsresult MediaDecoderStateMachine::Sched
   // Since there is already a pending task that will run immediately,
   // we don't need to schedule a timer task.
   if (mRunAgain) {
     return NS_OK;
   }
 
   mTimeout = timeout;
 
-  nsresult res;
-  if (!mTimer) {
-    mTimer = do_CreateInstance("@mozilla.org/timer;1", &res);
-    if (NS_FAILED(res)) return res;
-    mTimer->SetTarget(GetStateMachineThread());
-  }
-
-  res = mTimer->InitWithFuncCallback(mozilla::TimeoutExpired,
-                                     this,
-                                     ms,
-                                     nsITimer::TYPE_ONE_SHOT);
-  return res;
+  nsresult rv = mTimer->InitWithFuncCallback(mozilla::TimeoutExpired,
+                                             this,
+                                             ms,
+                                             nsITimer::TYPE_ONE_SHOT);
+  NS_ENSURE_SUCCESS(rv, rv);
+  return NS_OK;
 }
 
 bool MediaDecoderStateMachine::OnDecodeThread() const
 {
   return mDecodeTaskQueue->IsCurrentThreadIn();
 }
 
 bool MediaDecoderStateMachine::OnStateMachineThread() const