Skip to content

Commit

Permalink
Bug 1791350 - Replace C++ uses of Services.startup.shuttingDown with …
Browse files Browse the repository at this point in the history
…appropriate AppShutdown::IsInOrBeyond. r=florian

Differential Revision: https://phabricator.services.mozilla.com/D157628
  • Loading branch information
jensstutte committed Sep 20, 2022
1 parent 3557a0e commit 8e845bc
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 17 deletions.
5 changes: 2 additions & 3 deletions chrome/nsChromeRegistryChrome.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
#include "mozilla/LookAndFeel.h"
#include "mozilla/Unused.h"

#include "nsIAppStartup.h"
#include "nsIObserverService.h"
#include "mozilla/AppShutdown.h"
#include "mozilla/Components.h"
#include "mozilla/Preferences.h"
#include "nsIResProtocolHandler.h"
Expand Down Expand Up @@ -203,8 +203,7 @@ nsChromeRegistryChrome::Observe(nsISupports* aSubject, const char* aTopic,

NS_IMETHODIMP
nsChromeRegistryChrome::CheckForNewChrome() {
nsCOMPtr<nsIAppStartup> appStartup = components::AppStartup::Service();
if (appStartup->GetShuttingDown()) {
if (AppShutdown::IsInOrBeyond(ShutdownPhase::AppShutdownConfirmed)) {
MOZ_ASSERT(false, "checking for new chrome during shutdown");
return NS_ERROR_UNEXPECTED;
}
Expand Down
8 changes: 3 additions & 5 deletions dom/base/WindowDestroyedEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "nsCOMPtr.h"
#include "nsContentUtils.h"
#include "xpcpublic.h"
#include "mozilla/AppShutdown.h"
#include "mozilla/BasePrincipal.h"
#include "mozilla/Components.h"
#include "mozilla/ProfilerLabels.h"
Expand Down Expand Up @@ -71,11 +72,8 @@ WindowDestroyedEvent::Run() {
case Phase::Destroying: {
bool skipNukeCrossCompartment = false;
#ifndef DEBUG
nsCOMPtr<nsIAppStartup> appStartup = components::AppStartup::Service();

if (appStartup) {
appStartup->GetShuttingDown(&skipNukeCrossCompartment);
}
skipNukeCrossCompartment =
AppShutdown::IsInOrBeyond(ShutdownPhase::AppShutdownConfirmed);
#endif

if (!skipNukeCrossCompartment) {
Expand Down
5 changes: 2 additions & 3 deletions dom/ipc/ContentParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@
#include "nsHyphenationManager.h"
#include "nsIAlertsService.h"
#include "nsIAppShell.h"
#include "nsIAppStartup.h"
#include "nsIAppWindow.h"
#include "nsIAsyncInputStream.h"
#include "nsIBidiKeyboard.h"
Expand Down Expand Up @@ -4280,8 +4279,8 @@ void ContentParent::GeneratePairedMinidump(const char* aReason) {
// Something has gone wrong to get us here, so we generate a minidump
// of the parent and child for submission to the crash server unless we're
// already shutting down.
nsCOMPtr<nsIAppStartup> appStartup = components::AppStartup::Service();
if (mCrashReporter && !appStartup->GetShuttingDown() &&
if (mCrashReporter &&
!AppShutdown::IsInOrBeyond(ShutdownPhase::AppShutdownConfirmed) &&
StaticPrefs::dom_ipc_tabs_createKillHardCrashReports_AtStartup()) {
// GeneratePairedMinidump creates two minidumps for us - the main
// one is for the content process we're about to kill, and the other
Expand Down
3 changes: 3 additions & 0 deletions toolkit/components/startup/public/nsIAppStartup.idl
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ interface nsIAppStartup : nsISupports

/**
* True if the application is in the process of shutting down.
* This is functionally equivalent to the C++ call
* AppShutdown::IsInOrBeyond(ShutdownPhase::AppShutdownConfirmed);
* (which is the preferred way of checking for shutdown in C++).
*/
[infallible] readonly attribute boolean shuttingDown;

Expand Down
5 changes: 2 additions & 3 deletions toolkit/mozapps/extensions/AddonManagerStartup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "js/TracingAPI.h"
#include "xpcpublic.h"

#include "mozilla/AppShutdown.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/EndianUtils.h"
#include "mozilla/Components.h"
Expand All @@ -32,7 +33,6 @@
#include "nsAppRunner.h"
#include "nsContentUtils.h"
#include "nsChromeRegistry.h"
#include "nsIAppStartup.h"
#include "nsIDOMWindowUtils.h" // for nsIJSRAIIHelper
#include "nsIFileURL.h"
#include "nsIIOService.h"
Expand Down Expand Up @@ -756,8 +756,7 @@ RegistryEntries::Destruct() {

// No point in doing I/O to check for new chrome during shutdown, return
// early in that case.
nsCOMPtr<nsIAppStartup> appStartup = components::AppStartup::Service();
if (!appStartup || appStartup->GetShuttingDown()) {
if (AppShutdown::IsInOrBeyond(ShutdownPhase::AppShutdownConfirmed)) {
return NS_OK;
}

Expand Down
9 changes: 6 additions & 3 deletions toolkit/xre/nsAppRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5480,7 +5480,8 @@ nsresult XREMain::XRE_mainRun() {
CrashReporter::AnnotateCrashReport(
CrashReporter::Annotation::useragent_locale, userAgentLocale);

appStartup->GetShuttingDown(&mShuttingDown);
mShuttingDown =
AppShutdown::IsInOrBeyond(ShutdownPhase::AppShutdownConfirmed);

if (!mShuttingDown) {
/* Special-case services that need early access to the command
Expand Down Expand Up @@ -5615,14 +5616,16 @@ nsresult XREMain::XRE_mainRun() {
CrashReporter::AnnotateCrashReport(
CrashReporter::Annotation::StartupCrash, false);

appStartup->GetShuttingDown(&mShuttingDown);
mShuttingDown =
AppShutdown::IsInOrBeyond(ShutdownPhase::AppShutdownConfirmed);
}

if (!mShuttingDown) {
rv = cmdLine->Run();
NS_ENSURE_SUCCESS_LOG(rv, NS_ERROR_FAILURE);

appStartup->GetShuttingDown(&mShuttingDown);
mShuttingDown =
AppShutdown::IsInOrBeyond(ShutdownPhase::AppShutdownConfirmed);
}

if (!mShuttingDown) {
Expand Down

0 comments on commit 8e845bc

Please sign in to comment.