OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/common/child_process.h" | 5 #include "content/common/child_process.h" |
6 | 6 |
7 #if defined(OS_POSIX) && !defined(OS_ANDROID) | 7 #if defined(OS_POSIX) && !defined(OS_ANDROID) |
8 #include <signal.h> // For SigUSR1Handler below. | 8 #include <signal.h> // For SigUSR1Handler below. |
9 #endif | 9 #endif |
10 | 10 |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "base/metrics/statistics_recorder.h" | |
12 #include "base/process_util.h" | 13 #include "base/process_util.h" |
13 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
14 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
15 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
16 #include "content/common/child_thread.h" | 17 #include "content/common/child_thread.h" |
17 | 18 |
18 #if defined(OS_ANDROID) | 19 #if defined(OS_ANDROID) |
19 #include "base/debug/debugger.h" | 20 #include "base/debug/debugger.h" |
20 #endif | 21 #endif |
21 | 22 |
22 #if defined(OS_POSIX) && !defined(OS_ANDROID) | 23 #if defined(OS_POSIX) && !defined(OS_ANDROID) |
23 static void SigUSR1Handler(int signal) { } | 24 static void SigUSR1Handler(int signal) { } |
24 #endif | 25 #endif |
25 | 26 |
26 ChildProcess* ChildProcess::child_process_; | 27 ChildProcess* ChildProcess::child_process_; |
27 | 28 |
28 ChildProcess::ChildProcess() | 29 ChildProcess::ChildProcess() |
29 : ref_count_(0), | 30 : ref_count_(0), |
30 shutdown_event_(true, false), | 31 shutdown_event_(true, false), |
31 io_thread_("Chrome_ChildIOThread") { | 32 io_thread_("Chrome_ChildIOThread") { |
32 DCHECK(!child_process_); | 33 DCHECK(!child_process_); |
33 child_process_ = this; | 34 child_process_ = this; |
34 | 35 |
36 // Initialize histogram statistics gathering system. | |
37 // Don't create StatisticsRecorder in the single process mode. | |
38 if (!base::StatisticsRecorder::IsActive()) { | |
39 statistics_recorder_.reset(new base::StatisticsRecorder()); | |
40 } | |
41 | |
35 // We can't recover from failing to start the IO thread. | 42 // We can't recover from failing to start the IO thread. |
36 CHECK(io_thread_.StartWithOptions( | 43 CHECK(io_thread_.StartWithOptions( |
37 base::Thread::Options(MessageLoop::TYPE_IO, 0))); | 44 base::Thread::Options(MessageLoop::TYPE_IO, 0))); |
38 } | 45 } |
39 | 46 |
40 ChildProcess::~ChildProcess() { | 47 ChildProcess::~ChildProcess() { |
41 DCHECK(child_process_ == this); | 48 DCHECK(child_process_ == this); |
42 | 49 |
43 // Signal this event before destroying the child process. That way all | 50 // Signal this event before destroying the child process. That way all |
44 // background threads can cleanup. | 51 // background threads can cleanup. |
45 // For example, in the renderer the RenderThread instances will be able to | 52 // For example, in the renderer the RenderThread instances will be able to |
46 // notice shutdown before the render process begins waiting for them to exit. | 53 // notice shutdown before the render process begins waiting for them to exit. |
47 shutdown_event_.Signal(); | 54 shutdown_event_.Signal(); |
48 | 55 |
49 // Kill the main thread object before nulling child_process_, since | 56 // Kill the main thread object before nulling child_process_, since |
50 // destruction code might depend on it. | 57 // destruction code might depend on it. |
51 main_thread_.reset(); | 58 main_thread_.reset(); |
52 | 59 |
60 statistics_recorder_.reset(); | |
jam
2012/07/18 01:22:06
nit: is this necessary? if not, leave it out
ramant (doing other things)
2012/07/18 03:20:32
Done.
| |
61 | |
53 child_process_ = NULL; | 62 child_process_ = NULL; |
54 } | 63 } |
55 | 64 |
56 ChildThread* ChildProcess::main_thread() { | 65 ChildThread* ChildProcess::main_thread() { |
57 return main_thread_.get(); | 66 return main_thread_.get(); |
58 } | 67 } |
59 | 68 |
60 void ChildProcess::set_main_thread(ChildThread* thread) { | 69 void ChildProcess::set_main_thread(ChildThread* thread) { |
61 main_thread_.reset(thread); | 70 main_thread_.reset(thread); |
62 } | 71 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 // Install a signal handler so that pause can be woken. | 123 // Install a signal handler so that pause can be woken. |
115 struct sigaction sa; | 124 struct sigaction sa; |
116 memset(&sa, 0, sizeof(sa)); | 125 memset(&sa, 0, sizeof(sa)); |
117 sa.sa_handler = SigUSR1Handler; | 126 sa.sa_handler = SigUSR1Handler; |
118 sigaction(SIGUSR1, &sa, NULL); | 127 sigaction(SIGUSR1, &sa, NULL); |
119 | 128 |
120 pause(); | 129 pause(); |
121 #endif // defined(OS_ANDROID) | 130 #endif // defined(OS_ANDROID) |
122 #endif // defined(OS_POSIX) | 131 #endif // defined(OS_POSIX) |
123 } | 132 } |
OLD | NEW |