Bug 1113062 - Part 2: ArchiveReaderZipFile non-CCed. r=smaug, a=sledru
authorAndrea Marchesini <amarchesini@mozilla.com>
Sun, 11 Jan 2015 21:34:57 +0000
changeset 242852 f203230f49f4
parent 242851 23f5b373f676
child 242853 962ac9efa80c
push id4321
push userryanvm@gmail.com
push date2015-01-14 15:04 +0000
treeherdermozilla-beta@a78eb4dd84f0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, sledru
bugs1113062
milestone36.0
Bug 1113062 - Part 2: ArchiveReaderZipFile non-CCed. r=smaug, a=sledru
dom/archivereader/ArchiveReader.cpp
dom/archivereader/ArchiveReader.h
dom/archivereader/ArchiveZipEvent.cpp
dom/archivereader/ArchiveZipFile.cpp
dom/archivereader/ArchiveZipFile.h
--- a/dom/archivereader/ArchiveReader.cpp
+++ b/dom/archivereader/ArchiveReader.cpp
@@ -43,17 +43,17 @@ ArchiveReader::Constructor(const GlobalO
 
   nsRefPtr<ArchiveReader> reader =
     new ArchiveReader(aBlob, window, encoding);
   return reader.forget();
 }
 
 ArchiveReader::ArchiveReader(File& aBlob, nsPIDOMWindow* aWindow,
                              const nsACString& aEncoding)
-  : mBlob(&aBlob)
+  : mFileImpl(aBlob.Impl())
   , mWindow(aWindow)
   , mStatus(NOT_STARTED)
   , mEncoding(aEncoding)
 {
   MOZ_ASSERT(aWindow);
 }
 
 ArchiveReader::~ArchiveReader()
@@ -90,27 +90,27 @@ ArchiveReader::RegisterRequest(ArchiveRe
   return NS_OK;
 }
 
 // This returns the input stream
 nsresult
 ArchiveReader::GetInputStream(nsIInputStream** aInputStream)
 {
   // Getting the input stream
-  mBlob->GetInternalStream(aInputStream);
+  mFileImpl->GetInternalStream(aInputStream);
   NS_ENSURE_TRUE(*aInputStream, NS_ERROR_UNEXPECTED);
   return NS_OK;
 }
 
 nsresult
 ArchiveReader::GetSize(uint64_t* aSize)
 {
-  nsresult rv = mBlob->GetSize(aSize);
-  NS_ENSURE_SUCCESS(rv, rv);
-  return NS_OK;
+  ErrorResult rv;
+  *aSize = mFileImpl->GetSize(rv);
+  return rv.ErrorCode();
 }
 
 // Here we open the archive:
 nsresult
 ArchiveReader::OpenArchive()
 {
   mStatus = WORKING;
   nsresult rv;
@@ -194,17 +194,17 @@ ArchiveReader::GetFiles()
 already_AddRefed<ArchiveRequest>
 ArchiveReader::GenerateArchiveRequest()
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
   return ArchiveRequest::Create(mWindow, this);
 }
 
 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(ArchiveReader,
-                                      mBlob,
+                                      mFileImpl,
                                       mWindow,
                                       mData.fileList,
                                       mRequests)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ArchiveReader)
   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
   NS_INTERFACE_MAP_ENTRY(nsISupports)
 NS_INTERFACE_MAP_END
--- a/dom/archivereader/ArchiveReader.h
+++ b/dom/archivereader/ArchiveReader.h
@@ -15,16 +15,17 @@
 #include "nsIChannel.h"
 #include "nsIDOMFile.h"
 #include "mozilla/Attributes.h"
 
 namespace mozilla {
 namespace dom {
 struct ArchiveReaderOptions;
 class File;
+class FileImpl;
 class GlobalObject;
 } // namespace dom
 } // namespace mozilla
 
 BEGIN_ARCHIVEREADER_NAMESPACE
 
 class ArchiveRequest;
 
@@ -44,44 +45,50 @@ public:
 
   ArchiveReader(File& aBlob, nsPIDOMWindow* aWindow,
                 const nsACString& aEncoding);
 
   nsIDOMWindow* GetParentObject() const
   {
     return mWindow;
   }
+
   virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
 
   already_AddRefed<ArchiveRequest> GetFilenames();
   already_AddRefed<ArchiveRequest> GetFile(const nsAString& filename);
   already_AddRefed<ArchiveRequest> GetFiles();
 
   nsresult GetInputStream(nsIInputStream** aInputStream);
   nsresult GetSize(uint64_t* aSize);
 
 public: // for the ArchiveRequest:
   nsresult RegisterRequest(ArchiveRequest* aRequest);
 
 public: // For events:
+  FileImpl* GetFileImpl() const
+  {
+    return mFileImpl;
+  }
+
   void Ready(nsTArray<nsCOMPtr<nsIDOMFile> >& aFileList,
              nsresult aStatus);
 
 private:
   ~ArchiveReader();
 
   already_AddRefed<ArchiveRequest> GenerateArchiveRequest();
 
   nsresult OpenArchive();
 
   void RequestReady(ArchiveRequest* aRequest);
 
 protected:
   // The archive blob/file
-  nsRefPtr<File> mBlob;
+  nsRefPtr<FileImpl> mFileImpl;
 
   // The window is needed by the requests
   nsCOMPtr<nsPIDOMWindow> mWindow;
 
   // Are we ready to return data?
   enum {
     NOT_STARTED = 0,
     WORKING,
--- a/dom/archivereader/ArchiveZipEvent.cpp
+++ b/dom/archivereader/ArchiveZipEvent.cpp
@@ -83,17 +83,17 @@ ArchiveZipItem::File(ArchiveReader* aArc
   if (NS_FAILED(GetFilename(filename))) {
     return nullptr;
   }
 
   return new dom::File(aArchiveReader,
     new ArchiveZipFileImpl(filename,
                            NS_ConvertUTF8toUTF16(GetType()),
                            StrToInt32(mCentralStruct.orglen),
-                           mCentralStruct, aArchiveReader));
+                           mCentralStruct, aArchiveReader->GetFileImpl()));
 }
 
 uint32_t
 ArchiveZipItem::StrToInt32(const uint8_t* aStr)
 {
   return (uint32_t)( (aStr [0] <<  0) |
                      (aStr [1] <<  8) |
                      (aStr [2] << 16) |
--- a/dom/archivereader/ArchiveZipFile.cpp
+++ b/dom/archivereader/ArchiveZipFile.cpp
@@ -357,57 +357,45 @@ ArchiveInputStream::SetEOF()
 
 nsresult
 ArchiveZipFileImpl::GetInternalStream(nsIInputStream** aStream)
 {
   if (mLength > INT32_MAX) {
     return NS_ERROR_FAILURE;
   }
 
-  uint64_t size;
-  nsresult rv = mArchiveReader->GetSize(&size);
-  NS_ENSURE_SUCCESS(rv, rv);
+  ErrorResult rv;
+  uint64_t size = mFileImpl->GetSize(rv);
+  if (NS_WARN_IF(rv.Failed())) {
+    return rv.ErrorCode();
+  }
 
   nsCOMPtr<nsIInputStream> inputStream;
-  rv = mArchiveReader->GetInputStream(getter_AddRefs(inputStream));
-  if (NS_FAILED(rv) || !inputStream) {
+  rv = mFileImpl->GetInternalStream(getter_AddRefs(inputStream));
+  if (NS_WARN_IF(rv.Failed()) || !inputStream) {
     return NS_ERROR_UNEXPECTED;
   }
 
   nsRefPtr<ArchiveInputStream> stream = new ArchiveInputStream(size,
                                                                inputStream,
                                                                mFilename,
                                                                mStart,
                                                                mLength,
                                                                mCentral);
   NS_ADDREF(stream);
 
   *aStream = stream;
   return NS_OK;
 }
 
-void
-ArchiveZipFileImpl::Unlink()
-{
-  ArchiveZipFileImpl* tmp = this;
-  NS_IMPL_CYCLE_COLLECTION_UNLINK(mArchiveReader);
-}
-
-void
-ArchiveZipFileImpl::Traverse(nsCycleCollectionTraversalCallback &cb)
-{
-  ArchiveZipFileImpl* tmp = this;
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mArchiveReader);
-}
-
 already_AddRefed<mozilla::dom::FileImpl>
 ArchiveZipFileImpl::CreateSlice(uint64_t aStart,
                                 uint64_t aLength,
                                 const nsAString& aContentType,
                                 mozilla::ErrorResult& aRv)
 {
   nsRefPtr<FileImpl> impl =
     new ArchiveZipFileImpl(mFilename, mContentType, aStart, mLength, mCentral,
-                           mArchiveReader);
+                           mFileImpl);
   return impl.forget();
 }
 
 NS_IMPL_ISUPPORTS_INHERITED0(ArchiveZipFileImpl, FileImpl)
--- a/dom/archivereader/ArchiveZipFile.h
+++ b/dom/archivereader/ArchiveZipFile.h
@@ -25,64 +25,55 @@ class ArchiveZipFileImpl : public FileIm
 {
 public:
   NS_DECL_ISUPPORTS_INHERITED
 
   ArchiveZipFileImpl(const nsAString& aName,
                      const nsAString& aContentType,
                      uint64_t aLength,
                      ZipCentral& aCentral,
-                     ArchiveReader* aReader)
+                     FileImpl* aFileImpl)
   : FileImplBase(aName, aContentType, aLength),
     mCentral(aCentral),
-    mArchiveReader(aReader),
+    mFileImpl(aFileImpl),
     mFilename(aName)
   {
-    NS_ASSERTION(mArchiveReader, "must have a reader");
+    MOZ_ASSERT(mFileImpl);
     MOZ_COUNT_CTOR(ArchiveZipFileImpl);
   }
 
   ArchiveZipFileImpl(const nsAString& aName,
                      const nsAString& aContentType,
                      uint64_t aStart,
                      uint64_t aLength,
                      ZipCentral& aCentral,
-                     ArchiveReader* aReader)
+                     FileImpl* aFileImpl)
   : FileImplBase(aContentType, aStart, aLength),
     mCentral(aCentral),
-    mArchiveReader(aReader),
+    mFileImpl(aFileImpl),
     mFilename(aName)
   {
-    NS_ASSERTION(mArchiveReader, "must have a reader");
+    MOZ_ASSERT(mFileImpl);
     MOZ_COUNT_CTOR(ArchiveZipFileImpl);
   }
 
   // Overrides:
   virtual nsresult GetInternalStream(nsIInputStream**) MOZ_OVERRIDE;
-
-  virtual void Unlink() MOZ_OVERRIDE;
-  virtual void Traverse(nsCycleCollectionTraversalCallback &aCb) MOZ_OVERRIDE;
-
-  virtual bool IsCCed() const MOZ_OVERRIDE
-  {
-    return true;
-  }
-
 protected:
   virtual ~ArchiveZipFileImpl()
   {
     MOZ_COUNT_DTOR(ArchiveZipFileImpl);
   }
 
   virtual already_AddRefed<FileImpl>
   CreateSlice(uint64_t aStart, uint64_t aLength, const nsAString& aContentType,
               mozilla::ErrorResult& aRv) MOZ_OVERRIDE;
 
 private: // Data
   ZipCentral mCentral;
-  nsRefPtr<ArchiveReader> mArchiveReader;
+  nsRefPtr<FileImpl> mFileImpl;
 
   nsString mFilename;
 };
 
 END_ARCHIVEREADER_NAMESPACE
 
 #endif // mozilla_dom_archivereader_domarchivefile_h__