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

Side by Side Diff: chrome/common/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 | « chrome/common/child_process.h ('k') | chrome/common/child_thread.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/common/child_process.h" 5 #include "chrome/common/child_process.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/process_util.h" 9 #include "base/process_util.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "chrome/common/child_thread.h"
12 #include "grit/chromium_strings.h" 11 #include "grit/chromium_strings.h"
13 12
14 #if defined(OS_POSIX)
15 #include <signal.h>
16
17 static void SigUSR1Handler(int signal) { }
18 #endif
19
20 ChildProcess* ChildProcess::child_process_;
21
22 ChildProcess::ChildProcess() 13 ChildProcess::ChildProcess()
23 : ref_count_(0), 14 : io_thread_("Chrome_ChildIOThread") {
24 shutdown_event_(true, false),
25 io_thread_("Chrome_ChildIOThread") {
26 DCHECK(!child_process_);
27 child_process_ = this;
28
29 io_thread_.StartWithOptions(base::Thread::Options(MessageLoop::TYPE_IO, 0)); 15 io_thread_.StartWithOptions(base::Thread::Options(MessageLoop::TYPE_IO, 0));
30 } 16 }
31 17
32 ChildProcess::~ChildProcess() { 18 ChildProcess::~ChildProcess() {
33 DCHECK(child_process_ == this);
34
35 // Signal this event before destroying the child process. That way all
36 // background threads can cleanup.
37 // For example, in the renderer the RenderThread instances will be able to
38 // notice shutdown before the render process begins waiting for them to exit.
39 shutdown_event_.Signal();
40
41 // Kill the main thread object before nulling child_process_, since
42 // destruction code might depend on it.
43 main_thread_.reset();
44
45 child_process_ = NULL;
46 }
47
48 void ChildProcess::AddRefProcess() {
49 DCHECK(!main_thread_.get() || // null in unittests.
50 MessageLoop::current() == main_thread_->message_loop());
51 ref_count_++;
52 }
53
54 void ChildProcess::ReleaseProcess() {
55 DCHECK(!main_thread_.get() || // null in unittests.
56 MessageLoop::current() == main_thread_->message_loop());
57 DCHECK(ref_count_);
58 DCHECK(child_process_);
59 if (--ref_count_)
60 return;
61
62 if (main_thread_.get()) // null in unittests.
63 main_thread_->OnProcessFinalRelease();
64 }
65
66 base::WaitableEvent* ChildProcess::GetShutDownEvent() {
67 DCHECK(child_process_);
68 return &child_process_->shutdown_event_;
69 } 19 }
70 20
71 void ChildProcess::WaitForDebugger(const std::wstring& label) { 21 void ChildProcess::WaitForDebugger(const std::wstring& label) {
72 #if defined(OS_WIN) 22 #if defined(OS_WIN)
73 std::wstring title = l10n_util::GetString(IDS_PRODUCT_NAME); 23 std::wstring title = l10n_util::GetString(IDS_PRODUCT_NAME);
74 std::wstring message = label; 24 std::wstring message = label;
75 message += L" starting with pid: "; 25 message += L" starting with pid: ";
76 message += IntToWString(base::GetCurrentProcId()); 26 message += IntToWString(base::GetCurrentProcId());
77 title += L" "; 27 title += L" ";
78 title += label; // makes attaching to process easier 28 title += label; // makes attaching to process easier
79 ::MessageBox(NULL, message.c_str(), title.c_str(), 29 ::MessageBox(NULL, message.c_str(), title.c_str(),
80 MB_OK | MB_SETFOREGROUND); 30 MB_OK | MB_SETFOREGROUND);
81 #elif defined(OS_POSIX) 31 #elif defined(OS_POSIX)
82 // TODO(playmobil): In the long term, overriding this flag doesn't seem 32 // TODO(playmobil): In the long term, overriding this flag doesn't seem
83 // right, either use our own flag or open a dialog we can use. 33 // right, either use our own flag or open a dialog we can use.
84 // This is just to ease debugging in the interim. 34 // This is just to ease debugging in the interim.
85 LOG(WARNING) << label 35 LOG(WARNING) << label
86 << " (" 36 << " ("
87 << getpid() 37 << getpid()
88 << ") paused waiting for debugger to attach @ pid"; 38 << ") paused waiting for debugger to attach @ pid";
89 // Install a signal handler so that pause can be woken. 39 // Install a signal handler so that pause can be woken.
90 struct sigaction sa; 40 struct sigaction sa;
91 memset(&sa, 0, sizeof(sa)); 41 memset(&sa, 0, sizeof(sa));
92 sa.sa_handler = SigUSR1Handler; 42 sa.sa_handler = SigUSR1Handler;
93 sigaction(SIGUSR1, &sa, NULL); 43 sigaction(SIGUSR1, &sa, NULL);
94 44
95 pause(); 45 pause();
96 #endif // defined(OS_POSIX) 46 #endif // defined(OS_POSIX)
97 } 47 }
OLDNEW
« no previous file with comments | « chrome/common/child_process.h ('k') | chrome/common/child_thread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698