Bug 831193 (part 20) - Make nsPrefixSetReporter a subclass of MemoryReporterBase. r=gcp.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
@@ -7,12 +7,14 @@
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsDebug.h"
|
||||
#include "nsPrintfCString.h"
|
||||
#include "nsTArray.h"
|
||||
#include "nsString.h"
|
||||
#include "nsUrlClassifierPrefixSet.h"
|
||||
#include "nsIUrlClassifierPrefixSet.h"
|
||||
#include "nsIRandomGenerator.h"
|
||||
#include "nsIFile.h"
|
||||
#include "nsIMemoryReporter.h"
|
||||
#include "nsToolkitCompsCID.h"
|
||||
#include "nsTArray.h"
|
||||
#include "nsThreadUtils.h"
|
||||
@@ -34,77 +36,29 @@ static const PRLogModuleInfo *gUrlClassifierPrefixSetLog = nullptr;
|
||||
#define LOG_ENABLED() (false)
|
||||
#endif
|
||||
|
||||
class nsPrefixSetReporter : public nsIMemoryReporter
|
||||
class PrefixSetReporter MOZ_FINAL : public MemoryReporterBase
|
||||
{
|
||||
public:
|
||||
nsPrefixSetReporter(nsUrlClassifierPrefixSet* aParent, const nsACString& aName);
|
||||
virtual ~nsPrefixSetReporter() {}
|
||||
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
NS_DECL_NSIMEMORYREPORTER
|
||||
PrefixSetReporter(nsUrlClassifierPrefixSet* aPrefixSet,
|
||||
const nsACString& aName)
|
||||
: MemoryReporterBase(
|
||||
nsPrintfCString(
|
||||
"explicit/storage/prefix-set/%s",
|
||||
(!aName.IsEmpty() ? PromiseFlatCString(aName).get() : "?!")
|
||||
).get(),
|
||||
KIND_HEAP, UNITS_BYTES,
|
||||
"Memory used by the prefix set for a URL classifier.")
|
||||
, mPrefixSet(aPrefixSet)
|
||||
{}
|
||||
|
||||
private:
|
||||
nsCString mPath;
|
||||
nsUrlClassifierPrefixSet* mParent;
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsPrefixSetReporter, nsIMemoryReporter)
|
||||
|
||||
NS_MEMORY_REPORTER_MALLOC_SIZEOF_FUN(StoragePrefixSetMallocSizeOf)
|
||||
|
||||
nsPrefixSetReporter::nsPrefixSetReporter(nsUrlClassifierPrefixSet* aParent,
|
||||
const nsACString& aName)
|
||||
: mParent(aParent)
|
||||
{
|
||||
mPath.Assign(NS_LITERAL_CSTRING("explicit/storage/prefixset"));
|
||||
if (!aName.IsEmpty()) {
|
||||
mPath.Append("/");
|
||||
mPath.Append(aName);
|
||||
int64_t Amount() MOZ_OVERRIDE
|
||||
{
|
||||
return mPrefixSet->SizeOfIncludingThis(MallocSizeOf);
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPrefixSetReporter::GetProcess(nsACString& aProcess)
|
||||
{
|
||||
aProcess.Truncate();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPrefixSetReporter::GetPath(nsACString& aPath)
|
||||
{
|
||||
aPath.Assign(mPath);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPrefixSetReporter::GetKind(int32_t* aKind)
|
||||
{
|
||||
*aKind = nsIMemoryReporter::KIND_HEAP;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPrefixSetReporter::GetUnits(int32_t* aUnits)
|
||||
{
|
||||
*aUnits = nsIMemoryReporter::UNITS_BYTES;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPrefixSetReporter::GetAmount(int64_t* aAmount)
|
||||
{
|
||||
*aAmount = mParent->SizeOfIncludingThis(StoragePrefixSetMallocSizeOf);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPrefixSetReporter::GetDescription(nsACString& aDescription)
|
||||
{
|
||||
aDescription.Assign(NS_LITERAL_CSTRING("Memory used by a PrefixSet for "
|
||||
"UrlClassifier, in bytes."));
|
||||
return NS_OK;
|
||||
}
|
||||
nsUrlClassifierPrefixSet* mPrefixSet;
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsUrlClassifierPrefixSet, nsIUrlClassifierPrefixSet)
|
||||
|
||||
@@ -120,7 +74,7 @@ nsUrlClassifierPrefixSet::nsUrlClassifierPrefixSet()
|
||||
NS_IMETHODIMP
|
||||
nsUrlClassifierPrefixSet::Init(const nsACString& aName)
|
||||
{
|
||||
mReporter = new nsPrefixSetReporter(this, aName);
|
||||
mReporter = new PrefixSetReporter(this, aName);
|
||||
NS_RegisterMemoryReporter(mReporter);
|
||||
|
||||
return NS_OK;
|
||||
|
||||
Reference in New Issue
Block a user