OLD | NEW |
(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 |
OLD | NEW |