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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« 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