From 2f4fe0da3f7b46edd69fae6b839260721a660a3a Mon Sep 17 00:00:00 2001 From: Agi Sferro Date: Wed, 24 Mar 2021 21:49:37 +0000 Subject: [PATCH] Bug 1567341 - Don't listen to xpcom-shutdown twice in nsAppShell. r=esawin nsBaseAppShell already listens to xpcom-shutdown and calls |Exit| when it receives it so we don't need to also listen for it in nsAppShell (which causes two calls to xpcom-shutdown instead of one). Differential Revision: https://phabricator.services.mozilla.com/D106209 --- widget/android/nsAppShell.cpp | 31 +++++++++++++++++-------------- widget/android/nsAppShell.h | 1 + 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/widget/android/nsAppShell.cpp b/widget/android/nsAppShell.cpp index 83d24ff10163..4b9c8a24206b 100644 --- a/widget/android/nsAppShell.cpp +++ b/widget/android/nsAppShell.cpp @@ -483,7 +483,6 @@ nsresult nsAppShell::Init() { obsServ->AddObserver(this, "profile-after-change", false); obsServ->AddObserver(this, "quit-application", false); obsServ->AddObserver(this, "quit-application-granted", false); - obsServ->AddObserver(this, "xpcom-shutdown", false); if (XRE_IsParentProcess()) { obsServ->AddObserver(this, "chrome-document-loaded", false); @@ -499,24 +498,26 @@ nsresult nsAppShell::Init() { return rv; } +NS_IMETHODIMP +nsAppShell::Exit(void) { + { + // Release any thread waiting for a sync call to finish. + mozilla::MutexAutoLock shellLock(*sAppShellLock); + mSyncRunQuit = true; + mSyncRunFinished.NotifyAll(); + } + // We need to ensure no observers stick around after XPCOM shuts down + // or we'll see crashes, as the app shell outlives XPConnect. + mObserversHash.Clear(); + return nsBaseAppShell::Exit(); +} + NS_IMETHODIMP nsAppShell::Observe(nsISupports* aSubject, const char* aTopic, const char16_t* aData) { bool removeObserver = false; - if (!strcmp(aTopic, "xpcom-shutdown")) { - { - // Release any thread waiting for a sync call to finish. - mozilla::MutexAutoLock shellLock(*sAppShellLock); - mSyncRunQuit = true; - mSyncRunFinished.NotifyAll(); - } - // We need to ensure no observers stick around after XPCOM shuts down - // or we'll see crashes, as the app shell outlives XPConnect. - mObserversHash.Clear(); - return nsBaseAppShell::Observe(aSubject, aTopic, aData); - - } else if (!strcmp(aTopic, "browser-delayed-startup-finished")) { + if (!strcmp(aTopic, "browser-delayed-startup-finished")) { NS_CreateServicesFromCategory("browser-delayed-startup-finished", nullptr, "browser-delayed-startup-finished"); } else if (!strcmp(aTopic, "geckoview-startup-complete")) { @@ -595,6 +596,8 @@ nsAppShell::Observe(nsISupports* aSubject, const char* aTopic, nsCOMPtr docShell = do_QueryInterface(aSubject); widget::GeckoEditableSupport::SetOnBrowserChild( dom::BrowserChild::GetFrom(docShell)); + } else { + return nsBaseAppShell::Observe(aSubject, aTopic, aData); } if (removeObserver) { diff --git a/widget/android/nsAppShell.h b/widget/android/nsAppShell.h index 935d635616d2..4898809c53c9 100644 --- a/widget/android/nsAppShell.h +++ b/widget/android/nsAppShell.h @@ -145,6 +145,7 @@ class nsAppShell : public nsBaseAppShell { virtual ~nsAppShell(); + NS_IMETHOD Exit() override; nsresult AddObserver(const nsAString& aObserverKey, nsIObserver* aObserver); class NativeCallbackEvent : public Event {