Bug 1518639: Hold the profile service as its concrete type. r=froydnj
authorDave Townsend <dtownsend@oxymoronical.com>
Tue, 12 Feb 2019 20:14:33 +0000
changeset 458793 be5bd597747afe360b14fd53453f6a35f920bd09
parent 458792 5006d54251f7a10118997f7214d0734b7e5121d7
child 458794 827f76ed2ca7404ce5efbd01d46bd089cad2440e
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)
reviewersfroydnj
bugs1518639
milestone67.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 1518639: Hold the profile service as its concrete type. r=froydnj We cast the nsIToolkitProfileService to nsToolkitProfileService in a bunch of places, might as well just hold that instead. Differential Revision: https://phabricator.services.mozilla.com/D19414
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;
 
-  nsCOMPtr<nsIToolkitProfileService> profileService =
+  RefPtr<nsToolkitProfileService> 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(nsIToolkitProfileService** aResult) {
+nsresult NS_NewToolkitProfileService(nsToolkitProfileService** 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(nsIToolkitProfileService**);
+  friend nsresult NS_NewToolkitProfileService(nsToolkitProfileService**);
 
   nsToolkitProfileService();
   ~nsToolkitProfileService();
 
   nsresult Init();
 
   nsresult CreateTimesInternal(nsIFile* profileDir);
   void GetProfileByDir(nsIFile* aRootDir, nsIFile* aLocalDir,
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -2064,17 +2064,17 @@ static nsCOMPtr<nsIToolkitProfile> gRese
 //
 // 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,
-                              nsIToolkitProfileService* aProfileSvc,
+                              nsToolkitProfileService* aProfileSvc,
                               nsINativeAppSupport* aNative, bool* aStartOffline,
                               nsACString* aProfileName) {
   StartupTimeline::Record(StartupTimeline::SELECT_PROFILE);
 
   nsresult rv;
   ArgResult ar;
   *aResult = nullptr;
   *aStartOffline = false;
@@ -2128,20 +2128,18 @@ 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 = service->SelectStartupProfile(
+  rv = aProfileSvc->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);
@@ -2168,17 +2166,17 @@ static nsresult SelectProfile(nsIProfile
       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 = service->CreateResetProfile(getter_AddRefs(profile));
+    rv = aProfileSvc->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);
@@ -2988,17 +2986,17 @@ 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;
-  nsCOMPtr<nsIToolkitProfileService> mProfileSvc;
+  RefPtr<nsToolkitProfileService> mProfileSvc;
   nsCOMPtr<nsIFile> mProfD;
   nsCOMPtr<nsIFile> mProfLD;
   nsCOMPtr<nsIProfileLock> mProfileLock;
 #if defined(MOZ_WIDGET_GTK)
   nsCOMPtr<nsIRemoteService> mRemoteService;
   nsProfileLock mRemoteLock;
   nsCOMPtr<nsIFile> mRemoteLockDir;
 #endif
@@ -4491,18 +4489,17 @@ nsresult XREMain::XRE_mainRun() {
           aKey = MOZ_APP_NAME;
           gResetOldProfile->GetName(aName);
         }
         pm->Migrate(&mDirProvider, aKey, aName);
       }
     }
 
     if (gDoProfileReset) {
-      nsresult backupCreated = ProfileResetCleanup(
-          static_cast<nsToolkitProfileService*>(mProfileSvc.get()),
+      nsresult backupCreated = ProfileResetCleanup(mProfileSvc,
           gResetOldProfile);
       if (NS_FAILED(backupCreated))
         NS_WARNING("Could not cleanup the profile that was reset");
     }
   }
 
 #ifndef XP_WIN
   nsCOMPtr<nsIFile> profileDir;
@@ -4690,17 +4687,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 */
 
-  static_cast<nsToolkitProfileService*>(mProfileSvc.get())->CompleteStartup();
+  mProfileSvc->CompleteStartup();
 
   {
     rv = appStartup->Run();
     if (NS_FAILED(rv)) {
       NS_ERROR("failed to run appstartup");
       gLogConsoleErrors = true;
     }
   }