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

Side by Side Diff: content/common/child_process.cc

Issue 15403002: Remving global statics from the headers, so we can split-link. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: adding export Created 7 years, 7 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
« no previous file with comments | « content/common/child_process.h ('k') | ppapi/shared_impl/ppapi_globals.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) 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/metrics/statistics_recorder.h"
13 #include "base/process_util.h" 13 #include "base/process_util.h"
14 #include "base/string_number_conversions.h" 14 #include "base/string_number_conversions.h"
15 #include "base/threading/thread.h" 15 #include "base/threading/thread.h"
16 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
17 #include "content/common/child_thread.h" 17 #include "content/common/child_thread.h"
18 18
19 #if defined(OS_ANDROID) 19 #if defined(OS_ANDROID)
20 #include "base/debug/debugger.h" 20 #include "base/debug/debugger.h"
21 // TODO(epenner): Move thread priorities to base. (crbug.com/170549) 21 // TODO(epenner): Move thread priorities to base. (crbug.com/170549)
22 #include <sys/resource.h> 22 #include <sys/resource.h>
23 #endif 23 #endif
24 24
25 #if defined(OS_POSIX) && !defined(OS_ANDROID) 25 #if defined(OS_POSIX) && !defined(OS_ANDROID)
26 static void SigUSR1Handler(int signal) { } 26 static void SigUSR1Handler(int signal) { }
27 #endif 27 #endif
28 28
29 namespace content { 29 namespace content {
30 30 // The singleton instance for this process.
31 ChildProcess* ChildProcess::child_process_; 31 ChildProcess* child_process = NULL;
32 32
33 #if defined(OS_ANDROID) 33 #if defined(OS_ANDROID)
34 // TODO(epenner): Move thread priorities to base. (crbug.com/170549) 34 // TODO(epenner): Move thread priorities to base. (crbug.com/170549)
35 namespace { 35 namespace {
36 void SetHighThreadPriority() { 36 void SetHighThreadPriority() {
37 int nice_value = -6; // High priority. 37 int nice_value = -6; // High priority.
38 setpriority(PRIO_PROCESS, base::PlatformThread::CurrentId(), nice_value); 38 setpriority(PRIO_PROCESS, base::PlatformThread::CurrentId(), nice_value);
39 } 39 }
40 } 40 }
41 #endif 41 #endif
42 42
43 ChildProcess::ChildProcess() 43 ChildProcess::ChildProcess()
44 : ref_count_(0), 44 : ref_count_(0),
45 shutdown_event_(true, false), 45 shutdown_event_(true, false),
46 io_thread_("Chrome_ChildIOThread") { 46 io_thread_("Chrome_ChildIOThread") {
47 DCHECK(!child_process_); 47 DCHECK(!child_process);
48 child_process_ = this; 48 child_process = this;
49 49
50 base::StatisticsRecorder::Initialize(); 50 base::StatisticsRecorder::Initialize();
51 51
52 // We can't recover from failing to start the IO thread. 52 // We can't recover from failing to start the IO thread.
53 CHECK(io_thread_.StartWithOptions( 53 CHECK(io_thread_.StartWithOptions(
54 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); 54 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)));
55 55
56 #if defined(OS_ANDROID) 56 #if defined(OS_ANDROID)
57 // TODO(epenner): Move thread priorities to base. (crbug.com/170549) 57 // TODO(epenner): Move thread priorities to base. (crbug.com/170549)
58 io_thread_.message_loop()->PostTask(FROM_HERE, 58 io_thread_.message_loop()->PostTask(FROM_HERE,
59 base::Bind(&SetHighThreadPriority)); 59 base::Bind(&SetHighThreadPriority));
60 #endif 60 #endif
61 } 61 }
62 62
63 ChildProcess::~ChildProcess() { 63 ChildProcess::~ChildProcess() {
64 DCHECK(child_process_ == this); 64 DCHECK(child_process == this);
65 65
66 // Signal this event before destroying the child process. That way all 66 // Signal this event before destroying the child process. That way all
67 // background threads can cleanup. 67 // background threads can cleanup.
68 // For example, in the renderer the RenderThread instances will be able to 68 // For example, in the renderer the RenderThread instances will be able to
69 // notice shutdown before the render process begins waiting for them to exit. 69 // notice shutdown before the render process begins waiting for them to exit.
70 shutdown_event_.Signal(); 70 shutdown_event_.Signal();
71 71
72 // Kill the main thread object before nulling child_process_, since 72 // Kill the main thread object before nulling child_process, since
73 // destruction code might depend on it. 73 // destruction code might depend on it.
74 if (main_thread_) { // null in unittests. 74 if (main_thread_) { // null in unittests.
75 main_thread_->Shutdown(); 75 main_thread_->Shutdown();
76 main_thread_.reset(); 76 main_thread_.reset();
77 } 77 }
78 78
79 child_process_ = NULL; 79 child_process = NULL;
80 } 80 }
81 81
82 ChildThread* ChildProcess::main_thread() { 82 ChildThread* ChildProcess::main_thread() {
83 return main_thread_.get(); 83 return main_thread_.get();
84 } 84 }
85 85
86 void ChildProcess::set_main_thread(ChildThread* thread) { 86 void ChildProcess::set_main_thread(ChildThread* thread) {
87 main_thread_.reset(thread); 87 main_thread_.reset(thread);
88 } 88 }
89 89
90 void ChildProcess::AddRefProcess() { 90 void ChildProcess::AddRefProcess() {
91 DCHECK(!main_thread_.get() || // null in unittests. 91 DCHECK(!main_thread_.get() || // null in unittests.
92 base::MessageLoop::current() == main_thread_->message_loop()); 92 base::MessageLoop::current() == main_thread_->message_loop());
93 ref_count_++; 93 ref_count_++;
94 } 94 }
95 95
96 void ChildProcess::ReleaseProcess() { 96 void ChildProcess::ReleaseProcess() {
97 DCHECK(!main_thread_.get() || // null in unittests. 97 DCHECK(!main_thread_.get() || // null in unittests.
98 base::MessageLoop::current() == main_thread_->message_loop()); 98 base::MessageLoop::current() == main_thread_->message_loop());
99 DCHECK(ref_count_); 99 DCHECK(ref_count_);
100 DCHECK(child_process_); 100 DCHECK(child_process);
101 if (--ref_count_) 101 if (--ref_count_)
102 return; 102 return;
103 103
104 if (main_thread_) // null in unittests. 104 if (main_thread_) // null in unittests.
105 main_thread_->OnProcessFinalRelease(); 105 main_thread_->OnProcessFinalRelease();
106 } 106 }
107 107
108 ChildProcess* ChildProcess::current() {
109 return child_process;
110 }
111
108 base::WaitableEvent* ChildProcess::GetShutDownEvent() { 112 base::WaitableEvent* ChildProcess::GetShutDownEvent() {
109 DCHECK(child_process_); 113 DCHECK(child_process);
110 return &child_process_->shutdown_event_; 114 return &child_process->shutdown_event_;
111 } 115 }
112 116
113 void ChildProcess::WaitForDebugger(const std::string& label) { 117 void ChildProcess::WaitForDebugger(const std::string& label) {
114 #if defined(OS_WIN) 118 #if defined(OS_WIN)
115 #if defined(GOOGLE_CHROME_BUILD) 119 #if defined(GOOGLE_CHROME_BUILD)
116 std::string title = "Google Chrome"; 120 std::string title = "Google Chrome";
117 #else // CHROMIUM_BUILD 121 #else // CHROMIUM_BUILD
118 std::string title = "Chromium"; 122 std::string title = "Chromium";
119 #endif // CHROMIUM_BUILD 123 #endif // CHROMIUM_BUILD
120 title += " "; 124 title += " ";
(...skipping 22 matching lines...) Expand all
143 memset(&sa, 0, sizeof(sa)); 147 memset(&sa, 0, sizeof(sa));
144 sa.sa_handler = SigUSR1Handler; 148 sa.sa_handler = SigUSR1Handler;
145 sigaction(SIGUSR1, &sa, NULL); 149 sigaction(SIGUSR1, &sa, NULL);
146 150
147 pause(); 151 pause();
148 #endif // defined(OS_ANDROID) 152 #endif // defined(OS_ANDROID)
149 #endif // defined(OS_POSIX) 153 #endif // defined(OS_POSIX)
150 } 154 }
151 155
152 } // namespace content 156 } // namespace content
OLDNEW
« no previous file with comments | « content/common/child_process.h ('k') | ppapi/shared_impl/ppapi_globals.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698