Bug 1438615: profileCount should actually return the number of profiles. r=florian
authorDave Townsend <dtownsend@oxymoronical.com>
Wed, 08 Nov 2017 08:56:37 -0800
changeset 404542 c4420500cda8ce75074b7fa5972c7c922002693c
parent 404541 b80453dc653f1242cb4d28e030cda96657278186
child 404543 96327b595b918d83f24131a2c0d34087a22c23ec
push id33482
push userrgurzau@mozilla.com
push dateWed, 21 Feb 2018 10:00:30 +0000
treeherdermozilla-central@bb0271610fd8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersflorian
bugs1438615
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 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
@@ -943,22 +943,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