Bug 1359087 - Use IPCBlob in FileHandle - part 2 - FileHandle and IPCBlob, r=janv
authorAndrea Marchesini <amarchesini@mozilla.com>
Tue, 09 May 2017 22:35:42 +0200
changeset 357434 66fafc2b84cf145190468eee4e08de99e5934ad6
parent 357433 9294be2d9f63c527304cd6f33a6ce73fa5d858a3
child 357435 f4a5a1808b5f3b55362559c63cd135bb29a202fe
push id31792
push usercbook@mozilla.com
push dateWed, 10 May 2017 13:07:59 +0000
treeherdermozilla-central@ebbcdaa5b580 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjanv
bugs1359087
milestone55.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 1359087 - Use IPCBlob in FileHandle - part 2 - FileHandle and IPCBlob, r=janv
dom/filehandle/ActorsChild.cpp
dom/filehandle/ActorsParent.cpp
dom/filehandle/FileHandleBase.cpp
dom/filehandle/PBackgroundFileHandle.ipdl
dom/filehandle/PBackgroundFileRequest.ipdl
--- a/dom/filehandle/ActorsChild.cpp
+++ b/dom/filehandle/ActorsChild.cpp
@@ -5,17 +5,17 @@
 #include "ActorsChild.h"
 
 #include "BackgroundChildImpl.h"
 #include "FileHandleBase.h"
 #include "FileRequestBase.h"
 #include "js/Date.h"
 #include "mozilla/dom/EncodingUtils.h"
 #include "mozilla/dom/File.h"
-#include "mozilla/dom/ipc/BlobChild.h"
+#include "mozilla/dom/ipc/PendingIPCBlobChild.h"
 #include "MutableFileBase.h"
 #include "nsCOMPtr.h"
 #include "nsContentUtils.h"
 #include "nsString.h"
 #include "xpcpublic.h"
 #include "mozilla/dom/BindingUtils.h"
 
 namespace mozilla {
@@ -298,35 +298,34 @@ private:
     return NS_OK;
   }
 };
 
 already_AddRefed<File>
 ConvertActorToFile(FileHandleBase* aFileHandle,
                    const FileRequestGetFileResponse& aResponse)
 {
-  auto* actor = static_cast<BlobChild*>(aResponse.fileChild());
+  auto* actor = static_cast<PendingIPCBlobChild*>(aResponse.fileChild());
 
   MutableFileBase* mutableFile = aFileHandle->MutableFile();
   MOZ_ASSERT(mutableFile);
 
   const FileRequestMetadata& metadata = aResponse.metadata();
 
   const FileRequestSize& size = metadata.size();
   MOZ_ASSERT(size.type() == FileRequestSize::Tuint64_t);
 
   const FileRequestLastModified& lastModified = metadata.lastModified();
   MOZ_ASSERT(lastModified.type() == FileRequestLastModified::Tint64_t);
 
-  actor->SetMysteryBlobInfo(mutableFile->Name(),
-                            mutableFile->Type(),
-                            size.get_uint64_t(),
-                            lastModified.get_int64_t());
-
-  RefPtr<BlobImpl> blobImpl = actor->GetBlobImpl();
+  RefPtr<BlobImpl> blobImpl =
+    actor->SetPendingInfoAndDeleteActor(mutableFile->Name(),
+                                        mutableFile->Type(),
+                                        size.get_uint64_t(),
+                                        lastModified.get_int64_t());
   MOZ_ASSERT(blobImpl);
 
   RefPtr<File> file = mutableFile->CreateFileFor(blobImpl, aFileHandle);
   return file.forget();
 }
 
 void
 HandleSuccess(ResultHelper* aResultHelper)
--- a/dom/filehandle/ActorsParent.cpp
+++ b/dom/filehandle/ActorsParent.cpp
@@ -9,17 +9,18 @@
 #include "mozilla/Attributes.h"
 #include "mozilla/Unused.h"
 #include "mozilla/dom/File.h"
 #include "mozilla/dom/FileHandleCommon.h"
 #include "mozilla/dom/PBackgroundFileHandleParent.h"
 #include "mozilla/dom/PBackgroundFileRequestParent.h"
 #include "mozilla/dom/indexedDB/ActorsParent.h"
 #include "mozilla/dom/indexedDB/PBackgroundIDBDatabaseParent.h"
-#include "mozilla/dom/ipc/BlobParent.h"
+#include "mozilla/dom/IPCBlobUtils.h"
+#include "mozilla/dom/ipc/PendingIPCBlobParent.h"
 #include "nsAutoPtr.h"
 #include "nsComponentManagerUtils.h"
 #include "nsDebug.h"
 #include "nsError.h"
 #include "nsIEventTarget.h"
 #include "nsIFileStreams.h"
 #include "nsIInputStream.h"
 #include "nsIOutputStream.h"
@@ -1772,29 +1773,16 @@ FileHandle::VerifyRequestData(const File
         ASSERT_UNLESS_FUZZING();
         return false;
       }
 
       break;
     }
 
     case FileRequestData::TFileRequestBlobData: {
-      const FileRequestBlobData& data =
-        aData.get_FileRequestBlobData();
-
-      if (NS_WARN_IF(data.blobChild())) {
-        ASSERT_UNLESS_FUZZING();
-        return false;
-      }
-
-      if (NS_WARN_IF(!data.blobParent())) {
-        ASSERT_UNLESS_FUZZING();
-        return false;
-      }
-
       break;
     }
 
     default:
       MOZ_CRASH("Should never get here!");
   }
 
   return true;
@@ -2533,24 +2521,24 @@ WriteOp::Init(FileHandle* aFileHandle)
       }
 
       break;
     }
     case FileRequestData::TFileRequestBlobData: {
       const FileRequestBlobData& blobData =
         data.get_FileRequestBlobData();
 
-      auto blobActor = static_cast<BlobParent*>(blobData.blobParent());
-
-      RefPtr<BlobImpl> blobImpl = blobActor->GetBlobImpl();
-
-      ErrorResult rv;
+      RefPtr<BlobImpl> blobImpl = IPCBlobUtils::Deserialize(blobData.blob());
+      if (NS_WARN_IF(!blobImpl)) {
+        return false;
+      }
+
+      IgnoredErrorResult rv;
       blobImpl->GetInternalStream(getter_AddRefs(inputStream), rv);
       if (NS_WARN_IF(rv.Failed())) {
-        rv.SuppressException();
         return false;
       }
 
       break;
     }
 
     default:
       MOZ_CRASH("Should never get here!");
@@ -2651,18 +2639,18 @@ GetFileOp::GetFileOp(FileHandle* aFileHa
 void
 GetFileOp::GetResponse(FileRequestResponse& aResponse)
 {
   AssertIsOnOwningThread();
 
   RefPtr<BlobImpl> blobImpl = mFileHandle->GetMutableFile()->CreateBlobImpl();
   MOZ_ASSERT(blobImpl);
 
-  PBlobParent* actor =
-    BackgroundParent::GetOrCreateActorForBlobImpl(mBackgroundParent, blobImpl);
+  PendingIPCBlobParent* actor =
+    PendingIPCBlobParent::Create(mBackgroundParent, blobImpl);
   if (NS_WARN_IF(!actor)) {
     // This can only fail if the child has crashed.
     aResponse = NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR;
     return;
   }
 
   FileRequestGetFileResponse response;
   response.fileParent() = actor;
--- a/dom/filehandle/FileHandleBase.cpp
+++ b/dom/filehandle/FileHandleBase.cpp
@@ -7,16 +7,17 @@
 #include "FileHandleBase.h"
 
 #include "ActorsChild.h"
 #include "BackgroundChildImpl.h"
 #include "FileRequestBase.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/ErrorResult.h"
 #include "mozilla/dom/File.h"
+#include "mozilla/dom/IPCBlobUtils.h"
 #include "mozilla/dom/PBackgroundFileHandle.h"
 #include "mozilla/dom/UnionConversions.h"
 #include "mozilla/ipc/BackgroundChild.h"
 #include "MutableFileBase.h"
 #include "nsCOMPtr.h"
 #include "nsDebug.h"
 #include "nsError.h"
 #include "nsString.h"
@@ -532,39 +533,40 @@ FileHandleBase::WriteOrAppend(Blob& aVal
 {
   AssertIsOnOwningThread();
 
   // State checking for write or append
   if (!CheckStateForWriteOrAppend(aAppend, aRv)) {
     return nullptr;
   }
 
-  ErrorResult rv;
-  uint64_t dataLength = aValue.GetSize(rv);
-  if (NS_WARN_IF(rv.Failed())) {
+  ErrorResult error;
+  uint64_t dataLength = aValue.GetSize(error);
+  if (NS_WARN_IF(error.Failed())) {
     aRv.Throw(NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR);
     return nullptr;
   }
 
   if (!dataLength) {
     return nullptr;
   }
 
   PBackgroundChild* backgroundActor = BackgroundChild::GetForCurrentThread();
   MOZ_ASSERT(backgroundActor);
 
-  PBlobChild* blobActor =
-    BackgroundChild::GetOrCreateActorForBlob(backgroundActor, &aValue);
-  if (NS_WARN_IF(!blobActor)) {
+  IPCBlob ipcBlob;
+  nsresult rv =
+    IPCBlobUtils::Serialize(aValue.Impl(), backgroundActor, ipcBlob);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
     aRv.Throw(NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR);
     return nullptr;
   }
 
   FileRequestBlobData blobData;
-  blobData.blobChild() = blobActor;
+  blobData.blob() = ipcBlob;
 
   // Do nothing if the window is closed
   if (!CheckWindow()) {
     return nullptr;
   }
 
   return WriteInternal(blobData, dataLength, aAppend, aRv);
 }
--- a/dom/filehandle/PBackgroundFileHandle.ipdl
+++ b/dom/filehandle/PBackgroundFileHandle.ipdl
@@ -1,15 +1,20 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 include protocol PBackgroundFileRequest;
 include protocol PBackgroundMutableFile;
-include protocol PBlob;
+include protocol PChildToParentStream; // FIXME: bug 792908
+include protocol PFileDescriptorSet; // FIXME: bug 792908
+include protocol PIPCBlobInputStream; // FIXME: bug 792908
+include protocol PParentToChildStream; // FIXME: bug 792908
+
+include IPCBlob;
 
 namespace mozilla {
 namespace dom {
 
 struct FileRequestGetMetadataParams
 {
   bool size;
   bool lastModified;
@@ -23,17 +28,17 @@ struct FileRequestReadParams
 
 struct FileRequestStringData
 {
   nsCString string;
 };
 
 struct FileRequestBlobData
 {
-  PBlob blob;
+  IPCBlob blob;
 };
 
 union FileRequestData
 {
   FileRequestStringData;
   FileRequestBlobData;
 };
 
--- a/dom/filehandle/PBackgroundFileRequest.ipdl
+++ b/dom/filehandle/PBackgroundFileRequest.ipdl
@@ -1,14 +1,14 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 include protocol PBackgroundFileHandle;
-include protocol PBlob;
+include protocol PPendingIPCBlob;
 
 using struct mozilla::void_t
   from "ipc/IPCMessageUtils.h";
 
 namespace mozilla {
 namespace dom {
 
 union FileRequestSize
@@ -48,17 +48,17 @@ struct FileRequestTruncateResponse
 };
 
 struct FileRequestFlushResponse
 {
 };
 
 struct FileRequestGetFileResponse
 {
-  PBlob file;
+  PPendingIPCBlob file;
   FileRequestMetadata metadata;
 };
 
 union FileRequestResponse
 {
   nsresult;
   FileRequestGetMetadataResponse;
   FileRequestReadResponse;