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); | 107 PostLaunchOnLauncherThread(std::move(process), launch_result, false); |
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) { |
114 // Release the client handle now that the process has been started (the pipe | 115 // Release the client handle now that the process has been started (the pipe |
115 // may not signal when the process dies otherwise and we would not detect the | 116 // may not signal when the process dies otherwise and we would not detect the |
116 // child process died). | 117 // child process died). |
117 mojo_client_handle_.reset(); | 118 mojo_client_handle_.reset(); |
118 | 119 |
119 if (process.process.IsValid()) { | 120 if (process.process.IsValid()) { |
120 RecordHistogramsOnLauncherThread(base::TimeTicks::Now() - | 121 RecordHistogramsOnLauncherThread( |
121 begin_launch_time_); | 122 base::TimeTicks::Now() - begin_launch_time_); |
122 } | 123 } |
123 | 124 |
124 BrowserThread::PostTask( | 125 if (!post_launch_on_client_thread_called) { |
125 client_thread_id_, FROM_HERE, | 126 BrowserThread::PostTask( |
126 base::Bind(&ChildProcessLauncherHelper::PostLaunchOnClientThread, this, | 127 client_thread_id_, FROM_HERE, |
127 base::Passed(&process), launch_result)); | 128 base::Bind(&ChildProcessLauncherHelper::PostLaunchOnClientThread, |
| 129 this, base::Passed(&process), launch_result)); |
| 130 } |
128 } | 131 } |
129 | 132 |
130 void ChildProcessLauncherHelper::PostLaunchOnClientThread( | 133 void ChildProcessLauncherHelper::PostLaunchOnClientThread( |
131 ChildProcessLauncherHelper::Process process, | 134 ChildProcessLauncherHelper::Process process, |
132 int error_code) { | 135 int error_code) { |
133 if (child_process_launcher_) { | 136 if (child_process_launcher_) { |
134 child_process_launcher_->Notify( | 137 child_process_launcher_->Notify( |
135 std::move(process), std::move(mojo_server_handle_), error_code); | 138 std::move(process), std::move(mojo_server_handle_), error_code); |
136 } else if (process.process.IsValid() && terminate_on_shutdown_) { | 139 } else if (process.process.IsValid() && terminate_on_shutdown_) { |
137 // Client is gone, terminate the process. | 140 // Client is gone, terminate the process. |
(...skipping 15 matching lines...) Expand all Loading... |
153 // On Posix, EnsureProcessTerminated can lead to 2 seconds of sleep! | 156 // On Posix, EnsureProcessTerminated can lead to 2 seconds of sleep! |
154 // So don't do this on the UI/IO threads. | 157 // So don't do this on the UI/IO threads. |
155 BrowserThread::PostTask( | 158 BrowserThread::PostTask( |
156 BrowserThread::PROCESS_LAUNCHER, FROM_HERE, | 159 BrowserThread::PROCESS_LAUNCHER, FROM_HERE, |
157 base::Bind(&ChildProcessLauncherHelper::ForceNormalProcessTerminationSync, | 160 base::Bind(&ChildProcessLauncherHelper::ForceNormalProcessTerminationSync, |
158 base::Passed(&process))); | 161 base::Passed(&process))); |
159 } | 162 } |
160 | 163 |
161 } // namespace internal | 164 } // namespace internal |
162 } // namespace content | 165 } // namespace content |
OLD | NEW |