From d015f6354ec57b4d606087fd830973bf6212eae1 Mon Sep 17 00:00:00 2001 From: "ccarlen%netscape.com" Date: Sat, 4 Nov 2000 16:27:30 +0000 Subject: [PATCH] Bug 46866. Splitting profile API into public and internal parts. r=racham@netscape.com, sr=alecf@netscape.com --- profile/macbuild/ProfileServicesIDL.mcp | Bin 71154 -> 69520 bytes profile/public/Makefile.in | 1 + profile/public/makefile.win | 1 + profile/public/nsIProfile.idl | 53 ++--------------- profile/src/nsProfile.cpp | 33 +++++++---- profile/src/nsProfile.h | 6 +- profile/src/nsProfileAccess.cpp | 73 +++++++++++++++++++----- profile/src/nsProfileAccess.h | 2 +- xpfe/appshell/src/nsFileLocations.cpp | 4 +- xpfe/bootstrap/nsAppRunner.cpp | 4 +- 10 files changed, 98 insertions(+), 79 deletions(-) diff --git a/profile/macbuild/ProfileServicesIDL.mcp b/profile/macbuild/ProfileServicesIDL.mcp index cbe640c2acb8cbb4ba637cd83aa35ba019d5ee9d..f34a362642d1bf984a5195ae25b7d0a9587afb8b 100644 GIT binary patch delta 1592 zcmZWpZ%kWN6u;-a*HYTo*OtBq6ev{VLgyb)VlwxEGGc~7$x_*f(M*DF1(!gJP!cjq zKt7C-5VmsNZk!1c=LhBzC){Mt;20*$B-JqZVvrAN<{y@2l8G=sY!1)utFg|Lo_EhV zzjMw#_uO;4ab7w3fubLZ#o7rWG9eHopv)7n+?>|!HmkB1&3pKlzG0wG*e0QdF4)?V z4GAZpT|ySClB|urj-aKTb^Dc${_SI>6GLpg;J9%4cXD-unJ(IbN)xiOI4cF*vE6e&Xaj^c+igpJS(5Q`=&U#Ceh`R6rT?lf?0I+N|~J| z68p`8pkY^lZze_*_L2&bB4x0nJB}|xzA0L6QtlLv)gVi$@HjZwmI{?GI?zPi9r4a1 zxMq!q;}Ys>N4!1uko_v^K}?PQ*{O}^SkwvmQsOms%n2tT&hj;=kiu73od$K1vyY8w zkYD5+#&FGiH-~0XehL}Md5X;mTzemtkcqqEC|3#;L%w6{h)X3)%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%%MndSC2={SWb5ziFo*t^L zaQl4#C}nQ-oM&BIk;$&nm~bx80{dC$7mV2i{dcBBpY%GnauBKdt(Yv-FL{k~bcI)O zB2D(h$M$VUE;w%?r6sbfJaUc0nK1{OFpYLJPlxv=dh?TI_zu3X1CR YDSRO=ohqZ7AA2LcOh3GetProfileList(profileListStr); - return NS_OK; +NS_IMETHODIMP nsProfile::GetProfileList(PRUint32 *length, PRUnichar ***profileNames) +{ + NS_ENSURE_ARG_POINTER(length); + *length = 0; + NS_ENSURE_ARG_POINTER(profileNames); + *profileNames = nsnull; + + return gProfileDataAccess->GetProfileList(nsIProfileInternal::LIST_ONLY_NEW, length, profileNames); +} + + +NS_IMETHODIMP nsProfile::GetProfileListX(PRUint32 whichKind, PRUint32 *length, PRUnichar ***profileNames) +{ + NS_ENSURE_ARG_POINTER(length); + *length = 0; + NS_ENSURE_ARG_POINTER(profileNames); + *profileNames = nsnull; + + return gProfileDataAccess->GetProfileList(whichKind, length, profileNames); } @@ -1532,7 +1543,7 @@ NS_IMETHODIMP nsProfile::StartApprunner(const PRUnichar* profileName) return rv; } -NS_IMETHODIMP nsProfile::LoadNewProfilePrefs() +nsresult nsProfile::LoadNewProfilePrefs() { nsresult rv; NS_WITH_SERVICE(nsIPref, prefs, kPrefCID, &rv); diff --git a/profile/src/nsProfile.h b/profile/src/nsProfile.h index c25762e0871..175d8161820 100644 --- a/profile/src/nsProfile.h +++ b/profile/src/nsProfile.h @@ -21,6 +21,7 @@ */ #include "nsIProfile.h" +#include "nsIProfileInternal.h" #include "nsIProfileStartupListener.h" #include "nsCOMPtr.h" #include "nsISupports.h" @@ -57,11 +58,12 @@ #define REGISTRY_VERSION_STRING "Version" #define REGISTRY_VERSION_1_0 "1.0" -class nsProfile: public nsIProfile, +class nsProfile: public nsIProfileInternal, public nsIDirectoryServiceProvider { NS_DECL_ISUPPORTS NS_DECL_NSIPROFILE + NS_DECL_NSIPROFILEINTERNAL NS_DECL_NSIDIRECTORYSERVICEPROVIDER private: @@ -73,6 +75,8 @@ private: nsIFile *newProfDir, const char *fileName); nsresult EnsureProfileFileExists(nsIFile *aFile); + nsresult LoadNewProfilePrefs(); + nsresult SetProfileDir(const PRUnichar *profileName, nsIFile *profileDir); nsresult CloneProfileDirectorySpec(nsILocalFile **aLocalFile); nsresult AddLevelOfIndirection(nsIFile *aDir); diff --git a/profile/src/nsProfileAccess.cpp b/profile/src/nsProfileAccess.cpp index aa2b19c1acb..693cabeb826 100644 --- a/profile/src/nsProfileAccess.cpp +++ b/profile/src/nsProfileAccess.cpp @@ -1155,31 +1155,74 @@ nsProfileAccess::UpdateRegistry(nsIFile* regName) return rv; } -// Return the list of profiles, 4x and 5x. +// Return the list of profiles, 4x, 5x, or both. // For 4x profiles text "- migrate" is appended // to inform the JavaScript about the migration status. -void -nsProfileAccess::GetProfileList(PRUnichar **profileListStr) +nsresult +nsProfileAccess::GetProfileList(PRInt32 whichKind, PRUint32 *length, PRUnichar ***result) { - NS_ASSERTION(profileListStr, "Invalid profileListStr pointer"); + NS_ENSURE_ARG_POINTER(length); + *length = 0; + NS_ENSURE_ARG_POINTER(result); + *result = nsnull; - nsAutoString profileList; - - for (PRInt32 index=0; index < mCount; index++) + nsresult rv = NS_OK; + PRInt32 count, localLength = 0; + PRUnichar **outArray, **next; + + switch (whichKind) + { + case nsIProfileInternal::LIST_ONLY_NEW: + count = mNumProfiles; + break; + case nsIProfileInternal::LIST_ONLY_OLD: + GetNum4xProfiles(&count); + break; + case nsIProfileInternal::LIST_ALL: + count = mCount; + break; + default: + NS_ASSERTION(PR_FALSE, "Bad parameter"); + return NS_ERROR_INVALID_ARG; + } + + next = outArray = (PRUnichar **)nsMemory::Alloc(count * sizeof(PRUnichar *)); + if (!outArray) + return NS_ERROR_OUT_OF_MEMORY; + + for (PRInt32 index=0; index < mCount && localLength < count; index++) { ProfileStruct* profileItem = (ProfileStruct *) (mProfiles->ElementAt(index)); + PRBool isMigrated = profileItem->isMigrated.EqualsWithConversion(REGISTRY_YES_STRING); + + if (whichKind == nsIProfileInternal::LIST_ONLY_OLD && isMigrated) + continue; + else if (whichKind == nsIProfileInternal::LIST_ONLY_NEW && !isMigrated) + continue; - if (index != 0) + *next = profileItem->profileName.ToNewUnicode(); + if (*next == nsnull) { - profileList.AppendWithConversion(","); + rv = NS_ERROR_OUT_OF_MEMORY; + break; } - profileList += profileItem->profileName; - - if (profileItem->isMigrated.EqualsWithConversion(REGISTRY_NO_STRING)) - profileList.AppendWithConversion(" - migrate"); + next++; + localLength++; } - - *profileListStr = profileList.ToNewUnicode(); + + if (NS_SUCCEEDED(rv)) + { + *result = outArray; + *length = localLength; + } + else + { + while (--next >= outArray) + nsMemory::Free(*next); + nsMemory::Free(outArray); + } + + return rv; } // Return a boolean based on the profile existence. diff --git a/profile/src/nsProfileAccess.h b/profile/src/nsProfileAccess.h index a1c9fce18da..5707471bfd4 100644 --- a/profile/src/nsProfileAccess.h +++ b/profile/src/nsProfileAccess.h @@ -112,7 +112,7 @@ public: PRInt32 FindProfileIndex(const PRUnichar* profileName); nsresult UpdateRegistry(nsIFile* regName); - void GetProfileList(PRUnichar **profileListStr); + nsresult GetProfileList(PRInt32 whichKind, PRUint32 *length, PRUnichar ***result); PRBool ProfileExists(const PRUnichar *profileName); nsresult Get4xProfileInfo(const char *registryName); nsresult UpdateProfileArray(); diff --git a/xpfe/appshell/src/nsFileLocations.cpp b/xpfe/appshell/src/nsFileLocations.cpp index 5a51c2b5303..78eecaa8eb2 100644 --- a/xpfe/appshell/src/nsFileLocations.cpp +++ b/xpfe/appshell/src/nsFileLocations.cpp @@ -52,7 +52,7 @@ #include #endif -#include "nsIProfile.h" +#include "nsIProfileInternal.h" #include "nsIPrefMigration.h" // for NEW_IMAPMAIL_DIR_NAME, etc #include "plstr.h" @@ -185,7 +185,7 @@ static PRBool GetProfileDirectory(nsFileSpec& outSpec) { // First time, initialize gProfileDir nsresult rv; - NS_WITH_SERVICE(nsIProfile, profileService, kProfileCID, &rv); + NS_WITH_SERVICE(nsIProfileInternal, profileService, kProfileCID, &rv); if (NS_FAILED(rv)) return PR_FALSE; diff --git a/xpfe/bootstrap/nsAppRunner.cpp b/xpfe/bootstrap/nsAppRunner.cpp index adb1625f9c5..d589050350c 100644 --- a/xpfe/bootstrap/nsAppRunner.cpp +++ b/xpfe/bootstrap/nsAppRunner.cpp @@ -99,7 +99,7 @@ static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); #endif // header file for profile manager -#include "nsIProfile.h" +#include "nsIProfileInternal.h" #if defined(XP_UNIX) extern void InstallUnixSignalHandlers(const char *ProgramName); @@ -802,7 +802,7 @@ static nsresult InitializeProfileService(nsICmdLineService *cmdLineArgs) } else { - nsCOMPtr profileMgr = do_GetService(kProfileCID, &rv); + nsCOMPtr profileMgr = do_GetService(kProfileCID, &rv); NS_ASSERTION(NS_SUCCEEDED(rv), "failed to get profile manager"); if (NS_FAILED(rv)) return rv;