Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: base/mp/mp_child_process.cc

Issue 1625015: Refactor ChildProcess and related classes to create a framework outside of br... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/mp/mp_child_process.h ('k') | base/mp/mp_child_process_context.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2010 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.
4
5 #include "base/mp/mp_child_process.h"
6
7 #include "base/message_loop.h"
8 #include "base/mp/mp_child_thread.h"
9
10 namespace base {
11
12 MpChildProcess* MpChildProcess::child_process_;
13
14 MpChildProcess::MpChildProcess()
15 : ref_count_(0),
16 shutdown_event_(true, false) {
17 DCHECK(!child_process_);
18 child_process_ = this;
19 }
20
21 MpChildProcess::~MpChildProcess() {
22 DCHECK(child_process_ == this);
23
24 // Signal this event before destroying the child process. That way all
25 // background threads can cleanup.
26 // For example, in the renderer the RenderThread instances will be able to
27 // notice shutdown before the render process begins waiting for them to exit.
28 shutdown_event_.Signal();
29
30 // Kill the main thread object before nulling child_process_, since
31 // destruction code might depend on it.
32 main_thread_.reset();
33
34 child_process_ = NULL;
35 }
36
37 void MpChildProcess::AddRefProcess() {
38 DCHECK(!main_thread_.get() || // null in unittests.
39 MessageLoop::current() == main_thread_->message_loop());
40 ref_count_++;
41 }
42
43 void MpChildProcess::ReleaseProcess() {
44 DCHECK(!main_thread_.get() || // null in unittests.
45 MessageLoop::current() == main_thread_->message_loop());
46 DCHECK(ref_count_);
47 DCHECK(child_process_);
48 if (--ref_count_)
49 return;
50
51 if (main_thread_.get()) // null in unittests.
52 main_thread_->OnProcessFinalRelease();
53 }
54
55 base::WaitableEvent* MpChildProcess::GetShutDownEvent() {
56 DCHECK(child_process_);
57 return &child_process_->shutdown_event_;
58 }
59
60 } // namespace base
OLDNEW
« no previous file with comments | « base/mp/mp_child_process.h ('k') | base/mp/mp_child_process_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698