Bug 1079616 - Dispatch PushBlobRunnable in RequestData function, and remove CreateAndDispatchBlobEventRunnable. r=roc, a=lmandel
authorBenjamin Chen <bechen@mozilla.com>
Fri, 17 Oct 2014 17:26:11 +0800
changeset 225806 d9664db594e9
parent 225805 2c49dc84f1a0
child 225807 47065beeef20
push id4023
push userryanvm@gmail.com
push date2014-10-24 20:40 +0000
treeherdermozilla-beta@184b704568ff [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc, lmandel
bugs1079616
milestone34.0
Bug 1079616 - Dispatch PushBlobRunnable in RequestData function, and remove CreateAndDispatchBlobEventRunnable. r=roc, a=lmandel
content/media/MediaRecorder.cpp
content/media/MediaRecorder.h
--- a/content/media/MediaRecorder.cpp
+++ b/content/media/MediaRecorder.cpp
@@ -313,16 +313,29 @@ public:
     MOZ_ASSERT(NS_IsMainThread());
 
     NS_ENSURE_TRUE(mTrackUnionStream, NS_ERROR_FAILURE);
     mTrackUnionStream->ChangeExplicitBlockerCount(-1);
 
     return NS_OK;
   }
 
+  nsresult RequestData()
+  {
+    LOG(PR_LOG_DEBUG, ("Session.RequestData"));
+    MOZ_ASSERT(NS_IsMainThread());
+
+    if (NS_FAILED(NS_DispatchToMainThread(new PushBlobRunnable(this)))) {
+      MOZ_ASSERT(false, "RequestData NS_DispatchToMainThread failed");
+      return NS_ERROR_FAILURE;
+    }
+
+    return NS_OK;
+  }
+
   already_AddRefed<nsIDOMBlob> GetEncodedData()
   {
     MOZ_ASSERT(NS_IsMainThread());
     return mEncodedBufferCache->ExtractBlob(mMimeType);
   }
 
   bool IsEncoderError()
   {
@@ -733,47 +746,27 @@ MediaRecorder::Resume(ErrorResult& aResu
   nsresult rv = mSessions.LastElement()->Resume();
   if (NS_FAILED(rv)) {
     NotifyError(rv);
     return;
   }
   mState = RecordingState::Recording;
 }
 
-class CreateAndDispatchBlobEventRunnable : public nsRunnable {
-  nsCOMPtr<nsIDOMBlob> mBlob;
-  nsRefPtr<MediaRecorder> mRecorder;
-public:
-  CreateAndDispatchBlobEventRunnable(already_AddRefed<nsIDOMBlob>&& aBlob,
-                                     MediaRecorder* aRecorder)
-    : mBlob(aBlob), mRecorder(aRecorder)
-  { }
-
-  NS_IMETHOD
-  Run();
-};
-
-NS_IMETHODIMP
-CreateAndDispatchBlobEventRunnable::Run()
-{
-  return mRecorder->CreateAndDispatchBlobEvent(mBlob.forget());
-}
-
 void
 MediaRecorder::RequestData(ErrorResult& aResult)
 {
   if (mState != RecordingState::Recording) {
     aResult.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
     return;
   }
   MOZ_ASSERT(mSessions.Length() > 0);
-  if (NS_FAILED(NS_DispatchToMainThread(
-                  new CreateAndDispatchBlobEventRunnable(
-                    mSessions.LastElement()->GetEncodedData(), this)))) {
-    MOZ_ASSERT(false, "NS_DispatchToMainThread CreateAndDispatchBlobEventRunnable failed");
+  nsresult rv = mSessions.LastElement()->RequestData();
+  if (NS_FAILED(rv)) {
+    NotifyError(rv);
   }
 }
 
 JSObject*
 MediaRecorder::WrapObject(JSContext* aCx)
 {
   return MediaRecorderBinding::Wrap(aCx, this);
 }
--- a/content/media/MediaRecorder.h
+++ b/content/media/MediaRecorder.h
@@ -36,17 +36,16 @@ class AudioNode;
  * When the recorder starts, it creates a "Media Encoder" thread to read data from MediaEncoder object and store buffer in EncodedBufferCache object.
  * Also extract the encoded data and create blobs on every timeslice passed from start function or RequestData function called by UA.
  */
 
 class MediaRecorder : public DOMEventTargetHelper,
                       public nsIDocumentActivity
 {
   class Session;
-  friend class CreateAndDispatchBlobEventRunnable;
 
 public:
   MediaRecorder(DOMMediaStream& aSourceMediaStream, nsPIDOMWindow* aOwnerWindow);
   MediaRecorder(AudioNode& aSrcAudioNode, uint32_t aSrcOutput, nsPIDOMWindow* aOwnerWindow);
 
   // nsWrapperCache
   virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;