Closed Bug 177321 Opened 23 years ago Closed 23 years ago

nsIDirectoryServiceProvider needs to be factored out of nsProfile.cpp

Categories

(Core Graveyard :: Profile: BackEnd, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED
mozilla1.3alpha

People

(Reporter: ccarlen, Assigned: ccarlen)

Details

Attachments

(1 file, 2 obsolete files)

The are 2 implementations of nsIDirectoryServiceProvider which provide profile-relative file locations: (1) in modules/mpfilelocprovider which build a static lib (2) in nsProfile.cpp This is wrong, particularly for profile sharing. In that world, it should be possible to share the single "profile" that exists when apps use the standalone provider as well as for apps that use the profile mgr. Work will have to be done to the profile provider for sharing and it needs to happen in only one place. I have a patch which builds this provider as a static lib in the profile module. The profile mgr dll links with it but, since the static lib is exported, apps will be able to link with it as well (as the gtkWidget links with the static lib produced in modules/mpfilelocprovider). With the patch, the entire modules/mpfilelocprovider dir can be removed from the tree.
Attached patch patch v1 (obsolete) — Splinter Review
Target Milestone: --- → mozilla1.3alpha
Attached patch patch v2 (obsolete) — Splinter Review
Slight fixes. Built now on Mac CFM, Mac Mach-0, and clobber on Linux. Need r=/sr=.
Attachment #104514 - Attachment is obsolete: true
Doug, Darin - can you do the r=/sr=? CC'ing blizzard for the changes to Gtk widget (which actually uses this thing w/o profile mgr)
Status: NEW → ASSIGNED
Attachment #105537 - Flags: review+
Comment on attachment 105537 [details] [diff] [review] patch v2 r=dougt
Comment on attachment 105537 [details] [diff] [review] patch v2 >Index: embedding/browser/gtk/src/EmbedPrivate.cpp >+ nsProfileDirServiceProvider *locProvider; ... >+ locProvider = new nsProfileDirServiceProvider(PR_TRUE); >+ rv = locProvider->Initialize(); >+ if (NS_FAILED(rv)) >+ return rv; looks like locProvider would leak here as well as below on failure! >+ rv = locProvider->SetProfileDir(profileDir); >+ if (NS_FAILED(rv)) >+ return rv; >Index: embedding/browser/photon/src/PtMozilla.cpp >+ profileDir = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID); ... >+ rv = profileDir->InitWithNativePath(nsDependentCString(sProfileDir)); nit: how about calling NS_NewNativeLocalFile instead? it avoids a hit on the component manager. >+ nsProfileDirServiceProvider *locProvider; ... >+ locProvider = new nsProfileDirServiceProvider(PR_TRUE); >+ rv = locProvider->Initialize(); >+ if (NS_FAILED(rv)) >+ return rv; >+ rv = locProvider->SetProfileDir(profileDir); >+ if (NS_FAILED(rv)) >+ return rv; again locProvider would leak! >Index: embedding/browser/powerplant/source/CBrowserApp.cp >+ nsProfileDirServiceProvider *provider = new nsProfileDirServiceProvider(PR_TRUE); >+ ThrowIfNil_(provider); >+ rv = provider->Initialize(); >+ ThrowIfError_(rv); possible leak?? >Index: profile/build/nsProfileFactory.cpp >+ * Version: NPL 1.1/GPL 2.0/LGPL 2.1 NPL or MPL? i thought MPL/GPL/LGPL was the preferred license for new files, no? >Index: profile/dirserviceprovider/Makefile.in >+# The contents of this file are subject to the Netscape Public >+# License Version 1.1 (the "License"); you may not use this file this also looks to be the wrong license. double check all the licenses for new files. >Index: profile/dirserviceprovider/public/nsProfileDirServiceProvider.h >+ * @param aNotifyObservers If TRUE, profile change notifications will >+ * be sent on SetProfileDir >+ */ >+ >+ nsProfileDirServiceProvider(PRBool aNotifyObservers); wierd indentation throughout this file. >Index: profile/dirserviceprovider/src/nsProfileDirServiceProvider.cpp >+ nsIAtom* inAtom = NS_NewAtom(prop); nsCOMPtr<nsIAtom> inAtom ?? >+ if (localFile && NS_SUCCEEDED(rv)) >+ return localFile->QueryInterface(NS_GET_IID(nsIFile), (void**)_retval); nit: return CallQueryInterface(localFile, _retval); >Index: profile/src/nsProfileAccess.cpp >+#if DEBUG >+ printf("Size of struct flock = %d\n", sizeof(lock)); >+#endif should this be DEBUG_ccarlen? or maybe we don't even execute this code.
Attachment #105537 - Flags: needs-work+
Attached patch patch v3Splinter Review
New patch cleans up the possible leaks on failure by making the constructor of nsProfileDirServiceProvider protected. You can now only create one through NS_NewProfileDirServiceProvider, which returns an addref'd object, so an nsCOMPtr can be used for the local vars which may have leaked. Also, Initialize() is protected now and called by the NS_New... function. >+ profileDir = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID); ... >+ rv = profileDir->InitWithNativePath(nsDependentCString(sProfileDir)); nit: how about calling NS_NewNativeLocalFile instead? it avoids a hit on the component manager. 2. Changed that, though it wasn't mine. 3. Using MPL in all the new files. >Index: profile/dirserviceprovider/public/nsProfileDirServiceProvider.h wierd indentation throughout this file. 4. Fixed that - it was full of tabs. >Index: profile/dirserviceprovider/src/nsProfileDirServiceProvider.cpp >+ nsIAtom* inAtom = NS_NewAtom(prop); nsCOMPtr<nsIAtom> inAtom ?? 5. Kept that. it is realeased at the end, there are no early exits which get avoid that, and if it were an nsCOMPtr, each == in the method would have to invoke the operator T* of nsCOMPtr, or get() or whatever. The raw pointer is safer and more efficient here. >+ if (localFile && NS_SUCCEEDED(rv)) >+ return localFile->QueryInterface(NS_GET_IID(nsIFile), (void**)_retval); nit: return CallQueryInterface(localFile, _retval); 6. Did that. >Index: profile/src/nsProfileAccess.cpp >+#if DEBUG >+ printf("Size of struct flock = %d\n", sizeof(lock)); >+#endif 7. This garbage shouldn't have been in the patch :-/ Gone. Another look, Darin?
Attachment #105537 - Attachment is obsolete: true
Comment on attachment 105621 [details] [diff] [review] patch v3 sr=darin
Attachment #105621 - Flags: superreview+
Checked in.
Status: ASSIGNED → RESOLVED
Closed: 23 years ago
Resolution: --- → FIXED
QA Contact: ktrina → gbush
Product: Core → Core Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: