From 9f8f9a4aa55b9e84a2271bfb21ad4a65d2d1b073 Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Wed, 22 Jul 2015 09:42:01 -0700 Subject: [PATCH] Bug 1182980 - Part 5: Use nsTHashtable::Iterator in nsWindowMemoryReporter::CollectReports. r=khuey --- dom/base/nsWindowMemoryReporter.cpp | 83 +++++++++++------------------ 1 file changed, 31 insertions(+), 52 deletions(-) diff --git a/dom/base/nsWindowMemoryReporter.cpp b/dom/base/nsWindowMemoryReporter.cpp index c1edbebd0fe..292f1c0c75b 100644 --- a/dom/base/nsWindowMemoryReporter.cpp +++ b/dom/base/nsWindowMemoryReporter.cpp @@ -457,53 +457,6 @@ GetWindows(const uint64_t& aId, nsGlobalWindow*& aWindow, void* aClosure) return PL_DHASH_NEXT; } -struct ReportGhostWindowsEnumeratorData -{ - nsIMemoryReporterCallback* mCallback; - nsISupports* mData; - bool mAnonymize; - nsresult mRv; -}; - -static PLDHashOperator -ReportGhostWindowsEnumerator(nsUint64HashKey* aIDHashKey, void* aData) -{ - ReportGhostWindowsEnumeratorData *data = - static_cast(aData); - - nsGlobalWindow::WindowByIdTable* windowsById = - nsGlobalWindow::GetWindowsTable(); - if (!windowsById) { - NS_WARNING("Couldn't get window-by-id hashtable?"); - return PL_DHASH_NEXT; - } - - nsGlobalWindow* window = windowsById->Get(aIDHashKey->GetKey()); - if (!window) { - NS_WARNING("Could not look up window?"); - return PL_DHASH_NEXT; - } - - nsAutoCString path; - path.AppendLiteral("ghost-windows/"); - AppendWindowURI(window, path, data->mAnonymize); - - nsresult rv = data->mCallback->Callback( - /* process = */ EmptyCString(), - path, - nsIMemoryReporter::KIND_OTHER, - nsIMemoryReporter::UNITS_COUNT, - /* amount = */ 1, - /* description = */ NS_LITERAL_CSTRING("A ghost window."), - data->mData); - - if (NS_FAILED(rv) && NS_SUCCEEDED(data->mRv)) { - data->mRv = rv; - } - - return PL_DHASH_NEXT; -} - NS_IMETHODIMP nsWindowMemoryReporter::CollectReports(nsIMemoryReporterCallback* aCb, nsISupports* aClosure, bool aAnonymize) @@ -521,11 +474,37 @@ nsWindowMemoryReporter::CollectReports(nsIMemoryReporterCallback* aCb, // one. nsTHashtable ghostWindows; CheckForGhostWindows(&ghostWindows); - ReportGhostWindowsEnumeratorData reportGhostWindowsEnumData = - { aCb, aClosure, aAnonymize, NS_OK }; - ghostWindows.EnumerateEntries(ReportGhostWindowsEnumerator, - &reportGhostWindowsEnumData); - nsresult rv = reportGhostWindowsEnumData.mRv; + nsresult rv = NS_OK; + for (auto iter = ghostWindows.ConstIter(); !iter.Done(); iter.Next()) { + nsGlobalWindow::WindowByIdTable* windowsById = + nsGlobalWindow::GetWindowsTable(); + if (!windowsById) { + NS_WARNING("Couldn't get window-by-id hashtable?"); + continue; + } + + nsGlobalWindow* window = windowsById->Get(iter.Get()->GetKey()); + if (!window) { + NS_WARNING("Could not look up window?"); + continue; + } + + nsAutoCString path; + path.AppendLiteral("ghost-windows/"); + AppendWindowURI(window, path, aAnonymize); + + nsresult callbackRv = aCb->Callback( + /* process = */ EmptyCString(), + path, + nsIMemoryReporter::KIND_OTHER, + nsIMemoryReporter::UNITS_COUNT, + /* amount = */ 1, + /* description = */ NS_LITERAL_CSTRING("A ghost window."), + aClosure); + if (NS_FAILED(callbackRv) && NS_SUCCEEDED(rv)) { + rv = callbackRv; + } + } NS_ENSURE_SUCCESS(rv, rv); WindowPaths windowPaths;