Index: base/mp/mp_child_process.cc |
=================================================================== |
--- base/mp/mp_child_process.cc (revision 0) |
+++ base/mp/mp_child_process.cc (revision 0) |
@@ -0,0 +1,60 @@ |
+// Copyright (c) 2010 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "base/mp/mp_child_process.h" |
+ |
+#include "base/message_loop.h" |
+#include "base/mp/mp_child_thread.h" |
+ |
+namespace base { |
+ |
+MpChildProcess* MpChildProcess::child_process_; |
+ |
+MpChildProcess::MpChildProcess() |
+ : ref_count_(0), |
+ shutdown_event_(true, false) { |
+ DCHECK(!child_process_); |
+ child_process_ = this; |
+} |
+ |
+MpChildProcess::~MpChildProcess() { |
+ DCHECK(child_process_ == this); |
+ |
+ // Signal this event before destroying the child process. That way all |
+ // background threads can cleanup. |
+ // For example, in the renderer the RenderThread instances will be able to |
+ // notice shutdown before the render process begins waiting for them to exit. |
+ shutdown_event_.Signal(); |
+ |
+ // Kill the main thread object before nulling child_process_, since |
+ // destruction code might depend on it. |
+ main_thread_.reset(); |
+ |
+ child_process_ = NULL; |
+} |
+ |
+void MpChildProcess::AddRefProcess() { |
+ DCHECK(!main_thread_.get() || // null in unittests. |
+ MessageLoop::current() == main_thread_->message_loop()); |
+ ref_count_++; |
+} |
+ |
+void MpChildProcess::ReleaseProcess() { |
+ DCHECK(!main_thread_.get() || // null in unittests. |
+ MessageLoop::current() == main_thread_->message_loop()); |
+ DCHECK(ref_count_); |
+ DCHECK(child_process_); |
+ if (--ref_count_) |
+ return; |
+ |
+ if (main_thread_.get()) // null in unittests. |
+ main_thread_->OnProcessFinalRelease(); |
+} |
+ |
+base::WaitableEvent* MpChildProcess::GetShutDownEvent() { |
+ DCHECK(child_process_); |
+ return &child_process_->shutdown_event_; |
+} |
+ |
+} // namespace base |