Bug 1836980 - Move the check for late instantiation to UserIdleService[type] specializations. r=kmag,xpcom-reviewers,geckoview-reviewers,m_kato
We need to avoid the new for each specialization, the GetInstance of the base class does actually not create anything new. If the UserIdleService has been instantiated earlier than shutdown we continue to hand it out via GetInstance to give other things shutting down a chance to remove their observers, but if it has never been instantiated (or it is gone as we are very, very late in shutdown) we won't create a new one. Differential Revision: https://phabricator.services.mozilla.com/D180130
This commit is contained in:
@@ -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<nsUserIdleServiceAndroid> GetInstance() {
|
||||
RefPtr<nsUserIdleService> idleService = nsUserIdleService::GetInstance();
|
||||
if (!idleService) {
|
||||
// Avoid late instantiation or resurrection during shutdown.
|
||||
if (mozilla::AppShutdown::IsInOrBeyond(
|
||||
mozilla::ShutdownPhase::AppShutdownConfirmed)) {
|
||||
return nullptr;
|
||||
}
|
||||
idleService = new nsUserIdleServiceAndroid();
|
||||
}
|
||||
|
||||
|
||||
@@ -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<nsUserIdleServiceX> GetInstance() {
|
||||
RefPtr<nsUserIdleService> idleService = nsUserIdleService::GetInstance();
|
||||
if (!idleService) {
|
||||
// Avoid late instantiation or resurrection during shutdown.
|
||||
if (mozilla::AppShutdown::IsInOrBeyond(
|
||||
mozilla::ShutdownPhase::AppShutdownConfirmed)) {
|
||||
return nullptr;
|
||||
}
|
||||
idleService = new nsUserIdleServiceX();
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#define nsUserIdleServiceGTK_h__
|
||||
|
||||
#include "nsUserIdleService.h"
|
||||
#include "mozilla/AppShutdown.h"
|
||||
#ifdef MOZ_X11
|
||||
# include <X11/Xlib.h>
|
||||
# include <X11/Xutil.h>
|
||||
@@ -36,6 +37,11 @@ class nsUserIdleServiceGTK : public nsUserIdleService {
|
||||
RefPtr<nsUserIdleServiceGTK> idleService =
|
||||
nsUserIdleService::GetInstance().downcast<nsUserIdleServiceGTK>();
|
||||
if (!idleService) {
|
||||
// Avoid late instantiation or resurrection during shutdown.
|
||||
if (mozilla::AppShutdown::IsInOrBeyond(
|
||||
mozilla::ShutdownPhase::AppShutdownConfirmed)) {
|
||||
return nullptr;
|
||||
}
|
||||
idleService = new nsUserIdleServiceGTK();
|
||||
}
|
||||
|
||||
|
||||
@@ -350,10 +350,6 @@ nsUserIdleService* gIdleService;
|
||||
} // namespace
|
||||
|
||||
already_AddRefed<nsUserIdleService> nsUserIdleService::GetInstance() {
|
||||
// Avoid late instantiation or resurrection during shutdown.
|
||||
if (AppShutdown::IsInOrBeyond(ShutdownPhase::AppShutdownConfirmed)) {
|
||||
return nullptr;
|
||||
}
|
||||
RefPtr<nsUserIdleService> instance(gIdleService);
|
||||
return instance.forget();
|
||||
}
|
||||
|
||||
@@ -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<nsUserIdleServiceWin> idleService =
|
||||
nsUserIdleService::GetInstance().downcast<nsUserIdleServiceWin>();
|
||||
if (!idleService) {
|
||||
// Avoid late instantiation or resurrection during shutdown.
|
||||
if (mozilla::AppShutdown::IsInOrBeyond(
|
||||
mozilla::ShutdownPhase::AppShutdownConfirmed)) {
|
||||
return nullptr;
|
||||
}
|
||||
idleService = new nsUserIdleServiceWin();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user