Bug 1331854 - Create the PBlob actor on current thread if doesn't exist yet, r=bkelly
authorAndrea Marchesini <amarchesini@mozilla.com>
Fri, 17 Feb 2017 15:40:57 +0100
changeset 372629 4becea6f05dfe07f6fd49eb0080dc56f52280662
parent 372628 e66b5929cc7db7207dfdf0379d90283afda344e2
child 372630 d226bf0c5b39384fec0a48da7a7d5a8da92b7ef5
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbkelly
bugs1331854
milestone54.0a1
Bug 1331854 - Create the PBlob actor on current thread if doesn't exist yet, r=bkelly
dom/file/ipc/Blob.cpp
--- a/dom/file/ipc/Blob.cpp
+++ b/dom/file/ipc/Blob.cpp
@@ -23,16 +23,17 @@
 #include "mozilla/dom/nsIContentParent.h"
 #include "mozilla/dom/nsIContentChild.h"
 #include "mozilla/dom/PBlobStreamChild.h"
 #include "mozilla/dom/PBlobStreamParent.h"
 #include "mozilla/dom/indexedDB/FileSnapshot.h"
 #include "mozilla/dom/IndexedDatabaseManager.h"
 #include "mozilla/ipc/InputStreamUtils.h"
 #include "mozilla/ipc/IPCStreamUtils.h"
+#include "mozilla/ipc/BackgroundChild.h"
 #include "mozilla/ipc/PBackgroundChild.h"
 #include "mozilla/ipc/PBackgroundParent.h"
 #include "mozilla/ipc/PFileDescriptorSetParent.h"
 #include "MultipartBlobImpl.h"
 #include "nsDataHashtable.h"
 #include "nsHashKeys.h"
 #include "nsID.h"
 #include "nsIFileStreams.h"
@@ -46,20 +47,16 @@
 #include "nsServiceManagerUtils.h"
 #include "nsStringStream.h"
 #include "nsThreadUtils.h"
 #include "nsXULAppAPI.h"
 #include "StreamBlobImpl.h"
 #include "WorkerPrivate.h"
 #include "WorkerRunnable.h"
 
-#ifdef DEBUG
-#include "BackgroundChild.h" // BackgroundChild::GetForCurrentThread().
-#endif
-
 #ifdef OS_POSIX
 #include "chrome/common/file_descriptor_set_posix.h"
 #endif
 
 #define DISABLE_ASSERTS_FOR_FUZZING 0
 
 #if DISABLE_ASSERTS_FOR_FUZZING
 #define ASSERT_UNLESS_FUZZING(...) do { } while (0)
@@ -2600,16 +2597,28 @@ CreateStreamHelper::GetStream(nsIInputSt
   MOZ_ASSERT(!mDone);
 
   RefPtr<RemoteBlobImpl> baseRemoteBlobImpl =
     mRemoteBlobImpl->BaseRemoteBlobImpl();
   MOZ_ASSERT(baseRemoteBlobImpl);
 
   if (EventTargetIsOnCurrentThread(baseRemoteBlobImpl->GetActorEventTarget())) {
     RunInternal(baseRemoteBlobImpl, false);
+  } else if (PBackgroundChild* manager = mozilla::ipc::BackgroundChild::GetForCurrentThread()) {
+    BlobChild* blobChild = BlobChild::GetOrCreate(manager, baseRemoteBlobImpl);
+    MOZ_ASSERT(blobChild);
+
+    RefPtr<BlobImpl> blobImpl = blobChild->GetBlobImpl();
+    MOZ_ASSERT(blobImpl);
+
+    ErrorResult rv;
+    blobImpl->GetInternalStream(aInputStream, rv);
+    mRemoteBlobImpl = nullptr;
+    mDone = true;
+    return rv.StealNSResult();
   } else {
     nsresult rv = baseRemoteBlobImpl->DispatchToTarget(this);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
 
     DebugOnly<bool> warned = false;