ipc/chromium/src/chrome/common/child_process.cc

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ipc/chromium/src/chrome/common/child_process.cc	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,59 @@
     1.4 +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
     1.5 +// Use of this source code is governed by a BSD-style license that can be
     1.6 +// found in the LICENSE file.
     1.7 +
     1.8 +#include "chrome/common/child_process.h"
     1.9 +
    1.10 +#include "base/basictypes.h"
    1.11 +#include "base/string_util.h"
    1.12 +#include "chrome/common/child_thread.h"
    1.13 +
    1.14 +ChildProcess* ChildProcess::child_process_;
    1.15 +
    1.16 +ChildProcess::ChildProcess(ChildThread* child_thread)
    1.17 +    : child_thread_(child_thread),
    1.18 +      ref_count_(0),
    1.19 +      shutdown_event_(true, false) {
    1.20 +  DCHECK(!child_process_);
    1.21 +  child_process_ = this;
    1.22 +  if (child_thread_.get())  // null in unittests.
    1.23 +    child_thread_->Run();
    1.24 +}
    1.25 +
    1.26 +ChildProcess::~ChildProcess() {
    1.27 +  DCHECK(child_process_ == this);
    1.28 +
    1.29 +  // Signal this event before destroying the child process.  That way all
    1.30 +  // background threads can cleanup.
    1.31 +  // For example, in the renderer the RenderThread instances will be able to
    1.32 +  // notice shutdown before the render process begins waiting for them to exit.
    1.33 +  shutdown_event_.Signal();
    1.34 +
    1.35 +  if (child_thread_.get())
    1.36 +    child_thread_->Stop();
    1.37 +
    1.38 +  child_process_ = NULL;
    1.39 +}
    1.40 +
    1.41 +void ChildProcess::AddRefProcess() {
    1.42 +  DCHECK(!child_thread_.get() ||  // null in unittests.
    1.43 +         MessageLoop::current() == child_thread_->message_loop());
    1.44 +  ref_count_++;
    1.45 +}
    1.46 +
    1.47 +void ChildProcess::ReleaseProcess() {
    1.48 +  DCHECK(!child_thread_.get() ||  // null in unittests.
    1.49 +         MessageLoop::current() == child_thread_->message_loop());
    1.50 +  DCHECK(ref_count_);
    1.51 +  DCHECK(child_process_);
    1.52 +  if (--ref_count_)
    1.53 +    return;
    1.54 +
    1.55 +  if (child_thread_.get())  // null in unittests.
    1.56 +    child_thread_->OnProcessFinalRelease();
    1.57 +}
    1.58 +
    1.59 +base::WaitableEvent* ChildProcess::GetShutDownEvent() {
    1.60 +  DCHECK(child_process_);
    1.61 +  return &child_process_->shutdown_event_;
    1.62 +}

mercurial