Skip to content

Commit

Permalink
Backed out 2 changesets (bug 1630947) for causing build bustages on R…
Browse files Browse the repository at this point in the history
…eportingObserver.cpp. CLOSED TREE

Backed out changeset 18c357daf0f7 (bug 1630947)
Backed out changeset 6bfed9f2487d (bug 1630947)
  • Loading branch information
CosminSabou committed Apr 17, 2020
1 parent a4daa08 commit 948e626
Show file tree
Hide file tree
Showing 30 changed files with 434 additions and 600 deletions.
73 changes: 69 additions & 4 deletions dom/base/nsGlobalWindowInner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@
#include "mozilla/dom/ImageBitmap.h"
#include "mozilla/dom/ImageBitmapBinding.h"
#include "mozilla/dom/InstallTriggerBinding.h"
#include "mozilla/dom/Report.h"
#include "mozilla/dom/ReportingObserver.h"
#include "mozilla/dom/SharedWorker.h"
#include "mozilla/dom/ServiceWorker.h"
#include "mozilla/dom/ServiceWorkerRegistration.h"
Expand Down Expand Up @@ -326,6 +328,9 @@ static nsGlobalWindowOuter* GetOuterWindowForForwarding(
// dialogs for this window.
#define MAX_SUCCESSIVE_DIALOG_COUNT 5

// Max number of Report objects
#define MAX_REPORT_RECORDS 100

static LazyLogModule gDOMLeakPRLogInner("DOMLeakInner");
extern mozilla::LazyLogModule gTimeoutLog;

Expand Down Expand Up @@ -1129,7 +1134,7 @@ void nsGlobalWindowInner::FreeInnerObjects() {
mIndexedDB = nullptr;
}

nsIGlobalObject::UnlinkObjectsInGlobal();
UnlinkHostObjectURIs();

NotifyWindowIDDestroyed("inner-window-destroyed");

Expand Down Expand Up @@ -1359,8 +1364,10 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsGlobalWindowInner)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mExternal)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mInstallTrigger)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mIntlUtils)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mReportRecords)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mReportingObservers)

tmp->TraverseObjectsInGlobal(cb);
tmp->TraverseHostObjectURIs(cb);

NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mChromeFields.mMessageManager)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mChromeFields.mGroupMessageManagers)
Expand Down Expand Up @@ -1458,8 +1465,10 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGlobalWindowInner)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mExternal)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mInstallTrigger)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mIntlUtils)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mReportRecords)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mReportingObservers)

tmp->UnlinkObjectsInGlobal();
tmp->UnlinkHostObjectURIs();

NS_IMPL_CYCLE_COLLECTION_UNLINK(mIdleRequestExecutor)

Expand Down Expand Up @@ -4929,8 +4938,8 @@ nsresult nsGlobalWindowInner::Observe(nsISupports* aSubject, const char* aTopic,
if (!nsCRT::strcmp(aTopic, MEMORY_PRESSURE_OBSERVER_TOPIC)) {
if (mPerformance) {
mPerformance->MemoryPressure();
mReportRecords.Clear();
}
RemoveReportRecords();
return NS_OK;
}

Expand Down Expand Up @@ -7328,6 +7337,62 @@ nsPIDOMWindowInner::nsPIDOMWindowInner(nsPIDOMWindowOuter* aOuterWindow,
}
}

void nsPIDOMWindowInner::RegisterReportingObserver(ReportingObserver* aObserver,
bool aBuffered) {
MOZ_ASSERT(aObserver);

if (mReportingObservers.Contains(aObserver)) {
return;
}

if (NS_WARN_IF(!mReportingObservers.AppendElement(aObserver, fallible))) {
return;
}

if (!aBuffered) {
return;
}

for (Report* report : mReportRecords) {
aObserver->MaybeReport(report);
}
}

void nsPIDOMWindowInner::UnregisterReportingObserver(
ReportingObserver* aObserver) {
MOZ_ASSERT(aObserver);
mReportingObservers.RemoveElement(aObserver);
}

void nsPIDOMWindowInner::BroadcastReport(Report* aReport) {
MOZ_ASSERT(aReport);

for (ReportingObserver* observer : mReportingObservers) {
observer->MaybeReport(aReport);
}

if (NS_WARN_IF(!mReportRecords.AppendElement(aReport, fallible))) {
return;
}

while (mReportRecords.Length() > MAX_REPORT_RECORDS) {
mReportRecords.RemoveElementAt(0);
}
}

void nsPIDOMWindowInner::NotifyReportingObservers() {
const nsTArray<RefPtr<ReportingObserver>> reportingObservers(
mReportingObservers);
for (auto& observer : reportingObservers) {
// MOZ_KnownLive because 'reportingObservers' is guaranteed to
// keep it alive.
//
// This can go away once
// https://bugzilla.mozilla.org/show_bug.cgi?id=1620312 is fixed.
MOZ_KnownLive(observer)->MaybeNotify();
}
}

nsPIDOMWindowInner::~nsPIDOMWindowInner() = default;

#undef FORWARD_TO_OUTER
Expand Down
4 changes: 2 additions & 2 deletions dom/base/nsGlobalWindowOuter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1606,7 +1606,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsGlobalWindowOuter)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocShell)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mBrowsingContext)

tmp->TraverseObjectsInGlobal(cb);
tmp->TraverseHostObjectURIs(cb);

NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mChromeFields.mBrowserDOMWindow)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
Expand Down Expand Up @@ -1649,7 +1649,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGlobalWindowOuter)
tmp->mBrowsingContext = nullptr;
}

tmp->UnlinkObjectsInGlobal();
tmp->UnlinkHostObjectURIs();

if (tmp->IsChromeWindow()) {
NS_IMPL_CYCLE_COLLECTION_UNLINK(mChromeFields.mBrowserDOMWindow)
Expand Down
135 changes: 33 additions & 102 deletions dom/base/nsIGlobalObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,12 @@
#include "mozilla/CycleCollectedJSContext.h"
#include "mozilla/dom/BlobURLProtocolHandler.h"
#include "mozilla/dom/FunctionBinding.h"
#include "mozilla/dom/Report.h"
#include "mozilla/dom/ReportingObserver.h"
#include "mozilla/dom/ServiceWorker.h"
#include "mozilla/dom/ServiceWorkerRegistration.h"
#include "nsContentUtils.h"
#include "nsThreadUtils.h"
#include "nsGlobalWindowInner.h"

// Max number of Report objects
constexpr auto MAX_REPORT_RECORDS = 100;

using mozilla::AutoSlowOperation;
using mozilla::CycleCollectedJSContext;
using mozilla::DOMEventTargetHelper;
Expand All @@ -35,9 +30,6 @@ using mozilla::dom::ServiceWorkerRegistration;
using mozilla::dom::ServiceWorkerRegistrationDescriptor;
using mozilla::dom::VoidFunction;

nsIGlobalObject::nsIGlobalObject()
: mIsDying(false), mIsScriptForbidden(false), mIsInnerWindow(false) {}

bool nsIGlobalObject::IsScriptForbidden(JSObject* aCallback,
bool aIsJSImplementedWebIDL) const {
if (mIsScriptForbidden) {
Expand All @@ -57,7 +49,7 @@ bool nsIGlobalObject::IsScriptForbidden(JSObject* aCallback,
}

nsIGlobalObject::~nsIGlobalObject() {
UnlinkObjectsInGlobal();
UnlinkHostObjectURIs();
DisconnectEventTargetObjects();
MOZ_DIAGNOSTIC_ASSERT(mEventTargetObjects.isEmpty());
}
Expand Down Expand Up @@ -109,44 +101,47 @@ class UnlinkHostObjectURIsRunnable final : public mozilla::Runnable {

} // namespace

void nsIGlobalObject::UnlinkObjectsInGlobal() {
if (!mHostObjectURIs.IsEmpty()) {
// BlobURLProtocolHandler is main-thread only.
if (NS_IsMainThread()) {
for (uint32_t index = 0; index < mHostObjectURIs.Length(); ++index) {
BlobURLProtocolHandler::RemoveDataEntry(mHostObjectURIs[index]);
}

mHostObjectURIs.Clear();
} else {
RefPtr<UnlinkHostObjectURIsRunnable> runnable =
new UnlinkHostObjectURIsRunnable(mHostObjectURIs);
MOZ_ASSERT(mHostObjectURIs.IsEmpty());

nsresult rv = NS_DispatchToMainThread(runnable);
if (NS_FAILED(rv)) {
NS_WARNING("Failed to dispatch a runnable to the main-thread.");
}
void nsIGlobalObject::UnlinkHostObjectURIs() {
if (mHostObjectURIs.IsEmpty()) {
return;
}

if (NS_IsMainThread()) {
for (uint32_t index = 0; index < mHostObjectURIs.Length(); ++index) {
BlobURLProtocolHandler::RemoveDataEntry(mHostObjectURIs[index]);
}

mHostObjectURIs.Clear();
return;
}

mReportRecords.Clear();
mReportingObservers.Clear();
// BlobURLProtocolHandler is main-thread only.

RefPtr<UnlinkHostObjectURIsRunnable> runnable =
new UnlinkHostObjectURIsRunnable(mHostObjectURIs);
MOZ_ASSERT(mHostObjectURIs.IsEmpty());

nsresult rv = NS_DispatchToMainThread(runnable);
if (NS_FAILED(rv)) {
NS_WARNING("Failed to dispatch a runnable to the main-thread.");
}
}

void nsIGlobalObject::TraverseObjectsInGlobal(
nsCycleCollectionTraversalCallback& cb) {
void nsIGlobalObject::TraverseHostObjectURIs(
nsCycleCollectionTraversalCallback& aCb) {
if (mHostObjectURIs.IsEmpty()) {
return;
}

// Currently we only store BlobImpl objects off the the main-thread and they
// are not CCed.
if (!mHostObjectURIs.IsEmpty() && NS_IsMainThread()) {
for (uint32_t index = 0; index < mHostObjectURIs.Length(); ++index) {
BlobURLProtocolHandler::Traverse(mHostObjectURIs[index], cb);
}
if (!NS_IsMainThread()) {
return;
}

nsIGlobalObject* tmp = this;
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mReportRecords)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mReportingObservers)
for (uint32_t index = 0; index < mHostObjectURIs.Length(); ++index) {
BlobURLProtocolHandler::Traverse(mHostObjectURIs[index], aCb);
}
}

void nsIGlobalObject::AddEventTargetObject(DOMEventTargetHelper* aObject) {
Expand Down Expand Up @@ -279,67 +274,3 @@ void nsIGlobalObject::QueueMicrotask(VoidFunction& aCallback) {
context->DispatchToMicroTask(mt.forget());
}
}

void nsIGlobalObject::RegisterReportingObserver(ReportingObserver* aObserver,
bool aBuffered) {
MOZ_ASSERT(aObserver);

if (mReportingObservers.Contains(aObserver)) {
return;
}

if (NS_WARN_IF(!mReportingObservers.AppendElement(aObserver, fallible))) {
return;
}

if (!aBuffered) {
return;
}

for (Report* report : mReportRecords) {
aObserver->MaybeReport(report);
}
}

void nsIGlobalObject::UnregisterReportingObserver(
ReportingObserver* aObserver) {
MOZ_ASSERT(aObserver);
mReportingObservers.RemoveElement(aObserver);
}

void nsIGlobalObject::BroadcastReport(Report* aReport) {
MOZ_ASSERT(aReport);

for (ReportingObserver* observer : mReportingObservers) {
observer->MaybeReport(aReport);
}

if (NS_WARN_IF(!mReportRecords.AppendElement(aReport, fallible))) {
return;
}

while (mReportRecords.Length() > MAX_REPORT_RECORDS) {
mReportRecords.RemoveElementAt(0);
}
}

void nsIGlobalObject::NotifyReportingObservers() {
const nsTArray<RefPtr<ReportingObserver>> reportingObservers(
mReportingObservers);
for (auto& observer : reportingObservers) {
// MOZ_KnownLive because 'reportingObservers' is guaranteed to
// keep it alive.
//
// This can go away once
// https://bugzilla.mozilla.org/show_bug.cgi?id=1620312 is fixed.
MOZ_KnownLive(observer)->MaybeNotify();
}
}

void nsIGlobalObject::RemoveReportRecords() {
mReportRecords.Clear();

for (auto& observer : mReportingObservers) {
observer->ForgetReports();
}
}
30 changes: 6 additions & 24 deletions dom/base/nsIGlobalObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ class DOMEventTargetHelper;
namespace dom {
class VoidFunction;
class DebuggerNotificationManager;
class Report;
class ReportBody;
class ReportingObserver;
class ServiceWorker;
class ServiceWorkerRegistration;
class ServiceWorkerRegistrationDescriptor;
Expand All @@ -59,7 +56,8 @@ class nsIGlobalObject : public nsISupports,
protected:
bool mIsInnerWindow;

nsIGlobalObject();
nsIGlobalObject()
: mIsDying(false), mIsScriptForbidden(false), mIsInnerWindow(false) {}

public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_IGLOBALOBJECT_IID)
Expand Down Expand Up @@ -124,10 +122,10 @@ class nsIGlobalObject : public nsISupports,

void UnregisterHostObjectURI(const nsACString& aURI);

// Any CC class inheriting nsIGlobalObject should call these 2 methods to
// cleanup objects stored in nsIGlobalObject such as blobURLs and Reports.
void UnlinkObjectsInGlobal();
void TraverseObjectsInGlobal(nsCycleCollectionTraversalCallback& aCb);
// Any CC class inheriting nsIGlobalObject should call these 2 methods if it
// exposes the URL API.
void UnlinkHostObjectURIs();
void TraverseHostObjectURIs(nsCycleCollectionTraversalCallback& aCb);

// DETH objects must register themselves on the global when they
// bind to it in order to get the DisconnectFromOwner() method
Expand Down Expand Up @@ -189,17 +187,6 @@ class nsIGlobalObject : public nsISupports,

void QueueMicrotask(mozilla::dom::VoidFunction& aCallback);

void RegisterReportingObserver(mozilla::dom::ReportingObserver* aObserver,
bool aBuffered);

void UnregisterReportingObserver(mozilla::dom::ReportingObserver* aObserver);

void BroadcastReport(mozilla::dom::Report* aReport);

MOZ_CAN_RUN_SCRIPT void NotifyReportingObservers();

void RemoveReportRecords();

protected:
virtual ~nsIGlobalObject();

Expand All @@ -211,11 +198,6 @@ class nsIGlobalObject : public nsISupports,
void DisconnectEventTargetObjects();

size_t ShallowSizeOfExcludingThis(mozilla::MallocSizeOf aSizeOf) const;

private:
// List of Report objects for ReportingObservers.
nsTArray<RefPtr<mozilla::dom::ReportingObserver>> mReportingObservers;
nsTArray<RefPtr<mozilla::dom::Report>> mReportRecords;
};

NS_DEFINE_STATIC_IID_ACCESSOR(nsIGlobalObject, NS_IGLOBALOBJECT_IID)
Expand Down
Loading

0 comments on commit 948e626

Please sign in to comment.