Bug 1501404 - Part 7: Remove the XPCOM registration for nsSyncStreamListener r=valentin
authorEhsan Akhgari <ehsan@mozilla.com>
Tue, 23 Oct 2018 20:07:29 +0000
changeset 442630 89474459aeb8d21854d18c26822069d94625ea16
parent 442629 1766ed669623dd83d791586c65a65a5a7d1097c0
child 442631 d826438ea26dc82c57ab98156b7ed84eb2354362
push id34916
push useraiakab@mozilla.com
push dateWed, 24 Oct 2018 04:14:42 +0000
treeherdermozilla-central@e61ca916da32 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvalentin
bugs1501404
milestone65.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 1501404 - Part 7: Remove the XPCOM registration for nsSyncStreamListener r=valentin Depends on D9575 Differential Revision: https://phabricator.services.mozilla.com/D9576
netwerk/base/nsNetUtil.cpp
netwerk/base/nsSyncStreamListener.cpp
netwerk/base/nsSyncStreamListener.h
netwerk/build/nsNetCID.h
netwerk/build/nsNetModule.cpp
--- a/netwerk/base/nsNetUtil.cpp
+++ b/netwerk/base/nsNetUtil.cpp
@@ -55,17 +55,17 @@
 #include "nsISimpleStreamListener.h"
 #include "nsISocketProvider.h"
 #include "nsISocketProviderService.h"
 #include "nsIStandardURL.h"
 #include "nsIStreamLoader.h"
 #include "nsIIncrementalStreamLoader.h"
 #include "nsIStreamTransportService.h"
 #include "nsStringStream.h"
-#include "nsISyncStreamListener.h"
+#include "nsSyncStreamListener.h"
 #include "nsITransport.h"
 #include "nsIURIWithSpecialOrigin.h"
 #include "nsIURLParser.h"
 #include "nsIUUIDGenerator.h"
 #include "nsIViewSourceChannel.h"
 #include "nsInterfaceRequestorAgg.h"
 #include "plstr.h"
 #include "nsINestedURI.h"
@@ -1181,26 +1181,25 @@ NS_NewStreamLoader(nsIStreamLoader      
                                     aLoadFlags,
                                     aReferrer);
 }
 
 nsresult
 NS_NewSyncStreamListener(nsIStreamListener **result,
                          nsIInputStream    **stream)
 {
-    nsresult rv;
-    nsCOMPtr<nsISyncStreamListener> listener =
-        do_CreateInstance(NS_SYNCSTREAMLISTENER_CONTRACTID, &rv);
-    if (NS_SUCCEEDED(rv)) {
-        rv = listener->GetInputStream(stream);
+    nsCOMPtr<nsISyncStreamListener> listener = nsSyncStreamListener::Create();
+    if (listener) {
+        nsresult rv = listener->GetInputStream(stream);
         if (NS_SUCCEEDED(rv)) {
             listener.forget(result);
         }
+        return rv;
     }
-    return rv;
+    return NS_ERROR_FAILURE;
 }
 
 nsresult
 NS_ImplementChannelOpen(nsIChannel      *channel,
                         nsIInputStream **result)
 {
     nsCOMPtr<nsIStreamListener> listener;
     nsCOMPtr<nsIInputStream> stream;
--- a/netwerk/base/nsSyncStreamListener.cpp
+++ b/netwerk/base/nsSyncStreamListener.cpp
@@ -16,16 +16,29 @@ nsSyncStreamListener::Init()
     return NS_NewPipe(getter_AddRefs(mPipeIn),
                       getter_AddRefs(mPipeOut),
                       mozilla::net::nsIOService::gDefaultSegmentSize,
                       UINT32_MAX, // no size limit
                       false,
                       false);
 }
 
+// static
+already_AddRefed<nsISyncStreamListener>
+nsSyncStreamListener::Create()
+{
+  MOZ_ASSERT(NS_IsMainThread());
+
+  RefPtr<nsSyncStreamListener> inst = new nsSyncStreamListener();
+  nsresult rv = inst->Init();
+  NS_ENSURE_SUCCESS(rv, nullptr);
+
+  return inst.forget();
+}
+
 nsresult
 nsSyncStreamListener::WaitForData()
 {
     mKeepWaiting = true;
 
     if (!mozilla::SpinEventLoopUntil([&]() { return !mKeepWaiting; })) {
       return NS_ERROR_FAILURE;
     }
--- a/netwerk/base/nsSyncStreamListener.h
+++ b/netwerk/base/nsSyncStreamListener.h
@@ -18,26 +18,27 @@ class nsSyncStreamListener final : publi
 {
 public:
     NS_DECL_ISUPPORTS
     NS_DECL_NSIREQUESTOBSERVER
     NS_DECL_NSISTREAMLISTENER
     NS_DECL_NSISYNCSTREAMLISTENER
     NS_DECL_NSIINPUTSTREAM
 
+    static already_AddRefed<nsISyncStreamListener> Create();
+
+private:
     nsSyncStreamListener()
         : mStatus(NS_OK)
         , mKeepWaiting(false)
         , mDone(false) {}
+    ~nsSyncStreamListener() = default;
 
     nsresult Init();
 
-private:
-    ~nsSyncStreamListener() = default;
-
     nsresult WaitForData();
 
     nsCOMPtr<nsIInputStream>    mPipeIn;
     nsCOMPtr<nsIOutputStream>   mPipeOut;
     nsresult                    mStatus;
     bool                        mKeepWaiting;
     bool                        mDone;
 };
--- a/netwerk/build/nsNetCID.h
+++ b/netwerk/build/nsNetCID.h
@@ -289,27 +289,16 @@
 #define NS_BACKGROUNDFILESAVERSTREAMLISTENER_CID \
 { /* 208de7fc-a781-4031-bbae-cc0de539f61a */         \
     0x208de7fc,                                      \
     0xa781,                                          \
     0x4031,                                          \
     {0xbb, 0xae, 0xcc, 0x0d, 0xe5, 0x39, 0xf6, 0x1a} \
 }
 
-// component implementing nsISyncStreamListener.
-#define NS_SYNCSTREAMLISTENER_CONTRACTID \
-    "@mozilla.org/network/sync-stream-listener;1"
-#define NS_SYNCSTREAMLISTENER_CID \
-{ /* 439400d3-6f23-43db-8b06-8aafe1869bd8 */         \
-    0x439400d3,                                      \
-    0x6f23,                                          \
-    0x43db,                                          \
-    {0x8b, 0x06, 0x8a, 0xaf, 0xe1, 0x86, 0x9b, 0xd8} \
-}
-
 // component implementing nsIIncrementalDownload.
 #define NS_INCREMENTALDOWNLOAD_CONTRACTID \
     "@mozilla.org/network/incremental-download;1"
 
 // component implementing nsISystemProxySettings.
 #define NS_SYSTEMPROXYSETTINGS_CONTRACTID \
     "@mozilla.org/system-proxy-settings;1"
 
--- a/netwerk/build/nsNetModule.cpp
+++ b/netwerk/build/nsNetModule.cpp
@@ -102,19 +102,16 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsDownloa
 #include "BackgroundFileSaver.h"
 namespace mozilla {
 namespace net {
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(BackgroundFileSaverOutputStream, Init)
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(BackgroundFileSaverStreamListener, Init)
 } // namespace net
 } // namespace mozilla
 
-#include "nsSyncStreamListener.h"
-NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsSyncStreamListener, Init)
-
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsAtomicFileOutputStream)
 
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsSafeFileOutputStream)
 
 typedef mozilla::net::nsLoadGroup nsLoadGroup;
 NS_GENERIC_AGGREGATED_CONSTRUCTOR_INIT(nsLoadGroup, Init)
 
 #include "ArrayBufferInputStream.h"
@@ -652,17 +649,16 @@ NS_DEFINE_NAMED_CID(NS_SIMPLENESTEDURIMU
 NS_DEFINE_NAMED_CID(NS_ASYNCSTREAMCOPIER_CID);
 NS_DEFINE_NAMED_CID(NS_INPUTSTREAMPUMP_CID);
 NS_DEFINE_NAMED_CID(NS_INPUTSTREAMCHANNEL_CID);
 NS_DEFINE_NAMED_CID(NS_STREAMLOADER_CID);
 NS_DEFINE_NAMED_CID(NS_INCREMENTALSTREAMLOADER_CID);
 NS_DEFINE_NAMED_CID(NS_DOWNLOADER_CID);
 NS_DEFINE_NAMED_CID(NS_BACKGROUNDFILESAVEROUTPUTSTREAM_CID);
 NS_DEFINE_NAMED_CID(NS_BACKGROUNDFILESAVERSTREAMLISTENER_CID);
-NS_DEFINE_NAMED_CID(NS_SYNCSTREAMLISTENER_CID);
 NS_DEFINE_NAMED_CID(NS_SIMPLESTREAMLISTENER_CID);
 NS_DEFINE_NAMED_CID(NS_STREAMLISTENERTEE_CID);
 NS_DEFINE_NAMED_CID(NS_LOADGROUP_CID);
 NS_DEFINE_NAMED_CID(NS_LOCALFILEINPUTSTREAM_CID);
 NS_DEFINE_NAMED_CID(NS_LOCALFILEOUTPUTSTREAM_CID);
 NS_DEFINE_NAMED_CID(NS_ATOMICLOCALFILEOUTPUTSTREAM_CID);
 NS_DEFINE_NAMED_CID(NS_SAFELOCALFILEOUTPUTSTREAM_CID);
 NS_DEFINE_NAMED_CID(NS_INCREMENTALDOWNLOAD_CID);
@@ -762,17 +758,16 @@ static const mozilla::Module::CIDEntry k
     { &kNS_INPUTSTREAMCHANNEL_CID, false, nullptr, nsInputStreamChannelConstructor },
     { &kNS_STREAMLOADER_CID, false, nullptr, mozilla::net::nsStreamLoader::Create },
     { &kNS_INCREMENTALSTREAMLOADER_CID, false, nullptr, nsIncrementalStreamLoader::Create },
     { &kNS_DOWNLOADER_CID, false, nullptr, nsDownloaderConstructor },
     { &kNS_BACKGROUNDFILESAVEROUTPUTSTREAM_CID, false, nullptr,
       mozilla::net::BackgroundFileSaverOutputStreamConstructor },
     { &kNS_BACKGROUNDFILESAVERSTREAMLISTENER_CID, false, nullptr,
       mozilla::net::BackgroundFileSaverStreamListenerConstructor },
-    { &kNS_SYNCSTREAMLISTENER_CID, false, nullptr, nsSyncStreamListenerConstructor },
     { &kNS_SIMPLESTREAMLISTENER_CID, false, nullptr, nsSimpleStreamListenerConstructor },
     { &kNS_STREAMLISTENERTEE_CID, false, nullptr, nsStreamListenerTeeConstructor },
     { &kNS_LOADGROUP_CID, false, nullptr, nsLoadGroupConstructor },
     { &kNS_LOCALFILEINPUTSTREAM_CID, false, nullptr, nsFileInputStream::Create },
     { &kNS_LOCALFILEOUTPUTSTREAM_CID, false, nullptr, nsFileOutputStream::Create },
     { &kNS_ATOMICLOCALFILEOUTPUTSTREAM_CID, false, nullptr, nsAtomicFileOutputStreamConstructor },
     { &kNS_SAFELOCALFILEOUTPUTSTREAM_CID, false, nullptr, nsSafeFileOutputStreamConstructor },
     { &kNS_INCREMENTALDOWNLOAD_CID, false, nullptr, net_NewIncrementalDownload },
@@ -873,17 +868,16 @@ static const mozilla::Module::ContractID
     { NS_ASYNCSTREAMCOPIER_CONTRACTID, &kNS_ASYNCSTREAMCOPIER_CID },
     { NS_INPUTSTREAMPUMP_CONTRACTID, &kNS_INPUTSTREAMPUMP_CID },
     { NS_INPUTSTREAMCHANNEL_CONTRACTID, &kNS_INPUTSTREAMCHANNEL_CID },
     { NS_STREAMLOADER_CONTRACTID, &kNS_STREAMLOADER_CID },
     { NS_INCREMENTALSTREAMLOADER_CONTRACTID, &kNS_INCREMENTALSTREAMLOADER_CID },
     { NS_DOWNLOADER_CONTRACTID, &kNS_DOWNLOADER_CID },
     { NS_BACKGROUNDFILESAVEROUTPUTSTREAM_CONTRACTID, &kNS_BACKGROUNDFILESAVEROUTPUTSTREAM_CID },
     { NS_BACKGROUNDFILESAVERSTREAMLISTENER_CONTRACTID, &kNS_BACKGROUNDFILESAVERSTREAMLISTENER_CID },
-    { NS_SYNCSTREAMLISTENER_CONTRACTID, &kNS_SYNCSTREAMLISTENER_CID },
     { NS_SIMPLESTREAMLISTENER_CONTRACTID, &kNS_SIMPLESTREAMLISTENER_CID },
     { NS_STREAMLISTENERTEE_CONTRACTID, &kNS_STREAMLISTENERTEE_CID },
     { NS_LOADGROUP_CONTRACTID, &kNS_LOADGROUP_CID },
     { NS_LOCALFILEINPUTSTREAM_CONTRACTID, &kNS_LOCALFILEINPUTSTREAM_CID },
     { NS_LOCALFILEOUTPUTSTREAM_CONTRACTID, &kNS_LOCALFILEOUTPUTSTREAM_CID },
     { NS_ATOMICLOCALFILEOUTPUTSTREAM_CONTRACTID, &kNS_ATOMICLOCALFILEOUTPUTSTREAM_CID },
     { NS_SAFELOCALFILEOUTPUTSTREAM_CONTRACTID, &kNS_SAFELOCALFILEOUTPUTSTREAM_CID },
     { NS_INCREMENTALDOWNLOAD_CONTRACTID, &kNS_INCREMENTALDOWNLOAD_CID },