xpcom/build/Services.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/xpcom/build/Services.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,64 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "mozilla/Services.h"
    1.10 +#include "nsComponentManager.h"
    1.11 +#include "nsIIOService.h"
    1.12 +#include "nsIDirectoryService.h"
    1.13 +#ifdef ACCESSIBILITY
    1.14 +#include "nsIAccessibilityService.h"
    1.15 +#endif
    1.16 +#include "nsIChromeRegistry.h"
    1.17 +#include "nsIObserverService.h"
    1.18 +#include "nsNetCID.h"
    1.19 +#include "nsObserverService.h"
    1.20 +#include "nsXPCOMPrivate.h"
    1.21 +#include "nsIStringBundle.h"
    1.22 +#include "nsIToolkitChromeRegistry.h"
    1.23 +#include "nsIXULOverlayProvider.h"
    1.24 +#include "IHistory.h"
    1.25 +#include "nsIXPConnect.h"
    1.26 +#include "inIDOMUtils.h"
    1.27 +
    1.28 +using namespace mozilla;
    1.29 +using namespace mozilla::services;
    1.30 +
    1.31 +/*
    1.32 + * Define a global variable and a getter for every service in ServiceList.
    1.33 + * eg. gIOService and GetIOService()
    1.34 + */
    1.35 +#define MOZ_SERVICE(NAME, TYPE, CONTRACT_ID)                            \
    1.36 +  static TYPE* g##NAME = nullptr;                                       \
    1.37 +                                                                        \
    1.38 +  already_AddRefed<TYPE>                                                \
    1.39 +  mozilla::services::Get##NAME()                                        \
    1.40 +  {                                                                     \
    1.41 +    if (!g##NAME) {                                                     \
    1.42 +      nsCOMPtr<TYPE> os = do_GetService(CONTRACT_ID);                   \
    1.43 +      g##NAME = os.forget().take();                            \
    1.44 +    }                                                                   \
    1.45 +    nsRefPtr<TYPE> ret = g##NAME;                                       \
    1.46 +    return ret.forget();                                                \
    1.47 +  }                                                                     \
    1.48 +  NS_EXPORT_(already_AddRefed<TYPE>)                                    \
    1.49 +  mozilla::services::_external_Get##NAME()                              \
    1.50 +  {                                                                     \
    1.51 +    return Get##NAME();                                                 \
    1.52 +  }
    1.53 +
    1.54 +#include "ServiceList.h"
    1.55 +#undef MOZ_SERVICE
    1.56 +
    1.57 +/**
    1.58 + * Clears service cache, sets gXPCOMShuttingDown
    1.59 + */
    1.60 +void 
    1.61 +mozilla::services::Shutdown()
    1.62 +{
    1.63 +  gXPCOMShuttingDown = true;
    1.64 +#define MOZ_SERVICE(NAME, TYPE, CONTRACT_ID) NS_IF_RELEASE(g##NAME);
    1.65 +#include "ServiceList.h"
    1.66 +#undef MOZ_SERVICE
    1.67 +}

mercurial