Bug 1438615: profileCount should actually return the number of profiles. r?florian
MozReview-Commit-ID: 5GyndTCKCCZ
--- 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