Bug 1438614: Remove unused createDefaultProfileForApp. r=florian
authorDave Townsend <dtownsend@oxymoronical.com>
Wed, 08 Nov 2017 08:36:51 -0800
changeset 443853 3ec5b80c7677c777307ccbe681c35978ebc2fd2c
parent 443852 f27a86a05cb55331b56eda04d7c41c6a36313af9
child 443854 3fef64d3e7a9a422cd6bd95e8c5d2856026fd580
push idunknown
push userunknown
push dateunknown
reviewersflorian
bugs1438614
milestone60.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 1438614: Remove unused createDefaultProfileForApp. r=florian MozReview-Commit-ID: EPc9MT3jpki
toolkit/profile/nsIToolkitProfileService.idl
toolkit/profile/nsToolkitProfileService.cpp
toolkit/xre/nsXREDirProvider.cpp
toolkit/xre/nsXREDirProvider.h
--- a/toolkit/profile/nsIToolkitProfileService.idl
+++ b/toolkit/profile/nsIToolkitProfileService.idl
@@ -64,39 +64,16 @@ interface nsIToolkitProfileService : nsI
      *        default will be chosen based on the profile name.
      * @param aName
      *        The profile name.
      */
     nsIToolkitProfile createProfile(in nsIFile aRootDir,
                                     in AUTF8String aName);
 
     /**
-     * Create the default profile for an application.
-     *
-     * The profile will be typically in
-     * {Application Data}/.profilename/{salt}.default or
-     * {Application Data}/.appname/{salt}.default
-     * or if aVendorName is provided
-     * {Application Data}/.vendor/appname/{salt}.default
-     *
-     * @note Either aProfileName or aAppName must be non-empty
-     *
-     * @param  aProfileName
-     *         The name of the profile
-     * @param  aAppName
-     *         The name of the application
-     * @param  aVendorName
-     *         The name of the vendor
-     * @return The created profile.
-     */                                    
-    nsIToolkitProfile createDefaultProfileForApp(in AUTF8String aProfileName,
-                                                 in AUTF8String aAppName,
-                                                 in AUTF8String aVendorName);
-
-    /**
      * Returns the number of profiles.
      * @return the number of profiles.
      */
     readonly attribute unsigned long profileCount;
 
     /**
      * Flush the profiles list file.
      */
--- a/toolkit/profile/nsToolkitProfileService.cpp
+++ b/toolkit/profile/nsToolkitProfileService.cpp
@@ -59,29 +59,27 @@ public:
     nsToolkitProfile          *mPrev;
 
 private:
     ~nsToolkitProfile() { }
 
     nsToolkitProfile(const nsACString& aName,
                      nsIFile* aRootDir,
                      nsIFile* aLocalDir,
-                     nsToolkitProfile* aPrev,
-                     bool aForExternalApp);
+                     nsToolkitProfile* aPrev);
 
     nsresult
     RemoveInternal(bool aRemoveFiles, bool aInBackground);
 
     friend class nsToolkitProfileLock;
 
     nsCString                  mName;
     nsCOMPtr<nsIFile>          mRootDir;
     nsCOMPtr<nsIFile>          mLocalDir;
     nsIProfileLock*            mLock;
-    bool                       mForExternalApp;
 };
 
 class nsToolkitProfileLock final : public nsIProfileLock
 {
 public:
     NS_DECL_ISUPPORTS
     NS_DECL_NSIPROFILELOCK
 
@@ -130,24 +128,16 @@ private:
     {
         gService = nullptr;
     }
 
     nsresult Init();
 
     nsresult CreateTimesInternal(nsIFile *profileDir);
 
-    nsresult CreateProfileInternal(nsIFile* aRootDir,
-                                   const nsACString& aName,
-                                   const nsACString* aProfileName,
-                                   const nsACString* aAppName,
-                                   const nsACString* aVendorName,
-                                   bool aForExternalApp,
-                                   nsIToolkitProfile** aResult);
-
     RefPtr<nsToolkitProfile>  mFirst;
     nsCOMPtr<nsIToolkitProfile> mChosen;
     nsCOMPtr<nsIToolkitProfile> mDefault;
     nsCOMPtr<nsIFile>           mAppData;
     nsCOMPtr<nsIFile>           mTempData;
     nsCOMPtr<nsIFile>           mListFile;
     bool mStartWithLast;
     bool mStartOffline;
@@ -166,33 +156,29 @@ private:
         ~ProfileEnumerator() { }
         RefPtr<nsToolkitProfile> mCurrent;
     };
 };
 
 nsToolkitProfile::nsToolkitProfile(const nsACString& aName,
                                    nsIFile* aRootDir,
                                    nsIFile* aLocalDir,
-                                   nsToolkitProfile* aPrev,
-                                   bool aForExternalApp) :
+                                   nsToolkitProfile* aPrev) :
     mPrev(aPrev),
     mName(aName),
     mRootDir(aRootDir),
     mLocalDir(aLocalDir),
-    mLock(nullptr),
-    mForExternalApp(aForExternalApp)
+    mLock(nullptr)
 {
     NS_ASSERTION(aRootDir, "No file!");
 
-    if (!aForExternalApp) {
-        if (aPrev) {
-            aPrev->mNext = this;
-        } else {
-            nsToolkitProfileService::gService->mFirst = this;
-        }
+    if (aPrev) {
+        aPrev->mNext = this;
+    } else {
+        nsToolkitProfileService::gService->mFirst = this;
     }
 }
 
 NS_IMPL_ISUPPORTS(nsToolkitProfile, nsIToolkitProfile)
 
 NS_IMETHODIMP
 nsToolkitProfile::GetRootDir(nsIFile* *aResult)
 {
@@ -214,31 +200,28 @@ nsToolkitProfile::GetName(nsACString& aR
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsToolkitProfile::SetName(const nsACString& aName)
 {
     NS_ASSERTION(nsToolkitProfileService::gService,
                  "Where did my service go?");
-    NS_ENSURE_TRUE(!mForExternalApp, NS_ERROR_NOT_IMPLEMENTED);
 
     mName = aName;
 
     return NS_OK;
 }
 
 nsresult
 nsToolkitProfile::RemoveInternal(bool aRemoveFiles, bool aInBackground)
 {
     NS_ASSERTION(nsToolkitProfileService::gService,
                  "Whoa, my service is gone.");
 
-    NS_ENSURE_TRUE(!mForExternalApp, NS_ERROR_NOT_IMPLEMENTED);
-
     if (mLock)
         return NS_ERROR_FILE_IS_LOCKED;
 
     if (!mPrev && !mNext && nsToolkitProfileService::gService->mFirst != this)
         return NS_ERROR_NOT_INITIALIZED;
 
     if (aRemoveFiles) {
         // Check if another instance is using this profile.
@@ -524,17 +507,17 @@ nsToolkitProfileService::Init()
 
             rv = localDir->SetRelativeDescriptor(mTempData, filePath);
         } else {
             localDir = rootDir;
         }
 
         currentProfile = new nsToolkitProfile(name,
                                               rootDir, localDir,
-                                              currentProfile, false);
+                                              currentProfile);
         NS_ENSURE_TRUE(currentProfile, NS_ERROR_OUT_OF_MEMORY);
 
         rv = parser.GetString(profileID.get(), "Default", buffer);
         if (NS_SUCCEEDED(rv) && buffer.EqualsLiteral("1") && !foundAuroraDefault) {
             mChosen = currentProfile;
             this->SetDefaultProfile(currentProfile);
         }
 #ifdef MOZ_DEV_EDITION
@@ -729,114 +712,30 @@ static void SaltProfileName(nsACString& 
         salt[i] = kTable[rand() % ArrayLength(kTable)];
 
     salt[8] = '.';
 
     aName.Insert(salt, 0, 9);
 }
 
 NS_IMETHODIMP
-nsToolkitProfileService::CreateDefaultProfileForApp(const nsACString& aProfileName,
-                                                    const nsACString& aAppName,
-                                                    const nsACString& aVendorName,
-                                                    nsIToolkitProfile** aResult)
-{
-    NS_ENSURE_STATE(!aProfileName.IsEmpty() || !aAppName.IsEmpty());
-    nsCOMPtr<nsIFile> appData;
-    nsresult rv =
-        gDirServiceProvider->GetUserDataDirectory(getter_AddRefs(appData),
-                                                  false,
-                                                  &aProfileName,
-                                                  &aAppName,
-                                                  &aVendorName);
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    nsCOMPtr<nsIFile> profilesini;
-    appData->Clone(getter_AddRefs(profilesini));
-    rv = profilesini->AppendNative(NS_LITERAL_CSTRING("profiles.ini"));
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    bool exists = false;
-    profilesini->Exists(&exists);
-    NS_ENSURE_FALSE(exists, NS_ERROR_ALREADY_INITIALIZED);
-
-    rv = CreateProfileInternal(nullptr,
-                               NS_LITERAL_CSTRING("default"),
-                               &aProfileName, &aAppName, &aVendorName,
-                               true, aResult);
-    NS_ENSURE_SUCCESS(rv, rv);
-    NS_ENSURE_STATE(*aResult);
-
-    nsCOMPtr<nsIFile> rootDir;
-    (*aResult)->GetRootDir(getter_AddRefs(rootDir));
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    nsAutoCString profileDir;
-    rv = rootDir->GetRelativeDescriptor(appData, profileDir);
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    nsCString ini;
-    ini.SetCapacity(512);
-    ini.AppendLiteral("[General]\n");
-    ini.AppendLiteral("StartWithLastProfile=1\n\n");
-
-    ini.AppendLiteral("[Profile0]\n");
-    ini.AppendLiteral("Name=default\n");
-    ini.AppendLiteral("IsRelative=1\n");
-    ini.AppendLiteral("Path=");
-    ini.Append(profileDir);
-    ini.Append('\n');
-    ini.AppendLiteral("Default=1\n\n");
-
-    FILE* writeFile;
-    rv = profilesini->OpenANSIFileDesc("w", &writeFile);
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    if (fwrite(ini.get(), sizeof(char), ini.Length(), writeFile) !=
-        ini.Length()) {
-        rv = NS_ERROR_UNEXPECTED;
-    }
-    fclose(writeFile);
-    return rv;
-}
-
-NS_IMETHODIMP
 nsToolkitProfileService::CreateProfile(nsIFile* aRootDir,
                                        const nsACString& aName,
                                        nsIToolkitProfile** aResult)
 {
-    return CreateProfileInternal(aRootDir, aName,
-                                 nullptr, nullptr, nullptr, false, aResult);
-}
-
-nsresult
-nsToolkitProfileService::CreateProfileInternal(nsIFile* aRootDir,
-                                               const nsACString& aName,
-                                               const nsACString* aProfileName,
-                                               const nsACString* aAppName,
-                                               const nsACString* aVendorName,
-                                               bool aForExternalApp,
-                                               nsIToolkitProfile** aResult)
-{
-    nsresult rv = NS_ERROR_FAILURE;
-
-    if (!aForExternalApp) {
-        rv = GetProfileByName(aName, aResult);
-        if (NS_SUCCEEDED(rv)) {
-            return rv;
-        }
+    nsresult rv = GetProfileByName(aName, aResult);
+    if (NS_SUCCEEDED(rv)) {
+        return rv;
     }
 
     nsCOMPtr<nsIFile> rootDir (aRootDir);
 
     nsAutoCString dirName;
     if (!rootDir) {
-        rv = gDirServiceProvider->GetUserProfilesRootDir(getter_AddRefs(rootDir),
-                                                         aProfileName, aAppName,
-                                                         aVendorName);
+        rv = gDirServiceProvider->GetUserProfilesRootDir(getter_AddRefs(rootDir));
         NS_ENSURE_SUCCESS(rv, rv);
 
         dirName = aName;
         SaltProfileName(dirName);
 
         if (NS_IsNativeUTF8()) {
             rootDir->AppendNative(dirName);
         } else {
@@ -902,24 +801,24 @@ nsToolkitProfileService::CreateProfileIn
     }
 
     // We created a new profile dir. Let's store a creation timestamp.
     // Note that this code path does not apply if the profile dir was
     // created prior to launching.
     rv = CreateTimesInternal(rootDir);
     NS_ENSURE_SUCCESS(rv, rv);
 
-    nsToolkitProfile* last = aForExternalApp ? nullptr : mFirst.get();
+    nsToolkitProfile* last = mFirst.get();
     if (last) {
         while (last->mNext)
             last = last->mNext;
     }
 
     nsCOMPtr<nsIToolkitProfile> profile =
-        new nsToolkitProfile(aName, rootDir, localDir, last, aForExternalApp);
+        new nsToolkitProfile(aName, rootDir, localDir, last);
     if (!profile) return NS_ERROR_OUT_OF_MEMORY;
 
     profile.forget(aResult);
     return NS_OK;
 }
 
 nsresult
 nsToolkitProfileService::CreateTimesInternal(nsIFile* aProfileDir)
--- a/toolkit/xre/nsXREDirProvider.cpp
+++ b/toolkit/xre/nsXREDirProvider.cpp
@@ -218,50 +218,40 @@ nsXREDirProvider::AddRef()
 
 NS_IMETHODIMP_(MozExternalRefCountType)
 nsXREDirProvider::Release()
 {
   return 0;
 }
 
 nsresult
-nsXREDirProvider::GetUserProfilesRootDir(nsIFile** aResult,
-                                         const nsACString* aProfileName,
-                                         const nsACString* aAppName,
-                                         const nsACString* aVendorName)
+nsXREDirProvider::GetUserProfilesRootDir(nsIFile** aResult)
 {
   nsCOMPtr<nsIFile> file;
-  nsresult rv = GetUserDataDirectory(getter_AddRefs(file),
-                                     false,
-                                     aProfileName, aAppName, aVendorName);
+  nsresult rv = GetUserDataDirectory(getter_AddRefs(file), false);
 
   if (NS_SUCCEEDED(rv)) {
 #if !defined(XP_UNIX) || defined(XP_MACOSX)
     rv = file->AppendNative(NS_LITERAL_CSTRING("Profiles"));
 #endif
     // We must create the profile directory here if it does not exist.
     nsresult tmp = EnsureDirectoryExists(file);
     if (NS_FAILED(tmp)) {
       rv = tmp;
     }
   }
   file.swap(*aResult);
   return rv;
 }
 
 nsresult
-nsXREDirProvider::GetUserProfilesLocalDir(nsIFile** aResult,
-                                          const nsACString* aProfileName,
-                                          const nsACString* aAppName,
-                                          const nsACString* aVendorName)
+nsXREDirProvider::GetUserProfilesLocalDir(nsIFile** aResult)
 {
   nsCOMPtr<nsIFile> file;
-  nsresult rv = GetUserDataDirectory(getter_AddRefs(file),
-                                     true,
-                                     aProfileName, aAppName, aVendorName);
+  nsresult rv = GetUserDataDirectory(getter_AddRefs(file), true);
 
   if (NS_SUCCEEDED(rv)) {
 #if !defined(XP_UNIX) || defined(XP_MACOSX)
     rv = file->AppendNative(NS_LITERAL_CSTRING("Profiles"));
 #endif
     // We must create the profile directory here if it does not exist.
     nsresult tmp = EnsureDirectoryExists(file);
     if (NS_FAILED(tmp)) {
@@ -414,20 +404,20 @@ nsXREDirProvider::GetFile(const char* aP
     rv = GetUpdateRootDir(getter_AddRefs(file));
   }
   else if (!strcmp(aProperty, NS_APP_APPLICATION_REGISTRY_FILE)) {
     rv = GetUserAppDataDirectory(getter_AddRefs(file));
     if (NS_SUCCEEDED(rv))
       rv = file->AppendNative(NS_LITERAL_CSTRING(APP_REGISTRY_NAME));
   }
   else if (!strcmp(aProperty, NS_APP_USER_PROFILES_ROOT_DIR)) {
-    rv = GetUserProfilesRootDir(getter_AddRefs(file), nullptr, nullptr, nullptr);
+    rv = GetUserProfilesRootDir(getter_AddRefs(file));
   }
   else if (!strcmp(aProperty, NS_APP_USER_PROFILES_LOCAL_ROOT_DIR)) {
-    rv = GetUserProfilesLocalDir(getter_AddRefs(file), nullptr, nullptr, nullptr);
+    rv = GetUserProfilesLocalDir(getter_AddRefs(file));
   }
   else if (!strcmp(aProperty, XRE_EXECUTABLE_FILE)) {
     nsCOMPtr<nsIFile> lf;
     rv = XRE_GetBinaryPath(getter_AddRefs(lf));
     if (NS_SUCCEEDED(rv))
       file = lf;
   }
 
@@ -1547,26 +1537,23 @@ nsXREDirProvider::GetSystemExtensionsDir
       localDir.forget(aFile);
     }
   }
   return rv;
 }
 #endif
 
 nsresult
-nsXREDirProvider::GetUserDataDirectory(nsIFile** aFile, bool aLocal,
-                                       const nsACString* aProfileName,
-                                       const nsACString* aAppName,
-                                       const nsACString* aVendorName)
+nsXREDirProvider::GetUserDataDirectory(nsIFile** aFile, bool aLocal)
 {
   nsCOMPtr<nsIFile> localDir;
   nsresult rv = GetUserDataDirectoryHome(getter_AddRefs(localDir), aLocal);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  rv = AppendProfilePath(localDir, aProfileName, aAppName, aVendorName, aLocal);
+  rv = AppendProfilePath(localDir, aLocal);
   NS_ENSURE_SUCCESS(rv, rv);
 
 #ifdef DEBUG_jungshik
   nsAutoCString cwd;
   localDir->GetNativePath(cwd);
   printf("nsXREDirProvider::GetUserDataDirectory: %s\n", cwd.get());
 #endif
   rv = EnsureDirectoryExists(localDir);
@@ -1662,39 +1649,28 @@ nsXREDirProvider::AppendSysUserExtension
 #else
 #error "Don't know how to get XRE system extension dev path on your platform"
 #endif
   return NS_OK;
 }
 
 
 nsresult
-nsXREDirProvider::AppendProfilePath(nsIFile* aFile,
-                                    const nsACString* aProfileName,
-                                    const nsACString* aAppName,
-                                    const nsACString* aVendorName,
-                                    bool aLocal)
+nsXREDirProvider::AppendProfilePath(nsIFile* aFile, bool aLocal)
 {
   NS_ASSERTION(aFile, "Null pointer!");
 
   if (!gAppData) {
     return NS_ERROR_FAILURE;
   }
 
   nsAutoCString profile;
   nsAutoCString appName;
   nsAutoCString vendor;
-  if (aProfileName && !aProfileName->IsEmpty()) {
-    profile = *aProfileName;
-  } else if (aAppName) {
-    appName = *aAppName;
-    if (aVendorName) {
-      vendor = *aVendorName;
-    }
-  } else if (gAppData->profile) {
+  if (gAppData->profile) {
     profile = gAppData->profile;
   } else {
     appName = gAppData->name;
     vendor = gAppData->vendor;
   }
 
   nsresult rv;
 
@@ -1723,18 +1699,16 @@ nsXREDirProvider::AppendProfilePath(nsIF
   }
   NS_ENSURE_SUCCESS(rv, rv);
 
 #elif defined(ANDROID)
   // The directory used for storing profiles
   // The parent of this directory is set in GetUserDataDirectoryHome
   // XXX: handle gAppData->profile properly
   // XXXsmaug ...and the rest of the profile creation!
-  MOZ_ASSERT(!aAppName,
-             "Profile creation for external applications is not implemented!");
   rv = aFile->AppendNative(nsDependentCString("mozilla"));
   NS_ENSURE_SUCCESS(rv, rv);
 #elif defined(XP_UNIX)
   nsAutoCString folder;
   // Make it hidden (by starting with "."), except when local (the
   // profile is already under ~/.cache or XDG_CACHE_HOME).
   if (!aLocal)
     folder.Assign('.');
--- a/toolkit/xre/nsXREDirProvider.h
+++ b/toolkit/xre/nsXREDirProvider.h
@@ -32,48 +32,38 @@ public:
   // if aXULAppDir is null, use gArgv[0]
   nsresult Initialize(nsIFile *aXULAppDir,
                       nsIFile *aGREDir,
                       nsIDirectoryServiceProvider* aAppProvider = nullptr);
   ~nsXREDirProvider();
 
   static nsXREDirProvider* GetSingleton();
 
-  nsresult GetUserProfilesRootDir(nsIFile** aResult,
-                                  const nsACString* aProfileName,
-                                  const nsACString* aAppName,
-                                  const nsACString* aVendorName);
-  nsresult GetUserProfilesLocalDir(nsIFile** aResult,
-                                   const nsACString* aProfileName,
-                                   const nsACString* aAppName,
-                                   const nsACString* aVendorName);
+  nsresult GetUserProfilesRootDir(nsIFile** aResult);
+  nsresult GetUserProfilesLocalDir(nsIFile** aResult);
 
   // We only set the profile dir, we don't ensure that it exists;
   // that is the responsibility of the toolkit profile service.
   // We also don't fire profile-changed notifications... that is
   // the responsibility of the apprunner.
   nsresult SetProfile(nsIFile* aProfileDir, nsIFile* aProfileLocalDir);
 
   void InitializeUserPrefs();
 
   void DoShutdown();
 
   static nsresult GetUserAppDataDirectory(nsIFile* *aFile) {
-    return GetUserDataDirectory(aFile, false, nullptr, nullptr, nullptr);
+    return GetUserDataDirectory(aFile, false);
   }
   static nsresult GetUserLocalDataDirectory(nsIFile* *aFile) {
-    return GetUserDataDirectory(aFile, true, nullptr, nullptr, nullptr);
+    return GetUserDataDirectory(aFile, true);
   }
 
-  // By default GetUserDataDirectory gets profile path from gAppData,
-  // but that can be overridden by using aProfileName/aAppName/aVendorName.
-  static nsresult GetUserDataDirectory(nsIFile** aFile, bool aLocal,
-                                       const nsACString* aProfileName,
-                                       const nsACString* aAppName,
-                                       const nsACString* aVendorName);
+  // GetUserDataDirectory gets the profile path from gAppData.
+  static nsresult GetUserDataDirectory(nsIFile** aFile, bool aLocal);
 
   /* make sure you clone it, if you need to do stuff to it */
   nsIFile* GetGREDir() { return mGREDir; }
   nsIFile* GetGREBinDir() { return mGREBinDir; }
   nsIFile* GetAppDir() {
     if (mXULAppDir)
       return mXULAppDir;
     return mGREDir;
@@ -107,21 +97,17 @@ protected:
   static nsresult GetSysUserExtensionsDevDirectory(nsIFile* *aFile);
 #if defined(XP_UNIX) || defined(XP_MACOSX)
   static nsresult GetSystemExtensionsDirectory(nsIFile** aFile);
 #endif
   static nsresult EnsureDirectoryExists(nsIFile* aDirectory);
 
   // Determine the profile path within the UAppData directory. This is different
   // on every major platform.
-  static nsresult AppendProfilePath(nsIFile* aFile,
-                                    const nsACString* aProfileName,
-                                    const nsACString* aAppName,
-                                    const nsACString* aVendorName,
-                                    bool aLocal);
+  static nsresult AppendProfilePath(nsIFile* aFile, bool aLocal);
 
   static nsresult AppendSysUserExtensionPath(nsIFile* aFile);
   static nsresult AppendSysUserExtensionsDevPath(nsIFile* aFile);
 
   // Internal helper that splits a path into components using the '/' and '\\'
   // delimiters.
   static inline nsresult AppendProfileString(nsIFile* aFile, const char* aPath);