Bug 606575 - Profile local data dir (ProfLD / NS_APP_USER_PROFILE_LOCAL_50_DIR) is incorrect for a newly created profile. r=Neil

This commit is contained in:
Hector Zhao 2013-11-19 11:46:00 +08:00
parent f79900bf50
commit 2a195a70de
7 changed files with 45 additions and 38 deletions

View File

@ -124,7 +124,7 @@ BrowserDebuggerProcess.prototype = {
}
// Create a new chrome debugging profile.
this._dbgProfile = profileService.createProfile(null, null, profileName);
this._dbgProfile = profileService.createProfile(null, profileName);
profileService.flush();
dumpn("Finished creating the chrome debugger user profile.");

View File

@ -195,7 +195,7 @@ function onFinish()
// Create profile named profileName in profileRoot.
try {
profile = gProfileService.createProfile(gProfileRoot, null, profileName);
profile = gProfileService.createProfile(gProfileRoot, profileName);
}
catch (e) {
var profileCreationFailed =

View File

@ -10,7 +10,7 @@ interface nsIFile;
interface nsIToolkitProfile;
interface nsIProfileLock;
[scriptable, uuid(b619f83d-8317-473c-b342-67905993fdc7)]
[scriptable, uuid(b81c33a6-1ce8-4695-856b-02b7f15cc114)]
interface nsIToolkitProfileService : nsISupports
{
attribute boolean startWithLastProfile;
@ -37,19 +37,17 @@ interface nsIToolkitProfileService : nsISupports
/**
* Create a new profile.
*
* The profile temporary directory will be chosen based on where the
* profile directory is located.
*
* @param aRootDir
* The profile directory. May be null, in which case a suitable
* default will be chosen based on the profile name.
* @param aTempDir
* The profile temporary directory. May be null, in which case a
* suitable default will be chosen based either on the profile name
* if aRootDir is null or aRootDir itself.
* @param aName
* The profile name.
*/
nsIToolkitProfile createProfile(in nsIFile aRootDir,
in nsIFile aTempDir,
in AUTF8String aName);
/**

View File

@ -127,7 +127,6 @@ private:
nsresult CreateTimesInternal(nsIFile *profileDir);
nsresult CreateProfileInternal(nsIFile* aRootDir,
nsIFile* aLocalDir,
const nsACString& aName,
const nsACString* aProfileName,
const nsACString* aAppName,
@ -656,7 +655,7 @@ nsToolkitProfileService::CreateDefaultProfileForApp(const nsACString& aProfileNa
NS_ENSURE_FALSE(exists, NS_ERROR_ALREADY_INITIALIZED);
nsIFile* profileDefaultsDir = aProfileDefaultsDir;
rv = CreateProfileInternal(nullptr, nullptr,
rv = CreateProfileInternal(nullptr,
NS_LITERAL_CSTRING("default"),
&aProfileName, &aAppName, &aVendorName,
&profileDefaultsDir, true, aResult);
@ -698,17 +697,15 @@ nsToolkitProfileService::CreateDefaultProfileForApp(const nsACString& aProfileNa
NS_IMETHODIMP
nsToolkitProfileService::CreateProfile(nsIFile* aRootDir,
nsIFile* aLocalDir,
const nsACString& aName,
nsIToolkitProfile** aResult)
{
return CreateProfileInternal(aRootDir, aLocalDir, aName,
return CreateProfileInternal(aRootDir, aName,
nullptr, nullptr, nullptr, nullptr, false, aResult);
}
nsresult
nsToolkitProfileService::CreateProfileInternal(nsIFile* aRootDir,
nsIFile* aLocalDir,
const nsACString& aName,
const nsACString* aProfileName,
const nsACString* aAppName,
@ -745,26 +742,22 @@ nsToolkitProfileService::CreateProfileInternal(nsIFile* aRootDir,
}
}
nsCOMPtr<nsIFile> localDir (aLocalDir);
nsCOMPtr<nsIFile> localDir;
if (!localDir) {
if (aRootDir) {
localDir = aRootDir;
}
else {
rv = gDirServiceProvider->GetUserProfilesLocalDir(getter_AddRefs(localDir),
aProfileName,
aAppName,
aVendorName);
NS_ENSURE_SUCCESS(rv, rv);
bool isRelative;
rv = mAppData->Contains(rootDir, true, &isRelative);
if (NS_SUCCEEDED(rv) && isRelative) {
nsAutoCString path;
rv = rootDir->GetRelativeDescriptor(mAppData, path);
NS_ENSURE_SUCCESS(rv, rv);
// use same salting
if (NS_IsNativeUTF8()) {
localDir->AppendNative(dirName);
} else {
localDir->Append(NS_ConvertUTF8toUTF16(dirName));
}
}
rv = NS_NewNativeLocalFile(EmptyCString(), true,
getter_AddRefs(localDir));
NS_ENSURE_SUCCESS(rv, rv);
rv = localDir->SetRelativeDescriptor(mTempData, path);
} else {
localDir = rootDir;
}
bool exists;

View File

@ -29,15 +29,23 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=543854
const ASCIIName = "myprofile";
const UnicodeName = "\u09A0\u09BE\u0995\u09C1\u09B0"; // A Bengali name
var gDirService;
var gIOService;
var gProfileService;
var gDefaultLocalProfileParent;
gDirService = Cc["@mozilla.org/file/directory_service;1"].
getService(Ci.nsIProperties);
gIOService = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService);
gProfileService = Cc["@mozilla.org/toolkit/profile-service;1"].
getService(Ci.nsIToolkitProfileService);
gDefaultLocalProfileParent = gDirService.get("DefProfLRt", Ci.nsIFile);
createProfile(ASCIIName);
createProfile(UnicodeName);
SimpleTest.finish();
@ -76,7 +84,7 @@ function createProfile(profileName) {
// Filesystem precision is lower than Date precision.
let lowerBound = Date.now() - 1000;
let profile = gProfileService.createProfile(null, null, profileName);
let profile = gProfileService.createProfile(null, profileName);
// check that the directory was created
isnot(profile, null, "Profile " + profileName + " created");
@ -107,6 +115,16 @@ function createProfile(profileName) {
// Check against real clock time.
checkBounds(lowerBound, created, upperBound);
// Clean up the profile before local profile test.
profile.remove(true);
// Create with non-null aRootDir
let profile = gProfileService.createProfile(profileDir, profileName);
let localProfileDir = profile.localDir;
ok(gDefaultLocalProfileParent.contains(localProfileDir, false),
"Local profile dir created in DefProfLRt");
// Clean up the profile.
profile.remove(true);
}

View File

@ -40,7 +40,6 @@ CreateResetProfile(nsIToolkitProfileService* aProfileSvc, nsIToolkitProfile* *aN
nsAutoCString newProfileName("default-");
newProfileName.Append(nsPrintfCString("%lld", PR_Now() / 1000));
nsresult rv = aProfileSvc->CreateProfile(nullptr, // choose a default dir for us
nullptr, // choose a default dir for us
newProfileName,
getter_AddRefs(newProfile));
if (NS_FAILED(rv)) return rv;

View File

@ -2184,12 +2184,12 @@ SelectProfile(nsIProfileLock* *aResult, nsIToolkitProfileService* aProfileSvc, n
return rv;
}
// As with -profile, assume that the given path will be used for both the
// main profile directory and the temp profile directory.
rv = aProfileSvc->CreateProfile(lf, lf, nsDependentCSubstring(arg, delim),
// As with -profile, assume that the given path will be used for the
// main profile directory.
rv = aProfileSvc->CreateProfile(lf, nsDependentCSubstring(arg, delim),
getter_AddRefs(profile));
} else {
rv = aProfileSvc->CreateProfile(nullptr, nullptr, nsDependentCString(arg),
rv = aProfileSvc->CreateProfile(nullptr, nsDependentCString(arg),
getter_AddRefs(profile));
}
// Some pathological arguments can make it this far
@ -2274,7 +2274,6 @@ SelectProfile(nsIProfileLock* *aResult, nsIToolkitProfileService* aProfileSvc, n
// create a default profile
nsCOMPtr<nsIToolkitProfile> profile;
nsresult rv = aProfileSvc->CreateProfile(nullptr, // choose a default dir for us
nullptr, // choose a default dir for us
NS_LITERAL_CSTRING("default"),
getter_AddRefs(profile));
if (NS_SUCCEEDED(rv)) {