1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "nsErrorService.h"
9 #include "mozilla/StaticPtr.h"
10 #include "mozilla/ClearOnShutdown.h"
14 mozilla::StaticRefPtr
<nsErrorService
> gSingleton
;
18 NS_IMPL_ISUPPORTS(nsErrorService
, nsIErrorService
)
21 already_AddRefed
<nsIErrorService
> nsErrorService::GetOrCreate() {
22 // Be careful to not recreate the service for a second time if GetOrCreate is
23 // called super late during shutdown.
24 static bool serviceCreated
= false;
25 RefPtr
<nsErrorService
> svc
;
28 } else if (!serviceCreated
) {
29 gSingleton
= new nsErrorService();
30 mozilla::ClearOnShutdown(&gSingleton
);
32 serviceCreated
= true;
39 nsErrorService::RegisterErrorStringBundle(int16_t aErrorModule
,
40 const char* aStringBundleURL
) {
41 mErrorStringBundleURLMap
.Put(aErrorModule
, new nsCString(aStringBundleURL
));
46 nsErrorService::UnregisterErrorStringBundle(int16_t aErrorModule
) {
47 mErrorStringBundleURLMap
.Remove(aErrorModule
);
52 nsErrorService::GetErrorStringBundle(int16_t aErrorModule
, char** aResult
) {
53 nsCString
* bundleURL
= mErrorStringBundleURLMap
.Get(aErrorModule
);
55 return NS_ERROR_FAILURE
;
57 *aResult
= ToNewCString(*bundleURL
);
61 ////////////////////////////////////////////////////////////////////////////////