Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(946)

Side by Side Diff: content/browser/android/child_process_launcher_android.cc

Issue 1307793003: Execute operations of ChildProcessLauncher on launcher thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Resolve Yaron's comments Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/android/child_process_launcher_android.h" 5 #include "content/browser/android/child_process_launcher_android.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_array.h" 8 #include "base/android/jni_array.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 } 81 }
82 82
83 } // anonymous namespace 83 } // anonymous namespace
84 84
85 // Called from ChildProcessLauncher.java when the ChildProcess was 85 // Called from ChildProcessLauncher.java when the ChildProcess was
86 // started. 86 // started.
87 // |client_context| is the pointer to StartChildProcessCallback which was 87 // |client_context| is the pointer to StartChildProcessCallback which was
88 // passed in from StartChildProcess. 88 // passed in from StartChildProcess.
89 // |handle| is the processID of the child process as originated in Java, 0 if 89 // |handle| is the processID of the child process as originated in Java, 0 if
90 // the ChildProcess could not be created. 90 // the ChildProcess could not be created.
91 static void OnChildProcessStarted(JNIEnv*, 91 static void OnChildProcessStarted(JNIEnv*,
Yaron 2015/09/14 22:30:59 This is now always happening on the process_launch
Jaekyun Seok (inactive) 2015/09/14 23:44:11 Done.
92 const JavaParamRef<jclass>&, 92 const JavaParamRef<jclass>&,
93 jlong client_context, 93 jlong client_context,
94 jint handle) { 94 jint handle) {
95 StartChildProcessCallback* callback = 95 StartChildProcessCallback* callback =
96 reinterpret_cast<StartChildProcessCallback*>(client_context); 96 reinterpret_cast<StartChildProcessCallback*>(client_context);
97 if (handle) 97 if (handle)
98 callback->Run(static_cast<base::ProcessHandle>(handle)); 98 callback->Run(static_cast<base::ProcessHandle>(handle));
99 delete callback; 99 delete callback;
100 } 100 }
101 101
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 return gfx::ScopedJavaSurface::AcquireExternalSurface( 223 return gfx::ScopedJavaSurface::AcquireExternalSurface(
224 Java_ChildProcessLauncher_getSurfaceTextureSurface( 224 Java_ChildProcessLauncher_getSurfaceTextureSurface(
225 env, surface_texture_id, client_id).obj()); 225 env, surface_texture_id, client_id).obj());
226 } 226 }
227 227
228 jboolean IsSingleProcess(JNIEnv* env, const JavaParamRef<jclass>& clazz) { 228 jboolean IsSingleProcess(JNIEnv* env, const JavaParamRef<jclass>& clazz) {
229 return base::CommandLine::ForCurrentProcess()->HasSwitch( 229 return base::CommandLine::ForCurrentProcess()->HasSwitch(
230 switches::kSingleProcess); 230 switches::kSingleProcess);
231 } 231 }
232 232
233 static void ExecuteOnLauncherThread(
234 const base::android::JavaRef<jobject>& runnable) {
235 JNIEnv* env = AttachCurrentThread();
236 DCHECK(env);
237 Java_ChildProcessLauncher_executeOnLauncherThread(env, runnable.obj());
238 }
239
240 jboolean RunOnLauncherThread(JNIEnv* env,
241 const JavaParamRef<jclass>& clazz,
242 const JavaParamRef<jobject>& jrunnable,
243 jlong delayInMS) {
244 if (!BrowserThread::IsThreadInitialized(BrowserThread::PROCESS_LAUNCHER))
245 return false;
246
247 if (delayInMS > 0) {
248 ScopedJavaGlobalRef<jobject> scoped_runnable;
249 scoped_runnable.Reset(env, jrunnable.obj());
250 BrowserThread::PostDelayedTask(
251 BrowserThread::PROCESS_LAUNCHER, FROM_HERE,
252 base::Bind(&ExecuteOnLauncherThread, scoped_runnable),
253 base::TimeDelta::FromMilliseconds(delayInMS));
254 } else if (BrowserThread::CurrentlyOn(BrowserThread::PROCESS_LAUNCHER)) {
255 ExecuteOnLauncherThread(jrunnable);
256 } else {
257 ScopedJavaGlobalRef<jobject> scoped_runnable;
258 scoped_runnable.Reset(env, jrunnable.obj());
259 BrowserThread::PostTask(
260 BrowserThread::PROCESS_LAUNCHER, FROM_HERE,
261 base::Bind(&ExecuteOnLauncherThread, scoped_runnable));
262 }
263 return true;
264 }
265
233 bool RegisterChildProcessLauncher(JNIEnv* env) { 266 bool RegisterChildProcessLauncher(JNIEnv* env) {
234 return RegisterNativesImpl(env); 267 return RegisterNativesImpl(env);
235 } 268 }
236 269
237 } // namespace content 270 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698