diff --git a/widget/android/nsUserIdleServiceAndroid.h b/widget/android/nsUserIdleServiceAndroid.h index 81ab790d9d31..4e089b3db603 100644 --- a/widget/android/nsUserIdleServiceAndroid.h +++ b/widget/android/nsUserIdleServiceAndroid.h @@ -9,6 +9,7 @@ #define nsUserIdleServiceAndroid_h__ #include "nsUserIdleService.h" +#include "mozilla/AppShutdown.h" class nsUserIdleServiceAndroid : public nsUserIdleService { public: @@ -20,6 +21,11 @@ class nsUserIdleServiceAndroid : public nsUserIdleService { static already_AddRefed GetInstance() { RefPtr idleService = nsUserIdleService::GetInstance(); if (!idleService) { + // Avoid late instantiation or resurrection during shutdown. + if (mozilla::AppShutdown::IsInOrBeyond( + mozilla::ShutdownPhase::AppShutdownConfirmed)) { + return nullptr; + } idleService = new nsUserIdleServiceAndroid(); } diff --git a/widget/cocoa/nsUserIdleServiceX.h b/widget/cocoa/nsUserIdleServiceX.h index cdd5130a33f4..ff559293e95d 100644 --- a/widget/cocoa/nsUserIdleServiceX.h +++ b/widget/cocoa/nsUserIdleServiceX.h @@ -6,6 +6,7 @@ #define nsUserIdleServiceX_h_ #include "nsUserIdleService.h" +#include "mozilla/AppShutdown.h" class nsUserIdleServiceX : public nsUserIdleService { public: @@ -16,6 +17,11 @@ class nsUserIdleServiceX : public nsUserIdleService { static already_AddRefed GetInstance() { RefPtr idleService = nsUserIdleService::GetInstance(); if (!idleService) { + // Avoid late instantiation or resurrection during shutdown. + if (mozilla::AppShutdown::IsInOrBeyond( + mozilla::ShutdownPhase::AppShutdownConfirmed)) { + return nullptr; + } idleService = new nsUserIdleServiceX(); } diff --git a/widget/gtk/nsUserIdleServiceGTK.h b/widget/gtk/nsUserIdleServiceGTK.h index a1dd010f3ac5..66f9206f0702 100644 --- a/widget/gtk/nsUserIdleServiceGTK.h +++ b/widget/gtk/nsUserIdleServiceGTK.h @@ -9,6 +9,7 @@ #define nsUserIdleServiceGTK_h__ #include "nsUserIdleService.h" +#include "mozilla/AppShutdown.h" #ifdef MOZ_X11 # include # include @@ -36,6 +37,11 @@ class nsUserIdleServiceGTK : public nsUserIdleService { RefPtr idleService = nsUserIdleService::GetInstance().downcast(); if (!idleService) { + // Avoid late instantiation or resurrection during shutdown. + if (mozilla::AppShutdown::IsInOrBeyond( + mozilla::ShutdownPhase::AppShutdownConfirmed)) { + return nullptr; + } idleService = new nsUserIdleServiceGTK(); } diff --git a/widget/nsUserIdleService.cpp b/widget/nsUserIdleService.cpp index 7137d31fed22..c889affd7428 100644 --- a/widget/nsUserIdleService.cpp +++ b/widget/nsUserIdleService.cpp @@ -350,10 +350,6 @@ nsUserIdleService* gIdleService; } // namespace already_AddRefed nsUserIdleService::GetInstance() { - // Avoid late instantiation or resurrection during shutdown. - if (AppShutdown::IsInOrBeyond(ShutdownPhase::AppShutdownConfirmed)) { - return nullptr; - } RefPtr instance(gIdleService); return instance.forget(); } diff --git a/widget/windows/nsUserIdleServiceWin.h b/widget/windows/nsUserIdleServiceWin.h index b920646bc6e9..f9a47c8df5d3 100644 --- a/widget/windows/nsUserIdleServiceWin.h +++ b/widget/windows/nsUserIdleServiceWin.h @@ -9,6 +9,7 @@ #define nsUserIdleServiceWin_h__ #include "nsUserIdleService.h" +#include "mozilla/AppShutdown.h" /* NOTE: Compare of GetTickCount() could overflow. This corrects for * overflow situations. @@ -28,6 +29,11 @@ class nsUserIdleServiceWin : public nsUserIdleService { RefPtr idleService = nsUserIdleService::GetInstance().downcast(); if (!idleService) { + // Avoid late instantiation or resurrection during shutdown. + if (mozilla::AppShutdown::IsInOrBeyond( + mozilla::ShutdownPhase::AppShutdownConfirmed)) { + return nullptr; + } idleService = new nsUserIdleServiceWin(); }