Bug 1487113 - Use CloseWithStatus in ScriptLoader.cpp to indicate failure (r=baku)
authorLuke Wagner <luke@mozilla.com>
Mon, 04 Mar 2019 19:35:41 -0600
changeset 520203 bd4cd4017fd48b359d44c1436f2cde8bfa714924
parent 520202 dfeea1a4375a8c70d1700f9a2a4bad3fd0e1397e
child 520204 c59f0f40e0f6995c2bf70499e783afc7626cab96
child 520217 27986829a1604fbbdcdaf8fbfb2ab7f8f1310bc0
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1487113
milestone67.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 1487113 - Use CloseWithStatus in ScriptLoader.cpp to indicate failure (r=baku)
dom/script/ScriptLoader.cpp
netwerk/base/nsICacheInfoChannel.idl
netwerk/cache2/CacheEntry.cpp
netwerk/cache2/CacheEntry.h
netwerk/cache2/CacheFile.cpp
netwerk/cache2/CacheFile.h
netwerk/cache2/OldWrappers.h
netwerk/cache2/nsICacheEntry.idl
netwerk/ipc/NeckoParent.cpp
netwerk/protocol/http/HttpChannelChild.cpp
netwerk/protocol/http/HttpChannelParent.cpp
netwerk/protocol/http/HttpChannelParent.h
netwerk/protocol/http/InterceptedHttpChannel.cpp
netwerk/protocol/http/nsHttpChannel.cpp
--- a/dom/script/ScriptLoader.cpp
+++ b/dom/script/ScriptLoader.cpp
@@ -65,17 +65,17 @@
 #include "mozilla/LoadInfo.h"
 
 #include "mozilla/AsyncEventDispatcher.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/Telemetry.h"
 #include "mozilla/TimeStamp.h"
 #include "mozilla/Unused.h"
 #include "nsIScriptError.h"
-#include "nsIOutputStream.h"
+#include "nsIAsyncOutputStream.h"
 
 using JS::SourceText;
 
 using mozilla::Telemetry::LABELS_DOM_SCRIPT_PRELOAD_RESULT;
 
 namespace mozilla {
 namespace dom {
 
@@ -2865,30 +2865,31 @@ void ScriptLoader::EncodeRequestBytecode
          "correctly.",
          aRequest));
     return;
   }
 
   // Open the output stream to the cache entry alternate data storage. This
   // might fail if the stream is already open by another request, in which
   // case, we just ignore the current one.
-  nsCOMPtr<nsIOutputStream> output;
+  nsCOMPtr<nsIAsyncOutputStream> output;
   rv = aRequest->mCacheInfo->OpenAlternativeOutputStream(
       nsContentUtils::JSBytecodeMimeType(), aRequest->mScriptBytecode.length(),
       getter_AddRefs(output));
   if (NS_FAILED(rv)) {
     LOG(
         ("ScriptLoadRequest (%p): Cannot open bytecode cache (rv = %X, output "
          "= %p)",
          aRequest, unsigned(rv), output.get()));
     return;
   }
   MOZ_ASSERT(output);
+
   auto closeOutStream = mozilla::MakeScopeExit([&]() {
-    nsresult rv = output->Close();
+    rv = output->CloseWithStatus(rv);
     LOG(("ScriptLoadRequest (%p): Closing (rv = %X)", aRequest, unsigned(rv)));
   });
 
   uint32_t n;
   rv = output->Write(reinterpret_cast<char*>(aRequest->mScriptBytecode.begin()),
                      aRequest->mScriptBytecode.length(), &n);
   LOG((
       "ScriptLoadRequest (%p): Write bytecode cache (rv = %X, length = %u, "
--- a/netwerk/base/nsICacheInfoChannel.idl
+++ b/netwerk/base/nsICacheInfoChannel.idl
@@ -1,15 +1,15 @@
 /* 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 "nsISupports.idl"
 
-interface nsIOutputStream;
+interface nsIAsyncOutputStream;
 interface nsIInputStream;
 
 %{C++
 namespace mozilla {
 namespace net {
 class PreferredAlternativeDataTypeParams;
 }
 } // namespace mozilla
@@ -145,20 +145,23 @@ interface nsICacheInfoChannel : nsISuppo
   void getOriginalInputStream(in nsIInputStreamReceiver aReceiver);
 
   /**
    * Opens and returns an output stream that a consumer may use to save an
    * alternate representation of the data.
    * Must be called after the OnStopRequest that delivered the real data.
    * The consumer may choose to replace the saved alt representation.
    * Opening the output stream will fail if there are any open input streams
-   * reading the already saved alt representation.
+   * reading the already saved alt representation. After successfully opening
+   * an output stream, if there is an error before the entire alt data can be
+   * written successfully, the client must signal failure by passing an error
+   * code to CloseWithStatus().
    *
    * @param type
    *        type of the alternative data representation
    * @param predictedSize
    *        Predicted size of the data that will be written. It's used to decide
    *        whether the resulting entry would exceed size limit, in which case
    *        an error is thrown. If the size isn't known in advance, -1 should be
    *        passed.
    */
-  nsIOutputStream openAlternativeOutputStream(in ACString type, in long long predictedSize);
+  nsIAsyncOutputStream openAlternativeOutputStream(in ACString type, in long long predictedSize);
 };
--- a/netwerk/cache2/CacheEntry.cpp
+++ b/netwerk/cache2/CacheEntry.cpp
@@ -1218,19 +1218,19 @@ nsresult CacheEntry::OpenOutputStream(in
   if (mState < READY) mState = READY;
 
   // Invoke any pending readers now.
   InvokeCallbacks();
 
   return NS_OK;
 }
 
-nsresult CacheEntry::OpenAlternativeOutputStream(const nsACString &type,
-                                                 int64_t predictedSize,
-                                                 nsIOutputStream **_retval) {
+nsresult CacheEntry::OpenAlternativeOutputStream(
+    const nsACString &type, int64_t predictedSize,
+    nsIAsyncOutputStream **_retval) {
   LOG(("CacheEntry::OpenAlternativeOutputStream [this=%p, type=%s]", this,
        PromiseFlatCString(type).get()));
 
   nsresult rv;
 
   if (type.IsEmpty()) {
     // The empty string is reserved to mean no alt-data available.
     return NS_ERROR_INVALID_ARG;
@@ -1243,17 +1243,17 @@ nsresult CacheEntry::OpenAlternativeOutp
     return NS_ERROR_NOT_AVAILABLE;
   }
 
   if (mFile->EntryWouldExceedLimit(0, predictedSize, true)) {
     LOG(("  entry would exceed size limit"));
     return NS_ERROR_FILE_TOO_BIG;
   }
 
-  nsCOMPtr<nsIOutputStream> stream;
+  nsCOMPtr<nsIAsyncOutputStream> stream;
   rv = mFile->OpenAlternativeOutputStream(
       nullptr, PromiseFlatCString(type).get(), getter_AddRefs(stream));
   NS_ENSURE_SUCCESS(rv, rv);
 
   stream.swap(*_retval);
   return NS_OK;
 }
 
--- a/netwerk/cache2/CacheEntry.h
+++ b/netwerk/cache2/CacheEntry.h
@@ -89,17 +89,17 @@ class CacheEntry final : public nsIRunna
   nsresult SetValid(void);
   nsresult GetDiskStorageSizeInKB(uint32_t *aDiskStorageSizeInKB);
   nsresult Recreate(bool aMemoryOnly, nsICacheEntry **_retval);
   nsresult GetDataSize(int64_t *aDataSize);
   nsresult GetAltDataSize(int64_t *aAltDataSize);
   nsresult GetAltDataType(nsACString &aAltDataType);
   nsresult OpenAlternativeOutputStream(const nsACString &type,
                                        int64_t predictedSize,
-                                       nsIOutputStream **_retval);
+                                       nsIAsyncOutputStream **_retval);
   nsresult OpenAlternativeInputStream(const nsACString &type,
                                       nsIInputStream **_retval);
   nsresult GetLoadContextInfo(nsILoadContextInfo **aLoadContextInfo);
   nsresult Close(void);
   nsresult MarkValid(void);
   nsresult MaybeMarkValid(void);
   nsresult HasWriteAccess(bool aWriteAllowed, bool *_retval);
 
@@ -511,19 +511,19 @@ class CacheEntryHandle final : public ns
     return mEntry->GetDataSize(aDataSize);
   }
   NS_IMETHOD GetAltDataSize(int64_t *aAltDataSize) override {
     return mEntry->GetAltDataSize(aAltDataSize);
   }
   NS_IMETHOD GetAltDataType(nsACString &aType) override {
     return mEntry->GetAltDataType(aType);
   }
-  NS_IMETHOD OpenAlternativeOutputStream(const nsACString &type,
-                                         int64_t predictedSize,
-                                         nsIOutputStream **_retval) override {
+  NS_IMETHOD OpenAlternativeOutputStream(
+      const nsACString &type, int64_t predictedSize,
+      nsIAsyncOutputStream **_retval) override {
     return mEntry->OpenAlternativeOutputStream(type, predictedSize, _retval);
   }
   NS_IMETHOD OpenAlternativeInputStream(const nsACString &type,
                                         nsIInputStream **_retval) override {
     return mEntry->OpenAlternativeInputStream(type, _retval);
   }
   NS_IMETHOD GetLoadContextInfo(
       nsILoadContextInfo **aLoadContextInfo) override {
--- a/netwerk/cache2/CacheFile.cpp
+++ b/netwerk/cache2/CacheFile.cpp
@@ -897,17 +897,17 @@ nsresult CacheFile::OpenOutputStream(Cac
 
   mDataAccessed = true;
   NS_ADDREF(*_retval = mOutput);
   return NS_OK;
 }
 
 nsresult CacheFile::OpenAlternativeOutputStream(
     CacheOutputCloseListener *aCloseListener, const char *aAltDataType,
-    nsIOutputStream **_retval) {
+    nsIAsyncOutputStream **_retval) {
   CacheFileAutoLock lock(this);
 
   MOZ_ASSERT(mHandle || mMemoryOnly || mOpeningFile);
 
   if (!mReady) {
     LOG(
         ("CacheFile::OpenAlternativeOutputStream() - CacheFile is not ready "
          "[this=%p]",
--- a/netwerk/cache2/CacheFile.h
+++ b/netwerk/cache2/CacheFile.h
@@ -76,17 +76,17 @@ class CacheFile final : public CacheFile
                              nsIInputStream **_retval);
   NS_IMETHOD OpenAlternativeInputStream(nsICacheEntry *aCacheEntryHandle,
                                         const char *aAltDataType,
                                         nsIInputStream **_retval);
   NS_IMETHOD OpenOutputStream(CacheOutputCloseListener *aCloseListener,
                               nsIOutputStream **_retval);
   NS_IMETHOD OpenAlternativeOutputStream(
       CacheOutputCloseListener *aCloseListener, const char *aAltDataType,
-      nsIOutputStream **_retval);
+      nsIAsyncOutputStream **_retval);
   NS_IMETHOD SetMemoryOnly();
   NS_IMETHOD Doom(CacheFileListener *aCallback);
 
   void Kill() { mKill = true; }
   nsresult ThrowMemoryCachedData();
 
   nsresult GetAltDataSize(int64_t *aSize);
   nsresult GetAltDataType(nsACString &aType);
--- a/netwerk/cache2/OldWrappers.h
+++ b/netwerk/cache2/OldWrappers.h
@@ -37,19 +37,19 @@ class _OldCacheEntryWrapper : public nsI
   nsresult OpenInputStream(uint32_t offset, nsIInputStream **_retval) {
     return !mOldDesc ? NS_ERROR_NULL_POINTER
                      : mOldDesc->OpenInputStream(offset, _retval);
   }
   nsresult OpenOutputStream(uint32_t offset, nsIOutputStream **_retval) {
     return !mOldDesc ? NS_ERROR_NULL_POINTER
                      : mOldDesc->OpenOutputStream(offset, _retval);
   }
-  NS_IMETHOD OpenAlternativeOutputStream(const nsACString &type,
-                                         int64_t predictedSize,
-                                         nsIOutputStream **_retval) override {
+  NS_IMETHOD OpenAlternativeOutputStream(
+      const nsACString &type, int64_t predictedSize,
+      nsIAsyncOutputStream **_retval) override {
     return NS_ERROR_NOT_IMPLEMENTED;
   }
   NS_IMETHOD OpenAlternativeInputStream(const nsACString &type,
                                         nsIInputStream **_retval) override {
     return NS_ERROR_NOT_IMPLEMENTED;
   }
 
   NS_IMETHOD GetSecurityInfo(nsISupports **aSecurityInfo) override {
--- a/netwerk/cache2/nsICacheEntry.idl
+++ b/netwerk/cache2/nsICacheEntry.idl
@@ -2,16 +2,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 "nsISupports.idl"
 #include "nsICache.idl"
 
 interface nsIInputStream;
 interface nsIOutputStream;
+interface nsIAsyncOutputStream;
 interface nsICacheEntryDoomCallback;
 
 interface nsICacheListener;
 interface nsIFile;
 interface nsICacheEntryMetaDataVisitor;
 interface nsILoadContextInfo;
 
 [scriptable, uuid(607c2a2c-0a48-40b9-a956-8cf2bb9857cf)]
@@ -260,17 +261,17 @@ interface nsICacheEntry : nsISupports
    *
    * @throws
    *    - NS_ERROR_NOT_AVAILABLE if the real data hasn't been written.
    *    - NS_ERROR_IN_PROGRESS when the writing regular content or alt-data to
    *      the cache entry is still in progress.
    *
    * If there is alt-data already saved, it will be overwritten.
    */
-  nsIOutputStream openAlternativeOutputStream(in ACString type, in long long predictedSize);
+  nsIAsyncOutputStream openAlternativeOutputStream(in ACString type, in long long predictedSize);
 
   /**
    * Opens and returns an input stream that can be used to read the alternative
    * representation previously saved in the cache.
    * If this call is made while writing alt-data is still in progress, it is
    * still possible to read content from the input stream as it's being written.
    * @throws
    *    - NS_ERROR_NOT_AVAILABLE if the alt-data representation doesn't exist at
--- a/netwerk/ipc/NeckoParent.cpp
+++ b/netwerk/ipc/NeckoParent.cpp
@@ -352,17 +352,17 @@ bool NeckoParent::DeallocPWebrtcProxyCha
 #endif
   return true;
 }
 
 PAltDataOutputStreamParent* NeckoParent::AllocPAltDataOutputStreamParent(
     const nsCString& type, const int64_t& predictedSize,
     PHttpChannelParent* channel) {
   HttpChannelParent* chan = static_cast<HttpChannelParent*>(channel);
-  nsCOMPtr<nsIOutputStream> stream;
+  nsCOMPtr<nsIAsyncOutputStream> stream;
   nsresult rv = chan->OpenAlternativeOutputStream(type, predictedSize,
                                                   getter_AddRefs(stream));
   AltDataOutputStreamParent* parent = new AltDataOutputStreamParent(stream);
   parent->AddRef();
   // If the return value was not NS_OK, the error code will be sent
   // asynchronously to the child, after receiving the first message.
   parent->SetError(rv);
   return parent;
--- a/netwerk/protocol/http/HttpChannelChild.cpp
+++ b/netwerk/protocol/http/HttpChannelChild.cpp
@@ -3071,17 +3071,17 @@ HttpChannelChild::GetAlternativeDataType
 
   aType = mAvailableCachedAltDataType;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 HttpChannelChild::OpenAlternativeOutputStream(const nsACString& aType,
                                               int64_t aPredictedSize,
-                                              nsIOutputStream** _retval) {
+                                              nsIAsyncOutputStream** _retval) {
   MOZ_ASSERT(NS_IsMainThread(), "Main thread only");
 
   if (mSynthesizedCacheInfo) {
     return mSynthesizedCacheInfo->OpenAlternativeOutputStream(
         aType, aPredictedSize, _retval);
   }
 
   if (!mIPCOpen) {
--- a/netwerk/protocol/http/HttpChannelParent.cpp
+++ b/netwerk/protocol/http/HttpChannelParent.cpp
@@ -2348,17 +2348,18 @@ void HttpChannelParent::NotifyDiversionF
   // DoSendDeleteSelf will need channel Id to remove the strong reference in
   // BackgroundChannelRegistrar if channel pairing is aborted.
   // Thus we need to keep mChannel until DoSendDeleteSelf is done.
   mParentListener = nullptr;
   mChannel = nullptr;
 }
 
 nsresult HttpChannelParent::OpenAlternativeOutputStream(
-    const nsACString& type, int64_t predictedSize, nsIOutputStream** _retval) {
+    const nsACString& type, int64_t predictedSize,
+    nsIAsyncOutputStream** _retval) {
   // We need to make sure the child does not call SendDocumentChannelCleanup()
   // before opening the altOutputStream, because that clears mCacheEntry.
   if (!mCacheEntry) {
     return NS_ERROR_NOT_AVAILABLE;
   }
   nsresult rv =
       mCacheEntry->OpenAlternativeOutputStream(type, predictedSize, _retval);
   if (NS_SUCCEEDED(rv)) {
--- a/netwerk/protocol/http/HttpChannelParent.h
+++ b/netwerk/protocol/http/HttpChannelParent.h
@@ -96,19 +96,19 @@ class HttpChannelParent final : public n
 
   // Forwarded to nsHttpChannel::SetApplyConversion.
   void SetApplyConversion(bool aApplyConversion) {
     if (mChannel) {
       mChannel->SetApplyConversion(aApplyConversion);
     }
   }
 
-  MOZ_MUST_USE nsresult OpenAlternativeOutputStream(const nsACString& type,
-                                                    int64_t predictedSize,
-                                                    nsIOutputStream** _retval);
+  MOZ_MUST_USE nsresult
+  OpenAlternativeOutputStream(const nsACString& type, int64_t predictedSize,
+                              nsIAsyncOutputStream** _retval);
 
   // Callbacks for each asynchronous tasks required in AsyncOpen
   // procedure, will call InvokeAsyncOpen when all the expected
   // tasks is finished successfully or when any failure happened.
   // @see mAsyncOpenBarrier.
   void TryInvokeAsyncOpen(nsresult aRv);
 
   void InvokeAsyncOpen(nsresult rv);
--- a/netwerk/protocol/http/InterceptedHttpChannel.cpp
+++ b/netwerk/protocol/http/InterceptedHttpChannel.cpp
@@ -1260,19 +1260,19 @@ NS_IMETHODIMP
 InterceptedHttpChannel::GetAlternativeDataType(nsACString& aType) {
   if (mSynthesizedCacheInfo) {
     return mSynthesizedCacheInfo->GetAlternativeDataType(aType);
   }
   return NS_ERROR_NOT_AVAILABLE;
 }
 
 NS_IMETHODIMP
-InterceptedHttpChannel::OpenAlternativeOutputStream(const nsACString& type,
-                                                    int64_t predictedSize,
-                                                    nsIOutputStream** _retval) {
+InterceptedHttpChannel::OpenAlternativeOutputStream(
+    const nsACString& type, int64_t predictedSize,
+    nsIAsyncOutputStream** _retval) {
   if (mSynthesizedCacheInfo) {
     return mSynthesizedCacheInfo->OpenAlternativeOutputStream(
         type, predictedSize, _retval);
   }
   return NS_ERROR_NOT_AVAILABLE;
 }
 
 NS_IMETHODIMP
--- a/netwerk/protocol/http/nsHttpChannel.cpp
+++ b/netwerk/protocol/http/nsHttpChannel.cpp
@@ -8372,17 +8372,17 @@ nsHttpChannel::GetAlternativeDataType(ns
   }
   aType = mAvailableCachedAltDataType;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsHttpChannel::OpenAlternativeOutputStream(const nsACString &type,
                                            int64_t predictedSize,
-                                           nsIOutputStream **_retval) {
+                                           nsIAsyncOutputStream **_retval) {
   // OnStopRequest will clear mCacheEntry, but we may use mAltDataCacheEntry
   // if the consumer called PreferAlternativeDataType()
   nsCOMPtr<nsICacheEntry> cacheEntry =
       mCacheEntry ? mCacheEntry : mAltDataCacheEntry;
   if (!cacheEntry) {
     return NS_ERROR_NOT_AVAILABLE;
   }
   nsresult rv =