Bug 679352 - Remove libreg (Part 1: Clean nsProfileMigrator). r=bsmedberg
☠☠ backed out by c722928d8b69 ☠ ☠
authorMarco Castelluccio <mar.castelluccio@studenti.unina.it>
Sat, 24 Sep 2011 16:25:20 +0200
changeset 77506 81a7f5489ebcbca01203c689ceb6c307c49a02fa
parent 77505 8f064c1c1d4086e0b3fc050e9250b2208cf46425
child 77507 971ed890c27dfda9f4851165388fc2911c151659
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
reviewersbsmedberg
bugs679352
milestone9.0a1
Bug 679352 - Remove libreg (Part 1: Clean nsProfileMigrator). r=bsmedberg
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,41 +51,28 @@
 #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)
@@ -139,25 +126,16 @@ 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"
@@ -262,115 +240,8 @@ 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,18 +53,12 @@ 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,29 +68,16 @@ 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,45 +1856,16 @@ 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
@@ -2036,22 +2007,16 @@ 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);
@@ -3463,17 +3428,16 @@ 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");