Bug 964561 - Part 1: Use a type in StructuredCloneFile instead of a boolean; r=asuth
authorJan Varga <jan.varga@gmail.com>
Tue, 25 Oct 2016 21:18:03 +0200
changeset 362293 12213ad49dc0e2af83b3c85722d0f11d650ef9d4
parent 362292 2a18e840e4b8ac08fffe201e678a98eb45e9f8b1
child 362294 e2166a89ee403fc89507026491e6bcfa8f461658
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-beta@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs964561
milestone52.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 964561 - Part 1: Use a type in StructuredCloneFile instead of a boolean; r=asuth
dom/indexedDB/ActorsChild.cpp
dom/indexedDB/ActorsParent.cpp
dom/indexedDB/IDBObjectStore.cpp
dom/indexedDB/IndexedDatabase.h
dom/indexedDB/IndexedDatabaseInlines.h
--- a/dom/indexedDB/ActorsChild.cpp
+++ b/dom/indexedDB/ActorsChild.cpp
@@ -614,32 +614,32 @@ ConvertActorsToBlobs(IDBDatabase* aDatab
 
           RefPtr<Blob> blob = Blob::Create(aDatabase->GetOwner(), blobImpl);
 
           aDatabase->NoteReceivedBlob(blob);
 
           StructuredCloneFile* file = aFiles.AppendElement();
           MOZ_ASSERT(file);
 
-          file->mMutable = false;
+          file->mType = StructuredCloneFile::eBlob;
           file->mBlob.swap(blob);
 
           break;
         }
 
         case BlobOrMutableFile::TNullableMutableFile: {
           const NullableMutableFile& nullableMutableFile =
             blobOrMutableFile.get_NullableMutableFile();
 
           switch (nullableMutableFile.type()) {
             case NullableMutableFile::Tnull_t: {
               StructuredCloneFile* file = aFiles.AppendElement();
               MOZ_ASSERT(file);
 
-              file->mMutable = true;
+              file->mType = StructuredCloneFile::eMutableFile;
 
               break;
             }
 
             case NullableMutableFile::TPBackgroundMutableFileChild: {
               auto* actor =
                 static_cast<BackgroundMutableFileChild*>(
                   nullableMutableFile.get_PBackgroundMutableFileChild());
@@ -649,17 +649,17 @@ ConvertActorsToBlobs(IDBDatabase* aDatab
 
               auto* mutableFile =
                 static_cast<IDBMutableFile*>(actor->GetDOMObject());
               MOZ_ASSERT(mutableFile);
 
               StructuredCloneFile* file = aFiles.AppendElement();
               MOZ_ASSERT(file);
 
-              file->mMutable = true;
+              file->mType = StructuredCloneFile::eMutableFile;
               file->mMutableFile = mutableFile;
 
               actor->ReleaseDOMObject();
 
               break;
             }
 
             default:
--- a/dom/indexedDB/ActorsParent.cpp
+++ b/dom/indexedDB/ActorsParent.cpp
@@ -8174,24 +8174,30 @@ private:
   GetResponse(RequestResponse& aResponse) override;
 
   virtual void
   Cleanup() override;
 };
 
 struct ObjectStoreAddOrPutRequestOp::StoredFileInfo final
 {
+  enum Type
+  {
+    eBlob,
+    eMutableFile,
+  };
+
   RefPtr<DatabaseFile> mFileActor;
   RefPtr<FileInfo> mFileInfo;
   nsCOMPtr<nsIInputStream> mInputStream;
-  bool mMutable;
+  Type mType;
   bool mCopiedSuccessfully;
 
   StoredFileInfo()
-    : mMutable(false)
+    : mType(eBlob)
     , mCopiedSuccessfully(false)
   {
     AssertIsOnBackgroundThread();
 
     MOZ_COUNT_CTOR(ObjectStoreAddOrPutRequestOp::StoredFileInfo);
   }
 
   ~StoredFileInfo()
@@ -9612,56 +9618,67 @@ ConvertBlobsToActors(PBackgroundParent* 
 
     MOZ_ASSERT(NS_SUCCEEDED(nativeFile->Exists(&exists)));
     MOZ_ASSERT(exists);
 
     DebugOnly<bool> isFile;
     MOZ_ASSERT(NS_SUCCEEDED(nativeFile->IsFile(&isFile)));
     MOZ_ASSERT(isFile);
 
-    if (file.mMutable) {
-      if (aDatabase->IsFileHandleDisabled()) {
-        MOZ_ALWAYS_TRUE(aActors.AppendElement(NullableMutableFile(null_t()),
-                                              fallible));
-      } else {
-        RefPtr<MutableFile> actor =
-          MutableFile::Create(nativeFile, aDatabase, file.mFileInfo);
+    switch (file.mType) {
+      case StructuredCloneFile::eBlob: {
+        RefPtr<BlobImpl> impl = new BlobImplStoredFile(nativeFile,
+                                                       file.mFileInfo,
+                                                       /* aSnapshot */ false);
+
+        PBlobParent* actor =
+          BackgroundParent::GetOrCreateActorForBlobImpl(aBackgroundActor, impl);
         if (!actor) {
-          IDB_REPORT_INTERNAL_ERR();
-          return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
-        }
-
-        // Transfer ownership to IPDL.
-        actor->SetActorAlive();
-
-        if (!aDatabase->SendPBackgroundMutableFileConstructor(actor,
-                                                              EmptyString(),
-                                                              EmptyString())) {
           // This can only fail if the child has crashed.
           IDB_REPORT_INTERNAL_ERR();
           return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
         }
 
-        MOZ_ALWAYS_TRUE(aActors.AppendElement(NullableMutableFile(actor),
-                                              fallible));
-      }
-    } else {
-      RefPtr<BlobImpl> impl = new BlobImplStoredFile(nativeFile,
-                                                       file.mFileInfo,
-                                                       /* aSnapshot */ false);
-
-      PBlobParent* actor =
-        BackgroundParent::GetOrCreateActorForBlobImpl(aBackgroundActor, impl);
-      if (!actor) {
-        // This can only fail if the child has crashed.
-        IDB_REPORT_INTERNAL_ERR();
-        return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
-      }
-
-      MOZ_ALWAYS_TRUE(aActors.AppendElement(actor, fallible));
+        MOZ_ALWAYS_TRUE(aActors.AppendElement(actor, fallible));
+
+        break;
+      }
+
+      case StructuredCloneFile::eMutableFile: {
+        if (aDatabase->IsFileHandleDisabled()) {
+          MOZ_ALWAYS_TRUE(aActors.AppendElement(NullableMutableFile(null_t()),
+                                                fallible));
+        } else {
+          RefPtr<MutableFile> actor =
+            MutableFile::Create(nativeFile, aDatabase, file.mFileInfo);
+          if (!actor) {
+            IDB_REPORT_INTERNAL_ERR();
+            return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
+          }
+
+          // Transfer ownership to IPDL.
+          actor->SetActorAlive();
+
+          if (!aDatabase->SendPBackgroundMutableFileConstructor(actor,
+                                                                EmptyString(),
+                                                                EmptyString())) {
+            // This can only fail if the child has crashed.
+            IDB_REPORT_INTERNAL_ERR();
+            return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
+          }
+
+          MOZ_ALWAYS_TRUE(aActors.AppendElement(NullableMutableFile(actor),
+                                                fallible));
+        }
+
+        break;
+      }
+
+      default:
+        MOZ_CRASH("Should never get here!");
     }
   }
 
   return NS_OK;
 }
 
 already_AddRefed<nsIFile>
 GetFileForFileInfo(FileInfo* aFileInfo)
@@ -18909,17 +18926,17 @@ UpgradeFileIdsFunction::OnFunctionCall(m
     StructuredCloneFile& file = cloneInfo.mFiles[index];
     MOZ_ASSERT(file.mFileInfo);
 
     const int64_t id = file.mFileInfo->Id();
 
     if (index) {
       fileIds.Append(' ');
     }
-    fileIds.AppendInt(file.mMutable ? -id : id);
+    fileIds.AppendInt(file.mType == StructuredCloneFile::eBlob ? id : -id);
   }
 
   nsCOMPtr<nsIVariant> result = new mozilla::storage::TextVariant(fileIds);
 
   result.forget(aResult);
   return NS_OK;
 }
 
@@ -19091,17 +19108,18 @@ DatabaseOperationBase::GetStructuredClon
       int64_t id = array[index];
       MOZ_ASSERT(id != 0);
 
       RefPtr<FileInfo> fileInfo = aFileManager->GetFileInfo(Abs(id));
       MOZ_ASSERT(fileInfo);
 
       StructuredCloneFile* file = aInfo->mFiles.AppendElement();
       file->mFileInfo.swap(fileInfo);
-      file->mMutable = id < 0;
+      file->mType = id > 0 ? StructuredCloneFile::eBlob
+                           : StructuredCloneFile::eMutableFile;
     }
   }
 
   return NS_OK;
 }
 
 // static
 nsresult
@@ -25332,29 +25350,31 @@ ObjectStoreAddOrPutRequestOp::Init(Trans
           storedFileInfo->mFileInfo = storedFileInfo->mFileActor->GetFileInfo();
           MOZ_ASSERT(storedFileInfo->mFileInfo);
 
           storedFileInfo->mInputStream =
             storedFileInfo->mFileActor->GetInputStream();
           if (storedFileInfo->mInputStream && !mFileManager) {
             mFileManager = fileManager;
           }
+
+          storedFileInfo->mType = StoredFileInfo::eBlob;
           break;
         }
 
         case DatabaseOrMutableFile::TPBackgroundMutableFileParent: {
           auto mutableFileActor =
             static_cast<MutableFile*>(
               file.get_PBackgroundMutableFileParent());
           MOZ_ASSERT(mutableFileActor);
 
           storedFileInfo->mFileInfo = mutableFileActor->GetFileInfo();
           MOZ_ASSERT(storedFileInfo->mFileInfo);
 
-          storedFileInfo->mMutable = true;
+          storedFileInfo->mType = StoredFileInfo::eMutableFile;
           break;
         }
 
         case DatabaseOrMutableFile::TPBackgroundIDBDatabaseFileChild:
         default:
           MOZ_CRASH("Should never get here!");
       }
     }
@@ -25682,17 +25702,18 @@ ObjectStoreAddOrPutRequestOp::DoDatabase
 
           storedFileInfo.mCopiedSuccessfully = true;
         }
       }
 
       if (index) {
         fileIds.Append(' ');
       }
-      fileIds.AppendInt(storedFileInfo.mMutable ? -id : id);
+      fileIds.AppendInt(storedFileInfo.mType == StoredFileInfo::eBlob ? id
+                                                                      : -id);
     }
 
     rv = stmt->BindStringByName(NS_LITERAL_CSTRING("file_ids"), fileIds);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
   } else {
     rv = stmt->BindNullByName(NS_LITERAL_CSTRING("file_ids"));
--- a/dom/indexedDB/IDBObjectStore.cpp
+++ b/dom/indexedDB/IDBObjectStore.cpp
@@ -548,17 +548,17 @@ class ValueDeserializationHelper
 public:
   static bool
   CreateAndWrapMutableFile(JSContext* aCx,
                            StructuredCloneFile& aFile,
                            const MutableFileData& aData,
                            JS::MutableHandle<JSObject*> aResult)
   {
     MOZ_ASSERT(aCx);
-    MOZ_ASSERT(aFile.mMutable);
+    MOZ_ASSERT(aFile.mType == StructuredCloneFile::eMutableFile);
 
     if (!aFile.mMutableFile || !NS_IsMainThread()) {
       return false;
     }
 
     if (NS_WARN_IF(!ResolveMysteryMutableFile(aFile.mMutableFile,
                                               aData.name,
                                               aData.type))) {
@@ -580,17 +580,17 @@ public:
                           StructuredCloneFile& aFile,
                           const BlobOrFileData& aData,
                           JS::MutableHandle<JSObject*> aResult)
   {
     MOZ_ASSERT(aCx);
     MOZ_ASSERT(aData.tag == SCTAG_DOM_FILE ||
                aData.tag == SCTAG_DOM_FILE_WITHOUT_LASTMODIFIEDDATE ||
                aData.tag == SCTAG_DOM_BLOB);
-    MOZ_ASSERT(!aFile.mMutable);
+    MOZ_ASSERT(aFile.mType == StructuredCloneFile::eBlob);
     MOZ_ASSERT(aFile.mBlob);
 
     // It can happen that this IDB is chrome code, so there is no parent, but
     // still we want to set a correct parent for the new File object.
     nsCOMPtr<nsISupports> parent;
     if (NS_IsMainThread()) {
       if (aDatabase && aDatabase->GetParentObject()) {
         parent = aDatabase->GetParentObject();
@@ -750,22 +750,22 @@ class UpgradeDeserializationHelper
 public:
   static bool
   CreateAndWrapMutableFile(JSContext* aCx,
                            StructuredCloneFile& aFile,
                            const MutableFileData& aData,
                            JS::MutableHandle<JSObject*> aResult)
   {
     MOZ_ASSERT(aCx);
-    MOZ_ASSERT(!aFile.mMutable);
+    MOZ_ASSERT(aFile.mType == StructuredCloneFile::eBlob);
 
-    aFile.mMutable = true;
+    aFile.mType = StructuredCloneFile::eMutableFile;
 
     // Just make a dummy object. The file_ids upgrade function is only
-    // interested in the |mMutable| flag.
+    // interested in the |mType| flag.
     JS::Rooted<JSObject*> obj(aCx, JS_NewPlainObject(aCx));
 
     if (NS_WARN_IF(!obj)) {
       return false;
     }
 
     aResult.set(obj);
     return true;
@@ -774,23 +774,23 @@ public:
   static bool
   CreateAndWrapBlobOrFile(JSContext* aCx,
                           IDBDatabase* aDatabase,
                           StructuredCloneFile& aFile,
                           const BlobOrFileData& aData,
                           JS::MutableHandle<JSObject*> aResult)
   {
     MOZ_ASSERT(aCx);
-    MOZ_ASSERT(!aFile.mMutable);
+    MOZ_ASSERT(aFile.mType == StructuredCloneFile::eBlob);
     MOZ_ASSERT(aData.tag == SCTAG_DOM_FILE ||
                aData.tag == SCTAG_DOM_FILE_WITHOUT_LASTMODIFIEDDATE ||
                aData.tag == SCTAG_DOM_BLOB);
 
     // Just make a dummy object. The file_ids upgrade function is only interested
-    // in the |mMutable| flag.
+    // in the |mType| flag.
     JS::Rooted<JSObject*> obj(aCx, JS_NewPlainObject(aCx));
 
     if (NS_WARN_IF(!obj)) {
       return false;
     }
 
     aResult.set(obj);
     return true;
--- a/dom/indexedDB/IndexedDatabase.h
+++ b/dom/indexedDB/IndexedDatabase.h
@@ -20,20 +20,25 @@ class IDBMutableFile;
 
 namespace indexedDB {
 
 class FileInfo;
 class SerializedStructuredCloneReadInfo;
 
 struct StructuredCloneFile
 {
+  enum Type {
+    eBlob,
+    eMutableFile,
+  };
+
   RefPtr<Blob> mBlob;
   RefPtr<IDBMutableFile> mMutableFile;
   RefPtr<FileInfo> mFileInfo;
-  bool mMutable;
+  Type mType;
 
   // In IndexedDatabaseInlines.h
   inline
   StructuredCloneFile();
 
   // In IndexedDatabaseInlines.h
   inline
   ~StructuredCloneFile();
--- a/dom/indexedDB/IndexedDatabaseInlines.h
+++ b/dom/indexedDB/IndexedDatabaseInlines.h
@@ -18,17 +18,17 @@
 #include "nsIInputStream.h"
 
 namespace mozilla {
 namespace dom {
 namespace indexedDB {
 
 inline
 StructuredCloneFile::StructuredCloneFile()
-  : mMutable(false)
+  : mType(eBlob)
 {
   MOZ_COUNT_CTOR(StructuredCloneFile);
 }
 
 inline
 StructuredCloneFile::~StructuredCloneFile()
 {
   MOZ_COUNT_DTOR(StructuredCloneFile);
@@ -36,17 +36,17 @@ StructuredCloneFile::~StructuredCloneFil
 
 inline
 bool
 StructuredCloneFile::operator==(const StructuredCloneFile& aOther) const
 {
   return this->mBlob == aOther.mBlob &&
          this->mMutableFile == aOther.mMutableFile &&
          this->mFileInfo == aOther.mFileInfo &&
-         this->mMutable == aOther.mMutable;
+         this->mType == aOther.mType;
 }
 
 inline
 StructuredCloneReadInfo::StructuredCloneReadInfo()
   : mDatabase(nullptr)
 {
   MOZ_COUNT_CTOR(StructuredCloneReadInfo);
 }