| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_helper.h" | 5 #include "content/browser/child_process_launcher_helper.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram_macros.h" | 7 #include "base/metrics/histogram_macros.h" |
| 8 #include "content/browser/child_process_launcher.h" | 8 #include "content/browser/child_process_launcher.h" |
| 9 #include "content/public/common/content_switches.h" | 9 #include "content/public/common/content_switches.h" |
| 10 #include "content/public/common/sandboxed_process_launcher_delegate.h" | 10 #include "content/public/common/sandboxed_process_launcher_delegate.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 BeforeLaunchOnLauncherThread(*files_to_register, &options); | 97 BeforeLaunchOnLauncherThread(*files_to_register, &options); |
| 98 | 98 |
| 99 Process process = LaunchProcessOnLauncherThread(options, | 99 Process process = LaunchProcessOnLauncherThread(options, |
| 100 std::move(files_to_register), | 100 std::move(files_to_register), |
| 101 &is_synchronous_launch, | 101 &is_synchronous_launch, |
| 102 &launch_result); | 102 &launch_result); |
| 103 | 103 |
| 104 AfterLaunchOnLauncherThread(process, options); | 104 AfterLaunchOnLauncherThread(process, options); |
| 105 | 105 |
| 106 if (is_synchronous_launch) { | 106 if (is_synchronous_launch) { |
| 107 PostLaunchOnLauncherThread(std::move(process), launch_result, false); | 107 PostLaunchOnLauncherThread(std::move(process), launch_result); |
| 108 } | 108 } |
| 109 } | 109 } |
| 110 | 110 |
| 111 void ChildProcessLauncherHelper::PostLaunchOnLauncherThread( | 111 void ChildProcessLauncherHelper::PostLaunchOnLauncherThread( |
| 112 ChildProcessLauncherHelper::Process process, | 112 ChildProcessLauncherHelper::Process process, |
| 113 int launch_result, | 113 int launch_result) { |
| 114 bool post_launch_on_client_thread_called) { | |
| 115 // Release the client handle now that the process has been started (the pipe | 114 // Release the client handle now that the process has been started (the pipe |
| 116 // may not signal when the process dies otherwise and we would not detect the | 115 // may not signal when the process dies otherwise and we would not detect the |
| 117 // child process died). | 116 // child process died). |
| 118 mojo_client_handle_.reset(); | 117 mojo_client_handle_.reset(); |
| 119 | 118 |
| 120 if (process.process.IsValid()) { | 119 if (process.process.IsValid()) { |
| 121 RecordHistogramsOnLauncherThread( | 120 RecordHistogramsOnLauncherThread(base::TimeTicks::Now() - |
| 122 base::TimeTicks::Now() - begin_launch_time_); | 121 begin_launch_time_); |
| 123 } | 122 } |
| 124 | 123 |
| 125 if (!post_launch_on_client_thread_called) { | 124 BrowserThread::PostTask( |
| 126 BrowserThread::PostTask( | 125 client_thread_id_, FROM_HERE, |
| 127 client_thread_id_, FROM_HERE, | 126 base::Bind(&ChildProcessLauncherHelper::PostLaunchOnClientThread, this, |
| 128 base::Bind(&ChildProcessLauncherHelper::PostLaunchOnClientThread, | 127 base::Passed(&process), launch_result)); |
| 129 this, base::Passed(&process), launch_result)); | |
| 130 } | |
| 131 } | 128 } |
| 132 | 129 |
| 133 void ChildProcessLauncherHelper::PostLaunchOnClientThread( | 130 void ChildProcessLauncherHelper::PostLaunchOnClientThread( |
| 134 ChildProcessLauncherHelper::Process process, | 131 ChildProcessLauncherHelper::Process process, |
| 135 int error_code) { | 132 int error_code) { |
| 136 if (child_process_launcher_) { | 133 if (child_process_launcher_) { |
| 137 child_process_launcher_->Notify( | 134 child_process_launcher_->Notify( |
| 138 std::move(process), std::move(mojo_server_handle_), error_code); | 135 std::move(process), std::move(mojo_server_handle_), error_code); |
| 139 } else if (process.process.IsValid() && terminate_on_shutdown_) { | 136 } else if (process.process.IsValid() && terminate_on_shutdown_) { |
| 140 // Client is gone, terminate the process. | 137 // Client is gone, terminate the process. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 156 // On Posix, EnsureProcessTerminated can lead to 2 seconds of sleep! | 153 // On Posix, EnsureProcessTerminated can lead to 2 seconds of sleep! |
| 157 // So don't do this on the UI/IO threads. | 154 // So don't do this on the UI/IO threads. |
| 158 BrowserThread::PostTask( | 155 BrowserThread::PostTask( |
| 159 BrowserThread::PROCESS_LAUNCHER, FROM_HERE, | 156 BrowserThread::PROCESS_LAUNCHER, FROM_HERE, |
| 160 base::Bind(&ChildProcessLauncherHelper::ForceNormalProcessTerminationSync, | 157 base::Bind(&ChildProcessLauncherHelper::ForceNormalProcessTerminationSync, |
| 161 base::Passed(&process))); | 158 base::Passed(&process))); |
| 162 } | 159 } |
| 163 | 160 |
| 164 } // namespace internal | 161 } // namespace internal |
| 165 } // namespace content | 162 } // namespace content |
| OLD | NEW |