Bug 606575 - Profile local data dir (ProfLD / NS_APP_USER_PROFILE_LOCAL_50_DIR) is incorrect for a newly created profile. r=Neil
authorHector Zhao <bzhao@mozilla.com>
Tue, 19 Nov 2013 11:46:00 +0800
changeset 159997 e2cc0ab6587195ccd3ec154e9ff826dd9b58eb59
parent 159996 e3aba1d2f23f167df7ac3180f9d231264eb8b098
child 159998 c189beb8d5f5a01a8a55676702b9cbe011f5f250
push idunknown
push userunknown
push dateunknown
reviewersNeil
bugs606575
milestone28.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 606575 - Profile local data dir (ProfLD / NS_APP_USER_PROFILE_LOCAL_50_DIR) is incorrect for a newly created profile. r=Neil
browser/devtools/debugger/DebuggerProcess.jsm
toolkit/profile/content/createProfileWizard.js
toolkit/profile/nsIToolkitProfileService.idl
toolkit/profile/nsToolkitProfileService.cpp
toolkit/profile/test/test_create_profile.xul
toolkit/xre/ProfileReset.cpp
toolkit/xre/nsAppRunner.cpp
--- a/browser/devtools/debugger/DebuggerProcess.jsm
+++ b/browser/devtools/debugger/DebuggerProcess.jsm
@@ -119,17 +119,17 @@ BrowserDebuggerProcess.prototype = {
     } catch (e) {
       // Requested profile object was not found.
       let msg = "Creating a profile failed. " + e.name + ": " + e.message;
       dumpn(msg);
       Cu.reportError(msg);
     }
 
     // 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.");
     dumpn("Flushed profile service with: " + profileName);
   },
 
   /**
    * Creates and initializes the profile & process for the remote debugger.
--- a/toolkit/profile/content/createProfileWizard.js
+++ b/toolkit/profile/content/createProfileWizard.js
@@ -190,17 +190,17 @@ function enableNextButton()
 
 function onFinish() 
 {
   var profileName = document.getElementById("profileName").value;
   var profile;
 
   // Create profile named profileName in profileRoot.
   try {
-    profile = gProfileService.createProfile(gProfileRoot, null, profileName);
+    profile = gProfileService.createProfile(gProfileRoot, profileName);
   }
   catch (e) {
     var profileCreationFailed =
       gProfileManagerBundle.getString("profileCreationFailed");
     var profileCreationFailedTitle =
       gProfileManagerBundle.getString("profileCreationFailedTitle");
     var promptService = C["@mozilla.org/embedcomp/prompt-service;1"].
       getService(I.nsIPromptService);
--- a/toolkit/profile/nsIToolkitProfileService.idl
+++ b/toolkit/profile/nsIToolkitProfileService.idl
@@ -5,17 +5,17 @@
 
 #include "nsISupports.idl"
 
 interface nsISimpleEnumerator;
 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;
     attribute boolean startOffline;
 
     readonly attribute nsISimpleEnumerator /*nsIToolkitProfile*/ profiles;
 
     attribute nsIToolkitProfile selectedProfile;
@@ -32,29 +32,27 @@ interface nsIToolkitProfileService : nsI
      * Lock an arbitrary path as a profile. If the path does not exist, it
      * will be created and the defaults copied from the application directory.
      */
     nsIProfileLock lockProfilePath(in nsIFile aDirectory,
                                    in nsIFile aTempDirectory);
 
     /**
      * 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);
 
     /**
      * Create the default profile for an application.
      *
      * The profile will be typically in
      * {Application Data}/.profilename/{salt}.default or
      * {Application Data}/.appname/{salt}.default
--- a/toolkit/profile/nsToolkitProfileService.cpp
+++ b/toolkit/profile/nsToolkitProfileService.cpp
@@ -122,17 +122,16 @@ private:
         gService = nullptr;
     }
 
     NS_HIDDEN_(nsresult) Init();
 
     nsresult CreateTimesInternal(nsIFile *profileDir);
 
     nsresult CreateProfileInternal(nsIFile* aRootDir,
-                                   nsIFile* aLocalDir,
                                    const nsACString& aName,
                                    const nsACString* aProfileName,
                                    const nsACString* aAppName,
                                    const nsACString* aVendorName,
                                    /*in*/ nsIFile** aProfileDefaultsDir,
                                    bool aForExternalApp,
                                    nsIToolkitProfile** aResult);
 
@@ -651,17 +650,17 @@ nsToolkitProfileService::CreateDefaultPr
     rv = profilesini->AppendNative(NS_LITERAL_CSTRING("profiles.ini"));
     NS_ENSURE_SUCCESS(rv, rv);
 
     bool exists = false;
     profilesini->Exists(&exists);
     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);
     NS_ENSURE_SUCCESS(rv, rv);
     NS_ENSURE_STATE(*aResult);
 
     nsCOMPtr<nsIFile> rootDir;
     (*aResult)->GetRootDir(getter_AddRefs(rootDir));
@@ -693,27 +692,25 @@ nsToolkitProfileService::CreateDefaultPr
         rv = NS_ERROR_UNEXPECTED;
     }
     fclose(writeFile);
     return rv;
 }
 
 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,
                                                const nsACString* aVendorName,
                                                nsIFile** aProfileDefaultsDir,
                                                bool aForExternalApp,
                                                nsIToolkitProfile** aResult)
 {
@@ -740,36 +737,32 @@ nsToolkitProfileService::CreateProfileIn
 
         if (NS_IsNativeUTF8()) {
             rootDir->AppendNative(dirName);
         } else {
             rootDir->Append(NS_ConvertUTF8toUTF16(dirName));
         }
     }
 
-    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;
     rv = rootDir->Exists(&exists);
     NS_ENSURE_SUCCESS(rv, rv);
 
     if (exists) {
         rv = rootDir->IsDirectory(&exists);
--- a/toolkit/profile/test/test_create_profile.xul
+++ b/toolkit/profile/test/test_create_profile.xul
@@ -24,25 +24,33 @@ https://bugzilla.mozilla.org/show_bug.cg
   SimpleTest.waitForExplicitFinish();
 
   const Cc = Components.classes;
   const Ci = Components.interfaces;
 
   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();
 
 /**
  * Read the contents of an nsIFile. Throws on error.
 
  * @param file an nsIFile instance.
@@ -71,17 +79,17 @@ function checkBounds(lowerBound, value, 
   ok(upperBound >= value, "value " + value +
                           " is within upper bound " + upperBound);
 }
 
 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");
 
   let profileDir = profile.rootDir;
 
   ok(profileDir.exists(), "Profile dir created");
   ok(profileDir.isDirectory(), "Profile dir is a directory");
@@ -102,15 +110,25 @@ function createProfile(profileName) {
   let upperBound = Date.now() + 1000;
 
   let created = json.created;
   ok(created, "created is set");
 
   // 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);
 }
 
   ]]>
   </script>
 </window>
--- a/toolkit/xre/ProfileReset.cpp
+++ b/toolkit/xre/ProfileReset.cpp
@@ -35,17 +35,16 @@ CreateResetProfile(nsIToolkitProfileServ
 {
   NS_ABORT_IF_FALSE(aProfileSvc, "NULL profile service");
 
   nsCOMPtr<nsIToolkitProfile> newProfile;
   // Make the new profile "default-" + the time in seconds since epoch for uniqueness.
   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;
 
   rv = aProfileSvc->Flush();
   if (NS_FAILED(rv)) return rv;
 
   newProfile.swap(*aNewProfile);
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -2179,22 +2179,22 @@ SelectProfile(nsIProfileLock* *aResult, 
       nsCOMPtr<nsIFile> lf;
       rv = NS_NewNativeLocalFile(nsDependentCString(delim + 1),
                                    true, getter_AddRefs(lf));
       if (NS_FAILED(rv)) {
         PR_fprintf(PR_STDERR, "Error: profile path not valid.\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
     if (NS_FAILED(rv)) {
       PR_fprintf(PR_STDERR, "Error creating profile.\n");
       return rv; 
     }
     rv = NS_ERROR_ABORT;  
@@ -2269,17 +2269,16 @@ SelectProfile(nsIProfileLock* *aResult, 
 
   if (!count) {
     gDoMigration = true;
     gDoProfileReset = false;
 
     // 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)) {
       aProfileSvc->Flush();
       rv = profile->Lock(nullptr, aResult);
       if (NS_SUCCEEDED(rv)) {
         if (aProfileName)
           aProfileName->Assign(NS_LITERAL_CSTRING("default"));