Bug 1504557 - Remove the XPCOM registration for nsErrorService r=froydnj
☠☠ backed out by 0bebbbb44c53 ☠ ☠
authorEhsan Akhgari <ehsan@mozilla.com>
Mon, 05 Nov 2018 00:43:41 +0000
changeset 444361 cb84a3ed7bddc68cf1be5a31c824fa97789fa343
parent 444360 6dc5276a418a56303ccc1b1603b4a032da56b0ec
child 444362 3fb08858142852b5db780f7a96af5aeb49a8097e
push id109568
push userebalazs@mozilla.com
push dateMon, 05 Nov 2018 09:53:45 +0000
treeherdermozilla-inbound@4a54c96fade9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1504557
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1504557 - Remove the XPCOM registration for nsErrorService r=froydnj Differential Revision: https://phabricator.services.mozilla.com/D10848
dom/xslt/xslt/txMozillaXSLTProcessor.cpp
intl/strres/nsStringBundle.cpp
netwerk/base/nsIOService.cpp
xpcom/base/moz.build
xpcom/base/nsErrorService.cpp
xpcom/base/nsErrorService.h
xpcom/base/nsIErrorService.idl
xpcom/build/XPCOMInit.cpp
xpcom/build/XPCOMModule.inc
--- a/dom/xslt/xslt/txMozillaXSLTProcessor.cpp
+++ b/dom/xslt/xslt/txMozillaXSLTProcessor.cpp
@@ -21,17 +21,17 @@
 #include "txURIUtils.h"
 #include "txXMLUtils.h"
 #include "txUnknownHandler.h"
 #include "txXSLTProcessor.h"
 #include "nsIPrincipal.h"
 #include "nsThreadUtils.h"
 #include "jsapi.h"
 #include "txExprParser.h"
-#include "nsIErrorService.h"
+#include "nsErrorService.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsJSUtils.h"
 #include "nsIXPConnect.h"
 #include "nsVariant.h"
 #include "nsTextNode.h"
 #include "mozilla/dom/DocumentFragment.h"
 #include "mozilla/dom/XSLTProcessorBinding.h"
 
@@ -1281,37 +1281,31 @@ txMozillaXSLTProcessor::SetParameter(JSC
 /* static*/
 nsresult
 txMozillaXSLTProcessor::Startup()
 {
     if (!txXSLTProcessor::init()) {
         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;
 }
 
 /* static*/
 void
 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*/
 nsresult
 txVariable::Convert(nsIVariant *aValue, txAExprResult** aResult)
 {
     *aResult = nullptr;
 
--- a/intl/strres/nsStringBundle.cpp
+++ b/intl/strres/nsStringBundle.cpp
@@ -16,17 +16,17 @@
 #include "nsNetUtil.h"
 #include "nsComponentManagerUtils.h"
 #include "nsServiceManagerUtils.h"
 #include "nsIInputStream.h"
 #include "nsIURI.h"
 #include "nsIObserverService.h"
 #include "nsCOMArray.h"
 #include "nsTextFormatter.h"
-#include "nsIErrorService.h"
+#include "nsErrorService.h"
 #include "nsICategoryManager.h"
 #include "nsContentUtils.h"
 #include "nsPersistentProperties.h"
 #include "nsQueryObject.h"
 #include "nsSimpleEnumerator.h"
 #include "nsStringStream.h"
 #include "mozilla/BinarySearch.h"
 #include "mozilla/ResultExtensions.h"
@@ -44,18 +44,16 @@
 using namespace mozilla;
 
 using mozilla::dom::ContentParent;
 using mozilla::dom::StringBundleDescriptor;
 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
  * processes.
  *
  * Note: This layout is chosen to avoid having to create a separate char*
  * array pointing to the string constant values, which would require
  * per-process relocations. The second array size is the length of the longest
@@ -758,18 +756,18 @@ struct bundleCacheEntry_t final : public
     MOZ_COUNT_DTOR(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,
                   nsIStringBundleService,
                   nsIObserver,
                   nsISupportsWeakReference,
                   nsIMemoryReporter)
 
--- a/netwerk/base/nsIOService.cpp
+++ b/netwerk/base/nsIOService.cpp
@@ -7,17 +7,17 @@
 #include "mozilla/DebugOnly.h"
 
 #include "nsIOService.h"
 #include "nsIProtocolHandler.h"
 #include "nsIFileProtocolHandler.h"
 #include "nscore.h"
 #include "nsIURI.h"
 #include "prprf.h"
-#include "nsIErrorService.h"
+#include "nsErrorService.h"
 #include "netCore.h"
 #include "nsIObserverService.h"
 #include "nsIPrefService.h"
 #include "nsXPCOM.h"
 #include "nsIProxiedProtocolHandler.h"
 #include "nsIProxyInfo.h"
 #include "nsEscape.h"
 #include "nsNetUtil.h"
@@ -211,22 +211,19 @@ static const char* gCallbackPrefs[] = {
     NETWORK_CAPTIVE_PORTAL_PREF,
     nullptr,
 };
 
 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();
 
     // setup our bad port list stuff
     for(int i=0; gBadPortList[i]; i++)
         mRestrictedPortList.AppendElement(gBadPortList[i]);
 
     // Further modifications to the port list come from prefs
--- a/xpcom/base/moz.build
+++ b/xpcom/base/moz.build
@@ -62,16 +62,17 @@ EXPORTS += [
     'nsCycleCollectionNoteRootCallback.h',
     'nsCycleCollectionParticipant.h',
     'nsCycleCollectionTraversalCallback.h',
     'nsCycleCollector.h',
     'nsDebug.h',
     'nsDebugImpl.h',
     'nsDumpUtils.h',
     'nsError.h',
+    'nsErrorService.h',
     'nsGZFileWriter.h',
     'nsIClassInfoImpl.h',
     'nsID.h',
     'nsIID.h',
     'nsIInterfaceRequestorUtils.h',
     'nsINIParser.h',
     'nsInterfaceRequestorAgg.h',
     'nsISizeOf.h',
--- a/xpcom/base/nsErrorService.cpp
+++ b/xpcom/base/nsErrorService.cpp
@@ -2,28 +2,41 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #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
 nsErrorService::RegisterErrorStringBundle(int16_t aErrorModule,
                                           const char* aStringBundleURL)
 {
   mErrorStringBundleURLMap.Put(aErrorModule, new nsCString(aStringBundleURL));
   return NS_OK;
--- a/xpcom/base/nsErrorService.h
+++ b/xpcom/base/nsErrorService.h
@@ -14,24 +14,18 @@
 #include "nsHashKeys.h"
 
 class nsErrorService final : public nsIErrorService
 {
 public:
   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;
 };
 
 #endif // nsErrorService_h__
--- a/xpcom/base/nsIErrorService.idl
+++ b/xpcom/base/nsIErrorService.idl
@@ -27,23 +27,8 @@ interface nsIErrorService : nsISupports
      */
     void unregisterErrorStringBundle(in short errorModule);
 
     /**
      * Retrieves a string bundle URL for an error module.
      */
     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} \
-}
-
-%}
--- a/xpcom/build/XPCOMInit.cpp
+++ b/xpcom/build/XPCOMInit.cpp
@@ -32,17 +32,16 @@
 #include "nsBinaryStream.h"
 #include "nsStorageStream.h"
 #include "nsPipe.h"
 #include "nsScriptableBase64Encoder.h"
 
 #include "nsMemoryImpl.h"
 #include "nsDebugImpl.h"
 #include "nsTraceRefcnt.h"
-#include "nsErrorService.h"
 
 #include "nsArray.h"
 #include "nsINIParserImpl.h"
 #include "nsSupportsPrimitives.h"
 #include "nsConsoleService.h"
 
 #include "nsComponentManager.h"
 #include "nsCategoryManagerUtils.h"
--- a/xpcom/build/XPCOMModule.inc
+++ b/xpcom/build/XPCOMModule.inc
@@ -1,11 +1,10 @@
     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)
 
     COMPONENT(SCRIPTABLEINPUTSTREAM, nsScriptableInputStream::Create)
     COMPONENT(BINARYINPUTSTREAM, nsBinaryInputStreamConstructor)
     COMPONENT(BINARYOUTPUTSTREAM, nsBinaryOutputStreamConstructor)
     COMPONENT(STORAGESTREAM, nsStorageStreamConstructor)
     COMPONENT(VERSIONCOMPARATOR, nsVersionComparatorImplConstructor)