Skip to content

Commit

Permalink
Bug 1504557 - Remove the XPCOM registration for nsErrorService r=froydnj
Browse files Browse the repository at this point in the history
Differential Revision: https://phabricator.services.mozilla.com/D10848

--HG--
extra : moz-landing-system : lando
  • Loading branch information
ehsan committed Nov 5, 2018
1 parent 3f93a1a commit e95c3cc
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 57 deletions.
18 changes: 6 additions & 12 deletions dom/xslt/xslt/txMozillaXSLTProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "nsThreadUtils.h"
#include "jsapi.h"
#include "txExprParser.h"
#include "nsIErrorService.h"
#include "nsErrorService.h"
#include "nsIScriptSecurityManager.h"
#include "nsJSUtils.h"
#include "nsIXPConnect.h"
Expand Down Expand Up @@ -1286,12 +1286,9 @@ txMozillaXSLTProcessor::Startup()
return NS_ERROR_OUT_OF_MEMORY;
}

nsCOMPtr<nsIErrorService> errorService =
do_GetService(NS_ERRORSERVICE_CONTRACTID);
if (errorService) {
errorService->RegisterErrorStringBundle(NS_ERROR_MODULE_XSLT,
XSLT_MSGS_URL);
}
nsCOMPtr<nsIErrorService> errorService = nsErrorService::GetOrCreate();
errorService->RegisterErrorStringBundle(NS_ERROR_MODULE_XSLT,
XSLT_MSGS_URL);

return NS_OK;
}
Expand All @@ -1302,11 +1299,8 @@ txMozillaXSLTProcessor::Shutdown()
{
txXSLTProcessor::shutdown();

nsCOMPtr<nsIErrorService> errorService =
do_GetService(NS_ERRORSERVICE_CONTRACTID);
if (errorService) {
errorService->UnregisterErrorStringBundle(NS_ERROR_MODULE_XSLT);
}
nsCOMPtr<nsIErrorService> errorService = nsErrorService::GetOrCreate();
errorService->UnregisterErrorStringBundle(NS_ERROR_MODULE_XSLT);
}

/* static*/
Expand Down
8 changes: 3 additions & 5 deletions intl/strres/nsStringBundle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "nsIObserverService.h"
#include "nsCOMArray.h"
#include "nsTextFormatter.h"
#include "nsIErrorService.h"
#include "nsErrorService.h"
#include "nsICategoryManager.h"
#include "nsContentUtils.h"
#include "nsPersistentProperties.h"
Expand Down Expand Up @@ -49,8 +49,6 @@ using mozilla::dom::ipc::SharedStringMap;
using mozilla::dom::ipc::SharedStringMapBuilder;
using mozilla::ipc::FileDescriptor;

static NS_DEFINE_CID(kErrorServiceCID, NS_ERRORSERVICE_CID);

/**
* A set of string bundle URLs which are loaded by content processes, and
* should be allocated in a shared memory region, and then sent to content
Expand Down Expand Up @@ -763,8 +761,8 @@ struct bundleCacheEntry_t final : public LinkedListElement<bundleCacheEntry_t> {
nsStringBundleService::nsStringBundleService() :
mBundleMap(MAX_CACHED_BUNDLES)
{
mErrorService = do_GetService(kErrorServiceCID);
NS_ASSERTION(mErrorService, "Couldn't get error service");
mErrorService = nsErrorService::GetOrCreate();
MOZ_ALWAYS_TRUE(mErrorService);
}

NS_IMPL_ISUPPORTS(nsStringBundleService,
Expand Down
11 changes: 4 additions & 7 deletions netwerk/base/nsIOService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "nscore.h"
#include "nsIURI.h"
#include "prprf.h"
#include "nsIErrorService.h"
#include "nsErrorService.h"
#include "netCore.h"
#include "nsIObserverService.h"
#include "nsIPrefService.h"
Expand Down Expand Up @@ -216,12 +216,9 @@ nsresult
nsIOService::Init()
{
// XXX hack until xpidl supports error info directly (bug 13423)
nsCOMPtr<nsIErrorService> errorService = do_GetService(NS_ERRORSERVICE_CONTRACTID);
if (errorService) {
errorService->RegisterErrorStringBundle(NS_ERROR_MODULE_NETWORK, NECKO_MSGS_URL);
}
else
NS_WARNING("failed to get error service");
nsCOMPtr<nsIErrorService> errorService = nsErrorService::GetOrCreate();
MOZ_ALWAYS_TRUE(errorService);
errorService->RegisterErrorStringBundle(NS_ERROR_MODULE_NETWORK, NECKO_MSGS_URL);

InitializeCaptivePortalService();

Expand Down
1 change: 1 addition & 0 deletions xpcom/base/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ EXPORTS += [
'nsDebugImpl.h',
'nsDumpUtils.h',
'nsError.h',
'nsErrorService.h',
'nsGZFileWriter.h',
'nsIClassInfoImpl.h',
'nsID.h',
Expand Down
27 changes: 20 additions & 7 deletions xpcom/base/nsErrorService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,31 @@
#include "nsErrorService.h"
#include "nsCRTGlue.h"
#include "nsAutoPtr.h"
#include "mozilla/StaticPtr.h"
#include "mozilla/ClearOnShutdown.h"

namespace {

mozilla::StaticRefPtr<nsErrorService> gSingleton;

}

NS_IMPL_ISUPPORTS(nsErrorService, nsIErrorService)

nsresult
nsErrorService::Create(nsISupports* aOuter, const nsIID& aIID,
void** aInstancePtr)
// static
already_AddRefed<nsIErrorService>
nsErrorService::GetOrCreate()
{
if (NS_WARN_IF(aOuter)) {
return NS_ERROR_NO_AGGREGATION;
RefPtr<nsErrorService> svc;
if (gSingleton) {
svc = gSingleton;
} else {
gSingleton = new nsErrorService();
mozilla::ClearOnShutdown(&gSingleton);
svc = gSingleton;
}
RefPtr<nsErrorService> serv = new nsErrorService();
return serv->QueryInterface(aIID, aInstancePtr);

return svc.forget();
}

NS_IMETHODIMP
Expand Down
12 changes: 3 additions & 9 deletions xpcom/base/nsErrorService.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,11 @@ class nsErrorService final : public nsIErrorService
NS_DECL_ISUPPORTS
NS_DECL_NSIERRORSERVICE

nsErrorService()
{
}

static nsresult
Create(nsISupports* aOuter, const nsIID& aIID, void** aInstancePtr);
static already_AddRefed<nsIErrorService> GetOrCreate();

private:
~nsErrorService()
{
}
nsErrorService() = default;
~nsErrorService() = default;

nsClassHashtable<nsUint32HashKey, nsCString> mErrorStringBundleURLMap;
};
Expand Down
15 changes: 0 additions & 15 deletions xpcom/base/nsIErrorService.idl
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,3 @@ interface nsIErrorService : nsISupports
*/
string getErrorStringBundle(in short errorModule);
};

%{C++

// The global nsIErrorService:
#define NS_ERRORSERVICE_NAME "Error Service"
#define NS_ERRORSERVICE_CONTRACTID "@mozilla.org/xpcom/error-service;1"
#define NS_ERRORSERVICE_CID \
{ /* 744afd5e-5f8c-11d4-9877-00c04fa0cf4a */ \
0x744afd5e, \
0x5f8c, \
0x11d4, \
{0x98, 0x77, 0x00, 0xc0, 0x4f, 0xa0, 0xcf, 0x4a} \
}

%}
1 change: 0 additions & 1 deletion xpcom/build/XPCOMInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#include "nsMemoryImpl.h"
#include "nsDebugImpl.h"
#include "nsTraceRefcnt.h"
#include "nsErrorService.h"

#include "nsArray.h"
#include "nsINIParserImpl.h"
Expand Down
1 change: 0 additions & 1 deletion xpcom/build/XPCOMModule.inc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
COMPONENT_M(MEMORY, nsMemoryImpl::Create, Module::ALLOW_IN_GPU_PROCESS)
COMPONENT_M(DEBUG, nsDebugImpl::Create, Module::ALLOW_IN_GPU_PROCESS)
COMPONENT(ERRORSERVICE, nsErrorService::Create)

COMPONENT_M(CATEGORYMANAGER, nsCategoryManager::Create, Module::ALLOW_IN_GPU_PROCESS)

Expand Down

0 comments on commit e95c3cc

Please sign in to comment.