Bug 1686838 [wpt PR 27194] - [webcodecs] Deprecate VideoFrame.destroy()., a=testonly
[gecko.git] / xpcom / base / nsErrorService.cpp
blobb2337743beba51c17953eb315e37690c52642975
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"
8 #include "nsCRTGlue.h"
9 #include "mozilla/StaticPtr.h"
10 #include "mozilla/ClearOnShutdown.h"
12 namespace {
14 mozilla::StaticRefPtr<nsErrorService> gSingleton;
18 NS_IMPL_ISUPPORTS(nsErrorService, nsIErrorService)
20 // static
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;
26 if (gSingleton) {
27 svc = gSingleton;
28 } else if (!serviceCreated) {
29 gSingleton = new nsErrorService();
30 mozilla::ClearOnShutdown(&gSingleton);
31 svc = gSingleton;
32 serviceCreated = true;
35 return svc.forget();
38 NS_IMETHODIMP
39 nsErrorService::RegisterErrorStringBundle(int16_t aErrorModule,
40 const char* aStringBundleURL) {
41 mErrorStringBundleURLMap.Put(aErrorModule, new nsCString(aStringBundleURL));
42 return NS_OK;
45 NS_IMETHODIMP
46 nsErrorService::UnregisterErrorStringBundle(int16_t aErrorModule) {
47 mErrorStringBundleURLMap.Remove(aErrorModule);
48 return NS_OK;
51 NS_IMETHODIMP
52 nsErrorService::GetErrorStringBundle(int16_t aErrorModule, char** aResult) {
53 nsCString* bundleURL = mErrorStringBundleURLMap.Get(aErrorModule);
54 if (!bundleURL) {
55 return NS_ERROR_FAILURE;
57 *aResult = ToNewCString(*bundleURL);
58 return NS_OK;
61 ////////////////////////////////////////////////////////////////////////////////