From 32bd9256f491eacbf556ca43e8ff8c47b3d8e80d Mon Sep 17 00:00:00 2001 From: Daniel Holbert Date: Mon, 14 Nov 2022 23:22:17 +0000 Subject: [PATCH] Bug 1800344 part 2: Fold nsSyncStreamListener::Create() into NS_NewSyncStreamListener(). r=necko-reviewers,kershaw While we're at it: remove one layer of unnecessary error handling in NS_NewSyncStreamListener, since it's clearer now that we'll be getting infallible allocation. Differential Revision: https://phabricator.services.mozilla.com/D161949 --- netwerk/base/nsNetUtil.cpp | 13 +++++-------- netwerk/base/nsSyncStreamListener.cpp | 10 +--------- netwerk/base/nsSyncStreamListener.h | 5 +++-- 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/netwerk/base/nsNetUtil.cpp b/netwerk/base/nsNetUtil.cpp index 5e09328ab183..fa111f5328a4 100644 --- a/netwerk/base/nsNetUtil.cpp +++ b/netwerk/base/nsNetUtil.cpp @@ -1041,15 +1041,12 @@ nsresult NS_NewStreamLoader( nsresult NS_NewSyncStreamListener(nsIStreamListener** result, nsIInputStream** stream) { - nsCOMPtr listener = nsSyncStreamListener::Create(); - if (listener) { - nsresult rv = listener->GetInputStream(stream); - if (NS_SUCCEEDED(rv)) { - listener.forget(result); - } - return rv; + nsCOMPtr listener = new nsSyncStreamListener(); + nsresult rv = listener->GetInputStream(stream); + if (NS_SUCCEEDED(rv)) { + listener.forget(result); } - return NS_ERROR_FAILURE; + return rv; } nsresult NS_ImplementChannelOpen(nsIChannel* channel, nsIInputStream** result) { diff --git a/netwerk/base/nsSyncStreamListener.cpp b/netwerk/base/nsSyncStreamListener.cpp index da8d2f996cbf..5b3f5613d122 100644 --- a/netwerk/base/nsSyncStreamListener.cpp +++ b/netwerk/base/nsSyncStreamListener.cpp @@ -12,21 +12,13 @@ using namespace mozilla::net; nsSyncStreamListener::nsSyncStreamListener() { + MOZ_ASSERT(NS_IsMainThread()); NS_NewPipe(getter_AddRefs(mPipeIn), getter_AddRefs(mPipeOut), mozilla::net::nsIOService::gDefaultSegmentSize, UINT32_MAX, // no size limit false, false); } -// NOTE: Next patch in this series will remove this. -// static -already_AddRefed nsSyncStreamListener::Create() { - MOZ_ASSERT(NS_IsMainThread()); - - RefPtr inst = new nsSyncStreamListener(); - return inst.forget(); -} - nsresult nsSyncStreamListener::WaitForData() { mKeepWaiting = true; diff --git a/netwerk/base/nsSyncStreamListener.h b/netwerk/base/nsSyncStreamListener.h index 60a7f015092b..9bd99085352a 100644 --- a/netwerk/base/nsSyncStreamListener.h +++ b/netwerk/base/nsSyncStreamListener.h @@ -22,9 +22,10 @@ class nsSyncStreamListener final : public nsISyncStreamListener, NS_DECL_NSISYNCSTREAMLISTENER NS_DECL_NSIINPUTSTREAM - static already_AddRefed Create(); - private: + // Factory method: + friend nsresult NS_NewSyncStreamListener(nsIStreamListener** result, + nsIInputStream** stream); nsSyncStreamListener(); ~nsSyncStreamListener() = default;