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