michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "mozilla/Services.h" michael@0: #include "nsComponentManager.h" michael@0: #include "nsIIOService.h" michael@0: #include "nsIDirectoryService.h" michael@0: #ifdef ACCESSIBILITY michael@0: #include "nsIAccessibilityService.h" michael@0: #endif michael@0: #include "nsIChromeRegistry.h" michael@0: #include "nsIObserverService.h" michael@0: #include "nsNetCID.h" michael@0: #include "nsObserverService.h" michael@0: #include "nsXPCOMPrivate.h" michael@0: #include "nsIStringBundle.h" michael@0: #include "nsIToolkitChromeRegistry.h" michael@0: #include "nsIXULOverlayProvider.h" michael@0: #include "IHistory.h" michael@0: #include "nsIXPConnect.h" michael@0: #include "inIDOMUtils.h" michael@0: michael@0: using namespace mozilla; michael@0: using namespace mozilla::services; michael@0: michael@0: /* michael@0: * Define a global variable and a getter for every service in ServiceList. michael@0: * eg. gIOService and GetIOService() michael@0: */ michael@0: #define MOZ_SERVICE(NAME, TYPE, CONTRACT_ID) \ michael@0: static TYPE* g##NAME = nullptr; \ michael@0: \ michael@0: already_AddRefed \ michael@0: mozilla::services::Get##NAME() \ michael@0: { \ michael@0: if (!g##NAME) { \ michael@0: nsCOMPtr os = do_GetService(CONTRACT_ID); \ michael@0: g##NAME = os.forget().take(); \ michael@0: } \ michael@0: nsRefPtr ret = g##NAME; \ michael@0: return ret.forget(); \ michael@0: } \ michael@0: NS_EXPORT_(already_AddRefed) \ michael@0: mozilla::services::_external_Get##NAME() \ michael@0: { \ michael@0: return Get##NAME(); \ michael@0: } michael@0: michael@0: #include "ServiceList.h" michael@0: #undef MOZ_SERVICE michael@0: michael@0: /** michael@0: * Clears service cache, sets gXPCOMShuttingDown michael@0: */ michael@0: void michael@0: mozilla::services::Shutdown() michael@0: { michael@0: gXPCOMShuttingDown = true; michael@0: #define MOZ_SERVICE(NAME, TYPE, CONTRACT_ID) NS_IF_RELEASE(g##NAME); michael@0: #include "ServiceList.h" michael@0: #undef MOZ_SERVICE michael@0: }