From d26a1b29f5c93b8bb89dd4e76ef2780258e9e968 Mon Sep 17 00:00:00 2001 From: Kershaw Chang Date: Fri, 14 Mar 2025 09:43:48 +0000 Subject: [PATCH] Bug 1953331 - Generate WebTransport ID in a static function, r=jesup,necko-reviewers Differential Revision: https://phabricator.services.mozilla.com/D241288 --- netwerk/protocol/http/nsHttpChannel.cpp | 2 +- netwerk/protocol/http/nsHttpConnectionInfo.cpp | 9 +++++++++ netwerk/protocol/http/nsHttpConnectionInfo.h | 2 ++ netwerk/protocol/http/nsHttpConnectionMgr.h | 6 ------ 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/netwerk/protocol/http/nsHttpChannel.cpp b/netwerk/protocol/http/nsHttpChannel.cpp index a81ee8d17859..1cca0744878e 100644 --- a/netwerk/protocol/http/nsHttpChannel.cpp +++ b/netwerk/protocol/http/nsHttpChannel.cpp @@ -7005,7 +7005,7 @@ nsresult nsHttpChannel::BeginConnect() { wtconSettings->GetDedicated(&dedicated); if (dedicated) { connInfo->SetWebTransportId( - gHttpHandler->ConnMgr()->GenerateNewWebTransportId()); + nsHttpConnectionInfo::GenerateNewWebTransportId()); } } else { connInfo = new nsHttpConnectionInfo(host, port, ""_ns, mUsername, diff --git a/netwerk/protocol/http/nsHttpConnectionInfo.cpp b/netwerk/protocol/http/nsHttpConnectionInfo.cpp index 7e42c6b74ad9..1943fe4b2496 100644 --- a/netwerk/protocol/http/nsHttpConnectionInfo.cpp +++ b/netwerk/protocol/http/nsHttpConnectionInfo.cpp @@ -72,6 +72,15 @@ nsHttpConnectionInfo::nsHttpConnectionInfo( true, aIsHttp3, aWebTransport); } +// static +uint64_t nsHttpConnectionInfo::GenerateNewWebTransportId() { + // Used for generating unique IDSs for dedicated connections, currently used + // by WebTransport + MOZ_ASSERT(XRE_IsParentProcess()); + static Atomic id(0); + return ++id; +} + void nsHttpConnectionInfo::Init(const nsACString& host, int32_t port, const nsACString& npnToken, const nsACString& username, diff --git a/netwerk/protocol/http/nsHttpConnectionInfo.h b/netwerk/protocol/http/nsHttpConnectionInfo.h index f2fb38be6001..22b506424e38 100644 --- a/netwerk/protocol/http/nsHttpConnectionInfo.h +++ b/netwerk/protocol/http/nsHttpConnectionInfo.h @@ -276,6 +276,8 @@ class nsHttpConnectionInfo final : public ARefBase { void SetEchConfig(const nsACString& aEchConfig) { mEchConfig = aEchConfig; } const nsCString& GetEchConfig() const { return mEchConfig; } + static uint64_t GenerateNewWebTransportId(); + private: void Init(const nsACString& host, int32_t port, const nsACString& npnToken, const nsACString& username, nsProxyInfo* proxyInfo, diff --git a/netwerk/protocol/http/nsHttpConnectionMgr.h b/netwerk/protocol/http/nsHttpConnectionMgr.h index 8f7a2dc6b213..bd3408e7fb97 100644 --- a/netwerk/protocol/http/nsHttpConnectionMgr.h +++ b/netwerk/protocol/http/nsHttpConnectionMgr.h @@ -152,8 +152,6 @@ class nsHttpConnectionMgr final : public HttpConnectionMgrShell, const nsTArray>* GetServerCertHashes( nsHttpConnectionInfo* aConnInfo); - uint64_t GenerateNewWebTransportId() { return mMaxWebTransportId++; } - private: virtual ~nsHttpConnectionMgr(); @@ -471,10 +469,6 @@ class nsHttpConnectionMgr final : public HttpConnectionMgrShell, void NotifyConnectionOfBrowserIdChange(uint64_t previousId); void CheckTransInPendingQueue(nsHttpTransaction* aTrans); - - // Used for generating unique IDSs for dedicated connections, currently used - // by WebTransport - Atomic mMaxWebTransportId{1}; }; } // namespace mozilla::net