Skip to content

Commit

Permalink
Bug 1773770: Part 3 - Migrate XRE module to static component registra…
Browse files Browse the repository at this point in the history
…tion. r=xpcom-reviewers,nika

Differential Revision: https://phabricator.services.mozilla.com/D149431
  • Loading branch information
kmaglione committed Jun 23, 2022
1 parent 18cba4e commit 0c8c6bd
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 59 deletions.
20 changes: 0 additions & 20 deletions toolkit/profile/nsToolkitProfileService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2071,26 +2071,6 @@ nsToolkitProfileService::Flush() {
return NS_OK;
}

NS_IMPL_ISUPPORTS(nsToolkitProfileFactory, nsIFactory)

NS_IMETHODIMP
nsToolkitProfileFactory::CreateInstance(const nsID& aIID, void** aResult) {
RefPtr<nsToolkitProfileService> 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();
Expand Down
12 changes: 3 additions & 9 deletions toolkit/profile/nsToolkitProfileService.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#ifndef nsToolkitProfileService_h
#define nsToolkitProfileService_h

#include "mozilla/Components.h"
#include "mozilla/LinkedList.h"
#include "nsIToolkitProfileService.h"
#include "nsIToolkitProfile.h"
Expand Down Expand Up @@ -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
Expand All @@ -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();
Expand Down
7 changes: 7 additions & 0 deletions toolkit/xre/components.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
},
]
24 changes: 0 additions & 24 deletions toolkit/xre/nsAppRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<nsIFactory> ProfileServiceFactoryConstructor(
const mozilla::Module& module, const mozilla::Module::CIDEntry& entry) {
nsCOMPtr<nsIFactory> 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!");

Expand Down
2 changes: 0 additions & 2 deletions toolkit/xre/nsAppRunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ already_AddRefed<nsINativeAppSupport> NS_GetNativeAppSupport();

nsresult NS_NewToolkitProfileService(nsIToolkitProfileService** aResult);

nsresult NS_NewToolkitProfileFactory(nsIFactory** aResult);

/**
* Try to acquire exclusive access to the specified profile directory.
*
Expand Down
3 changes: 1 addition & 2 deletions xpcom/components/StaticComponents.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions xpcom/components/gen_static_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions xpcom/components/nsComponentManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const mozilla::Module*>* sExtraStaticModules;

Expand Down Expand Up @@ -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]);
Expand Down

0 comments on commit 0c8c6bd

Please sign in to comment.