Bug 1361330 - Part 1: Make quota stream constructors public and move the Create() helpers outside of the stream classes; r=asuth
authorJan Varga <jan.varga@gmail.com>
Mon, 20 Aug 2018 14:32:33 +0200
changeset 487442 03dfadb39d50cfc6822a66435e003c0b8802f8b8
parent 487441 7a34cfe5e1962171bf56bdb9dd162e538dfefc95
child 487443 3ef89713c643aea9bda9f69a60a1b76995c762ae
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1361330
milestone63.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 1361330 - Part 1: Make quota stream constructors public and move the Create() helpers outside of the stream classes; r=asuth
dom/cache/FileUtils.cpp
dom/indexedDB/ActorsParent.cpp
dom/quota/FileStreams.cpp
dom/quota/FileStreams.h
dom/quota/StorageManager.cpp
--- a/dom/cache/FileUtils.cpp
+++ b/dom/cache/FileUtils.cpp
@@ -179,18 +179,18 @@ BodyStartWriteStream(const QuotaInfo& aQ
   rv = BodyIdToFile(aBaseDir, *aIdOut, BODY_FILE_TMP, getter_AddRefs(tmpFile));
   if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
 
   rv = tmpFile->Exists(&exists);
   if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
   if (NS_WARN_IF(exists)) { return NS_ERROR_FILE_ALREADY_EXISTS; }
 
   nsCOMPtr<nsIOutputStream> fileStream =
-    FileOutputStream::Create(PERSISTENCE_TYPE_DEFAULT, aQuotaInfo.mGroup,
-                             aQuotaInfo.mOrigin, tmpFile);
+    CreateFileOutputStream(PERSISTENCE_TYPE_DEFAULT, aQuotaInfo.mGroup,
+                           aQuotaInfo.mOrigin, tmpFile);
   if (NS_WARN_IF(!fileStream)) { return NS_ERROR_UNEXPECTED; }
 
   RefPtr<SnappyCompressOutputStream> compressed =
     new SnappyCompressOutputStream(fileStream);
 
   nsCOMPtr<nsIEventTarget> target =
     do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
 
@@ -258,18 +258,18 @@ BodyOpen(const QuotaInfo& aQuotaInfo, ns
   if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
 
   bool exists;
   rv = finalFile->Exists(&exists);
   if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
   if (NS_WARN_IF(!exists)) { return NS_ERROR_FILE_NOT_FOUND; }
 
   nsCOMPtr<nsIInputStream> fileStream =
-    FileInputStream::Create(PERSISTENCE_TYPE_DEFAULT, aQuotaInfo.mGroup,
-                            aQuotaInfo.mOrigin, finalFile);
+    CreateFileInputStream(PERSISTENCE_TYPE_DEFAULT, aQuotaInfo.mGroup,
+                          aQuotaInfo.mOrigin, finalFile);
   if (NS_WARN_IF(!fileStream)) { return NS_ERROR_UNEXPECTED; }
 
   fileStream.forget(aStreamOut);
 
   return rv;
 }
 
 // static
--- a/dom/indexedDB/ActorsParent.cpp
+++ b/dom/indexedDB/ActorsParent.cpp
@@ -20415,24 +20415,24 @@ MutableFile::CreateStream(bool aReadOnly
   PersistenceType persistenceType = mDatabase->Type();
   const nsACString& group = mDatabase->Group();
   const nsACString& origin = mDatabase->Origin();
 
   nsCOMPtr<nsISupports> result;
 
   if (aReadOnly) {
     RefPtr<FileInputStream> stream =
-      FileInputStream::Create(persistenceType, group, origin, mFile, -1, -1,
-                              nsIFileInputStream::DEFER_OPEN);
+      CreateFileInputStream(persistenceType, group, origin, mFile, -1, -1,
+                            nsIFileInputStream::DEFER_OPEN);
     result = NS_ISUPPORTS_CAST(nsIFileInputStream*, stream);
   }
   else {
     RefPtr<FileStream> stream =
-      FileStream::Create(persistenceType, group, origin, mFile, -1, -1,
-                         nsIFileStream::DEFER_OPEN);
+      CreateFileStream(persistenceType, group, origin, mFile, -1, -1,
+                       nsIFileStream::DEFER_OPEN);
     result = NS_ISUPPORTS_CAST(nsIFileStream*, stream);
   }
   if (NS_WARN_IF(!result)) {
     return nullptr;
   }
 
   return result.forget();
 }
@@ -29082,20 +29082,20 @@ FileHelper::CreateFileFromStream(nsIFile
   // Create a journal file first.
   rv = aJournalFile->Create(nsIFile::NORMAL_FILE_TYPE, 0644);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // Now try to copy the stream.
   RefPtr<FileOutputStream> fileOutputStream =
-    FileOutputStream::Create(mFileManager->Type(),
-                             mFileManager->Group(),
-                             mFileManager->Origin(),
-                             aFile);
+    CreateFileOutputStream(mFileManager->Type(),
+                           mFileManager->Group(),
+                           mFileManager->Origin(),
+                           aFile);
   if (NS_WARN_IF(!fileOutputStream)) {
     return NS_ERROR_FAILURE;
   }
 
   if (aCompress) {
     RefPtr<SnappyCompressOutputStream> snappyOutputStream =
       new SnappyCompressOutputStream(fileOutputStream);
 
--- a/dom/quota/FileStreams.cpp
+++ b/dom/quota/FileStreams.cpp
@@ -4,17 +4,17 @@
  * 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 "FileStreams.h"
 
 #include "QuotaManager.h"
 #include "prio.h"
 
-USING_QUOTA_NAMESPACE
+BEGIN_QUOTA_NAMESPACE
 
 template <class FileStreamBase>
 NS_IMETHODIMP
 FileQuotaStream<FileStreamBase>::SetEOF()
 {
   nsresult rv = FileStreamBase::SetEOF();
   NS_ENSURE_SUCCESS(rv, rv);
 
@@ -86,44 +86,56 @@ FileQuotaStreamWithWrite<FileStreamBase>
 
   rv = FileStreamBase::Write(aBuf, aCount, _retval);
   NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
 }
 
 already_AddRefed<FileInputStream>
-FileInputStream::Create(PersistenceType aPersistenceType,
-                        const nsACString& aGroup, const nsACString& aOrigin,
-                        nsIFile* aFile, int32_t aIOFlags, int32_t aPerm,
-                        int32_t aBehaviorFlags)
+CreateFileInputStream(PersistenceType aPersistenceType,
+                      const nsACString& aGroup,
+                      const nsACString& aOrigin,
+                      nsIFile* aFile,
+                      int32_t aIOFlags,
+                      int32_t aPerm,
+                      int32_t aBehaviorFlags)
 {
   RefPtr<FileInputStream> stream =
     new FileInputStream(aPersistenceType, aGroup, aOrigin);
   nsresult rv = stream->Init(aFile, aIOFlags, aPerm, aBehaviorFlags);
   NS_ENSURE_SUCCESS(rv, nullptr);
   return stream.forget();
 }
 
 already_AddRefed<FileOutputStream>
-FileOutputStream::Create(PersistenceType aPersistenceType,
-                         const nsACString& aGroup, const nsACString& aOrigin,
-                         nsIFile* aFile, int32_t aIOFlags, int32_t aPerm,
-                         int32_t aBehaviorFlags)
+CreateFileOutputStream(PersistenceType aPersistenceType,
+                       const nsACString& aGroup,
+                       const nsACString& aOrigin,
+                       nsIFile* aFile,
+                       int32_t aIOFlags,
+                       int32_t aPerm,
+                       int32_t aBehaviorFlags)
 {
   RefPtr<FileOutputStream> stream =
     new FileOutputStream(aPersistenceType, aGroup, aOrigin);
   nsresult rv = stream->Init(aFile, aIOFlags, aPerm, aBehaviorFlags);
   NS_ENSURE_SUCCESS(rv, nullptr);
   return stream.forget();
 }
 
 already_AddRefed<FileStream>
-FileStream::Create(PersistenceType aPersistenceType, const nsACString& aGroup,
-                   const nsACString& aOrigin, nsIFile* aFile, int32_t aIOFlags,
-                   int32_t aPerm, int32_t aBehaviorFlags)
+CreateFileStream(PersistenceType aPersistenceType,
+                 const nsACString& aGroup,
+                 const nsACString& aOrigin,
+                 nsIFile* aFile,
+                 int32_t aIOFlags,
+                 int32_t aPerm,
+                 int32_t aBehaviorFlags)
 {
   RefPtr<FileStream> stream =
     new FileStream(aPersistenceType, aGroup, aOrigin);
   nsresult rv = stream->Init(aFile, aIOFlags, aPerm, aBehaviorFlags);
   NS_ENSURE_SUCCESS(rv, nullptr);
   return stream.forget();
 }
+
+END_QUOTA_NAMESPACE
--- a/dom/quota/FileStreams.h
+++ b/dom/quota/FileStreams.h
@@ -59,72 +59,84 @@ protected:
 };
 
 class FileInputStream : public FileQuotaStream<nsFileInputStream>
 {
 public:
   NS_INLINE_DECL_REFCOUNTING_INHERITED(FileInputStream,
                                        FileQuotaStream<nsFileInputStream>)
 
-  static already_AddRefed<FileInputStream>
-  Create(PersistenceType aPersistenceType, const nsACString& aGroup,
-         const nsACString& aOrigin, nsIFile* aFile, int32_t aIOFlags = -1,
-         int32_t aPerm = -1, int32_t aBehaviorFlags = 0);
-
-private:
   FileInputStream(PersistenceType aPersistenceType, const nsACString& aGroup,
                   const nsACString& aOrigin)
   : FileQuotaStream<nsFileInputStream>(aPersistenceType, aGroup, aOrigin)
   { }
 
+private:
   virtual ~FileInputStream() {
     Close();
   }
 };
 
 class FileOutputStream : public FileQuotaStreamWithWrite<nsFileOutputStream>
 {
 public:
   NS_INLINE_DECL_REFCOUNTING_INHERITED(FileOutputStream,
                                        FileQuotaStreamWithWrite<nsFileOutputStream>);
 
-  static already_AddRefed<FileOutputStream>
-  Create(PersistenceType aPersistenceType, const nsACString& aGroup,
-         const nsACString& aOrigin, nsIFile* aFile, int32_t aIOFlags = -1,
-         int32_t aPerm = -1, int32_t aBehaviorFlags = 0);
-
-private:
   FileOutputStream(PersistenceType aPersistenceType, const nsACString& aGroup,
                    const nsACString& aOrigin)
   : FileQuotaStreamWithWrite<nsFileOutputStream>(aPersistenceType, aGroup,
                                                  aOrigin)
   { }
 
+private:
   virtual ~FileOutputStream() {
     Close();
   }
 };
 
 class FileStream : public FileQuotaStreamWithWrite<nsFileStream>
 {
 public:
   NS_INLINE_DECL_REFCOUNTING_INHERITED(FileStream,
                                        FileQuotaStreamWithWrite<nsFileStream>)
 
-  static already_AddRefed<FileStream>
-  Create(PersistenceType aPersistenceType, const nsACString& aGroup,
-         const nsACString& aOrigin, nsIFile* aFile, int32_t aIOFlags = -1,
-         int32_t aPerm = -1, int32_t aBehaviorFlags = 0);
-
-private:
   FileStream(PersistenceType aPersistenceType, const nsACString& aGroup,
              const nsACString& aOrigin)
   : FileQuotaStreamWithWrite<nsFileStream>(aPersistenceType, aGroup, aOrigin)
   { }
 
+private:
   virtual ~FileStream() {
     Close();
   }
 };
 
+already_AddRefed<FileInputStream>
+CreateFileInputStream(PersistenceType aPersistenceType,
+                      const nsACString& aGroup,
+                      const nsACString& aOrigin,
+                      nsIFile* aFile,
+                      int32_t aIOFlags = -1,
+                      int32_t aPerm = -1,
+                      int32_t aBehaviorFlags = 0);
+
+already_AddRefed<FileOutputStream>
+CreateFileOutputStream(PersistenceType aPersistenceType,
+                       const nsACString& aGroup,
+                       const nsACString& aOrigin,
+                       nsIFile* aFile,
+                       int32_t aIOFlags = -1,
+                       int32_t aPerm = -1,
+                       int32_t aBehaviorFlags = 0);
+
+already_AddRefed<FileStream>
+CreateFileStream(PersistenceType aPersistenceType,
+                 const nsACString& aGroup,
+                 const nsACString& aOrigin,
+                 nsIFile* aFile,
+                 int32_t aIOFlags = -1,
+                 int32_t aPerm = -1,
+                 int32_t aBehaviorFlags = 0);
+
 END_QUOTA_NAMESPACE
 
 #endif /* mozilla_dom_quota_filestreams_h__ */
--- a/dom/quota/StorageManager.cpp
+++ b/dom/quota/StorageManager.cpp
@@ -14,16 +14,18 @@
 #include "mozilla/ErrorResult.h"
 #include "mozilla/EventStateManager.h"
 #include "mozilla/Telemetry.h"
 #include "nsContentPermissionHelper.h"
 #include "nsIQuotaCallbacks.h"
 #include "nsIQuotaRequests.h"
 #include "nsPIDOMWindow.h"
 
+using namespace mozilla::dom::quota;
+
 namespace mozilla {
 namespace dom {
 
 namespace {
 
 // This class is used to get quota usage, request persist and check persisted
 // status callbacks.
 class RequestResolver final