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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
michael@0 2 // Use of this source code is governed by a BSD-style license that can be
michael@0 3 // found in the LICENSE file.
michael@0 4
michael@0 5 #include "chrome/common/child_process.h"
michael@0 6
michael@0 7 #include "base/basictypes.h"
michael@0 8 #include "base/string_util.h"
michael@0 9 #include "chrome/common/child_thread.h"
michael@0 10
michael@0 11 ChildProcess* ChildProcess::child_process_;
michael@0 12
michael@0 13 ChildProcess::ChildProcess(ChildThread* child_thread)
michael@0 14 : child_thread_(child_thread),
michael@0 15 ref_count_(0),
michael@0 16 shutdown_event_(true, false) {
michael@0 17 DCHECK(!child_process_);
michael@0 18 child_process_ = this;
michael@0 19 if (child_thread_.get()) // null in unittests.
michael@0 20 child_thread_->Run();
michael@0 21 }
michael@0 22
michael@0 23 ChildProcess::~ChildProcess() {
michael@0 24 DCHECK(child_process_ == this);
michael@0 25
michael@0 26 // Signal this event before destroying the child process. That way all
michael@0 27 // background threads can cleanup.
michael@0 28 // For example, in the renderer the RenderThread instances will be able to
michael@0 29 // notice shutdown before the render process begins waiting for them to exit.
michael@0 30 shutdown_event_.Signal();
michael@0 31
michael@0 32 if (child_thread_.get())
michael@0 33 child_thread_->Stop();
michael@0 34
michael@0 35 child_process_ = NULL;
michael@0 36 }
michael@0 37
michael@0 38 void ChildProcess::AddRefProcess() {
michael@0 39 DCHECK(!child_thread_.get() || // null in unittests.
michael@0 40 MessageLoop::current() == child_thread_->message_loop());
michael@0 41 ref_count_++;
michael@0 42 }
michael@0 43
michael@0 44 void ChildProcess::ReleaseProcess() {
michael@0 45 DCHECK(!child_thread_.get() || // null in unittests.
michael@0 46 MessageLoop::current() == child_thread_->message_loop());
michael@0 47 DCHECK(ref_count_);
michael@0 48 DCHECK(child_process_);
michael@0 49 if (--ref_count_)
michael@0 50 return;
michael@0 51
michael@0 52 if (child_thread_.get()) // null in unittests.
michael@0 53 child_thread_->OnProcessFinalRelease();
michael@0 54 }
michael@0 55
michael@0 56 base::WaitableEvent* ChildProcess::GetShutDownEvent() {
michael@0 57 DCHECK(child_process_);
michael@0 58 return &child_process_->shutdown_event_;
michael@0 59 }

mercurial