Bug 1438615: profileCount should actually return the number of profiles. r?florian draft
authorDave Townsend <dtownsend@oxymoronical.com>
Wed, 08 Nov 2017 08:56:37 -0800
changeset 757295 3b6c649d425fcb85735cb7ad05cd6ac92d3dd728
parent 755722 4a5043e1601a2496386cb0f09000eedb8bd8febb
push id99746
push userdtownsend@mozilla.com
push dateTue, 20 Feb 2018 17:21:40 +0000
reviewersflorian
bugs1438615
milestone60.0a1
Bug 1438615: profileCount should actually return the number of profiles. r?florian MozReview-Commit-ID: 5GyndTCKCCZ
toolkit/profile/nsIToolkitProfileService.idl
toolkit/profile/nsToolkitProfileService.cpp
toolkit/xre/nsXREDirProvider.cpp
--- a/toolkit/profile/nsIToolkitProfileService.idl
+++ b/toolkit/profile/nsIToolkitProfileService.idl
@@ -88,17 +88,17 @@ interface nsIToolkitProfileService : nsI
      * @return The created profile.
      */                                    
     nsIToolkitProfile createDefaultProfileForApp(in AUTF8String aProfileName,
                                                  in AUTF8String aAppName,
                                                  in AUTF8String aVendorName);
 
     /**
      * Returns the number of profiles.
-     * @return 0, 1, or 2. More than 2 profiles will always return 2.
+     * @return the number of profiles.
      */
     readonly attribute unsigned long profileCount;
 
     /**
      * Flush the profiles list file.
      */
     void flush();
 };
--- a/toolkit/profile/nsToolkitProfileService.cpp
+++ b/toolkit/profile/nsToolkitProfileService.cpp
@@ -951,22 +951,22 @@ nsToolkitProfileService::CreateTimesInte
     PR_fprintf(writeFile, "{\n\"created\": %lld\n}\n", msec);
     PR_Close(writeFile);
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsToolkitProfileService::GetProfileCount(uint32_t *aResult)
 {
-    if (!mFirst)
-        *aResult = 0;
-    else if (! mFirst->mNext)
-        *aResult = 1;
-    else
-        *aResult = 2;
+    *aResult = 0;
+    nsToolkitProfile* profile = mFirst;
+    while (profile) {
+        (*aResult)++;
+        profile = profile->mNext;
+    }
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsToolkitProfileService::Flush()
 {
     // Errors during writing might cause unhappy semi-written files.
--- a/toolkit/xre/nsXREDirProvider.cpp
+++ b/toolkit/xre/nsXREDirProvider.cpp
@@ -1046,28 +1046,22 @@ nsXREDirProvider::DoStartup()
         mode = 2;
     }
     mozilla::Telemetry::Accumulate(mozilla::Telemetry::SAFE_MODE_USAGE, mode);
 
     // Telemetry about number of profiles.
     nsCOMPtr<nsIToolkitProfileService> profileService =
       do_GetService("@mozilla.org/toolkit/profile-service;1");
     if (profileService) {
-      nsCOMPtr<nsISimpleEnumerator> profiles;
-      rv = profileService->GetProfiles(getter_AddRefs(profiles));
+      uint32_t count = 0;
+      rv = profileService->GetProfileCount(&count);
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return rv;
       }
 
-      uint32_t count = 0;
-      nsCOMPtr<nsISupports> profile;
-      while (NS_SUCCEEDED(profiles->GetNext(getter_AddRefs(profile)))) {
-        ++count;
-      }
-
       mozilla::Telemetry::Accumulate(mozilla::Telemetry::NUMBER_OF_PROFILES,
                                      count);
     }
 
     obsSvc->NotifyObservers(nullptr, "profile-initial-state", nullptr);
 
 #if defined(MOZ_CONTENT_SANDBOX)
     // Makes sure the content temp dir has been loaded if it hasn't been