Bug 1501404 - Part 8: Remove the XPCOM registration for NamedPipeService r=valentin

Depends on D9576

Differential Revision: https://phabricator.services.mozilla.com/D9577

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Ehsan Akhgari 2018-10-23 20:07:31 +00:00
parent d0ee7e43f9
commit 488ca4192a
7 changed files with 39 additions and 41 deletions

View File

@ -776,18 +776,6 @@
{ 0x85, 0x44, 0x5a, 0x8d, 0x1a, 0xb7, 0x95, 0x37 } \
}
#ifdef XP_WIN
#define NS_NAMEDPIPESERVICE_CONTRACTID \
"@mozilla.org/network/named-pipe-service;1"
#define NS_NAMEDPIPESERVICE_CID \
{ \
0xae298cf9, \
0x91f4, \
0x4337, \
{ 0x95, 0x69, 0x61, 0x88, 0xb9, 0xd0, 0x21, 0x6e } \
}
#endif
/******************************************************************************
* netwerk/cookie classes
*/

View File

@ -252,15 +252,6 @@ namespace net {
} // namespace net
} // namespace mozilla
#ifdef XP_WIN
#include "../socket/nsNamedPipeService.h"
namespace mozilla {
namespace net {
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(NamedPipeService, Init)
} // namespace net
} // namespace mozilla
#endif
// resource
#include "nsResProtocolHandler.h"
#include "ExtensionProtocolHandler.h"
@ -673,9 +664,6 @@ NS_DEFINE_NAMED_CID(NS_BUFFEREDOUTPUTSTREAM_CID);
NS_DEFINE_NAMED_CID(NS_MIMEINPUTSTREAM_CID);
NS_DEFINE_NAMED_CID(NS_PROTOCOLPROXYSERVICE_CID);
NS_DEFINE_NAMED_CID(NS_STREAMCONVERTERSERVICE_CID);
#if defined(XP_WIN)
NS_DEFINE_NAMED_CID(NS_NAMEDPIPESERVICE_CID);
#endif
NS_DEFINE_NAMED_CID(NS_DASHBOARD_CID);
NS_DEFINE_NAMED_CID(NS_FTPDIRLISTINGCONVERTER_CID);
NS_DEFINE_NAMED_CID(NS_NSINDEXEDTOHTMLCONVERTER_CID);
@ -782,9 +770,6 @@ static const mozilla::Module::CIDEntry kNeckoCIDs[] = {
{ &kNS_MIMEINPUTSTREAM_CID, false, nullptr, nsMIMEInputStreamConstructor },
{ &kNS_PROTOCOLPROXYSERVICE_CID, true, nullptr, nsProtocolProxyServiceConstructor },
{ &kNS_STREAMCONVERTERSERVICE_CID, false, nullptr, CreateNewStreamConvServiceFactory },
#if defined (XP_WIN)
{ &kNS_NAMEDPIPESERVICE_CID, false, NULL, mozilla::net::NamedPipeServiceConstructor },
#endif
{ &kNS_DASHBOARD_CID, false, nullptr, mozilla::net::DashboardConstructor },
{ &kNS_FTPDIRLISTINGCONVERTER_CID, false, nullptr, CreateNewFTPDirListingConv },
{ &kNS_NSINDEXEDTOHTMLCONVERTER_CID, false, nullptr, nsIndexedToHTML::Create },
@ -891,9 +876,6 @@ static const mozilla::Module::ContractIDEntry kNeckoContracts[] = {
{ NS_MIMEINPUTSTREAM_CONTRACTID, &kNS_MIMEINPUTSTREAM_CID },
{ NS_PROTOCOLPROXYSERVICE_CONTRACTID, &kNS_PROTOCOLPROXYSERVICE_CID },
{ NS_STREAMCONVERTERSERVICE_CONTRACTID, &kNS_STREAMCONVERTERSERVICE_CID },
#if defined(XP_WIN)
{ NS_NAMEDPIPESERVICE_CONTRACTID, &kNS_NAMEDPIPESERVICE_CID },
#endif
{ NS_DASHBOARD_CONTRACTID, &kNS_DASHBOARD_CID },
{ NS_ISTREAMCONVERTER_KEY FTP_TO_INDEX, &kNS_FTPDIRLISTINGCONVERTER_CID },
{ NS_ISTREAMCONVERTER_KEY INDEX_TO_HTML, &kNS_NSINDEXEDTOHTMLCONVERTER_CID },

View File

@ -33,6 +33,9 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':
XPIDL_SOURCES += [
'nsINamedPipeService.idl',
]
EXPORTS += [
'nsNamedPipeService.h',
]
UNIFIED_SOURCES += [
'nsNamedPipeIOLayer.cpp',
'nsNamedPipeService.cpp'

View File

@ -12,7 +12,7 @@
#include "mozilla/net/DNS.h"
#include "mozilla/RefPtr.h"
#include "mozilla/Unused.h"
#include "nsINamedPipeService.h"
#include "nsNamedPipeService.h"
#include "nsISupportsImpl.h"
#include "nsIThread.h"
#include "nsNamedPipeIOLayer.h"
@ -166,7 +166,7 @@ NS_IMPL_ISUPPORTS(NamedPipeInfo,
nsINamedPipeDataObserver)
NamedPipeInfo::NamedPipeInfo()
: mNamedPipeService(do_GetService(NS_NAMEDPIPESERVICE_CONTRACTID))
: mNamedPipeService(NamedPipeService::GetOrCreate())
, mPipe(INVALID_HANDLE_VALUE)
, mReadBegin(0)
, mReadEnd(0)

View File

@ -10,6 +10,7 @@
#include "nsNamedPipeService.h"
#include "nsNetCID.h"
#include "nsThreadUtils.h"
#include "mozilla/ClearOnShutdown.h"
namespace mozilla {
namespace net {
@ -20,6 +21,8 @@ static mozilla::LazyLogModule gNamedPipeServiceLog("NamedPipeWin");
#define LOG_NPS_ERROR(...) \
MOZ_LOG(gNamedPipeServiceLog, mozilla::LogLevel::Error, (__VA_ARGS__))
StaticRefPtr<NamedPipeService> NamedPipeService::gSingleton;
NS_IMPL_ISUPPORTS(NamedPipeService,
nsINamedPipeService,
nsIObserver,
@ -83,6 +86,26 @@ NamedPipeService::Init()
return NS_OK;
}
// static
already_AddRefed<nsINamedPipeService>
NamedPipeService::GetOrCreate()
{
MOZ_ASSERT(NS_IsMainThread());
RefPtr<NamedPipeService> inst;
if (gSingleton) {
inst = gSingleton;
} else {
inst = new NamedPipeService();
nsresult rv = inst->Init();
NS_ENSURE_SUCCESS(rv, nullptr);
gSingleton = inst;
ClearOnShutdown(&gSingleton);
}
return inst.forget();
}
void
NamedPipeService::Shutdown()
{
@ -319,7 +342,5 @@ NamedPipeService::Run()
return NS_OK;
}
static NS_DEFINE_CID(kNamedPipeServiceCID, NS_NAMEDPIPESERVICE_CID);
} // namespace net
} // namespace mozilla

View File

@ -12,7 +12,9 @@
#include "nsINamedPipeService.h"
#include "nsIObserver.h"
#include "nsIRunnable.h"
#include "nsIThread.h"
#include "nsTArray.h"
#include "mozilla/StaticPtr.h"
namespace mozilla {
namespace net {
@ -27,12 +29,14 @@ public:
NS_DECL_NSIOBSERVER
NS_DECL_NSIRUNNABLE
static already_AddRefed<nsINamedPipeService> GetOrCreate();
private:
explicit NamedPipeService();
virtual ~NamedPipeService() = default;
nsresult Init();
private:
virtual ~NamedPipeService() = default;
void Shutdown();
void RemoveRetiredObjects();
@ -51,6 +55,8 @@ private:
nsTArray<nsCOMPtr<nsINamedPipeDataObserver>> mObservers; // protected by mLock
nsTArray<nsCOMPtr<nsINamedPipeDataObserver>> mRetiredObservers; // protected by mLock
nsTArray<HANDLE> mRetiredHandles; // protected by mLock
static StaticRefPtr<NamedPipeService> gSingleton;
};
} // namespace net

View File

@ -10,7 +10,7 @@
#include "mozilla/Atomics.h"
#include "mozilla/Monitor.h"
#include "nsINamedPipeService.h"
#include "nsNamedPipeService.h"
#include "nsNetCID.h"
#define PIPE_NAME "\\\\.\\pipe\\TestNPS"
@ -286,13 +286,11 @@ CreateNamedPipe(LPHANDLE aServer, LPHANDLE aClient)
TEST(TestNamedPipeService,Test)
{
nsresult rv;
nsCOMPtr<nsINamedPipeService> svc =
do_GetService(NS_NAMEDPIPESERVICE_CONTRACTID, &rv);
ASSERT_TRUE(NS_SUCCEEDED(rv));
net::NamedPipeService::GetOrCreate();
HANDLE readPipe, writePipe;
rv = CreateNamedPipe(&readPipe, &writePipe);
nsresult rv = CreateNamedPipe(&readPipe, &writePipe);
ASSERT_TRUE(NS_SUCCEEDED(rv));
RefPtr<nsNamedPipeDataObserver> readObserver =