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 #ifndef nsComponentManager_h__
8 #define nsComponentManager_h__
12 #include "nsIComponentManager.h"
13 #include "nsIComponentRegistrar.h"
14 #include "nsIMemoryReporter.h"
15 #include "nsIServiceManager.h"
17 #include "mozilla/ArenaAllocator.h"
18 #include "mozilla/Atomics.h"
19 #include "mozilla/MemoryReporting.h"
20 #include "mozilla/Module.h"
21 #include "mozilla/Monitor.h"
22 #include "mozilla/UniquePtr.h"
23 #include "nsXULAppAPI.h"
24 #include "nsIFactory.h"
25 #include "nsIInterfaceRequestor.h"
26 #include "nsIInterfaceRequestorUtils.h"
27 #include "PLDHashTable.h"
30 #include "nsWeakReference.h"
31 #include "nsCOMArray.h"
32 #include "nsTHashMap.h"
33 #include "nsInterfaceHashtable.h"
34 #include "nsClassHashtable.h"
37 #include "mozilla/Components.h"
38 #include "mozilla/Maybe.h"
39 #include "mozilla/Omnijar.h"
40 #include "mozilla/Attributes.h"
42 struct nsFactoryEntry
;
45 #define NS_COMPONENTMANAGER_CID \
46 { /* 91775d60-d5dc-11d2-92fb-00e09805570f */ \
47 0x91775d60, 0xd5dc, 0x11d2, { \
48 0x92, 0xfb, 0x00, 0xe0, 0x98, 0x05, 0x57, 0x0f \
52 ////////////////////////////////////////////////////////////////////////////////
61 bool ProcessSelectorMatches(Module::ProcessSelector aSelector
);
62 bool FastProcessSelectorMatches(Module::ProcessSelector aSelector
);
65 } // namespace mozilla
67 class nsComponentManagerImpl final
: public nsIComponentManager
,
68 public nsIServiceManager
,
69 public nsSupportsWeakReference
,
70 public nsIComponentRegistrar
,
71 public nsIInterfaceRequestor
,
72 public nsIMemoryReporter
{
74 NS_DECL_THREADSAFE_ISUPPORTS
75 NS_DECL_NSIINTERFACEREQUESTOR
76 NS_DECL_NSICOMPONENTMANAGER
77 NS_DECL_NSICOMPONENTREGISTRAR
78 NS_DECL_NSIMEMORYREPORTER
80 static nsresult
Create(REFNSIID aIID
, void** aResult
);
82 nsresult
RegistryLocationForFile(nsIFile
* aFile
, nsCString
& aResult
);
83 nsresult
FileForRegistryLocation(const nsCString
& aLocation
, nsIFile
** aSpec
);
85 NS_DECL_NSISERVICEMANAGER
87 // nsComponentManagerImpl methods:
88 nsComponentManagerImpl();
90 static nsComponentManagerImpl
* gComponentManager
;
93 nsresult
Shutdown(void);
95 nsresult
FreeServices();
97 already_AddRefed
<nsIFactory
> FindFactory(const nsCID
& aClass
);
98 already_AddRefed
<nsIFactory
> FindFactory(const char* aContractID
,
99 uint32_t aContractIDLen
);
101 already_AddRefed
<nsIFactory
> LoadFactory(nsFactoryEntry
* aEntry
);
103 nsTHashMap
<nsIDPointerHashKey
, nsFactoryEntry
*> mFactories
;
104 nsTHashMap
<nsCStringHashKey
, nsFactoryEntry
*> mContractIDs
;
106 mozilla::Monitor mLock MOZ_UNANNOTATED
;
108 mozilla::Maybe
<EntryWrapper
> LookupByCID(const nsID
& aCID
);
109 mozilla::Maybe
<EntryWrapper
> LookupByCID(const mozilla::MonitorAutoLock
&,
112 mozilla::Maybe
<EntryWrapper
> LookupByContractID(
113 const nsACString
& aContractID
);
114 mozilla::Maybe
<EntryWrapper
> LookupByContractID(
115 const mozilla::MonitorAutoLock
&, const nsACString
& aContractID
);
117 nsresult
GetService(mozilla::xpcom::ModuleID
, const nsIID
& aIID
,
120 static bool JSLoaderReady() { return gComponentManager
->mJSLoaderReady
; }
122 static void InitializeStaticModules();
123 static void InitializeModuleLocations();
125 struct ComponentLocation
{
127 mozilla::FileLocation location
;
130 class ComponentLocationComparator
{
132 bool Equals(const ComponentLocation
& aA
,
133 const ComponentLocation
& aB
) const {
134 return (aA
.type
== aB
.type
&& aA
.location
.Equals(aB
.location
));
138 static nsTArray
<ComponentLocation
>* sModuleLocations
;
141 void RegisterManifest(NSLocationType aType
, mozilla::FileLocation
& aFile
,
144 struct ManifestProcessingContext
{
145 ManifestProcessingContext(NSLocationType aType
,
146 mozilla::FileLocation
& aFile
, bool aChromeOnly
)
147 : mType(aType
), mFile(aFile
), mChromeOnly(aChromeOnly
) {}
149 ~ManifestProcessingContext() = default;
151 NSLocationType mType
;
152 mozilla::FileLocation mFile
;
156 void ManifestManifest(ManifestProcessingContext
& aCx
, int aLineNo
,
158 void ManifestCategory(ManifestProcessingContext
& aCx
, int aLineNo
,
161 void RereadChromeManifests(bool aChromeOnly
= true);
167 SHUTDOWN_IN_PROGRESS
,
171 struct PendingServiceInfo
{
176 inline PendingServiceInfo
* AddPendingService(const nsCID
& aServiceCID
,
178 inline void RemovePendingService(mozilla::MonitorAutoLock
& aLock
,
179 const nsCID
& aServiceCID
);
180 inline PRThread
* GetPendingServiceThread(const nsCID
& aServiceCID
) const;
182 nsTArray
<PendingServiceInfo
> mPendingServices
;
184 bool mJSLoaderReady
= false;
186 size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf
) const;
189 ~nsComponentManagerImpl();
191 nsresult
GetServiceLocked(mozilla::Maybe
<mozilla::MonitorAutoLock
>& aLock
,
192 EntryWrapper
& aEntry
, const nsIID
& aIID
,
196 #define NS_MAX_FILENAME_LEN 1024
198 #define NS_ERROR_IS_DIR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_XPCOM, 24)
200 struct nsFactoryEntry
{
201 // nsIComponentRegistrar.registerFactory support
202 nsFactoryEntry(const nsCID
& aClass
, nsIFactory
* aFactory
);
204 ~nsFactoryEntry() = default;
206 already_AddRefed
<nsIFactory
> GetFactory();
208 nsresult
CreateInstance(const nsIID
& aIID
, void** aResult
);
210 size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf
);
214 nsCOMPtr
<nsIFactory
> mFactory
;
215 nsCOMPtr
<nsISupports
> mServiceObject
;
218 #endif // nsComponentManager_h__