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

Side by Side Diff: chrome/browser/child_process_launcher.cc

Issue 5519016: Add a new GetInstance() method for singleton classes used in chrome/browser files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 10 years 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/browser/browser_signin.cc ('k') | chrome/browser/chromeos/dom_ui/imageburner_ui.cc » ('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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/browser/child_process_launcher.h" 5 #include "chrome/browser/child_process_launcher.h"
6 6
7 #include <utility> // For std::pair. 7 #include <utility> // For std::pair.
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/lock.h" 10 #include "base/lock.h"
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 base::ProcessHandle handle = base::kNullProcessHandle; 108 base::ProcessHandle handle = base::kNullProcessHandle;
109 #if defined(OS_WIN) 109 #if defined(OS_WIN)
110 handle = sandbox::StartProcessWithAccess(cmd_line, exposed_dir); 110 handle = sandbox::StartProcessWithAccess(cmd_line, exposed_dir);
111 #elif defined(OS_POSIX) 111 #elif defined(OS_POSIX)
112 112
113 #if defined(OS_LINUX) 113 #if defined(OS_LINUX)
114 if (use_zygote) { 114 if (use_zygote) {
115 base::GlobalDescriptors::Mapping mapping; 115 base::GlobalDescriptors::Mapping mapping;
116 mapping.push_back(std::pair<uint32_t, int>(kPrimaryIPCChannel, ipcfd)); 116 mapping.push_back(std::pair<uint32_t, int>(kPrimaryIPCChannel, ipcfd));
117 const int crash_signal_fd = 117 const int crash_signal_fd =
118 Singleton<RendererCrashHandlerHostLinux>()->GetDeathSignalSocket(); 118 RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
119 if (crash_signal_fd >= 0) { 119 if (crash_signal_fd >= 0) {
120 mapping.push_back(std::pair<uint32_t, int>(kCrashDumpSignal, 120 mapping.push_back(std::pair<uint32_t, int>(kCrashDumpSignal,
121 crash_signal_fd)); 121 crash_signal_fd));
122 } 122 }
123 handle = Singleton<ZygoteHost>()->ForkRenderer(cmd_line->argv(), mapping); 123 handle = ZygoteHost::GetInstance()->ForkRenderer(cmd_line->argv(),
124 mapping);
124 } else 125 } else
125 // Fall through to the normal posix case below when we're not zygoting. 126 // Fall through to the normal posix case below when we're not zygoting.
126 #endif 127 #endif
127 { 128 {
128 base::file_handle_mapping_vector fds_to_map; 129 base::file_handle_mapping_vector fds_to_map;
129 fds_to_map.push_back(std::make_pair( 130 fds_to_map.push_back(std::make_pair(
130 ipcfd, 131 ipcfd,
131 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor)); 132 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor));
132 133
133 #if defined(OS_LINUX) 134 #if defined(OS_LINUX)
134 // On Linux, we need to add some extra file descriptors for crash handling 135 // On Linux, we need to add some extra file descriptors for crash handling
135 // and the sandbox. 136 // and the sandbox.
136 bool is_renderer = 137 bool is_renderer =
137 cmd_line->GetSwitchValueASCII(switches::kProcessType) == 138 cmd_line->GetSwitchValueASCII(switches::kProcessType) ==
138 switches::kRendererProcess; 139 switches::kRendererProcess;
139 bool is_plugin = 140 bool is_plugin =
140 cmd_line->GetSwitchValueASCII(switches::kProcessType) == 141 cmd_line->GetSwitchValueASCII(switches::kProcessType) ==
141 switches::kPluginProcess; 142 switches::kPluginProcess;
142 143
143 if (is_renderer || is_plugin) { 144 if (is_renderer || is_plugin) {
144 int crash_signal_fd; 145 int crash_signal_fd;
145 if (is_renderer) { 146 if (is_renderer) {
146 crash_signal_fd = Singleton<RendererCrashHandlerHostLinux>()-> 147 crash_signal_fd = RendererCrashHandlerHostLinux::GetInstance()->
147 GetDeathSignalSocket(); 148 GetDeathSignalSocket();
148 } else { 149 } else {
149 crash_signal_fd = Singleton<PluginCrashHandlerHostLinux>()-> 150 crash_signal_fd = PluginCrashHandlerHostLinux::GetInstance()->
150 GetDeathSignalSocket(); 151 GetDeathSignalSocket();
151 } 152 }
152 if (crash_signal_fd >= 0) { 153 if (crash_signal_fd >= 0) {
153 fds_to_map.push_back(std::make_pair( 154 fds_to_map.push_back(std::make_pair(
154 crash_signal_fd, 155 crash_signal_fd,
155 kCrashDumpSignal + base::GlobalDescriptors::kBaseDescriptor)); 156 kCrashDumpSignal + base::GlobalDescriptors::kBaseDescriptor));
156 } 157 }
157 } 158 }
158 if (is_renderer) { 159 if (is_renderer) {
159 const int sandbox_fd = 160 const int sandbox_fd =
160 Singleton<RenderSandboxHostLinux>()->GetRendererSocket(); 161 RenderSandboxHostLinux::GetInstance()->GetRendererSocket();
161 fds_to_map.push_back(std::make_pair( 162 fds_to_map.push_back(std::make_pair(
162 sandbox_fd, 163 sandbox_fd,
163 kSandboxIPCChannel + base::GlobalDescriptors::kBaseDescriptor)); 164 kSandboxIPCChannel + base::GlobalDescriptors::kBaseDescriptor));
164 } 165 }
165 #endif // defined(OS_LINUX) 166 #endif // defined(OS_LINUX)
166 167
167 bool launched = false; 168 bool launched = false;
168 #if defined(OS_MACOSX) 169 #if defined(OS_MACOSX)
169 // It is possible for the child process to die immediately after 170 // It is possible for the child process to die immediately after
170 // launching. To prevent leaking MachBroker map entries in this case, 171 // launching. To prevent leaking MachBroker map entries in this case,
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 base::Process process(handle); 247 base::Process process(handle);
247 // Client has gone away, so just kill the process. Using exit code 0 248 // Client has gone away, so just kill the process. Using exit code 0
248 // means that UMA won't treat this as a crash. 249 // means that UMA won't treat this as a crash.
249 process.Terminate(ResultCodes::NORMAL_EXIT); 250 process.Terminate(ResultCodes::NORMAL_EXIT);
250 // On POSIX, we must additionally reap the child. 251 // On POSIX, we must additionally reap the child.
251 #if defined(OS_POSIX) 252 #if defined(OS_POSIX)
252 #if defined(OS_LINUX) 253 #if defined(OS_LINUX)
253 if (zygote) { 254 if (zygote) {
254 // If the renderer was created via a zygote, we have to proxy the reaping 255 // If the renderer was created via a zygote, we have to proxy the reaping
255 // through the zygote process. 256 // through the zygote process.
256 Singleton<ZygoteHost>()->EnsureProcessTerminated(handle); 257 ZygoteHost::GetInstance()->EnsureProcessTerminated(handle);
257 } else 258 } else
258 #endif // OS_LINUX 259 #endif // OS_LINUX
259 { 260 {
260 ProcessWatcher::EnsureProcessTerminated(handle); 261 ProcessWatcher::EnsureProcessTerminated(handle);
261 } 262 }
262 #endif // OS_POSIX 263 #endif // OS_POSIX
263 process.Close(); 264 process.Close();
264 } 265 }
265 266
266 Client* client_; 267 Client* client_;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 base::ProcessHandle ChildProcessLauncher::GetHandle() { 309 base::ProcessHandle ChildProcessLauncher::GetHandle() {
309 DCHECK(!context_->starting_); 310 DCHECK(!context_->starting_);
310 return context_->process_.handle(); 311 return context_->process_.handle();
311 } 312 }
312 313
313 bool ChildProcessLauncher::DidProcessCrash() { 314 bool ChildProcessLauncher::DidProcessCrash() {
314 bool did_crash, child_exited; 315 bool did_crash, child_exited;
315 base::ProcessHandle handle = context_->process_.handle(); 316 base::ProcessHandle handle = context_->process_.handle();
316 #if defined(OS_LINUX) 317 #if defined(OS_LINUX)
317 if (context_->zygote_) { 318 if (context_->zygote_) {
318 did_crash = Singleton<ZygoteHost>()->DidProcessCrash(handle, &child_exited); 319 did_crash = ZygoteHost::GetInstance()->DidProcessCrash(handle,
320 &child_exited);
319 } else 321 } else
320 #endif 322 #endif
321 { 323 {
322 did_crash = base::DidProcessCrash(&child_exited, handle); 324 did_crash = base::DidProcessCrash(&child_exited, handle);
323 } 325 }
324 326
325 // POSIX: If the process crashed, then the kernel closed the socket for it 327 // POSIX: If the process crashed, then the kernel closed the socket for it
326 // and so the child has already died by the time we get here. Since 328 // and so the child has already died by the time we get here. Since
327 // DidProcessCrash called waitpid with WNOHANG, it'll reap the process. 329 // DidProcessCrash called waitpid with WNOHANG, it'll reap the process.
328 // However, if DidProcessCrash didn't reap the child, we'll need to in 330 // However, if DidProcessCrash didn't reap the child, we'll need to in
329 // Terminate via ProcessWatcher. So we can't close the handle here. 331 // Terminate via ProcessWatcher. So we can't close the handle here.
330 if (child_exited) 332 if (child_exited)
331 context_->process_.Close(); 333 context_->process_.Close();
332 334
333 return did_crash; 335 return did_crash;
334 } 336 }
335 337
336 void ChildProcessLauncher::SetProcessBackgrounded(bool background) { 338 void ChildProcessLauncher::SetProcessBackgrounded(bool background) {
337 DCHECK(!context_->starting_); 339 DCHECK(!context_->starting_);
338 context_->process_.SetProcessBackgrounded(background); 340 context_->process_.SetProcessBackgrounded(background);
339 } 341 }
OLDNEW
« no previous file with comments | « chrome/browser/browser_signin.cc ('k') | chrome/browser/chromeos/dom_ui/imageburner_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698