Bug 1498765 - Clean up ContentParent::KillHard handling. r=mccr8

MessageChannel shouldn't need to care about PContent-specific details.
This commit is contained in:
Jed Davis 2018-10-19 15:29:34 -06:00
parent 49d3852c79
commit 859f503587
4 changed files with 13 additions and 35 deletions

View File

@ -1731,28 +1731,14 @@ DelayedDeleteSubprocess(GeckoChildProcessHost* aSubprocess)
XRE_GetIOMessageLoop()->PostTask(task.forget());
}
// This runnable only exists to delegate ownership of the
// ContentParent to this runnable, until it's deleted by the event
// system.
struct DelayedDeleteContentParentTask : public Runnable
{
explicit DelayedDeleteContentParentTask(ContentParent* aObj)
: Runnable("dom::DelayedDeleteContentParentTask")
, mKungFuDeathGrip(aObj)
{
}
// No-op
NS_IMETHOD Run() override { return NS_OK; }
RefPtr<ContentParent> mKungFuDeathGrip;
};
} // namespace
void
ContentParent::ActorDestroy(ActorDestroyReason why)
{
RefPtr<ContentParent> kungFuDeathGrip(mSelfRef.forget());
MOZ_RELEASE_ASSERT(kungFuDeathGrip);
if (mForceKillTimer) {
mForceKillTimer->Cancel();
mForceKillTimer = nullptr;
@ -1783,7 +1769,6 @@ ContentParent::ActorDestroy(ActorDestroyReason why)
ShutDownProcess(why == NormalShutdown ? CLOSE_CHANNEL
: CLOSE_CHANNEL_WITH_ERROR);
RefPtr<ContentParent> kungFuDeathGrip(this);
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
if (obs) {
size_t length = ArrayLength(sObserverTopics);
@ -1870,7 +1855,9 @@ ContentParent::ActorDestroy(ActorDestroyReason why)
//
// This runnable ensures that a reference to |this| lives on at
// least until after the current task finishes running.
NS_DispatchToCurrentThread(new DelayedDeleteContentParentTask(this));
NS_DispatchToCurrentThread(
NS_NewRunnableFunction("DelayedReleaseContentParent",
[kungFuDeathGrip] { }));
ContentProcessManager* cpm = ContentProcessManager::GetSingleton();
nsTArray<ContentParentId> childIDArray =
@ -2245,6 +2232,9 @@ ContentParent::LaunchSubprocess(ProcessPriority aInitialPriority /* = PROCESS_PR
return false;
}
// See also ActorDestroy.
mSelfRef = this;
#ifdef ASYNC_CONTENTPROC_LAUNCH
OpenWithAsyncPid(mSubprocess->GetChannel());
#else
@ -2291,6 +2281,7 @@ ContentParent::ContentParent(ContentParent* aOpener,
const nsAString& aRecordingFile,
int32_t aJSPluginID)
: nsIContentParent()
, mSelfRef(nullptr)
, mSubprocess(nullptr)
, mLaunchTS(TimeStamp::Now())
, mActivateTS(TimeStamp::Now())
@ -3345,11 +3336,6 @@ ContentParent::KillHard(const char* aReason)
mCalledKillHard = true;
mForceKillTimer = nullptr;
MessageChannel* channel = GetIPCChannel();
if (channel) {
channel->SetInKillHardShutdown();
}
// We're about to kill the child process associated with this content.
// Something has gone wrong to get us here, so we generate a minidump
// of the parent and child for submission to the crash server.

View File

@ -1280,6 +1280,8 @@ public:
}
private:
// Released in ActorDestroy; deliberately not exposed to the CC.
RefPtr<ContentParent> mSelfRef;
// If you add strong pointers to cycle collected objects here, be sure to
// release these objects in ShutDownProcess. See the comment there for more

View File

@ -634,7 +634,6 @@ MessageChannel::MessageChannel(const char* aName,
mPeerPidSet(false),
mPeerPid(-1),
mIsPostponingSends(false),
mInKillHardShutdown(false),
mBuildIDsConfirmedMatch(false)
{
MOZ_COUNT_CTOR(ipc::MessageChannel);
@ -798,10 +797,7 @@ MessageChannel::Clear()
// before mListener. But just to be safe, mListener is a weak pointer.
#if !defined(ANDROID)
// KillHard shutdowns can occur with the channel in connected state. We are
// already collecting crash dump data about KillHard shutdowns and we
// shouldn't intentionally crash here.
if (!Unsound_IsClosed() && !mInKillHardShutdown) {
if (!Unsound_IsClosed()) {
CrashReporter::AnnotateCrashReport(
CrashReporter::Annotation::IPCFatalErrorProtocol, nsDependentCString(mName));
switch (mChannelState) {

View File

@ -331,10 +331,6 @@ private:
sIsPumpingMessages = aIsPumping;
}
void SetInKillHardShutdown() {
mInKillHardShutdown = true;
}
#ifdef OS_WIN
struct MOZ_STACK_CLASS SyncStackFrame
{
@ -864,8 +860,6 @@ private:
bool mIsPostponingSends;
std::vector<UniquePtr<Message>> mPostponedSends;
bool mInKillHardShutdown;
bool mBuildIDsConfirmedMatch;
};