Bug 1842825 - Split new Observer() outside of ipc::UtilityProcessManager r=ipc-reviewers,nika

Differential Revision: https://phabricator.services.mozilla.com/D183260
This commit is contained in:
Kagami Sascha Rosylight 2023-07-12 13:44:32 +00:00
parent 0b2d2afdea
commit b65d4356c8
2 changed files with 10 additions and 8 deletions

View File

@ -48,6 +48,7 @@ RefPtr<UtilityProcessManager> UtilityProcessManager::GetSingleton() {
if (!sXPCOMShutdown && sSingleton == nullptr) {
sSingleton = new UtilityProcessManager();
sSingleton->Init();
}
return sSingleton;
}
@ -57,11 +58,14 @@ RefPtr<UtilityProcessManager> UtilityProcessManager::GetIfExists() {
return sSingleton;
}
UtilityProcessManager::UtilityProcessManager() : mObserver(new Observer(this)) {
UtilityProcessManager::UtilityProcessManager() {
LOGD("[%p] UtilityProcessManager::UtilityProcessManager", this);
}
void UtilityProcessManager::Init() {
// Start listening for pref changes so we can
// forward them to the process once it is running.
mObserver = new Observer(this);
nsContentUtils::RegisterShutdownObserver(mObserver);
Preferences::AddStrongObserver(mObserver, "");
}
@ -75,9 +79,8 @@ UtilityProcessManager::~UtilityProcessManager() {
NS_IMPL_ISUPPORTS(UtilityProcessManager::Observer, nsIObserver);
UtilityProcessManager::Observer::Observer(
RefPtr<UtilityProcessManager> aManager)
: mManager(std::move(aManager)) {}
UtilityProcessManager::Observer::Observer(UtilityProcessManager* aManager)
: mManager(aManager) {}
NS_IMETHODIMP
UtilityProcessManager::Observer::Observe(nsISupports* aSubject,

View File

@ -41,9 +41,6 @@ class UtilityProcessManager final : public UtilityProcessHost::Listener {
using WindowsUtilsPromise =
MozPromise<RefPtr<dom::WindowsUtilsParent>, nsresult, true>;
static void Initialize();
static void Shutdown();
static RefPtr<UtilityProcessManager> GetSingleton();
static RefPtr<UtilityProcessManager> GetIfExists();
@ -165,6 +162,8 @@ class UtilityProcessManager final : public UtilityProcessHost::Listener {
UtilityProcessManager();
void Init();
void DestroyProcess(SandboxingKind aSandbox);
bool IsShutdown() const;
@ -173,7 +172,7 @@ class UtilityProcessManager final : public UtilityProcessHost::Listener {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
explicit Observer(RefPtr<UtilityProcessManager> aManager);
explicit Observer(UtilityProcessManager* aManager);
protected:
~Observer() = default;