Bug 1517653 - give the power manager service its own xpcom module; r=mccr8

The layout module is a little weird.  It's described as being loadable
in the GPU process, but very few of the contracts and CIDs it contains
are also marked as such.  In fact, the sole reason the layout module is
marked as being loadable in the GPU process is so that the power manager
service can be registered; everything else is inconsequential.  This
setup also means that the initializer for the layout module has to
specifically check whether it's running in the GPU process (or several
other processes...), so we don't try to spin up a bunch of stuff we
don't need, like xpconnect and similar.

This setup is silly: we should have a module solely for the power
manager's use and that module can be loaded in the GPU process.  Then
the layout module can go back to being an ordinary module, and we don't
have to play games in its initialization method.
This commit is contained in:
Nathan Froyd 2019-01-07 10:02:57 -05:00
Родитель 7a023634d0
Коммит 4517f22757
2 изменённых файлов: 34 добавлений и 31 удалений

Просмотреть файл

@ -8,6 +8,7 @@
#include "mozilla/Hal.h"
#include "mozilla/HalWakeLock.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/ModuleUtils.h"
#include "mozilla/Preferences.h"
#include "nsIDOMWakeLockListener.h"
#include "nsIDOMWindow.h"
@ -148,3 +149,35 @@ already_AddRefed<WakeLock> PowerManagerService::NewWakeLockOnBehalfOfProcess(
} // namespace power
} // namespace dom
} // namespace mozilla
NS_DEFINE_NAMED_CID(NS_POWERMANAGERSERVICE_CID);
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIPowerManagerService,
mozilla::dom::power::PowerManagerService::GetInstance)
static const mozilla::Module::CIDEntry kPowerManagerCIDs[] = {
// clang-format off
{ &kNS_POWERMANAGERSERVICE_CID, false, nullptr, nsIPowerManagerServiceConstructor, mozilla::Module::ALLOW_IN_GPU_PROCESS },
{ nullptr }
// clang-format on
};
static const mozilla::Module::ContractIDEntry kPowerManagerContracts[] = {
// clang-format off
{ POWERMANAGERSERVICE_CONTRACTID, &kNS_POWERMANAGERSERVICE_CID, mozilla::Module::ALLOW_IN_GPU_PROCESS },
{ nullptr }
// clang-format on
};
// We mark the power module as being available in the GPU process because the
// appshell depends on the power manager service.
static const mozilla::Module kPowerManagerModule = {mozilla::Module::kVersion,
kPowerManagerCIDs,
kPowerManagerContracts,
nullptr,
nullptr,
nullptr,
nullptr,
mozilla::Module::ALLOW_IN_GPU_PROCESS};
NSMODULE_DEFN(nsPowerManagerModule) = &kPowerManagerModule;

Просмотреть файл

@ -126,14 +126,11 @@ static void Shutdown();
#include "mozilla/dom/nsContentSecurityManager.h"
#include "mozilla/dom/nsCSPService.h"
#include "mozilla/dom/nsCSPContext.h"
#include "nsIPowerManagerService.h"
#include "nsIMediaManager.h"
#include "mozilla/dom/nsMixedContentBlocker.h"
#include "mozilla/net/WebSocketEventService.h"
#include "mozilla/dom/power/PowerManagerService.h"
#include "nsIPresentationService.h"
#include "MediaManager.h"
@ -152,7 +149,6 @@ static void Shutdown();
using namespace mozilla;
using namespace mozilla::dom;
using namespace mozilla::net;
using mozilla::dom::power::PowerManagerService;
using mozilla::dom::quota::QuotaManagerService;
using mozilla::gmp::GeckoMediaPluginService;
@ -208,8 +204,6 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceSensors)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsHapticFeedback)
#endif
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(ThirdPartyUtil, Init)
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIPowerManagerService,
PowerManagerService::GetInstance)
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIMediaManagerService,
MediaManager::GetInstance)
@ -238,20 +232,6 @@ void nsLayoutModuleInitialize() {
gInitialized = true;
if (XRE_GetProcessType() == GeckoProcessType_VR) {
// VR process doesn't need the layout module.
return;
}
if (XRE_GetProcessType() == GeckoProcessType_GPU ||
XRE_GetProcessType() == GeckoProcessType_RDD) {
// We mark the layout module as being available in the GPU and RDD
// process so that XPCOM's component manager initializes the power
// manager service, which is needed for nsAppShell. However, we
// don't actually need anything in the layout module itself.
return;
}
if (NS_FAILED(xpcModuleCtor())) {
MOZ_CRASH("xpcModuleCtor failed");
}
@ -495,7 +475,6 @@ NS_DEFINE_NAMED_CID(NS_DEVICE_SENSORS_CID);
#if defined(ANDROID)
NS_DEFINE_NAMED_CID(NS_HAPTICFEEDBACK_CID);
#endif
NS_DEFINE_NAMED_CID(NS_POWERMANAGERSERVICE_CID);
NS_DEFINE_NAMED_CID(OSFILECONSTANTSSERVICE_CID);
NS_DEFINE_NAMED_CID(NS_MEDIAMANAGERSERVICE_CID);
#ifdef MOZ_WEBSPEECH_TEST_BACKEND
@ -592,7 +571,6 @@ static const mozilla::Module::CIDEntry kLayoutCIDs[] = {
#endif
{ &kTHIRDPARTYUTIL_CID, false, nullptr, ThirdPartyUtilConstructor },
{ &kNS_STRUCTUREDCLONECONTAINER_CID, false, nullptr, nsStructuredCloneContainerConstructor },
{ &kNS_POWERMANAGERSERVICE_CID, false, nullptr, nsIPowerManagerServiceConstructor, Module::ALLOW_IN_GPU_PROCESS },
{ &kOSFILECONSTANTSSERVICE_CID, true, nullptr, OSFileConstantsServiceConstructor },
{ &kGECKO_MEDIA_PLUGIN_SERVICE_CID, true, nullptr, GeckoMediaPluginServiceConstructor },
{ &kNS_MEDIAMANAGERSERVICE_CID, false, nullptr, nsIMediaManagerServiceConstructor },
@ -664,7 +642,6 @@ static const mozilla::Module::ContractIDEntry kLayoutContracts[] = {
#endif
{ THIRDPARTYUTIL_CONTRACTID, &kTHIRDPARTYUTIL_CID },
{ NS_STRUCTUREDCLONECONTAINER_CONTRACTID, &kNS_STRUCTUREDCLONECONTAINER_CID },
{ POWERMANAGERSERVICE_CONTRACTID, &kNS_POWERMANAGERSERVICE_CID, Module::ALLOW_IN_GPU_PROCESS },
{ OSFILECONSTANTSSERVICE_CONTRACTID, &kOSFILECONSTANTSSERVICE_CID },
{ MEDIAMANAGERSERVICE_CONTRACTID, &kNS_MEDIAMANAGERSERVICE_CID },
#ifdef ACCESSIBILITY
@ -705,12 +682,6 @@ static nsresult Initialize() {
}
static void LayoutModuleDtor() {
if (XRE_GetProcessType() == GeckoProcessType_GPU ||
XRE_GetProcessType() == GeckoProcessType_VR ||
XRE_GetProcessType() == GeckoProcessType_RDD) {
return;
}
Shutdown();
nsContentUtils::XPCOMShutdown();
@ -730,7 +701,6 @@ static const mozilla::Module kLayoutModule = {mozilla::Module::kVersion,
kLayoutCategories,
nullptr,
Initialize,
LayoutModuleDtor,
Module::ALLOW_IN_GPU_PROCESS};
LayoutModuleDtor};
NSMODULE_DEFN(nsLayoutModule) = &kLayoutModule;