OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser/child_process_launcher.h" | 5 #include "content/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/logging.h" | 10 #include "base/logging.h" |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 void LaunchInternal( | 98 void LaunchInternal( |
99 #if defined(OS_WIN) | 99 #if defined(OS_WIN) |
100 const FilePath& exposed_dir, | 100 const FilePath& exposed_dir, |
101 #elif defined(OS_POSIX) | 101 #elif defined(OS_POSIX) |
102 bool use_zygote, | 102 bool use_zygote, |
103 const base::environment_vector& env, | 103 const base::environment_vector& env, |
104 int ipcfd, | 104 int ipcfd, |
105 #endif | 105 #endif |
106 CommandLine* cmd_line) { | 106 CommandLine* cmd_line) { |
107 scoped_ptr<CommandLine> cmd_line_deleter(cmd_line); | 107 scoped_ptr<CommandLine> cmd_line_deleter(cmd_line); |
108 process_type_ = cmd_line->GetSwitchValueASCII(switches::kProcessType); | |
108 base::ProcessHandle handle = base::kNullProcessHandle; | 109 base::ProcessHandle handle = base::kNullProcessHandle; |
109 #if defined(OS_WIN) | 110 #if defined(OS_WIN) |
110 handle = sandbox::StartProcessWithAccess(cmd_line, exposed_dir); | 111 handle = sandbox::StartProcessWithAccess(cmd_line, exposed_dir); |
111 #elif defined(OS_POSIX) | 112 #elif defined(OS_POSIX) |
112 | 113 |
113 #if defined(OS_LINUX) | 114 #if defined(OS_LINUX) |
114 // On Linux, we need to add some extra file descriptors for crash handling. | 115 // On Linux, we need to add some extra file descriptors for crash handling. |
115 std::string process_type = | 116 std::string process_type = |
116 cmd_line->GetSwitchValueASCII(switches::kProcessType); | 117 cmd_line->GetSwitchValueASCII(switches::kProcessType); |
117 int crash_signal_fd = | 118 int crash_signal_fd = |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
203 client_->OnProcessLaunched(); | 204 client_->OnProcessLaunched(); |
204 } else { | 205 } else { |
205 Terminate(); | 206 Terminate(); |
206 } | 207 } |
207 } | 208 } |
208 | 209 |
209 void Terminate() { | 210 void Terminate() { |
210 if (!process_.handle()) | 211 if (!process_.handle()) |
211 return; | 212 return; |
212 | 213 |
214 const int kPluginProcessTerminateTimeoutMs = 2000; | |
215 | |
213 // On Posix, EnsureProcessTerminated can lead to 2 seconds of sleep! So | 216 // On Posix, EnsureProcessTerminated can lead to 2 seconds of sleep! So |
214 // don't this on the UI/IO threads. | 217 // don't this on the UI/IO threads. |
215 BrowserThread::PostTask( | 218 // Allow plugins to shutdown gracefully before terminating the process. |
216 BrowserThread::PROCESS_LAUNCHER, FROM_HERE, | 219 if (process_type_ == switches::kPluginProcess) { |
jam
2011/05/23 22:32:59
ChildProcessLauncher is the base class that's used
| |
217 NewRunnableFunction( | 220 BrowserThread::PostDelayedTask( |
218 &ChildProcessLauncher::Context::TerminateInternal, | 221 BrowserThread::PROCESS_LAUNCHER, FROM_HERE, |
219 #if defined(OS_LINUX) | 222 NewRunnableFunction( |
220 zygote_, | 223 &ChildProcessLauncher::Context::TerminateInternal, |
221 #endif | 224 #if defined(OS_LINUX) |
222 process_.handle())); | 225 zygote_, |
226 #endif | |
227 process_.handle()), kPluginProcessTerminateTimeoutMs); | |
228 } else { | |
229 BrowserThread::PostTask( | |
230 BrowserThread::PROCESS_LAUNCHER, FROM_HERE, | |
231 NewRunnableFunction( | |
232 &ChildProcessLauncher::Context::TerminateInternal, | |
233 #if defined(OS_LINUX) | |
234 zygote_, | |
235 #endif | |
236 process_.handle())); | |
237 } | |
223 process_.set_handle(base::kNullProcessHandle); | 238 process_.set_handle(base::kNullProcessHandle); |
224 } | 239 } |
225 | 240 |
226 void SetProcessBackgrounded(bool background) { | 241 void SetProcessBackgrounded(bool background) { |
227 DCHECK(!starting_); | 242 DCHECK(!starting_); |
228 process_.SetProcessBackgrounded(background); | 243 process_.SetProcessBackgrounded(background); |
229 } | 244 } |
230 | 245 |
231 static void TerminateInternal( | 246 static void TerminateInternal( |
232 #if defined(OS_LINUX) | 247 #if defined(OS_LINUX) |
(...skipping 17 matching lines...) Expand all Loading... | |
250 ProcessWatcher::EnsureProcessTerminated(handle); | 265 ProcessWatcher::EnsureProcessTerminated(handle); |
251 } | 266 } |
252 #endif // OS_POSIX | 267 #endif // OS_POSIX |
253 process.Close(); | 268 process.Close(); |
254 } | 269 } |
255 | 270 |
256 Client* client_; | 271 Client* client_; |
257 BrowserThread::ID client_thread_id_; | 272 BrowserThread::ID client_thread_id_; |
258 base::Process process_; | 273 base::Process process_; |
259 bool starting_; | 274 bool starting_; |
275 std::string process_type_; | |
260 | 276 |
261 #if defined(OS_LINUX) | 277 #if defined(OS_LINUX) |
262 bool zygote_; | 278 bool zygote_; |
263 #endif | 279 #endif |
264 }; | 280 }; |
265 | 281 |
266 | 282 |
267 ChildProcessLauncher::ChildProcessLauncher( | 283 ChildProcessLauncher::ChildProcessLauncher( |
268 #if defined(OS_WIN) | 284 #if defined(OS_WIN) |
269 const FilePath& exposed_dir, | 285 const FilePath& exposed_dir, |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
326 } | 342 } |
327 | 343 |
328 void ChildProcessLauncher::SetProcessBackgrounded(bool background) { | 344 void ChildProcessLauncher::SetProcessBackgrounded(bool background) { |
329 BrowserThread::PostTask( | 345 BrowserThread::PostTask( |
330 BrowserThread::PROCESS_LAUNCHER, FROM_HERE, | 346 BrowserThread::PROCESS_LAUNCHER, FROM_HERE, |
331 NewRunnableMethod( | 347 NewRunnableMethod( |
332 context_.get(), | 348 context_.get(), |
333 &ChildProcessLauncher::Context::SetProcessBackgrounded, | 349 &ChildProcessLauncher::Context::SetProcessBackgrounded, |
334 background)); | 350 background)); |
335 } | 351 } |
OLD | NEW |