gecko/xpcom/base/nsMemoryReporterManager.cpp

53 lines
1.3 KiB
C++

#include "nsCOMPtr.h"
#include "nsServiceManagerUtils.h"
#include "nsMemoryReporterManager.h"
#include "nsArrayEnumerator.h"
NS_IMPL_ISUPPORTS1(nsMemoryReporterManager, nsIMemoryReporterManager)
NS_IMETHODIMP
nsMemoryReporterManager::EnumerateReporters(nsISimpleEnumerator **result)
{
return NS_NewArrayEnumerator(result, mReporters);
}
NS_IMETHODIMP
nsMemoryReporterManager::RegisterReporter(nsIMemoryReporter *reporter)
{
if (mReporters.IndexOf(reporter) != -1)
return NS_ERROR_FAILURE;
mReporters.AppendObject(reporter);
return NS_OK;
}
NS_IMETHODIMP
nsMemoryReporterManager::UnregisterReporter(nsIMemoryReporter *reporter)
{
if (!mReporters.RemoveObject(reporter))
return NS_ERROR_FAILURE;
return NS_OK;
}
NS_COM nsresult
NS_RegisterMemoryReporter (nsIMemoryReporter *reporter)
{
nsCOMPtr<nsIMemoryReporterManager> mgr = do_GetService("@mozilla.org/memory-reporter-manager;1");
if (mgr == nsnull)
return NS_ERROR_FAILURE;
return mgr->RegisterReporter(reporter);
}
NS_COM nsresult
NS_UnregisterMemoryReporter (nsIMemoryReporter *reporter)
{
nsCOMPtr<nsIMemoryReporterManager> mgr = do_GetService("@mozilla.org/memory-reporter-manager;1");
if (mgr == nsnull)
return NS_ERROR_FAILURE;
return mgr->UnregisterReporter(reporter);
}