Bug 1792354, part 2 - Remove nsErrorService and nsIErrorService. r=xpcom-reviewers,necko-reviewers,nika,valentin

Nika pointed out that there are only two places that register
something, and only one place that uses it, so this entire module
can be turned into a couple of lines of a switch statement.

Differential Revision: https://phabricator.services.mozilla.com/D158132
This commit is contained in:
Andrew McCreight 2022-09-27 21:27:17 +00:00
parent 773cd20b07
commit e626a91a81
14 changed files with 34 additions and 179 deletions

View file

@ -4,7 +4,10 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this # 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/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
EXPORTS.mozilla.dom += ["txMozillaXSLTProcessor.h"] EXPORTS.mozilla.dom += [
"txMozillaXSLTProcessor.h",
"txXSLTMsgsURL.h",
]
XPIDL_MODULE = "dom_xslt" XPIDL_MODULE = "dom_xslt"

View file

@ -18,12 +18,12 @@
#include "txURIUtils.h" #include "txURIUtils.h"
#include "txXMLUtils.h" #include "txXMLUtils.h"
#include "txUnknownHandler.h" #include "txUnknownHandler.h"
#include "txXSLTMsgsURL.h"
#include "txXSLTProcessor.h" #include "txXSLTProcessor.h"
#include "nsIPrincipal.h" #include "nsIPrincipal.h"
#include "nsThreadUtils.h" #include "nsThreadUtils.h"
#include "jsapi.h" #include "jsapi.h"
#include "txExprParser.h" #include "txExprParser.h"
#include "nsErrorService.h"
#include "nsJSUtils.h" #include "nsJSUtils.h"
#include "nsIXPConnect.h" #include "nsIXPConnect.h"
#include "nsNameSpaceManager.h" #include "nsNameSpaceManager.h"
@ -1114,24 +1114,11 @@ nsresult txMozillaXSLTProcessor::Startup() {
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
} }
nsCOMPtr<nsIErrorService> errorService = nsErrorService::GetOrCreate();
if (errorService) {
errorService->RegisterErrorStringBundle(NS_ERROR_MODULE_XSLT,
XSLT_MSGS_URL);
}
return NS_OK; return NS_OK;
} }
/* static*/ /* static*/
void txMozillaXSLTProcessor::Shutdown() { void txMozillaXSLTProcessor::Shutdown() { txXSLTProcessor::shutdown(); }
txXSLTProcessor::shutdown();
nsCOMPtr<nsIErrorService> errorService = nsErrorService::GetOrCreate();
if (errorService) {
errorService->UnregisterErrorStringBundle(NS_ERROR_MODULE_XSLT);
}
}
/* static */ /* static */
UniquePtr<txVariable::OwningXSLTParameterValue> txVariable::convertToOwning( UniquePtr<txVariable::OwningXSLTParameterValue> txVariable::convertToOwning(

View file

@ -36,8 +36,6 @@ enum class ReferrerPolicy : uint8_t;
} // namespace dom } // namespace dom
} // namespace mozilla } // namespace mozilla
#define XSLT_MSGS_URL "chrome://global/locale/xslt/xslt.properties"
/** /**
* txMozillaXSLTProcessor is a front-end to the XSLT Processor. * txMozillaXSLTProcessor is a front-end to the XSLT Processor.
*/ */

View file

@ -0,0 +1,11 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#ifndef DOM_XSLT_XSLT_TXXSLTMSGSURL_H_
#define DOM_XSLT_XSLT_TXXSLTMSGSURL_H_
#define XSLT_MSGS_URL "chrome://global/locale/xslt/xslt.properties"
#endif // DOM_XSLT_XSLT_TXXSLTMSGSURL_H_

View file

@ -83,7 +83,7 @@ interface nsIStringBundleService : nsISupports
/** /**
* Formats a message string from a status code and status arguments. * Formats a message string from a status code and status arguments.
* @param aStatus - The status code. This is mapped into a string ID and * @param aStatus - The status code. This is mapped into a string ID and
* and used in the string lookup process (see nsIErrorService). * used in the string lookup process.
* @param aStatusArg - The status message argument(s). Multiple arguments * @param aStatusArg - The status message argument(s). Multiple arguments
* can be separated by newline ('\n') characters. * can be separated by newline ('\n') characters.
* @return the formatted message * @return the formatted message

View file

@ -4,6 +4,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsStringBundle.h" #include "nsStringBundle.h"
#include "netCore.h"
#include "nsID.h" #include "nsID.h"
#include "nsString.h" #include "nsString.h"
#include "nsIStringBundle.h" #include "nsIStringBundle.h"
@ -20,12 +22,12 @@
#include "nsIObserverService.h" #include "nsIObserverService.h"
#include "nsCOMArray.h" #include "nsCOMArray.h"
#include "nsTextFormatter.h" #include "nsTextFormatter.h"
#include "nsErrorService.h"
#include "nsContentUtils.h" #include "nsContentUtils.h"
#include "nsPersistentProperties.h" #include "nsPersistentProperties.h"
#include "nsQueryObject.h" #include "nsQueryObject.h"
#include "nsSimpleEnumerator.h" #include "nsSimpleEnumerator.h"
#include "nsStringStream.h" #include "nsStringStream.h"
#include "mozilla/dom/txXSLTMsgsURL.h"
#include "mozilla/BinarySearch.h" #include "mozilla/BinarySearch.h"
#include "mozilla/ClearOnShutdown.h" #include "mozilla/ClearOnShutdown.h"
#include "mozilla/ResultExtensions.h" #include "mozilla/ResultExtensions.h"
@ -740,10 +742,7 @@ struct bundleCacheEntry_t final : public LinkedListElement<bundleCacheEntry_t> {
}; };
nsStringBundleService::nsStringBundleService() nsStringBundleService::nsStringBundleService()
: mBundleMap(MAX_CACHED_BUNDLES) { : mBundleMap(MAX_CACHED_BUNDLES) {}
mErrorService = nsErrorService::GetOrCreate();
MOZ_ALWAYS_TRUE(mErrorService);
}
NS_IMPL_ISUPPORTS(nsStringBundleService, nsIStringBundleService, nsIObserver, NS_IMPL_ISUPPORTS(nsStringBundleService, nsIStringBundleService, nsIObserver,
nsISupportsWeakReference, nsIMemoryReporter) nsISupportsWeakReference, nsIMemoryReporter)
@ -980,10 +979,8 @@ NS_IMETHODIMP
nsStringBundleService::FormatStatusMessage(nsresult aStatus, nsStringBundleService::FormatStatusMessage(nsresult aStatus,
const char16_t* aStatusArg, const char16_t* aStatusArg,
nsAString& result) { nsAString& result) {
nsresult rv;
uint32_t i, argCount = 0; uint32_t i, argCount = 0;
nsCOMPtr<nsIStringBundle> bundle; nsCOMPtr<nsIStringBundle> bundle;
nsCString stringBundleURL;
// XXX hack for mailnews who has already formatted their messages: // XXX hack for mailnews who has already formatted their messages:
if (aStatus == NS_OK && aStatusArg) { if (aStatus == NS_OK && aStatusArg) {
@ -1014,17 +1011,17 @@ nsStringBundleService::FormatStatusMessage(nsresult aStatus,
} }
} }
// find the string bundle for the error's module: switch (NS_ERROR_GET_MODULE(aStatus)) {
rv = mErrorService->GetErrorStringBundle(NS_ERROR_GET_MODULE(aStatus), case NS_ERROR_MODULE_XSLT:
getter_Copies(stringBundleURL)); getStringBundle(XSLT_MSGS_URL, getter_AddRefs(bundle));
if (NS_SUCCEEDED(rv)) { break;
getStringBundle(stringBundleURL.get(), getter_AddRefs(bundle)); case NS_ERROR_MODULE_NETWORK:
rv = FormatWithBundle(bundle, aStatus, argArray, result); getStringBundle(NECKO_MSGS_URL, getter_AddRefs(bundle));
} break;
if (NS_FAILED(rv)) { default:
getStringBundle(GLOBAL_PROPERTIES, getter_AddRefs(bundle)); getStringBundle(GLOBAL_PROPERTIES, getter_AddRefs(bundle));
rv = FormatWithBundle(bundle, aStatus, argArray, result); break;
} }
return rv; return FormatWithBundle(bundle, aStatus, argArray, result);
} }

View file

@ -12,7 +12,6 @@
#include "nsIStringBundle.h" #include "nsIStringBundle.h"
#include "nsIObserver.h" #include "nsIObserver.h"
#include "nsWeakReference.h" #include "nsWeakReference.h"
#include "nsIErrorService.h"
#include "nsIMemoryReporter.h" #include "nsIMemoryReporter.h"
#include "mozilla/LinkedList.h" #include "mozilla/LinkedList.h"
@ -65,8 +64,6 @@ class nsStringBundleService : public nsIStringBundleService,
mozilla::LinkedList<bundleCacheEntry_t> mBundleCache; mozilla::LinkedList<bundleCacheEntry_t> mBundleCache;
// List of cached shared-memory string bundles, in arbitrary order. // List of cached shared-memory string bundles, in arbitrary order.
mozilla::AutoCleanLinkedList<bundleCacheEntry_t> mSharedBundles; mozilla::AutoCleanLinkedList<bundleCacheEntry_t> mSharedBundles;
nsCOMPtr<nsIErrorService> mErrorService;
}; };
#endif #endif

View file

@ -12,7 +12,6 @@
#include "nscore.h" #include "nscore.h"
#include "nsIURI.h" #include "nsIURI.h"
#include "prprf.h" #include "prprf.h"
#include "nsErrorService.h"
#include "netCore.h" #include "netCore.h"
#include "nsIObserverService.h" #include "nsIObserverService.h"
#include "nsXPCOM.h" #include "nsXPCOM.h"
@ -256,12 +255,6 @@ static const char* gCallbackSecurityPrefs[] = {
}; };
nsresult nsIOService::Init() { nsresult nsIOService::Init() {
// XXX hack until xpidl supports error info directly (bug 13423)
nsCOMPtr<nsIErrorService> errorService = nsErrorService::GetOrCreate();
MOZ_ALWAYS_TRUE(errorService);
errorService->RegisterErrorStringBundle(NS_ERROR_MODULE_NETWORK,
NECKO_MSGS_URL);
SSLTokensCache::Init(); SSLTokensCache::Init();
InitializeCaptivePortalService(); InitializeCaptivePortalService();

View file

@ -146,8 +146,7 @@ interface nsITransportEventSink : nsISupports
* @param aTransport * @param aTransport
* the transport sending this status notification. * the transport sending this status notification.
* @param aStatus * @param aStatus
* the transport status (resolvable to a string using * the transport status. See nsISocketTransport for socket specific
* nsIErrorService). See nsISocketTransport for socket specific
* status codes and more comments. * status codes and more comments.
* @param aProgress * @param aProgress
* the amount of data either read or written depending on the value * the amount of data either read or written depending on the value

View file

@ -11,7 +11,6 @@ XPIDL_SOURCES += [
"nsIConsoleService.idl", "nsIConsoleService.idl",
"nsICycleCollectorListener.idl", "nsICycleCollectorListener.idl",
"nsIDebug2.idl", "nsIDebug2.idl",
"nsIErrorService.idl",
"nsIException.idl", "nsIException.idl",
"nsIInterfaceRequestor.idl", "nsIInterfaceRequestor.idl",
"nsIMemory.idl", "nsIMemory.idl",
@ -71,7 +70,6 @@ EXPORTS += [
"nsDebugImpl.h", "nsDebugImpl.h",
"nsDumpUtils.h", "nsDumpUtils.h",
"nsError.h", "nsError.h",
"nsErrorService.h",
"nsGZFileWriter.h", "nsGZFileWriter.h",
"nsIClassInfoImpl.h", "nsIClassInfoImpl.h",
"nsID.h", "nsID.h",
@ -178,7 +176,6 @@ UNIFIED_SOURCES += [
"nsCycleCollectionParticipant.cpp", "nsCycleCollectionParticipant.cpp",
"nsCycleCollector.cpp", "nsCycleCollector.cpp",
"nsCycleCollectorTraceJSHelpers.cpp", "nsCycleCollectorTraceJSHelpers.cpp",
"nsErrorService.cpp",
"nsGZFileWriter.cpp", "nsGZFileWriter.cpp",
"nsID.cpp", "nsID.cpp",
"nsIInterfaceRequestorUtils.cpp", "nsIInterfaceRequestorUtils.cpp",

View file

@ -1,62 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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 "mozilla/StaticPtr.h"
#include "mozilla/ClearOnShutdown.h"
namespace {
mozilla::StaticRefPtr<nsErrorService> gSingleton;
}
NS_IMPL_ISUPPORTS(nsErrorService, nsIErrorService)
// static
already_AddRefed<nsIErrorService> nsErrorService::GetOrCreate() {
// Be careful to not recreate the service for a second time if GetOrCreate is
// called super late during shutdown.
static bool serviceCreated = false;
RefPtr<nsErrorService> svc;
if (gSingleton) {
svc = gSingleton;
} else if (!serviceCreated) {
gSingleton = new nsErrorService();
mozilla::ClearOnShutdown(&gSingleton);
svc = gSingleton;
serviceCreated = true;
}
return svc.forget();
}
NS_IMETHODIMP
nsErrorService::RegisterErrorStringBundle(int16_t aErrorModule,
const char* aStringBundleURL) {
mErrorStringBundleURLMap.InsertOrUpdate(
aErrorModule, mozilla::MakeUnique<nsCString>(aStringBundleURL));
return NS_OK;
}
NS_IMETHODIMP
nsErrorService::UnregisterErrorStringBundle(int16_t aErrorModule) {
mErrorStringBundleURLMap.Remove(aErrorModule);
return NS_OK;
}
NS_IMETHODIMP
nsErrorService::GetErrorStringBundle(int16_t aErrorModule, char** aResult) {
nsCString* bundleURL = mErrorStringBundleURLMap.Get(aErrorModule);
if (!bundleURL) {
return NS_ERROR_FAILURE;
}
*aResult = ToNewCString(*bundleURL);
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -1,30 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#ifndef nsErrorService_h__
#define nsErrorService_h__
#include "mozilla/Attributes.h"
#include "nsIErrorService.h"
#include "nsClassHashtable.h"
#include "nsHashKeys.h"
class nsErrorService final : public nsIErrorService {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIERRORSERVICE
static already_AddRefed<nsIErrorService> GetOrCreate();
private:
nsErrorService() = default;
~nsErrorService() = default;
nsClassHashtable<nsUint32HashKey, nsCString> mErrorStringBundleURLMap;
};
#endif // nsErrorService_h__

View file

@ -1,34 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* 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 "nsISupports.idl"
/**
* nsIErrorService: This is an interim service that allows nsresult codes to be mapped to
* string bundles that can be used to look up error messages. String bundle keys can also
* be mapped.
*
* This service will eventually get replaced by extending xpidl to allow errors to be defined.
* (http://bugzilla.mozilla.org/show_bug.cgi?id=13423).
*/
[uuid(afe1f190-a3c2-11e3-a5e2-0800200c9a66)]
interface nsIErrorService : nsISupports
{
/**
* Registers a string bundle URL for an error module. Error modules are obtained from
* nsresult code with NS_ERROR_GET_MODULE.
*/
void registerErrorStringBundle(in short errorModule, in string stringBundleURL);
/**
* Unregisters a string bundle URL for an error module.
*/
void unregisterErrorStringBundle(in short errorModule);
/**
* Retrieves a string bundle URL for an error module.
*/
string getErrorStringBundle(in short errorModule);
};

View file

@ -68,7 +68,6 @@
#include "nsIDebug2.h" #include "nsIDebug2.h"
#include "nsIDirectoryEnumerator.h" #include "nsIDirectoryEnumerator.h"
#include "nsIEnvironment.h" #include "nsIEnvironment.h"
#include "nsIErrorService.h"
#include "nsIEventTarget.h" #include "nsIEventTarget.h"
#include "nsIException.h" #include "nsIException.h"
#include "nsIFactory.h" #include "nsIFactory.h"