Bug 1340921 - Introduce PMemoryStream for having PBlob and Multi-e10s happy - part 4 - Delete of the PMemoryStream actor, r=mrbkap a=gchang
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 29 Mar 2017 10:40:38 +0200
changeset 375671 02a7a514a2655c5ef44bdb2b2d5f4af926f09e0f
parent 375670 8d1a61d60b993bdd306de6c5711427c03e1c1ecf
child 375672 d0b605e7f5c7e2b6f69fa39c37f5bdef06e038ca
push id11002
push usercbook@mozilla.com
push dateMon, 03 Apr 2017 09:29:08 +0000
treeherdermozilla-aurora@c53411a2c11f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmrbkap, gchang
bugs1340921
milestone54.0a2
Bug 1340921 - Introduce PMemoryStream for having PBlob and Multi-e10s happy - part 4 - Delete of the PMemoryStream actor, r=mrbkap a=gchang
dom/file/ipc/Blob.cpp
dom/file/ipc/MemoryStreamParent.h
--- a/dom/file/ipc/Blob.cpp
+++ b/dom/file/ipc/Blob.cpp
@@ -659,16 +659,73 @@ SerializeInputStreamInChunks(nsIInputStr
     }
 
     child->SendAddChunk(buffer);
   }
 
   return child;
 }
 
+void
+DeleteStreamMemoryFromBlobDataStream(BlobDataStream& aStream)
+{
+  PMemoryStreamChild* actor = aStream.streamChild();
+  if (actor) {
+    actor->Send__delete__(actor);
+  }
+}
+
+void
+DeleteStreamMemoryFromBlobData(BlobData& aBlobData)
+{
+  switch (aBlobData.type()) {
+    case BlobData::TBlobDataStream:
+      DeleteStreamMemoryFromBlobDataStream(aBlobData.get_BlobDataStream());
+      return;
+
+    case BlobData::TArrayOfBlobData: {
+      nsTArray<BlobData>& arrayBlobData = aBlobData.get_ArrayOfBlobData();
+      for (uint32_t i = 0; i < arrayBlobData.Length(); ++i) {
+        DeleteStreamMemoryFromBlobData(arrayBlobData[i]);
+      }
+      return;
+    }
+
+    default:
+      // Nothing to do here.
+      return;
+  }
+}
+
+void
+DeleteStreamMemoryFromOptionalBlobData(OptionalBlobData& aParams)
+{
+  if (aParams.type() == OptionalBlobData::Tvoid_t) {
+    return;
+  }
+
+  DeleteStreamMemoryFromBlobData(aParams.get_BlobData());
+}
+
+void
+DeleteStreamMemory(AnyBlobConstructorParams& aParams)
+{
+  if (aParams.type() == AnyBlobConstructorParams::TFileBlobConstructorParams) {
+    FileBlobConstructorParams& fileParams = aParams.get_FileBlobConstructorParams();
+    DeleteStreamMemoryFromOptionalBlobData(fileParams.optionalBlobData());
+    return;
+  }
+
+  if (aParams.type() == AnyBlobConstructorParams::TNormalBlobConstructorParams) {
+    NormalBlobConstructorParams& normalParams = aParams.get_NormalBlobConstructorParams();
+    DeleteStreamMemoryFromOptionalBlobData(normalParams.optionalBlobData());
+    return;
+  }
+}
+
 } // namespace
 
 already_AddRefed<BlobImpl>
 CreateBlobImpl(const nsID& aKnownBlobIDData,
                const CreateBlobImplMetadata& aMetadata)
 {
   MOZ_ASSERT(gProcessType == GeckoProcessType_Default);
   MOZ_ASSERT(aMetadata.mHasRecursed);
@@ -3574,16 +3631,18 @@ BlobChild::GetOrCreateFromImpl(ChildMana
   auto* actor = new BlobChild(aManager, aBlobImpl);
 
   ParentBlobConstructorParams params(blobParams);
 
   if (NS_WARN_IF(!aManager->SendPBlobConstructor(actor, params))) {
     return nullptr;
   }
 
+  DeleteStreamMemory(params.blobParams());
+
   return actor;
 }
 
 // static
 template <class ChildManagerType>
 BlobChild*
 BlobChild::CreateFromParams(ChildManagerType* aManager,
                             const ChildBlobConstructorParams& aParams)
--- a/dom/file/ipc/MemoryStreamParent.h
+++ b/dom/file/ipc/MemoryStreamParent.h
@@ -11,17 +11,17 @@
 #include "mozilla/dom/MemoryBlobImpl.h"
 
 namespace mozilla {
 namespace dom {
 
 class MemoryStreamParent final : public mozilla::ipc::PMemoryStreamParent
 {
 public:
-  MemoryStreamParent(uint64_t aSize);
+  explicit MemoryStreamParent(uint64_t aSize);
 
   mozilla::ipc::IPCResult
   RecvAddChunk(nsTArray<unsigned char>&& aData) override;
 
   void
   ActorDestroy(IProtocol::ActorDestroyReason) override;
 
   void