Bug 1485494 - Remove the XPCOM registration for RedirectChannelRegistrar; r=mayhemer

This commit is contained in:
Ehsan Akhgari 2018-08-22 00:37:28 -04:00
Родитель 7daebb448d
Коммит 9172f9d616
8 изменённых файлов: 46 добавлений и 30 удалений

Просмотреть файл

@ -3,10 +3,15 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "RedirectChannelRegistrar.h"
#include "mozilla/StaticPtr.h"
namespace mozilla {
namespace net {
namespace {
StaticRefPtr<RedirectChannelRegistrar> gSingleton;
}
NS_IMPL_ISUPPORTS(RedirectChannelRegistrar, nsIRedirectChannelRegistrar)
RedirectChannelRegistrar::RedirectChannelRegistrar()
@ -15,6 +20,26 @@ RedirectChannelRegistrar::RedirectChannelRegistrar()
, mId(1)
, mLock("RedirectChannelRegistrar")
{
MOZ_ASSERT(!gSingleton);
}
// static
already_AddRefed<nsIRedirectChannelRegistrar>
RedirectChannelRegistrar::GetOrCreate()
{
MOZ_ASSERT(NS_IsMainThread());
if (!gSingleton) {
gSingleton = new RedirectChannelRegistrar();
}
return do_AddRef(gSingleton);
}
// static
void
RedirectChannelRegistrar::Shutdown()
{
MOZ_ASSERT(NS_IsMainThread());
gSingleton = nullptr;
}
NS_IMETHODIMP

Просмотреть файл

@ -26,6 +26,13 @@ class RedirectChannelRegistrar final : public nsIRedirectChannelRegistrar
private:
~RedirectChannelRegistrar() = default;
public:
// Singleton accessor
static already_AddRefed<nsIRedirectChannelRegistrar> GetOrCreate();
// Cleanup the singleton instance on shutdown
static void Shutdown();
protected:
typedef nsInterfaceHashtable<nsUint32HashKey, nsIChannel>
ChannelHashtable;

Просмотреть файл

@ -176,6 +176,7 @@ EXPORTS.mozilla.net += [
'MemoryDownloader.h',
'PartiallySeekableInputStream.h',
'Predictor.h',
'RedirectChannelRegistrar.h',
'ReferrerPolicy.h',
'SimpleChannelParent.h',
'TCPFastOpen.h',

Просмотреть файл

@ -47,7 +47,7 @@
#include "nsIPrivateBrowsingChannel.h"
#include "nsIPropertyBag2.h"
#include "nsIProtocolProxyService.h"
#include "nsIRedirectChannelRegistrar.h"
#include "mozilla/net/RedirectChannelRegistrar.h"
#include "nsIRequestObserverProxy.h"
#include "nsIScriptSecurityManager.h"
#include "nsISensitiveInfoHiddenURI.h"
@ -2757,11 +2757,9 @@ NS_LinkRedirectChannels(uint32_t channelId,
nsIParentChannel *parentChannel,
nsIChannel **_result)
{
nsresult rv;
nsCOMPtr<nsIRedirectChannelRegistrar> registrar =
do_GetService("@mozilla.org/redirectchannelregistrar;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
RedirectChannelRegistrar::GetOrCreate();
MOZ_ASSERT(registrar);
return registrar->LinkChannels(channelId,
parentChannel,

Просмотреть файл

@ -474,17 +474,6 @@
#define NS_URICLASSIFIERSERVICE_CONTRACTID \
"@mozilla.org/uriclassifierservice"
// Redirect channel registrar used for redirect to various protocols
#define NS_REDIRECTCHANNELREGISTRAR_CONTRACTID \
"@mozilla.org/redirectchannelregistrar;1"
#define NS_REDIRECTCHANNELREGISTRAR_CID \
{ /* {b69043a6-8929-4d60-8d17-a27e44a8393e} */ \
0xb69043a6, \
0x8929, \
0x4d60, \
{ 0x8d, 0x17, 0xa2, 0x7e, 0x44, 0xa8, 0x39, 0x3e } \
}
// service implementing nsINetworkPredictor
#define NS_NETWORKPREDICTOR_CONTRACTID \
"@mozilla.org/network/predictor;1"

Просмотреть файл

@ -39,6 +39,7 @@
#include "Predictor.h"
#include "nsIThreadPool.h"
#include "mozilla/net/NeckoChild.h"
#include "RedirectChannelRegistrar.h"
#include "nsNetCID.h"
@ -131,10 +132,6 @@ NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsEffectiveTLDService, Init)
#include "nsSerializationHelper.h"
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSerializationHelper)
#include "RedirectChannelRegistrar.h"
typedef mozilla::net::RedirectChannelRegistrar RedirectChannelRegistrar;
NS_GENERIC_FACTORY_CONSTRUCTOR(RedirectChannelRegistrar)
#include "CacheStorageService.h"
typedef mozilla::net::CacheStorageService CacheStorageService;
NS_GENERIC_FACTORY_CONSTRUCTOR(CacheStorageService)
@ -652,6 +649,8 @@ static void nsNetShutdown()
mozilla::net::Http2CompressionCleanup();
mozilla::net::RedirectChannelRegistrar::Shutdown();
delete gNetSniffers;
gNetSniffers = nullptr;
delete gDataSniffers;
@ -768,7 +767,6 @@ NS_DEFINE_NAMED_CID(NS_NETWORK_LINK_SERVICE_CID);
NS_DEFINE_NAMED_CID(NS_NETWORK_LINK_SERVICE_CID);
#endif
NS_DEFINE_NAMED_CID(NS_SERIALIZATION_HELPER_CID);
NS_DEFINE_NAMED_CID(NS_REDIRECTCHANNELREGISTRAR_CID);
NS_DEFINE_NAMED_CID(NS_CACHE_STORAGE_SERVICE_CID);
NS_DEFINE_NAMED_CID(NS_NSILOADCONTEXTINFOFACTORY_CID);
NS_DEFINE_NAMED_CID(NS_NETWORKPREDICTOR_CID);
@ -893,7 +891,6 @@ static const mozilla::Module::CIDEntry kNeckoCIDs[] = {
{ &kNS_NETWORK_LINK_SERVICE_CID, false, nullptr, nsNotifyAddrListenerConstructor },
#endif
{ &kNS_SERIALIZATION_HELPER_CID, false, nullptr, nsSerializationHelperConstructor },
{ &kNS_REDIRECTCHANNELREGISTRAR_CID, false, nullptr, RedirectChannelRegistrarConstructor },
{ &kNS_CACHE_STORAGE_SERVICE_CID, false, nullptr, CacheStorageServiceConstructor },
{ &kNS_NSILOADCONTEXTINFOFACTORY_CID, false, nullptr, LoadContextInfoFactoryConstructor },
{ &kNS_NETWORKPREDICTOR_CID, false, nullptr, mozilla::net::Predictor::Create },
@ -1017,7 +1014,6 @@ static const mozilla::Module::ContractIDEntry kNeckoContracts[] = {
{ NS_NETWORK_LINK_SERVICE_CONTRACTID, &kNS_NETWORK_LINK_SERVICE_CID },
#endif
{ NS_SERIALIZATION_HELPER_CONTRACTID, &kNS_SERIALIZATION_HELPER_CID },
{ NS_REDIRECTCHANNELREGISTRAR_CONTRACTID, &kNS_REDIRECTCHANNELREGISTRAR_CID },
{ NS_CACHE_STORAGE_SERVICE_CONTRACTID, &kNS_CACHE_STORAGE_SERVICE_CID },
{ NS_CACHE_STORAGE_SERVICE_CONTRACTID2, &kNS_CACHE_STORAGE_SERVICE_CID },
{ NS_NSILOADCONTEXTINFOFACTORY_CONTRACTID, &kNS_NSILOADCONTEXTINFOFACTORY_CID },

Просмотреть файл

@ -45,7 +45,7 @@
#include "nsCORSListenerProxy.h"
#include "nsIIPCSerializableInputStream.h"
#include "nsIPrompt.h"
#include "nsIRedirectChannelRegistrar.h"
#include "mozilla/net/RedirectChannelRegistrar.h"
#include "nsIWindowWatcher.h"
#include "nsIDocument.h"
#include "nsStreamUtils.h"
@ -972,7 +972,7 @@ HttpChannelParent::RecvRedirect2Verify(const nsresult& aResult,
// Wait for background channel ready on target channel
nsCOMPtr<nsIRedirectChannelRegistrar> redirectReg =
do_GetService(NS_REDIRECTCHANNELREGISTRAR_CONTRACTID);
RedirectChannelRegistrar::GetOrCreate();
MOZ_ASSERT(redirectReg);
nsCOMPtr<nsIParentChannel> redirectParentChannel;

Просмотреть файл

@ -15,7 +15,7 @@
#include "nsIAuthPrompt.h"
#include "nsIAuthPrompt2.h"
#include "nsIHttpHeaderVisitor.h"
#include "nsIRedirectChannelRegistrar.h"
#include "mozilla/net/RedirectChannelRegistrar.h"
#include "nsIPromptFactory.h"
#include "nsIWindowWatcher.h"
#include "nsQueryObject.h"
@ -179,8 +179,8 @@ HttpChannelParentListener::AsyncOnChannelRedirect(
// Register the new channel and obtain id for it
nsCOMPtr<nsIRedirectChannelRegistrar> registrar =
do_GetService("@mozilla.org/redirectchannelregistrar;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
RedirectChannelRegistrar::GetOrCreate();
MOZ_ASSERT(registrar);
rv = registrar->RegisterChannel(newChannel, &mRedirectChannelId);
NS_ENSURE_SUCCESS(rv, rv);
@ -208,8 +208,8 @@ HttpChannelParentListener::OnRedirectResult(bool succeeded)
nsCOMPtr<nsIParentChannel> redirectChannel;
if (mRedirectChannelId) {
nsCOMPtr<nsIRedirectChannelRegistrar> registrar =
do_GetService("@mozilla.org/redirectchannelregistrar;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
RedirectChannelRegistrar::GetOrCreate();
MOZ_ASSERT(registrar);
rv = registrar->GetParentChannel(mRedirectChannelId,
getter_AddRefs(redirectChannel));