diff --git a/toolkit/profile/nsToolkitProfileService.cpp b/toolkit/profile/nsToolkitProfileService.cpp index f1ea2aa519390..b788d383c201f 100644 --- a/toolkit/profile/nsToolkitProfileService.cpp +++ b/toolkit/profile/nsToolkitProfileService.cpp @@ -2071,26 +2071,6 @@ nsToolkitProfileService::Flush() { return NS_OK; } -NS_IMPL_ISUPPORTS(nsToolkitProfileFactory, nsIFactory) - -NS_IMETHODIMP -nsToolkitProfileFactory::CreateInstance(const nsID& aIID, void** aResult) { - RefPtr profileService = - nsToolkitProfileService::gService; - if (!profileService) { - nsresult rv = NS_NewToolkitProfileService(getter_AddRefs(profileService)); - if (NS_FAILED(rv)) return rv; - } - return profileService->QueryInterface(aIID, aResult); -} - -nsresult NS_NewToolkitProfileFactory(nsIFactory** aResult) { - *aResult = new nsToolkitProfileFactory(); - - NS_ADDREF(*aResult); - return NS_OK; -} - nsresult NS_NewToolkitProfileService(nsToolkitProfileService** aResult) { nsToolkitProfileService* profileService = new nsToolkitProfileService(); nsresult rv = profileService->Init(); diff --git a/toolkit/profile/nsToolkitProfileService.h b/toolkit/profile/nsToolkitProfileService.h index d281d39ebe597..97ef74855956b 100644 --- a/toolkit/profile/nsToolkitProfileService.h +++ b/toolkit/profile/nsToolkitProfileService.h @@ -8,6 +8,7 @@ #ifndef nsToolkitProfileService_h #define nsToolkitProfileService_h +#include "mozilla/Components.h" #include "mozilla/LinkedList.h" #include "nsIToolkitProfileService.h" #include "nsIToolkitProfile.h" @@ -64,14 +65,6 @@ class nsToolkitProfileLock final : public nsIProfileLock { nsProfileLock mLock; }; -class nsToolkitProfileFactory final : public nsIFactory { - ~nsToolkitProfileFactory() = default; - - public: - NS_DECL_ISUPPORTS - NS_DECL_NSIFACTORY -}; - class nsToolkitProfileService final : public nsIToolkitProfileService { public: NS_DECL_ISUPPORTS @@ -87,8 +80,9 @@ class nsToolkitProfileService final : public nsIToolkitProfileService { private: friend class nsToolkitProfile; - friend class nsToolkitProfileFactory; friend nsresult NS_NewToolkitProfileService(nsToolkitProfileService**); + friend nsresult mozilla::xpcom::CreateInstanceImpl( + mozilla::xpcom::ModuleID aID, const nsIID& aIID, void** aResult); nsToolkitProfileService(); ~nsToolkitProfileService(); diff --git a/toolkit/xre/components.conf b/toolkit/xre/components.conf index 45fbe18717c82..5f23dc4a13b09 100644 --- a/toolkit/xre/components.conf +++ b/toolkit/xre/components.conf @@ -59,4 +59,11 @@ Classes = [ 'type': 'nsDialogParamBlock', 'headers': ['/toolkit/components/windowwatcher/nsDialogParamBlock.h'], }, + { + 'cid': '{5f5e59ce-27bc-47eb-9d1f-b09ca9049836}', + 'contract_ids': ['@mozilla.org/toolkit/profile-service;1'], + 'type': 'nsToolkitProfileService', + 'init_method': 'Init', + 'headers': ['/toolkit/profile/nsToolkitProfileService.h'], + }, ] diff --git a/toolkit/xre/nsAppRunner.cpp b/toolkit/xre/nsAppRunner.cpp index ca206b450ca27..47ddc99374e59 100644 --- a/toolkit/xre/nsAppRunner.cpp +++ b/toolkit/xre/nsAppRunner.cpp @@ -2063,30 +2063,6 @@ ScopedXPCOMStartup::~ScopedXPCOMStartup() { } } -// {5F5E59CE-27BC-47eb-9D1F-B09CA9049836} -static const nsCID kProfileServiceCID = { - 0x5f5e59ce, - 0x27bc, - 0x47eb, - {0x9d, 0x1f, 0xb0, 0x9c, 0xa9, 0x4, 0x98, 0x36}}; - -static already_AddRefed ProfileServiceFactoryConstructor( - const mozilla::Module& module, const mozilla::Module::CIDEntry& entry) { - nsCOMPtr factory; - NS_NewToolkitProfileFactory(getter_AddRefs(factory)); - return factory.forget(); -} - -static const mozilla::Module::CIDEntry kXRECIDs[] = { - {&kProfileServiceCID, false, ProfileServiceFactoryConstructor, nullptr}, - {nullptr}}; - -static const mozilla::Module::ContractIDEntry kXREContracts[] = { - {NS_PROFILESERVICE_CONTRACTID, &kProfileServiceCID}, {nullptr}}; - -extern const mozilla::Module kXREModule = {mozilla::Module::kVersion, kXRECIDs, - kXREContracts}; - nsresult ScopedXPCOMStartup::Initialize(bool aInitJSContext) { NS_ASSERTION(gDirServiceProvider, "Should not get here!"); diff --git a/toolkit/xre/nsAppRunner.h b/toolkit/xre/nsAppRunner.h index 69508165dc90c..a09d665e3aa0f 100644 --- a/toolkit/xre/nsAppRunner.h +++ b/toolkit/xre/nsAppRunner.h @@ -80,8 +80,6 @@ already_AddRefed NS_GetNativeAppSupport(); nsresult NS_NewToolkitProfileService(nsIToolkitProfileService** aResult); -nsresult NS_NewToolkitProfileFactory(nsIFactory** aResult); - /** * Try to acquire exclusive access to the specified profile directory. * diff --git a/xpcom/components/StaticComponents.cpp.in b/xpcom/components/StaticComponents.cpp.in index 5a6378fffda55..7b7c6b109ccc8 100644 --- a/xpcom/components/StaticComponents.cpp.in +++ b/xpcom/components/StaticComponents.cpp.in @@ -192,8 +192,7 @@ static void CallUnloadFuncs() { //# @unload_funcs@ } -static nsresult CreateInstanceImpl(ModuleID aID, const nsIID& aIID, - void** aResult) { +nsresult CreateInstanceImpl(ModuleID aID, const nsIID& aIID, void** aResult) { // The full set of constructors for all static modules. // This switch statement will be compiled to a relative address jump table // with no runtime relocations and a single indirect jump. diff --git a/xpcom/components/gen_static_components.py b/xpcom/components/gen_static_components.py index 3a1714a7f9a8b..c38b17fcc8655 100644 --- a/xpcom/components/gen_static_components.py +++ b/xpcom/components/gen_static_components.py @@ -997,6 +997,10 @@ def replacer(match): %(module_ids)s }; +// May be added as a friend function to allow constructing services via +// private constructors and init methods. +nsresult CreateInstanceImpl(ModuleID aID, const nsIID& aIID, void** aResult); + class MOZ_STACK_CLASS StaticModuleHelper : public nsCOMPtr_helper { public: StaticModuleHelper(ModuleID aId, nsresult* aErrorPtr) diff --git a/xpcom/components/nsComponentManager.cpp b/xpcom/components/nsComponentManager.cpp index b6cb6220c4246..58f77e31cbe40 100644 --- a/xpcom/components/nsComponentManager.cpp +++ b/xpcom/components/nsComponentManager.cpp @@ -277,7 +277,6 @@ extern const mozilla::Module kContentProcessWidgetModule; #if defined(MOZ_WIDGET_COCOA) || defined(MOZ_WIDGET_UIKIT) extern const mozilla::Module kWidgetModule; #endif -extern const mozilla::Module kXREModule; static nsTArray* sExtraStaticModules; @@ -369,7 +368,6 @@ nsresult nsComponentManagerImpl::Init() { #if defined(MOZ_WIDGET_COCOA) || defined(MOZ_WIDGET_UIKIT) RegisterModule(&kWidgetModule); #endif - RegisterModule(&kXREModule); for (uint32_t i = 0; i < sExtraStaticModules->Length(); ++i) { RegisterModule((*sExtraStaticModules)[i]);