Backout changeset 81a7f5489ebc (bug 679352), since burning comm-central; a=callek
authorEd Morley <bmo@edmorley.co.uk>
Sun, 25 Sep 2011 16:27:30 +0100
changeset 78826 c722928d8b69b18daf5c6a29e1c66ea35cf7e230
parent 78825 183d0e60d82c2b0e81b0ac2d0675f9aabd07b8f5
child 78880 44ef245b870628514f0fd9ba667788b56b0ecd65
child 78973 168f1c6b69dcea14020201a73a7b4671488df760
push id78
push userclegnitto@mozilla.com
push dateFri, 16 Dec 2011 17:32:24 +0000
treeherdermozilla-release@79d24e644fdd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscallek
bugs679352
milestone9.0a1
backs out81a7f5489ebcbca01203c689ceb6c307c49a02fa
first release with
nightly linux32
c722928d8b69 / 9.0a1 / 20110926030901 / files
nightly linux64
c722928d8b69 / 9.0a1 / 20110926030901 / files
nightly mac
c722928d8b69 / 9.0a1 / 20110926030901 / files
nightly win32
c722928d8b69 / 9.0a1 / 20110926030901 / files
nightly win64
c722928d8b69 / 9.0a1 / 20110926030901 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Backout changeset 81a7f5489ebc (bug 679352), since burning comm-central; a=callek
browser/components/migration/src/nsProfileMigrator.cpp
browser/components/migration/src/nsProfileMigrator.h
toolkit/profile/nsIProfileMigrator.idl
toolkit/xre/nsAppRunner.cpp
--- a/browser/components/migration/src/nsProfileMigrator.cpp
+++ b/browser/components/migration/src/nsProfileMigrator.cpp
@@ -51,28 +51,41 @@
 #include "nsIWindowWatcher.h"
 
 #include "nsCOMPtr.h"
 #include "nsBrowserCompsCID.h"
 #include "nsComponentManagerUtils.h"
 #include "nsDirectoryServiceDefs.h"
 #include "nsServiceManagerUtils.h"
 
+#include "NSReg.h"
 #include "nsStringAPI.h"
 #include "nsUnicharUtils.h"
 #ifdef XP_WIN
 #include <windows.h>
 #include "nsIWindowsRegKey.h"
 #include "nsILocalFileWin.h"
 #else
 #include <limits.h>
 #endif
 
 #include "nsAutoPtr.h"
 
+#ifndef MAXPATHLEN
+#ifdef PATH_MAX
+#define MAXPATHLEN PATH_MAX
+#elif defined(_MAX_PATH)
+#define MAXPATHLEN _MAX_PATH
+#elif defined(CCHMAXPATH)
+#define MAXPATHLEN CCHMAXPATH
+#else
+#define MAXPATHLEN 1024
+#endif
+#endif
+
 ///////////////////////////////////////////////////////////////////////////////
 // nsIProfileMigrator
 
 #define MIGRATION_WIZARD_FE_URL "chrome://browser/content/migration/migration.xul"
 #define MIGRATION_WIZARD_FE_FEATURES "chrome,dialog,modal,centerscreen,titlebar"
 
 NS_IMETHODIMP
 nsProfileMigrator::Migrate(nsIProfileStartup* aStartup)
@@ -126,16 +139,25 @@ nsProfileMigrator::Migrate(nsIProfileSta
   return ww->OpenWindow(nsnull, 
                         MIGRATION_WIZARD_FE_URL,
                         "_blank",
                         MIGRATION_WIZARD_FE_FEATURES,
                         params,
                         getter_AddRefs(migrateWizard));
 }
 
+NS_IMETHODIMP
+nsProfileMigrator::Import()
+{
+  if (ImportRegistryProfiles(NS_LITERAL_CSTRING("Firefox")))
+    return NS_OK;
+
+  return NS_ERROR_FAILURE;
+}
+
 ///////////////////////////////////////////////////////////////////////////////
 // nsProfileMigrator
 
 NS_IMPL_ISUPPORTS1(nsProfileMigrator, nsIProfileMigrator)
 
 #ifdef XP_WIN
 
 #define INTERNAL_NAME_IEXPLORE        "iexplore"
@@ -240,8 +262,115 @@ nsProfileMigrator::GetDefaultBrowserMigr
   CHECK_MIGRATOR("safari");
 #endif
   CHECK_MIGRATOR("opera");
 
 #undef CHECK_MIGRATOR
 #endif
   return NS_ERROR_FAILURE;
 }
+
+PRBool
+nsProfileMigrator::ImportRegistryProfiles(const nsACString& aAppName)
+{
+  nsresult rv;
+
+  nsCOMPtr<nsIToolkitProfileService> profileSvc
+    (do_GetService(NS_PROFILESERVICE_CONTRACTID));
+  NS_ENSURE_TRUE(profileSvc, PR_FALSE);
+
+  nsCOMPtr<nsIProperties> dirService
+    (do_GetService("@mozilla.org/file/directory_service;1"));
+  NS_ENSURE_TRUE(dirService, PR_FALSE);
+
+  nsCOMPtr<nsILocalFile> regFile;
+#ifdef XP_WIN
+  rv = dirService->Get(NS_WIN_APPDATA_DIR, NS_GET_IID(nsILocalFile),
+                       getter_AddRefs(regFile));
+  NS_ENSURE_SUCCESS(rv, PR_FALSE);
+  regFile->AppendNative(aAppName);
+  regFile->AppendNative(NS_LITERAL_CSTRING("registry.dat"));
+#elif defined(XP_MACOSX)
+  rv = dirService->Get(NS_MAC_USER_LIB_DIR, NS_GET_IID(nsILocalFile),
+                       getter_AddRefs(regFile));
+  NS_ENSURE_SUCCESS(rv, PR_FALSE);
+  regFile->AppendNative(aAppName);
+  regFile->AppendNative(NS_LITERAL_CSTRING("Application Registry"));
+#elif defined(XP_OS2)
+  rv = dirService->Get(NS_OS2_HOME_DIR, NS_GET_IID(nsILocalFile),
+                       getter_AddRefs(regFile));
+  NS_ENSURE_SUCCESS(rv, PR_FALSE);
+  regFile->AppendNative(aAppName);
+  regFile->AppendNative(NS_LITERAL_CSTRING("registry.dat"));
+#else
+  rv = dirService->Get(NS_UNIX_HOME_DIR, NS_GET_IID(nsILocalFile),
+                       getter_AddRefs(regFile));
+  NS_ENSURE_SUCCESS(rv, PR_FALSE);
+  nsCAutoString dotAppName;
+  ToLowerCase(aAppName, dotAppName);
+  dotAppName.Insert('.', 0);
+  
+  regFile->AppendNative(dotAppName);
+  regFile->AppendNative(NS_LITERAL_CSTRING("appreg"));
+#endif
+
+  nsCAutoString path;
+  rv = regFile->GetNativePath(path);
+  NS_ENSURE_SUCCESS(rv, PR_FALSE);
+
+  if (NR_StartupRegistry())
+    return PR_FALSE;
+
+  PRBool migrated = PR_FALSE;
+  HREG reg = nsnull;
+  RKEY profiles = 0;
+  REGENUM enumstate = 0;
+  char profileName[MAXREGNAMELEN];
+
+  if (NR_RegOpen(path.get(), &reg))
+    goto cleanup;
+
+  if (NR_RegGetKey(reg, ROOTKEY_COMMON, "Profiles", &profiles))
+    goto cleanup;
+
+  while (!NR_RegEnumSubkeys(reg, profiles, &enumstate,
+                            profileName, MAXREGNAMELEN, REGENUM_CHILDREN)) {
+#ifdef DEBUG_bsmedberg
+    printf("Found profile %s.\n", profileName);
+#endif
+
+    RKEY profile = 0;
+    if (NR_RegGetKey(reg, profiles, profileName, &profile)) {
+      NS_ERROR("Could not get the key that was enumerated.");
+      continue;
+    }
+
+    char profilePath[MAXPATHLEN];
+    if (NR_RegGetEntryString(reg, profile, "directory",
+                             profilePath, MAXPATHLEN))
+      continue;
+
+    nsCOMPtr<nsILocalFile> profileFile
+      (do_CreateInstance("@mozilla.org/file/local;1"));
+    if (!profileFile)
+      continue;
+
+#if defined (XP_MACOSX)
+    rv = profileFile->SetPersistentDescriptor(nsDependentCString(profilePath));
+#else
+    NS_ConvertUTF8toUTF16 widePath(profilePath);
+    rv = profileFile->InitWithPath(widePath);
+#endif
+    if (NS_FAILED(rv)) continue;
+
+    nsCOMPtr<nsIToolkitProfile> tprofile;
+    profileSvc->CreateProfile(profileFile, nsnull,
+                              nsDependentCString(profileName),
+                              getter_AddRefs(tprofile));
+    migrated = PR_TRUE;
+  }
+
+cleanup:
+  if (reg)
+    NR_RegClose(reg);
+  NR_ShutdownRegistry();
+  return migrated;
+}
--- a/browser/components/migration/src/nsProfileMigrator.h
+++ b/browser/components/migration/src/nsProfileMigrator.h
@@ -53,12 +53,18 @@ public:
 
   nsProfileMigrator() { }
 
 protected:
   ~nsProfileMigrator() { }
 
   nsresult GetDefaultBrowserMigratorKey(nsACString& key,
                                         nsCOMPtr<nsIBrowserProfileMigrator>& bpm);
+
+  /**
+   * Import profiles from ~/.firefox/
+   * @return PR_TRUE if any profiles imported.
+   */
+  PRBool ImportRegistryProfiles(const nsACString& aAppName);
 };
 
 #endif
 
--- a/toolkit/profile/nsIProfileMigrator.idl
+++ b/toolkit/profile/nsIProfileMigrator.idl
@@ -68,16 +68,29 @@ interface nsIProfileStartup : nsISupport
  * @provider Application (Profile-migration code)
  * @client   Toolkit (Startup code)
  * @obtainable service, contractid("@mozilla.org/toolkit/profile-migrator;1")
  */
 [scriptable, uuid(24ce8b9d-b7ff-4279-aef4-26e158f03e34)]
 interface nsIProfileMigrator : nsISupports 
 {
   /**
+   * Import existing profile paths.  When the app is started the first
+   * time, if there are no INI-style profiles, appstartup will call
+   * this method to import any registry- style profiles that may
+   * exist. When this method is called, there is no event queue
+   * service and this method should not attempt to use the network or
+   * show any GUI.
+   *
+   * @note You don't actually have to move the profile data. Just call
+   *       nsIToolkitProfileService.create on the existing profile path(s).
+   */
+  void import();
+
+  /**
    * Do profile migration.
    *
    * When this method is called, a default profile has been created;
    * XPCOM has been initialized such that compreg.dat is in the
    * profile; the directory service does *not* return a key for
    * NS_APP_USER_PROFILE_50_DIR or any of the keys depending on an active
    * profile. To figure out the directory of the "current" profile, use
    * aStartup.directory.
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -1856,16 +1856,45 @@ ShowProfileManager(nsIToolkitProfileServ
   aProfileSvc->GetStartOffline(&offline);
   if (offline) {
     SaveToEnv("XRE_START_OFFLINE=1");
   }
 
   return LaunchChild(aNative);
 }
 
+static nsresult
+ImportProfiles(nsIToolkitProfileService* aPService,
+               nsINativeAppSupport* aNative)
+{
+  nsresult rv;
+
+  SaveToEnv("XRE_IMPORT_PROFILES=1");
+
+  // try to import old-style profiles
+  { // scope XPCOM
+    ScopedXPCOMStartup xpcom;
+    rv = xpcom.Initialize();
+    if (NS_SUCCEEDED(rv)) {
+#ifdef XP_MACOSX
+      CommandLineServiceMac::SetupMacCommandLine(gRestartArgc, gRestartArgv, PR_TRUE);
+#endif
+
+      nsCOMPtr<nsIProfileMigrator> migrator
+        (do_GetService(NS_PROFILEMIGRATOR_CONTRACTID));
+      if (migrator) {
+        migrator->Import();
+      }
+    }
+  }
+
+  aPService->Flush();
+  return LaunchChild(aNative);
+}
+
 // Pick a profile. We need to end up with a profile lock.
 //
 // 1) check for -profile <path>
 // 2) check for -P <name>
 // 3) check for -ProfileManager
 // 4) use the default profile, if there is one
 // 5) if there are *no* profiles, set up profile-migration
 // 6) display the profile-manager UI
@@ -2007,16 +2036,22 @@ SelectProfile(nsIProfileLock* *aResult, 
 
     return rv;
   }
 
   PRUint32 count;
   rv = profileSvc->GetProfileCount(&count);
   NS_ENSURE_SUCCESS(rv, rv);
 
+  if (gAppData->flags & NS_XRE_ENABLE_PROFILE_MIGRATOR) {
+    if (!count && !EnvHasValue("XRE_IMPORT_PROFILES")) {
+      return ImportProfiles(profileSvc, aNative);
+    }
+  }
+
   ar = CheckArg("p", PR_FALSE, &arg);
   if (ar == ARG_BAD) {
     ar = CheckArg("osint");
     if (ar == ARG_FOUND) {
       PR_fprintf(PR_STDERR, "Error: argument -p is invalid when argument -osint is specified\n");
       return NS_ERROR_FAILURE;
     }
     return ShowProfileManager(profileSvc, aNative);
@@ -3428,16 +3463,17 @@ XRE_main(int argc, char* argv[], const n
         SaveStateForAppInitiatedRestart();
 
         // clear out any environment variables which may have been set 
         // during the relaunch process now that we know we won't be relaunching.
         SaveToEnv("XRE_PROFILE_PATH=");
         SaveToEnv("XRE_PROFILE_LOCAL_PATH=");
         SaveToEnv("XRE_PROFILE_NAME=");
         SaveToEnv("XRE_START_OFFLINE=");
+        SaveToEnv("XRE_IMPORT_PROFILES=");
         SaveToEnv("NO_EM_RESTART=");
         SaveToEnv("XUL_APP_FILE=");
         SaveToEnv("XRE_BINARY_PATH=");
 
         NS_TIME_FUNCTION_MARK("env munging");
 
         if (!shuttingDown) {
           NS_TIME_FUNCTION_MARK("Next: CreateHiddenWindow");