mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 21:31:04 +00:00
Bug 1633791 part 1: Add ability to notify the child processes of an impending shutdown. r=nika
This also adds a call to the new function in ContentParent::StartForceKillTimer. Differential Revision: https://phabricator.services.mozilla.com/D75507
This commit is contained in:
parent
dbf7a05226
commit
5ef9be5d40
@ -1856,6 +1856,8 @@ void ContentParent::StartForceKillTimer() {
|
||||
return;
|
||||
}
|
||||
|
||||
NotifyImpendingShutdown();
|
||||
|
||||
int32_t timeoutSecs = StaticPrefs::dom_ipc_tabs_shutdownTimeoutSecs();
|
||||
if (timeoutSecs > 0) {
|
||||
NS_NewTimerWithFuncCallback(getter_AddRefs(mForceKillTimer),
|
||||
|
@ -1150,6 +1150,10 @@ bool MessageChannel::MaybeInterceptSpecialIOMessage(const Message& aMsg) {
|
||||
IPC_LOG("Build IDs match message");
|
||||
mBuildIDsConfirmedMatch = true;
|
||||
return true;
|
||||
} else if (IMPENDING_SHUTDOWN_MESSAGE_TYPE == aMsg.type()) {
|
||||
IPC_LOG("Impending Shutdown received");
|
||||
ProcessChild::NotifyImpendingShutdown();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@ -2688,6 +2692,17 @@ void MessageChannel::CloseWithTimeout() {
|
||||
mChannelState = ChannelTimeout;
|
||||
}
|
||||
|
||||
void MessageChannel::NotifyImpendingShutdown() {
|
||||
UniquePtr<Message> msg =
|
||||
MakeUnique<Message>(MSG_ROUTING_NONE, IMPENDING_SHUTDOWN_MESSAGE_TYPE);
|
||||
MonitorAutoLock lock(*mMonitor);
|
||||
if (Connected()) {
|
||||
MOZ_DIAGNOSTIC_ASSERT(mIsCrossProcess);
|
||||
// SendMessage takes ownership of the message.
|
||||
mLink->SendMessage(msg.release());
|
||||
}
|
||||
}
|
||||
|
||||
void MessageChannel::Close() {
|
||||
AssertWorkerThread();
|
||||
|
||||
|
@ -177,6 +177,12 @@ class MessageChannel : HasResultCodes, MessageLoop::DestructionObserver {
|
||||
// sends, to avoid deadlocks.
|
||||
bool OpenOnSameThread(MessageChannel* aTargetChan, Side aSide);
|
||||
|
||||
/**
|
||||
* This sends a special message that is processed on the IO thread, so that
|
||||
* other actors can know that the process will soon shutdown.
|
||||
*/
|
||||
void NotifyImpendingShutdown();
|
||||
|
||||
// Close the underlying transport channel.
|
||||
void Close();
|
||||
|
||||
|
@ -4,6 +4,8 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "mozilla/ipc/ProcessChild.h"
|
||||
|
||||
#include "nsDebug.h"
|
||||
|
||||
#ifdef XP_WIN
|
||||
@ -14,13 +16,14 @@
|
||||
|
||||
#include "mozilla/AppShutdown.h"
|
||||
#include "mozilla/ipc/IOThreadChild.h"
|
||||
#include "mozilla/ipc/ProcessChild.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace ipc {
|
||||
|
||||
ProcessChild* ProcessChild::gProcessChild;
|
||||
|
||||
static Atomic<bool> sExpectingShutdown(false);
|
||||
|
||||
ProcessChild::ProcessChild(ProcessId aParentPid)
|
||||
: ChildProcess(new IOThreadChild()),
|
||||
mUILoop(MessageLoop::current()),
|
||||
@ -32,6 +35,12 @@ ProcessChild::ProcessChild(ProcessId aParentPid)
|
||||
|
||||
ProcessChild::~ProcessChild() { gProcessChild = nullptr; }
|
||||
|
||||
/* static */
|
||||
void ProcessChild::NotifyImpendingShutdown() { sExpectingShutdown = true; }
|
||||
|
||||
/* static */
|
||||
bool ProcessChild::ExpectingShutdown() { return sExpectingShutdown; }
|
||||
|
||||
/* static */
|
||||
void ProcessChild::QuickExit() { AppShutdown::DoImmediateExit(); }
|
||||
|
||||
|
@ -32,6 +32,10 @@ class ProcessChild : public ChildProcess {
|
||||
|
||||
static MessageLoop* message_loop() { return gProcessChild->mUILoop; }
|
||||
|
||||
static void NotifyImpendingShutdown();
|
||||
|
||||
static bool ExpectingShutdown();
|
||||
|
||||
/**
|
||||
* Exit *now*. Do not shut down XPCOM, do not pass Go, do not run
|
||||
* static destructors, do not collect $200.
|
||||
|
@ -614,6 +614,10 @@ bool IToplevelProtocol::OpenOnSameThread(MessageChannel* aChannel, Side aSide) {
|
||||
return GetIPCChannel()->OpenOnSameThread(aChannel, aSide);
|
||||
}
|
||||
|
||||
void IToplevelProtocol::NotifyImpendingShutdown() {
|
||||
GetIPCChannel()->NotifyImpendingShutdown();
|
||||
}
|
||||
|
||||
void IToplevelProtocol::Close() { GetIPCChannel()->Close(); }
|
||||
|
||||
void IToplevelProtocol::SetReplyTimeoutMs(int32_t aTimeoutMs) {
|
||||
|
@ -52,6 +52,7 @@ namespace {
|
||||
// protocol 0. Oops! We can get away with this until protocol 0
|
||||
// starts approaching its 65,536th message.
|
||||
enum {
|
||||
IMPENDING_SHUTDOWN_MESSAGE_TYPE = kuint16max - 9,
|
||||
BUILD_IDS_MATCH_MESSAGE_TYPE = kuint16max - 8,
|
||||
BUILD_ID_MESSAGE_TYPE = kuint16max - 7, // unused
|
||||
CHANNEL_OPENED_MESSAGE_TYPE = kuint16max - 6,
|
||||
@ -444,6 +445,12 @@ class IToplevelProtocol : public IProtocol {
|
||||
bool OpenOnSameThread(MessageChannel* aChannel,
|
||||
mozilla::ipc::Side aSide = mozilla::ipc::UnknownSide);
|
||||
|
||||
/**
|
||||
* This sends a special message that is processed on the IO thread, so that
|
||||
* other actors can know that the process will soon shutdown.
|
||||
*/
|
||||
void NotifyImpendingShutdown();
|
||||
|
||||
void Close();
|
||||
|
||||
void SetReplyTimeoutMs(int32_t aTimeoutMs);
|
||||
|
Loading…
Reference in New Issue
Block a user