Fixed bug https://bugzilla.mozilla.org/show_bug.cgi?id=408490
authorromashin
Sat, 19 Apr 2008 18:37:06 +0300
changeset 16797 26414f2c3299545d246c414a0b4fe399532807cd
parent 16796 81d359b4a641f1779663afcc7e3b0a2089cdd790
child 16798 a7daf5a96c25bd6cb3267f1ee518695b8d5851dd
push id1298
push userpavlov@mozilla.com
push dateSun, 17 Aug 2008 05:03:09 +0000
treeherderautoland@4a506fa751d8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs408490
milestone2.0a1pre
Fixed bug https://bugzilla.mozilla.org/show_bug.cgi?id=408490
embedding/browser/qt/src/qgeckoglobals.cpp
--- a/embedding/browser/qt/src/qgeckoglobals.cpp
+++ b/embedding/browser/qt/src/qgeckoglobals.cpp
@@ -183,45 +183,55 @@ QGeckoGlobals::pushStartup()
             return;
 
         nsCOMPtr<nsILocalFile> greDir;
         rv = NS_NewNativeLocalFile(nsDependentCString(grePath), PR_TRUE,
                                    getter_AddRefs(greDir));
         if (NS_FAILED(rv))
             return;
 
+        if (sProfileDir && !sProfileLock) {
+            rv = XRE_LockProfileDirectory(sProfileDir,
+                                          &sProfileLock);
+            if (NS_FAILED(rv)) return;
+        }
+
         rv = XRE_InitEmbedding(greDir, binDir,
                                const_cast<QTEmbedDirectoryProvider*>
                                              (&kDirectoryProvider),
                                nsnull, nsnull);
 
         if (NS_FAILED(rv))
             return;
 
-        // we no longer need a reference to the DirectoryServiceProvider
-        if (sAppFileLocProvider) {
-            NS_RELEASE(sAppFileLocProvider);
-            sAppFileLocProvider = nsnull;
-        }
-
         if (sProfileDir)
           XRE_NotifyProfile();
 
         rv = registerAppComponents();
         NS_ASSERTION(NS_SUCCEEDED(rv), "Warning: Failed to register app components.\n");
     }
 }
 
 void
 QGeckoGlobals::popStartup()
 {
     sWidgetCount--;
     if (sWidgetCount == 0) {
+
+        // we no longer need a reference to the DirectoryServiceProvider
+        if (sAppFileLocProvider) {
+            NS_RELEASE(sAppFileLocProvider);
+            sAppFileLocProvider = nsnull;
+        }
+
         // shut down XPCOM/Embedding
         XRE_TermEmbedding();
+
+        NS_IF_RELEASE(sProfileLock);
+        NS_IF_RELEASE(sProfileDir);
     }
 }
 
 void
 QGeckoGlobals::setPath(const char *aPath)
 {
     if (sPath)
         free(sPath);
@@ -259,26 +269,37 @@ QGeckoGlobals::setProfilePath(const char
         }
 
         NS_RELEASE(sProfileDir);
         NS_RELEASE(sProfileLock);
     }
 
     nsresult rv =
         NS_NewNativeLocalFile(nsDependentCString(aDir), PR_TRUE, &sProfileDir);
+
+    if (NS_SUCCEEDED(rv) && aName)
+        rv = sProfileDir->AppendNative(nsDependentCString(aName));
+
     if (NS_SUCCEEDED(rv)) {
+        PRBool exists = PR_FALSE;
+        rv = sProfileDir->Exists(&exists);
+        if (!exists)
+            rv = sProfileDir->Create(nsIFile::DIRECTORY_TYPE, 0700);
         rv = XRE_LockProfileDirectory(sProfileDir, &sProfileLock);
-        if (NS_SUCCEEDED(rv)) {
-            if (sWidgetCount)
-                XRE_NotifyProfile();
-            return;
-        }
+    }
+
+    if (NS_SUCCEEDED(rv)) {
+        if (sWidgetCount)
+            XRE_NotifyProfile();
+
+        return;
     }
 
     NS_WARNING("Failed to lock profile.");
+
     // Failed
     NS_IF_RELEASE(sProfileDir);
     NS_IF_RELEASE(sProfileLock);
 }
 
 void
 QGeckoGlobals::setDirectoryServiceProvider(nsIDirectoryServiceProvider
                                         *appFileLocProvider)