Backed out 6 changesets (bug 1518639) for build bustages at builds/worker/workspace/build/src/toolkit/xre/nsAppRunner.cpp on a CLOSED TREE
authorCoroiu Cristina <ccoroiu@mozilla.com>
Tue, 12 Feb 2019 19:51:52 +0200
changeset 458772 fc8431c4497f
parent 458771 9f51da716b8a
child 458773 796f9bc52be8
push id35548
push useropoprus@mozilla.com
push dateWed, 13 Feb 2019 09:48:26 +0000
treeherdermozilla-central@93e37c529818 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1518639
milestone67.0a1
backs out9f51da716b8a
e2a0ca34bab9
0780bd0ba2e1
14c454f88604
51becd44a8cb
e8f1e89edf7f
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
Backed out 6 changesets (bug 1518639) for build bustages at builds/worker/workspace/build/src/toolkit/xre/nsAppRunner.cpp on a CLOSED TREE Backed out changeset 9f51da716b8a (bug 1518639) Backed out changeset e2a0ca34bab9 (bug 1518639) Backed out changeset 0780bd0ba2e1 (bug 1518639) Backed out changeset 14c454f88604 (bug 1518639) Backed out changeset 51becd44a8cb (bug 1518639) Backed out changeset e8f1e89edf7f (bug 1518639)
toolkit/profile/nsToolkitProfileService.cpp
toolkit/profile/nsToolkitProfileService.h
toolkit/xre/nsAppRunner.cpp
--- a/toolkit/profile/nsToolkitProfileService.cpp
+++ b/toolkit/profile/nsToolkitProfileService.cpp
@@ -1580,17 +1580,17 @@ nsToolkitProfileService::Flush() {
 
 NS_IMPL_ISUPPORTS(nsToolkitProfileFactory, nsIFactory)
 
 NS_IMETHODIMP
 nsToolkitProfileFactory::CreateInstance(nsISupports* aOuter, const nsID& aIID,
                                         void** aResult) {
   if (aOuter) return NS_ERROR_NO_AGGREGATION;
 
-  RefPtr<nsToolkitProfileService> profileService =
+  nsCOMPtr<nsIToolkitProfileService> profileService =
       nsToolkitProfileService::gService;
   if (!profileService) {
     nsresult rv = NS_NewToolkitProfileService(getter_AddRefs(profileService));
     if (NS_FAILED(rv)) return rv;
   }
   return profileService->QueryInterface(aIID, aResult);
 }
 
@@ -1600,17 +1600,17 @@ nsToolkitProfileFactory::LockFactory(boo
 nsresult NS_NewToolkitProfileFactory(nsIFactory** aResult) {
   *aResult = new nsToolkitProfileFactory();
   if (!*aResult) return NS_ERROR_OUT_OF_MEMORY;
 
   NS_ADDREF(*aResult);
   return NS_OK;
 }
 
-nsresult NS_NewToolkitProfileService(nsToolkitProfileService** aResult) {
+nsresult NS_NewToolkitProfileService(nsIToolkitProfileService** aResult) {
   nsToolkitProfileService* profileService = new nsToolkitProfileService();
   if (!profileService) return NS_ERROR_OUT_OF_MEMORY;
   nsresult rv = profileService->Init();
   if (NS_FAILED(rv)) {
     NS_ERROR("nsToolkitProfileService::Init failed!");
     delete profileService;
     return rv;
   }
--- a/toolkit/profile/nsToolkitProfileService.h
+++ b/toolkit/profile/nsToolkitProfileService.h
@@ -79,17 +79,17 @@ class nsToolkitProfileService final : pu
                                 nsIToolkitProfile** aProfile, bool* aDidCreate);
   nsresult CreateResetProfile(nsIToolkitProfile** aNewProfile);
   nsresult ApplyResetProfile(nsIToolkitProfile* aOldProfile);
   void CompleteStartup();
 
  private:
   friend class nsToolkitProfile;
   friend class nsToolkitProfileFactory;
-  friend nsresult NS_NewToolkitProfileService(nsToolkitProfileService**);
+  friend nsresult NS_NewToolkitProfileService(nsIToolkitProfileService**);
 
   nsToolkitProfileService();
   ~nsToolkitProfileService();
 
   nsresult Init();
 
   nsresult CreateTimesInternal(nsIFile* profileDir);
   void GetProfileByDir(nsIFile* aRootDir, nsIFile* aLocalDir,
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -1934,16 +1934,32 @@ static ReturnAbortOnError ProfileLockedD
       NS_ENSURE_SUCCESS_LOG(rv, rv);
 #endif
     }
 
     return NS_ERROR_ABORT;
   }
 }
 
+static nsresult ProfileLockedDialog(nsIToolkitProfile* aProfile,
+                                    nsIProfileUnlocker* aUnlocker,
+                                    nsINativeAppSupport* aNative,
+                                    nsIProfileLock** aResult) {
+  nsCOMPtr<nsIFile> profileDir;
+  nsresult rv = aProfile->GetRootDir(getter_AddRefs(profileDir));
+  if (NS_FAILED(rv)) return rv;
+
+  nsCOMPtr<nsIFile> profileLocalDir;
+  rv = aProfile->GetLocalDir(getter_AddRefs(profileLocalDir));
+  if (NS_FAILED(rv)) return rv;
+
+  return ProfileLockedDialog(profileDir, profileLocalDir, aUnlocker, aNative,
+                             aResult);
+}
+
 static const char kProfileManagerURL[] =
     "chrome://mozapps/content/profile/profileSelection.xul";
 
 static ReturnAbortOnError ShowProfileManager(
     nsIToolkitProfileService* aProfileSvc, nsINativeAppSupport* aNative) {
   nsresult rv;
 
   nsCOMPtr<nsIFile> profD, profLD;
@@ -2039,81 +2055,63 @@ static ReturnAbortOnError ShowProfileMan
 
   return LaunchChild(aNative);
 }
 
 static bool gDoMigration = false;
 static bool gDoProfileReset = false;
 static nsCOMPtr<nsIToolkitProfile> gResetOldProfile;
 
-static nsresult LockProfile(nsINativeAppSupport* aNative, nsIFile* aRootDir,
-                            nsIFile* aLocalDir, nsIToolkitProfile* aProfile,
-                            nsIProfileLock** aResult) {
-  // If you close Firefox and very quickly reopen it, the old Firefox may
-  // still be closing down. Rather than immediately showing the
-  // "Firefox is running but is not responding" message, we spend a few
-  // seconds retrying first.
-
-  static const int kLockRetrySeconds = 5;
-  static const int kLockRetrySleepMS = 100;
-
-  nsresult rv;
-  nsCOMPtr<nsIProfileUnlocker> unlocker;
-  const TimeStamp start = TimeStamp::Now();
-  do {
-    if (aProfile) {
-      rv = aProfile->Lock(getter_AddRefs(unlocker), aResult);
-    } else {
-      rv = NS_LockProfilePath(aRootDir, aLocalDir, getter_AddRefs(unlocker),
-                              aResult);
-    }
-    if (NS_SUCCEEDED(rv)) {
-      StartupTimeline::Record(StartupTimeline::AFTER_PROFILE_LOCKED);
-      return NS_OK;
-    }
-    PR_Sleep(kLockRetrySleepMS);
-  } while (TimeStamp::Now() - start <
-           TimeDuration::FromSeconds(kLockRetrySeconds));
-
-  return ProfileLockedDialog(aRootDir, aLocalDir, unlocker, aNative, aResult);
-}
-
 // 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
 static nsresult SelectProfile(nsIProfileLock** aResult,
-                              nsToolkitProfileService* aProfileSvc,
-                              nsINativeAppSupport* aNative) {
+                              nsIToolkitProfileService* aProfileSvc,
+                              nsINativeAppSupport* aNative, bool* aStartOffline,
+                              nsACString* aProfileName) {
   StartupTimeline::Record(StartupTimeline::SELECT_PROFILE);
 
   nsresult rv;
+  ArgResult ar;
   *aResult = nullptr;
+  *aStartOffline = false;
+
+  ar = CheckArg("offline", nullptr,
+                CheckArgFlag::CheckOSInt | CheckArgFlag::RemoveArg);
+  if (ar == ARG_BAD) {
+    PR_fprintf(PR_STDERR,
+               "Error: argument --offline is invalid when argument --osint is "
+               "specified\n");
+    return NS_ERROR_FAILURE;
+  }
+
+  if (ar || EnvHasValue("XRE_START_OFFLINE")) *aStartOffline = true;
 
   if (EnvHasValue("MOZ_RESET_PROFILE_RESTART")) {
     gDoProfileReset = true;
     gDoMigration = true;
     SaveToEnv("MOZ_RESET_PROFILE_RESTART=");
     // We only want to restore the previous session if the profile refresh was
     // triggered by user. And if it was a user-triggered profile refresh
     // through, say, the safeMode dialog or the troubleshooting page, the
     // MOZ_RESET_PROFILE_RESTART env variable would be set. Hence we set
     // MOZ_RESET_PROFILE_MIGRATE_SESSION here so that Firefox profile migrator
     // would migrate old session data later.
     SaveToEnv("MOZ_RESET_PROFILE_MIGRATE_SESSION=1");
   }
 
   // reset-profile and migration args need to be checked before any profiles are
   // chosen below.
-  ArgResult ar = CheckArg("reset-profile", nullptr,
-                          CheckArgFlag::CheckOSInt | CheckArgFlag::RemoveArg);
+  ar = CheckArg("reset-profile", nullptr,
+                CheckArgFlag::CheckOSInt | CheckArgFlag::RemoveArg);
   if (ar == ARG_BAD) {
     PR_fprintf(PR_STDERR,
                "Error: argument --reset-profile is invalid when argument "
                "--osint is specified\n");
     return NS_ERROR_FAILURE;
   }
   if (ar == ARG_FOUND) {
     gDoProfileReset = true;
@@ -2130,78 +2128,116 @@ static nsresult SelectProfile(nsIProfile
   if (ar == ARG_FOUND) {
     gDoMigration = true;
   }
 
   nsCOMPtr<nsIFile> rootDir;
   nsCOMPtr<nsIFile> localDir;
   nsCOMPtr<nsIToolkitProfile> profile;
   // Ask the profile manager to select the profile directories to use.
+  nsToolkitProfileService* service =
+      static_cast<nsToolkitProfileService*>(aProfileSvc);
   bool didCreate = false;
-  rv = aProfileSvc->SelectStartupProfile(
+  rv = service->SelectStartupProfile(
       &gArgc, gArgv, gDoProfileReset, getter_AddRefs(rootDir),
       getter_AddRefs(localDir), getter_AddRefs(profile), &didCreate);
 
   if (rv == NS_ERROR_SHOW_PROFILE_MANAGER) {
     return ShowProfileManager(aProfileSvc, aNative);
   }
 
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (didCreate) {
     // For a fresh install, we would like to let users decide
     // to do profile migration on their own later after using.
     gDoProfileReset = false;
     gDoMigration = false;
   }
 
-  if (gDoProfileReset && !profile) {
-    NS_WARNING("Profile reset is only supported for named profiles.");
-    return NS_ERROR_ABORT;
-  }
-
-  // No profile could be found. This generally shouldn't happen, a new profile
-  // should be created in all cases except for profile reset which is covered
-  // above, but just in case...
-  if (!rootDir) {
-    return NS_ERROR_FAILURE;
-  }
-
-  // We always want to lock the profile even if we're actually going to reset
-  // it later.
-  nsCOMPtr<nsIProfileLock> tempLock;
-  rv = LockProfile(aNative, rootDir, localDir, profile, getter_AddRefs(tempLock));
-  NS_ENSURE_SUCCESS(rv, rv);
-
   if (gDoProfileReset) {
-    // Unlock the old profile
-    tempLock->Unlock();
+    if (!profile) {
+      NS_WARNING("Profile reset is only supported for named profiles.");
+      return NS_ERROR_ABORT;
+    }
+
+    {
+      // Check that the source profile is not in use by temporarily
+      // acquiring its lock.
+      nsIProfileLock* tempProfileLock;
+      nsCOMPtr<nsIProfileUnlocker> unlocker;
+      rv = profile->Lock(getter_AddRefs(unlocker), &tempProfileLock);
+      if (NS_FAILED(rv)) {
+        return ProfileLockedDialog(profile, unlocker, aNative,
+                                   &tempProfileLock);
+      }
+    }
 
     // If we're resetting a profile, create a new one and use it to startup.
     gResetOldProfile = profile;
-    rv = aProfileSvc->CreateResetProfile(getter_AddRefs(profile));
+    rv = service->CreateResetProfile(getter_AddRefs(profile));
     if (NS_SUCCEEDED(rv)) {
       rv = profile->GetRootDir(getter_AddRefs(rootDir));
       NS_ENSURE_SUCCESS(rv, rv);
       SaveFileToEnv("XRE_PROFILE_PATH", rootDir);
 
       rv = profile->GetLocalDir(getter_AddRefs(localDir));
       NS_ENSURE_SUCCESS(rv, rv);
       SaveFileToEnv("XRE_PROFILE_LOCAL_PATH", localDir);
 
-      // Lock the new profile
-      return LockProfile(aNative, rootDir, localDir, profile, aResult);
+      rv = profile->GetName(*aProfileName);
+      if (NS_FAILED(rv)) {
+        aProfileName->Truncate(0);
+      }
     } else {
       NS_WARNING("Profile reset failed.");
       return NS_ERROR_ABORT;
     }
   }
 
-  tempLock.forget(aResult);
-  return rv;
+  // No profile could be found. This generally shouldn't happen, a new profile
+  // should be created in all cases except for profile reset which is covered
+  // above, but just in case...
+  if (!rootDir) {
+    return NS_ERROR_ABORT;
+  }
+
+  // If you close Firefox and very quickly reopen it, the old Firefox may
+  // still be closing down. Rather than immediately showing the
+  // "Firefox is running but is not responding" message, we spend a few
+  // seconds retrying first.
+
+  static const int kLockRetrySeconds = 5;
+  static const int kLockRetrySleepMS = 100;
+
+  nsCOMPtr<nsIProfileUnlocker> unlocker;
+  const TimeStamp start = TimeStamp::Now();
+  do {
+    if (profile) {
+      rv = profile->Lock(getter_AddRefs(unlocker), aResult);
+    } else {
+      rv = NS_LockProfilePath(rootDir, localDir, getter_AddRefs(unlocker),
+                              aResult);
+    }
+    if (NS_SUCCEEDED(rv)) {
+      StartupTimeline::Record(StartupTimeline::AFTER_PROFILE_LOCKED);
+      // Try to grab the profile name.
+      if (aProfileName && profile) {
+        rv = profile->GetName(*aProfileName);
+        if (NS_FAILED(rv)) {
+          aProfileName->Truncate(0);
+        }
+      }
+      return NS_OK;
+    }
+    PR_Sleep(kLockRetrySleepMS);
+  } while (TimeStamp::Now() - start <
+           TimeDuration::FromSeconds(kLockRetrySeconds));
+
+  return ProfileLockedDialog(rootDir, localDir, unlocker, aNative, aResult);
 }
 
 #ifdef MOZ_BLOCK_PROFILE_DOWNGRADE
 struct FileWriteFunc : public JSONWriteFunc {
   FILE* mFile;
   explicit FileWriteFunc(FILE* aFile) : mFile(aFile) {}
 
   void Write(const char* aStr) override { fprintf(mFile, "%s", aStr); }
@@ -2374,16 +2410,18 @@ static void SubmitDowngradeTelemetry(con
   process->Run(false, args, 2);
 #  endif
 }
 
 static const char kProfileDowngradeURL[] =
     "chrome://mozapps/content/profile/profileDowngrade.xul";
 
 static ReturnAbortOnError CheckDowngrade(nsIFile* aProfileDir,
+                                         nsIFile* aProfileLocalDir,
+                                         nsACString& aProfileName,
                                          nsINativeAppSupport* aNative,
                                          nsIToolkitProfileService* aProfileSvc,
                                          const nsCString& aLastVersion) {
   int32_t result = 0;
   nsresult rv;
 
   {
     if (gfxPlatform::IsHeadless()) {
@@ -2950,30 +2988,31 @@ class XREMain {
   int XRE_main(int argc, char* argv[], const BootstrapConfig& aConfig);
   int XRE_mainInit(bool* aExitFlag);
   int XRE_mainStartup(bool* aExitFlag);
   nsresult XRE_mainRun();
 
   Result<bool, nsresult> CheckLastStartupWasCrash();
 
   nsCOMPtr<nsINativeAppSupport> mNativeApp;
-  RefPtr<nsToolkitProfileService> mProfileSvc;
+  nsCOMPtr<nsIToolkitProfileService> mProfileSvc;
   nsCOMPtr<nsIFile> mProfD;
   nsCOMPtr<nsIFile> mProfLD;
   nsCOMPtr<nsIProfileLock> mProfileLock;
 #if defined(MOZ_WIDGET_GTK)
   nsCOMPtr<nsIRemoteService> mRemoteService;
   nsProfileLock mRemoteLock;
   nsCOMPtr<nsIFile> mRemoteLockDir;
 #endif
 
   UniquePtr<ScopedXPCOMStartup> mScopedXPCOM;
   UniquePtr<XREAppData> mAppData;
 
   nsXREDirProvider mDirProvider;
+  nsAutoCString mProfileName;
   nsAutoCString mDesktopStartupID;
 
   bool mStartOffline;
   bool mShuttingDown;
 #if defined(MOZ_WIDGET_GTK)
   bool mDisableRemote;
 #endif
 
@@ -3498,29 +3537,16 @@ int XREMain::XRE_mainInit(bool* aExitFla
                "Error: argument --new-instance is invalid when argument "
                "--osint is specified\n");
     return 1;
   }
   if (ar == ARG_FOUND) {
     SaveToEnv("MOZ_NEW_INSTANCE=1");
   }
 
-  ar = CheckArg("offline", nullptr,
-                CheckArgFlag::CheckOSInt | CheckArgFlag::RemoveArg);
-  if (ar == ARG_BAD) {
-    PR_fprintf(PR_STDERR,
-               "Error: argument --offline is invalid when argument --osint is "
-               "specified\n");
-    return 1;
-  }
-
-  if (ar || EnvHasValue("XRE_START_OFFLINE")) {
-    mStartOffline = true;
-  }
-
   // Handle --help and --version command line arguments.
   // They should return quickly, so we deal with them here.
   if (CheckArg("h") || CheckArg("help") || CheckArg("?")) {
     DumpHelp();
     *aExitFlag = true;
     return 0;
   }
 
@@ -4156,17 +4182,18 @@ int XREMain::XRE_mainStartup(bool* aExit
                "your profile directory.\n");
   }
   if (NS_FAILED(rv)) {
     // We failed to choose or create profile - notify user and quit
     ProfileMissingDialog(mNativeApp);
     return 1;
   }
 
-  rv = SelectProfile(getter_AddRefs(mProfileLock), mProfileSvc, mNativeApp);
+  rv = SelectProfile(getter_AddRefs(mProfileLock), mProfileSvc, mNativeApp,
+                     &mStartOffline, &mProfileName);
   if (rv == NS_ERROR_LAUNCHED_CHILD_PROCESS || rv == NS_ERROR_ABORT) {
     *aExitFlag = true;
     return 0;
   }
 
   if (NS_FAILED(rv)) {
     // We failed to choose or create profile - notify user and quit
     ProfileMissingDialog(mNativeApp);
@@ -4210,17 +4237,18 @@ int XREMain::XRE_mainStartup(bool* aExit
   bool isDowngrade;
   nsCString lastVersion;
   bool versionOK = CheckCompatibility(
       mProfD, version, osABI, mDirProvider.GetGREDir(), mAppData->directory,
       flagFile, &cachesOK, &isDowngrade, lastVersion);
 
 #ifdef MOZ_BLOCK_PROFILE_DOWNGRADE
   if (isDowngrade && !CheckArg("allow-downgrade")) {
-    rv = CheckDowngrade(mProfD, mNativeApp, mProfileSvc, lastVersion);
+    rv = CheckDowngrade(mProfD, mProfLD, mProfileName, mNativeApp, mProfileSvc,
+                        lastVersion);
     if (rv == NS_ERROR_LAUNCHED_CHILD_PROCESS || rv == NS_ERROR_ABORT) {
       *aExitFlag = true;
       return 0;
     }
   }
 #endif
 
   rv = mDirProvider.SetProfile(mProfD, mProfLD);
@@ -4463,17 +4491,18 @@ nsresult XREMain::XRE_mainRun() {
           aKey = MOZ_APP_NAME;
           gResetOldProfile->GetName(aName);
         }
         pm->Migrate(&mDirProvider, aKey, aName);
       }
     }
 
     if (gDoProfileReset) {
-      nsresult backupCreated = ProfileResetCleanup(mProfileSvc,
+      nsresult backupCreated = ProfileResetCleanup(
+          static_cast<nsToolkitProfileService*>(mProfileSvc.get()),
           gResetOldProfile);
       if (NS_FAILED(backupCreated))
         NS_WARNING("Could not cleanup the profile that was reset");
     }
   }
 
 #ifndef XP_WIN
   nsCOMPtr<nsIFile> profileDir;
@@ -4661,17 +4690,17 @@ nsresult XREMain::XRE_mainRun() {
   CrashReporter::AnnotateCrashReport(
       CrashReporter::Annotation::ContentSandboxCapabilities, flagsString);
 #endif /* MOZ_SANDBOX && XP_LINUX */
 
 #if defined(MOZ_CONTENT_SANDBOX)
   AddSandboxAnnotations();
 #endif /* MOZ_CONTENT_SANDBOX */
 
-  mProfileSvc->CompleteStartup();
+  static_cast<nsToolkitProfileService*>(mProfileSvc.get())->CompleteStartup();
 
   {
     rv = appStartup->Run();
     if (NS_FAILED(rv)) {
       NS_ERROR("failed to run appstartup");
       gLogConsoleErrors = true;
     }
   }