dom/ipc/ContentProcessHost.cpp
author Andreea Pavel <apavel@mozilla.com>
Tue, 27 Nov 2018 08:53:18 +0200
changeset 504619 b0e69b1368832a3846c0940a6fb8bb834bdc62a1
child 504710 f3361f0816dd2a7e63d1acb92e23b74f0e8f0f30
permissions -rw-r--r--
Backed out 8 changesets (bug 1446161, bug 1487287, bug 1488993, bug 1474991, bug 1496608) for very frequent automation.py crashes on a CLOSED TREE Backed out changeset 8b1f88d7bfeb (bug 1487287) Backed out changeset 8fa5e81ad801 (bug 1487287) Backed out changeset 7a480161fa0f (bug 1474991) Backed out changeset 80116391b7fe (bug 1446161) Backed out changeset 1bdf64b29121 (bug 1446161) Backed out changeset 37bf52f0e9cf (bug 1446161) Backed out changeset 8ede2ebe6b7a (bug 1496608) Backed out changeset cea43bc88c7a (bug 1488993)

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 * vim: sts=8 sw=2 ts=2 tw=99 et :
 * This Source Code Form is subject to the terms of the Mozilla Public
 * 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 "ContentProcessHost.h"

namespace mozilla {
namespace dom {

using namespace ipc;

ContentProcessHost::ContentProcessHost(ContentParent* aContentParent,
                                       bool aIsFileContent)
 : GeckoChildProcessHost(GeckoProcessType_Content, aIsFileContent),
   mHasLaunched(false),
   mContentParent(aContentParent)
{
  MOZ_COUNT_CTOR(ContentProcessHost);
}

ContentProcessHost::~ContentProcessHost()
{
  MOZ_COUNT_DTOR(ContentProcessHost);
}

bool
ContentProcessHost::Launch(StringVector aExtraOpts)
{
  MOZ_ASSERT(!mHasLaunched);
  MOZ_ASSERT(mContentParent);

  bool res = GeckoChildProcessHost::AsyncLaunch(aExtraOpts);
  MOZ_RELEASE_ASSERT(res);
  return true;
}

void
ContentProcessHost::OnProcessHandleReady(ProcessHandle aProcessHandle)
{
  MOZ_ASSERT(!NS_IsMainThread());

  // This will wake up the main thread if it is waiting for the process to
  // launch.
  mContentParent->SetOtherProcessId(base::GetProcId(aProcessHandle));

  mHasLaunched = true;
  GeckoChildProcessHost::OnProcessHandleReady(aProcessHandle);
}

void
ContentProcessHost::OnProcessLaunchError()
{
  MOZ_ASSERT(!NS_IsMainThread());
  mContentParent->SetOtherProcessId(mozilla::ipc::kInvalidProcessId,
                                    ContentParent::ProcessIdState::eError);
  mHasLaunched = true;
  GeckoChildProcessHost::OnProcessLaunchError();
}

} // namespace dom
} // namespace mozilla