From 7d3defab82537b64deb0922b3e8a6f5693272da2 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 19 Oct 2012 05:07:13 -0700 Subject: [PATCH] Bug 802894 - Add a memory reporter for nsEffectiveTLDService. r=jduell. --HG-- extra : rebase_source : 32cdfbf060c963d6a16875af406949b8eef50453 --- dom/base/nsWindowMemoryReporter.cpp | 4 --- netwerk/dns/nsEffectiveTLDService.cpp | 48 ++++++++++++++++++++++++++- netwerk/dns/nsEffectiveTLDService.h | 6 +++- 3 files changed, 52 insertions(+), 6 deletions(-) diff --git a/dom/base/nsWindowMemoryReporter.cpp b/dom/base/nsWindowMemoryReporter.cpp index 77ab0617ab15..eb736a7b3061 100644 --- a/dom/base/nsWindowMemoryReporter.cpp +++ b/dom/base/nsWindowMemoryReporter.cpp @@ -305,10 +305,6 @@ nsWindowMemoryReporter::CollectReports(nsIMemoryMultiReporterCallback* aCb, ghostWindows.Init(); CheckForGhostWindows(&ghostWindows); - nsCOMPtr tldService = do_GetService( - NS_EFFECTIVETLDSERVICE_CONTRACTID); - NS_ENSURE_STATE(tldService); - WindowPaths windowPaths; windowPaths.Init(); diff --git a/netwerk/dns/nsEffectiveTLDService.cpp b/netwerk/dns/nsEffectiveTLDService.cpp index 6d8aea304d69..311121b5fa75 100644 --- a/netwerk/dns/nsEffectiveTLDService.cpp +++ b/netwerk/dns/nsEffectiveTLDService.cpp @@ -11,10 +11,10 @@ #include "nsEffectiveTLDService.h" #include "nsIIDNService.h" +#include "nsIMemoryReporter.h" #include "nsNetUtil.h" #include "prnetdb.h" - using namespace mozilla; NS_IMPL_ISUPPORTS1(nsEffectiveTLDService, nsIEffectiveTLDService) @@ -57,6 +57,25 @@ nsDomainEntry::FuncForStaticAsserts(void) // ---------------------------------------------------------------------- +static nsEffectiveTLDService *gService = nullptr; + +NS_MEMORY_REPORTER_MALLOC_SIZEOF_FUN(EffectiveTLDServiceMallocSizeOf, + "effective-tld-service") + +static int64_t +GetEffectiveTLDSize() +{ + return gService->SizeOfIncludingThis(EffectiveTLDServiceMallocSizeOf); +} + +NS_MEMORY_REPORTER_IMPLEMENT( + EffectiveTLDService, + "explicit/xpcom/effective-TLD-service", + KIND_HEAP, + nsIMemoryReporter::UNITS_BYTES, + GetEffectiveTLDSize, + "Memory used by the effective TLD service.") + nsresult nsEffectiveTLDService::Init() { @@ -86,9 +105,36 @@ nsEffectiveTLDService::Init() NS_ENSURE_TRUE(entry, NS_ERROR_OUT_OF_MEMORY); entry->SetData(&entries[i]); } + + MOZ_ASSERT(!gService); + gService = this; + mReporter = new NS_MEMORY_REPORTER_NAME(EffectiveTLDService); + (void)::NS_RegisterMemoryReporter(mReporter); + return NS_OK; } +nsEffectiveTLDService::~nsEffectiveTLDService() +{ + (void)::NS_UnregisterMemoryReporter(mReporter); + mReporter = nullptr; + gService = nullptr; +} + +size_t +nsEffectiveTLDService::SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) +{ + size_t n = aMallocSizeOf(this); + n += mHash.SizeOfExcludingThis(nullptr, aMallocSizeOf); + + // Measurement of the following members may be added later if DMD finds it is + // worthwhile: + // - mReporter + // - mIDNService + + return n; +} + // External function for dealing with URI's correctly. // Pulls out the host portion from an nsIURI, and calls through to // GetPublicSuffixFromHost(). diff --git a/netwerk/dns/nsEffectiveTLDService.h b/netwerk/dns/nsEffectiveTLDService.h index 477e50f20828..560c515c0890 100644 --- a/netwerk/dns/nsEffectiveTLDService.h +++ b/netwerk/dns/nsEffectiveTLDService.h @@ -11,6 +11,7 @@ #include "mozilla/Attributes.h" class nsIIDNService; +class nsIMemoryReporter; #define ETLD_ENTRY_N_INDEX_BITS 30 @@ -109,11 +110,14 @@ public: nsEffectiveTLDService() { } nsresult Init(); + size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf); + private: nsresult GetBaseDomainInternal(nsCString &aHostname, uint32_t aAdditionalParts, nsACString &aBaseDomain); nsresult NormalizeHostname(nsCString &aHostname); - ~nsEffectiveTLDService() { } + ~nsEffectiveTLDService(); + nsIMemoryReporter* mReporter; nsTHashtable mHash; nsCOMPtr mIDNService; };