Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/browser/child_process_launcher.h" | 5 #include "content/browser/child_process_launcher.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/i18n/icu_util.h" | 10 #include "base/i18n/icu_util.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 // slower due to the rest of the browser initializing at the same time). | 63 // slower due to the rest of the browser initializing at the same time). |
| 64 static bool done_first_launch = false; | 64 static bool done_first_launch = false; |
| 65 if (done_first_launch) { | 65 if (done_first_launch) { |
| 66 UMA_HISTOGRAM_TIMES("MPArch.ChildProcessLaunchSubsequent", launch_time); | 66 UMA_HISTOGRAM_TIMES("MPArch.ChildProcessLaunchSubsequent", launch_time); |
| 67 } else { | 67 } else { |
| 68 UMA_HISTOGRAM_TIMES("MPArch.ChildProcessLaunchFirst", launch_time); | 68 UMA_HISTOGRAM_TIMES("MPArch.ChildProcessLaunchFirst", launch_time); |
| 69 done_first_launch = true; | 69 done_first_launch = true; |
| 70 } | 70 } |
| 71 } | 71 } |
| 72 | 72 |
| 73 #if defined(OS_ANDROID) | 73 #if defined(OS_ANDROID)// && !defined(USE_AURA) |
|
no sievers
2015/10/20 19:24:23
remove
| |
| 74 // TODO(sievers): Remove this by defining better what happens on what | 74 // TODO(sievers): Remove this by defining better what happens on what |
| 75 // thread in the corresponding Java code. | 75 // thread in the corresponding Java code. |
| 76 void OnChildProcessStartedAndroid(const NotifyCallback& callback, | 76 void OnChildProcessStartedAndroid(const NotifyCallback& callback, |
| 77 BrowserThread::ID client_thread_id, | 77 BrowserThread::ID client_thread_id, |
| 78 const base::TimeTicks begin_launch_time, | 78 const base::TimeTicks begin_launch_time, |
| 79 base::ScopedFD ipcfd, | 79 base::ScopedFD ipcfd, |
| 80 base::ProcessHandle handle) { | 80 base::ProcessHandle handle) { |
| 81 // This can be called on the launcher thread or UI thread. | 81 // This can be called on the launcher thread or UI thread. |
| 82 base::TimeDelta launch_time = base::TimeTicks::Now() - begin_launch_time; | 82 base::TimeDelta launch_time = base::TimeTicks::Now() - begin_launch_time; |
| 83 BrowserThread::PostTask( | 83 BrowserThread::PostTask( |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 if (process_type != switches::kZygoteProcess) { | 172 if (process_type != switches::kZygoteProcess) { |
| 173 cmd_line->AppendSwitch(::switches::kV8NativesPassedByFD); | 173 cmd_line->AppendSwitch(::switches::kV8NativesPassedByFD); |
| 174 if (snapshot_pf != -1) { | 174 if (snapshot_pf != -1) { |
| 175 cmd_line->AppendSwitch(::switches::kV8SnapshotPassedByFD); | 175 cmd_line->AppendSwitch(::switches::kV8SnapshotPassedByFD); |
| 176 } | 176 } |
| 177 } | 177 } |
| 178 #endif // defined(V8_USE_EXTERNAL_STARTUP_DATA) | 178 #endif // defined(V8_USE_EXTERNAL_STARTUP_DATA) |
| 179 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) | 179 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) |
| 180 | 180 |
| 181 #if defined(OS_ANDROID) | 181 #if defined(OS_ANDROID) |
| 182 //#if !defined(USE_AURA) | |
| 182 files_to_register->Share( | 183 files_to_register->Share( |
| 183 kAndroidICUDataDescriptor, | 184 kAndroidICUDataDescriptor, |
| 184 base::i18n::GetIcuDataFileHandle(®ions[kAndroidICUDataDescriptor])); | 185 base::i18n::GetIcuDataFileHandle(®ions[kAndroidICUDataDescriptor])); |
| 185 | 186 |
| 186 // Android WebView runs in single process, ensure that we never get here | 187 // Android WebView runs in single process, ensure that we never get here |
| 187 // when running in single process mode. | 188 // when running in single process mode. |
| 188 CHECK(!cmd_line->HasSwitch(switches::kSingleProcess)); | 189 CHECK(!cmd_line->HasSwitch(switches::kSingleProcess)); |
| 189 | 190 |
| 190 StartChildProcess( | 191 StartChildProcess( |
| 191 cmd_line->argv(), child_process_id, files_to_register.Pass(), regions, | 192 cmd_line->argv(), child_process_id, files_to_register.Pass(), regions, |
| 192 base::Bind(&OnChildProcessStartedAndroid, callback, client_thread_id, | 193 base::Bind(&OnChildProcessStartedAndroid, callback, client_thread_id, |
| 193 begin_launch_time, base::Passed(&ipcfd))); | 194 begin_launch_time, base::Passed(&ipcfd))); |
| 194 | 195 //#endif |
| 195 #elif defined(OS_POSIX) | 196 #elif defined(OS_POSIX) |
| 196 // We need to close the client end of the IPC channel to reliably detect | 197 // We need to close the client end of the IPC channel to reliably detect |
| 197 // child termination. | 198 // child termination. |
| 198 | 199 |
| 199 #if !defined(OS_MACOSX) | 200 #if !defined(OS_MACOSX) |
| 200 if (use_zygote) { | 201 if (use_zygote) { |
| 201 base::ProcessHandle handle = ZygoteHostImpl::GetInstance()->ForkRequest( | 202 base::ProcessHandle handle = ZygoteHostImpl::GetInstance()->ForkRequest( |
| 202 cmd_line->argv(), files_to_register.Pass(), process_type); | 203 cmd_line->argv(), files_to_register.Pass(), process_type); |
| 203 process = base::Process(handle); | 204 process = base::Process(handle); |
| 204 } else | 205 } else |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 278 BrowserThread::PostTask(client_thread_id, FROM_HERE, | 279 BrowserThread::PostTask(client_thread_id, FROM_HERE, |
| 279 base::Bind(callback, | 280 base::Bind(callback, |
| 280 use_zygote, | 281 use_zygote, |
| 281 base::Passed(&process))); | 282 base::Passed(&process))); |
| 282 #endif // !defined(OS_ANDROID) | 283 #endif // !defined(OS_ANDROID) |
| 283 } | 284 } |
| 284 | 285 |
| 285 void TerminateOnLauncherThread(bool zygote, base::Process process) { | 286 void TerminateOnLauncherThread(bool zygote, base::Process process) { |
| 286 DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER); | 287 DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER); |
| 287 #if defined(OS_ANDROID) | 288 #if defined(OS_ANDROID) |
| 289 //#if !defined(USE_AURA) | |
|
no sievers
2015/10/20 19:24:23
We should keep the StopChildProcess() call.
| |
| 288 VLOG(1) << "ChromeProcess: Stopping process with handle " | 290 VLOG(1) << "ChromeProcess: Stopping process with handle " |
| 289 << process.Handle(); | 291 << process.Handle(); |
| 290 StopChildProcess(process.Handle()); | 292 StopChildProcess(process.Handle()); |
| 293 //#endif | |
| 291 #else | 294 #else |
| 292 // Client has gone away, so just kill the process. Using exit code 0 | 295 // Client has gone away, so just kill the process. Using exit code 0 |
| 293 // means that UMA won't treat this as a crash. | 296 // means that UMA won't treat this as a crash. |
| 294 process.Terminate(RESULT_CODE_NORMAL_EXIT, false); | 297 process.Terminate(RESULT_CODE_NORMAL_EXIT, false); |
| 295 // On POSIX, we must additionally reap the child. | 298 // On POSIX, we must additionally reap the child. |
| 296 #if defined(OS_POSIX) | 299 #if defined(OS_POSIX) |
| 297 #if !defined(OS_MACOSX) | 300 #if !defined(OS_MACOSX) |
| 298 if (zygote) { | 301 if (zygote) { |
| 299 // If the renderer was created via a zygote, we have to proxy the reaping | 302 // If the renderer was created via a zygote, we have to proxy the reaping |
| 300 // through the zygote process. | 303 // through the zygote process. |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 311 DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER); | 314 DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER); |
| 312 #if defined(OS_MACOSX) | 315 #if defined(OS_MACOSX) |
| 313 MachBroker* broker = MachBroker::GetInstance(); | 316 MachBroker* broker = MachBroker::GetInstance(); |
| 314 mach_port_t task_port = broker->TaskForPid(process.Pid()); | 317 mach_port_t task_port = broker->TaskForPid(process.Pid()); |
| 315 if (task_port != TASK_NULL) { | 318 if (task_port != TASK_NULL) { |
| 316 process.SetProcessBackgrounded(task_port, background); | 319 process.SetProcessBackgrounded(task_port, background); |
| 317 } | 320 } |
| 318 #else | 321 #else |
| 319 process.SetProcessBackgrounded(background); | 322 process.SetProcessBackgrounded(background); |
| 320 #endif // defined(OS_MACOSX) | 323 #endif // defined(OS_MACOSX) |
| 321 #if defined(OS_ANDROID) | 324 #if defined(OS_ANDROID)// && !defined(USE_AURA) |
| 322 SetChildProcessInForeground(process.Handle(), !background); | 325 SetChildProcessInForeground(process.Handle(), !background); |
| 323 #endif | 326 #endif |
| 324 } | 327 } |
| 325 | 328 |
| 326 } // anonymous namespace | 329 } // anonymous namespace |
| 327 | 330 |
| 328 ChildProcessLauncher::ChildProcessLauncher( | 331 ChildProcessLauncher::ChildProcessLauncher( |
| 329 SandboxedProcessLauncherDelegate* delegate, | 332 SandboxedProcessLauncherDelegate* delegate, |
| 330 base::CommandLine* cmd_line, | 333 base::CommandLine* cmd_line, |
| 331 int child_process_id, | 334 int child_process_id, |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 405 GetTerminationStatus(process_.Handle(), known_dead, &exit_code_); | 408 GetTerminationStatus(process_.Handle(), known_dead, &exit_code_); |
| 406 } else if (known_dead) { | 409 } else if (known_dead) { |
| 407 termination_status_ = | 410 termination_status_ = |
| 408 base::GetKnownDeadTerminationStatus(process_.Handle(), &exit_code_); | 411 base::GetKnownDeadTerminationStatus(process_.Handle(), &exit_code_); |
| 409 } else { | 412 } else { |
| 410 #elif defined(OS_MACOSX) | 413 #elif defined(OS_MACOSX) |
| 411 if (known_dead) { | 414 if (known_dead) { |
| 412 termination_status_ = | 415 termination_status_ = |
| 413 base::GetKnownDeadTerminationStatus(process_.Handle(), &exit_code_); | 416 base::GetKnownDeadTerminationStatus(process_.Handle(), &exit_code_); |
| 414 } else { | 417 } else { |
| 415 #elif defined(OS_ANDROID) | 418 #elif defined(OS_ANDROID)// && !defined(USE_AURA) |
| 416 if (IsChildProcessOomProtected(process_.Handle())) { | 419 if (IsChildProcessOomProtected(process_.Handle())) { |
| 417 termination_status_ = base::TERMINATION_STATUS_OOM_PROTECTED; | 420 termination_status_ = base::TERMINATION_STATUS_OOM_PROTECTED; |
| 418 } else { | 421 } else { |
| 419 #else | 422 #else |
| 420 { | 423 { |
| 421 #endif | 424 #endif |
| 422 termination_status_ = | 425 termination_status_ = |
| 423 base::GetTerminationStatus(process_.Handle(), &exit_code_); | 426 base::GetTerminationStatus(process_.Handle(), &exit_code_); |
| 424 } | 427 } |
| 425 } | 428 } |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 541 } | 544 } |
| 542 | 545 |
| 543 ChildProcessLauncher::Client* ChildProcessLauncher::ReplaceClientForTest( | 546 ChildProcessLauncher::Client* ChildProcessLauncher::ReplaceClientForTest( |
| 544 Client* client) { | 547 Client* client) { |
| 545 Client* ret = client_; | 548 Client* ret = client_; |
| 546 client_ = client; | 549 client_ = client; |
| 547 return ret; | 550 return ret; |
| 548 } | 551 } |
| 549 | 552 |
| 550 } // namespace content | 553 } // namespace content |
| OLD | NEW |