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_android.h" | 5 #include "content/browser/child_process_launcher_helper_android.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/android/apk_assets.h" | 9 #include "base/android/apk_assets.h" |
10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 void ChildProcessLauncherHelper::ResetRegisteredFilesForTesting() { | 192 void ChildProcessLauncherHelper::ResetRegisteredFilesForTesting() { |
193 ResetFilesToShareForTestingPosix(); | 193 ResetFilesToShareForTestingPosix(); |
194 } | 194 } |
195 | 195 |
196 // static | 196 // static |
197 base::File OpenFileToShare(const base::FilePath& path, | 197 base::File OpenFileToShare(const base::FilePath& path, |
198 base::MemoryMappedFile::Region* region) { | 198 base::MemoryMappedFile::Region* region) { |
199 return base::File(base::android::OpenApkAsset(path.value(), region)); | 199 return base::File(base::android::OpenApkAsset(path.value(), region)); |
200 } | 200 } |
201 | 201 |
202 // Called from ChildProcessLauncher.java when the ChildProcess was | 202 // Called from ChildProcessLauncher.java when the ChildProcess was started. |
203 // started. | |
204 // |handle| is the processID of the child process as originated in Java, 0 if | 203 // |handle| is the processID of the child process as originated in Java, 0 if |
205 // the ChildProcess could not be created. | 204 // the ChildProcess could not be created. |
206 void ChildProcessLauncherHelper::OnChildProcessStarted( | 205 void ChildProcessLauncherHelper::OnChildProcessStarted( |
207 JNIEnv*, | 206 JNIEnv*, |
208 const base::android::JavaParamRef<jobject>& obj, | 207 const base::android::JavaParamRef<jobject>& obj, |
209 jint handle) { | 208 jint handle) { |
| 209 DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER); |
210 scoped_refptr<ChildProcessLauncherHelper> ref(this); | 210 scoped_refptr<ChildProcessLauncherHelper> ref(this); |
211 Release(); // Balances with LaunchProcessOnLauncherThread. | 211 Release(); // Balances with LaunchProcessOnLauncherThread. |
212 | 212 |
213 int launch_result = (handle == base::kNullProcessHandle) | 213 int launch_result = (handle == base::kNullProcessHandle) |
214 ? LAUNCH_RESULT_FAILURE | 214 ? LAUNCH_RESULT_FAILURE |
215 : LAUNCH_RESULT_SUCCESS; | 215 : LAUNCH_RESULT_SUCCESS; |
216 | 216 |
217 // TODO(jcivelli): Remove this by defining better what happens on what thread | |
218 // in the corresponding Java code. | |
219 ChildProcessLauncherHelper::Process process; | 217 ChildProcessLauncherHelper::Process process; |
220 process.process = base::Process(handle); | 218 process.process = base::Process(handle); |
221 if (BrowserThread::CurrentlyOn(BrowserThread::PROCESS_LAUNCHER)) { | 219 PostLaunchOnLauncherThread(std::move(process), launch_result); |
222 PostLaunchOnLauncherThread(std::move(process), launch_result, | |
223 false); // post_launch_on_client_thread_called | |
224 return; | |
225 } | |
226 | |
227 bool on_client_thread = BrowserThread::CurrentlyOn( | |
228 static_cast<BrowserThread::ID>(client_thread_id())); | |
229 BrowserThread::PostTask( | |
230 BrowserThread::PROCESS_LAUNCHER, FROM_HERE, | |
231 base::Bind(&ChildProcessLauncherHelper::PostLaunchOnLauncherThread, this, | |
232 base::Passed(std::move(process)), launch_result, | |
233 on_client_thread)); | |
234 if (on_client_thread) { | |
235 ChildProcessLauncherHelper::Process process; | |
236 process.process = base::Process(handle); | |
237 PostLaunchOnClientThread(std::move(process), launch_result); | |
238 } | |
239 } | 220 } |
240 | 221 |
241 // static | 222 // static |
242 size_t ChildProcessLauncherHelper::GetNumberOfRendererSlots() { | 223 size_t ChildProcessLauncherHelper::GetNumberOfRendererSlots() { |
243 return static_cast<size_t>( | 224 return static_cast<size_t>( |
244 Java_ChildProcessLauncherHelper_getNumberOfRendererSlots( | 225 Java_ChildProcessLauncherHelper_getNumberOfRendererSlots( |
245 AttachCurrentThread())); | 226 AttachCurrentThread())); |
246 } | 227 } |
247 | 228 |
248 } // namespace internal | 229 } // namespace internal |
249 | 230 |
250 bool RegisterChildProcessLauncher(JNIEnv* env) { | 231 bool RegisterChildProcessLauncher(JNIEnv* env) { |
251 return internal::RegisterNativesImpl(env); | 232 return internal::RegisterNativesImpl(env); |
252 } | 233 } |
253 | 234 |
254 } // namespace content | 235 } // namespace content |
OLD | NEW |