Bug 1778082: Ensure nsToolkitProfileService is a singleton regardless of how it is accessed. r=kmag

Differential Revision: https://phabricator.services.mozilla.com/D151020
This commit is contained in:
Dave Townsend 2022-07-05 14:49:53 +00:00
Родитель d3fba3f69b
Коммит 0df4377cec
5 изменённых файлов: 18 добавлений и 23 удалений

Просмотреть файл

@ -497,7 +497,6 @@ nsToolkitProfileService::nsToolkitProfileService()
#ifdef MOZ_DEV_EDITION
mUseDevEditionProfile = true;
#endif
gService = this;
}
nsToolkitProfileService::~nsToolkitProfileService() {
@ -2071,17 +2070,18 @@ nsToolkitProfileService::Flush() {
return NS_OK;
}
nsresult NS_NewToolkitProfileService(nsToolkitProfileService** aResult) {
nsToolkitProfileService* profileService = new nsToolkitProfileService();
nsresult rv = profileService->Init();
if (NS_FAILED(rv)) {
NS_ERROR("nsToolkitProfileService::Init failed!");
delete profileService;
return rv;
already_AddRefed<nsToolkitProfileService> NS_GetToolkitProfileService() {
if (!nsToolkitProfileService::gService) {
nsToolkitProfileService::gService = new nsToolkitProfileService();
nsresult rv = nsToolkitProfileService::gService->Init();
if (NS_FAILED(rv)) {
NS_ERROR("nsToolkitProfileService::Init failed!");
delete nsToolkitProfileService::gService;
return nullptr;
}
}
NS_ADDREF(*aResult = profileService);
return NS_OK;
return do_AddRef(nsToolkitProfileService::gService);
}
nsresult XRE_GetFileFromPath(const char* aPath, nsIFile** aResult) {

Просмотреть файл

@ -80,9 +80,8 @@ class nsToolkitProfileService final : public nsIToolkitProfileService {
private:
friend class nsToolkitProfile;
friend nsresult NS_NewToolkitProfileService(nsToolkitProfileService**);
friend nsresult mozilla::xpcom::CreateInstanceImpl(
mozilla::xpcom::ModuleID aID, const nsIID& aIID, void** aResult);
friend already_AddRefed<nsToolkitProfileService>
NS_GetToolkitProfileService();
nsToolkitProfileService();
~nsToolkitProfileService();
@ -173,4 +172,6 @@ class nsToolkitProfileService final : public nsIToolkitProfileService {
};
};
already_AddRefed<nsToolkitProfileService> NS_GetToolkitProfileService();
#endif

Просмотреть файл

@ -62,8 +62,9 @@ Classes = [
{
'cid': '{5f5e59ce-27bc-47eb-9d1f-b09ca9049836}',
'contract_ids': ['@mozilla.org/toolkit/profile-service;1'],
'singleton': True,
'constructor': 'NS_GetToolkitProfileService',
'type': 'nsToolkitProfileService',
'init_method': 'Init',
'headers': ['/toolkit/profile/nsToolkitProfileService.h'],
},
]

Просмотреть файл

@ -4892,13 +4892,8 @@ int XREMain::XRE_mainStartup(bool* aExitFlag) {
}
#endif
rv = NS_NewToolkitProfileService(getter_AddRefs(mProfileSvc));
if (rv == NS_ERROR_FILE_ACCESS_DENIED) {
PR_fprintf(PR_STDERR,
"Error: Access was denied while trying to open files in "
"your profile directory.\n");
}
if (NS_FAILED(rv)) {
mProfileSvc = NS_GetToolkitProfileService();
if (!mProfileSvc) {
// We failed to choose or create profile - notify user and quit
ProfileMissingDialog(mNativeApp);
return 1;

Просмотреть файл

@ -78,8 +78,6 @@ int32_t CompareCompatVersions(const nsACString& aOldCompatVersion,
nsresult NS_CreateNativeAppSupport(nsINativeAppSupport** aResult);
already_AddRefed<nsINativeAppSupport> NS_GetNativeAppSupport();
nsresult NS_NewToolkitProfileService(nsIToolkitProfileService** aResult);
/**
* Try to acquire exclusive access to the specified profile directory.
*