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

Side by Side Diff: content/public/android/java/src/org/chromium/content/app/ChildProcessServiceImpl.java

Issue 2760093002: Making callbacks in Android ChildProcessLauncher generic. (Closed)
Patch Set: Synced Created 3 years, 9 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 package org.chromium.content.app; 5 package org.chromium.content.app;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.content.Intent; 8 import android.content.Intent;
9 import android.graphics.SurfaceTexture; 9 import android.graphics.SurfaceTexture;
10 import android.os.Binder; 10 import android.os.Binder;
(...skipping 16 matching lines...) Expand all
27 import org.chromium.base.annotations.MainDex; 27 import org.chromium.base.annotations.MainDex;
28 import org.chromium.base.annotations.SuppressFBWarnings; 28 import org.chromium.base.annotations.SuppressFBWarnings;
29 import org.chromium.base.annotations.UsedByReflection; 29 import org.chromium.base.annotations.UsedByReflection;
30 import org.chromium.base.library_loader.LibraryLoader; 30 import org.chromium.base.library_loader.LibraryLoader;
31 import org.chromium.base.library_loader.Linker; 31 import org.chromium.base.library_loader.Linker;
32 import org.chromium.base.library_loader.ProcessInitException; 32 import org.chromium.base.library_loader.ProcessInitException;
33 import org.chromium.base.process_launcher.ChildProcessCreationParams; 33 import org.chromium.base.process_launcher.ChildProcessCreationParams;
34 import org.chromium.base.process_launcher.FileDescriptorInfo; 34 import org.chromium.base.process_launcher.FileDescriptorInfo;
35 import org.chromium.content.browser.ChildProcessConstants; 35 import org.chromium.content.browser.ChildProcessConstants;
36 import org.chromium.content.common.ContentSwitches; 36 import org.chromium.content.common.ContentSwitches;
37 import org.chromium.content.common.IChildProcessCallback;
38 import org.chromium.content.common.IChildProcessService; 37 import org.chromium.content.common.IChildProcessService;
38 import org.chromium.content.common.IGpuProcessCallback;
39 import org.chromium.content.common.SurfaceWrapper; 39 import org.chromium.content.common.SurfaceWrapper;
40 40
41 import java.util.concurrent.Semaphore; 41 import java.util.concurrent.Semaphore;
42 import java.util.concurrent.atomic.AtomicReference; 42 import java.util.concurrent.atomic.AtomicReference;
43 43
44 /** 44 /**
45 * This class implements all of the functionality for {@link ChildProcessService } which owns an 45 * This class implements all of the functionality for {@link ChildProcessService } which owns an
46 * object of {@link ChildProcessServiceImpl}. 46 * object of {@link ChildProcessServiceImpl}.
47 * It makes possible that WebAPK's ChildProcessService owns a ChildProcessServic eImpl object 47 * It makes possible that WebAPK's ChildProcessService owns a ChildProcessServic eImpl object
48 * and uses the same functionalities to create renderer process for WebAPKs when 48 * and uses the same functionalities to create renderer process for WebAPKs when
49 * "--enable-improved-a2hs" flag is turned on. 49 * "--enable-improved-a2hs" flag is turned on.
50 */ 50 */
51 @JNINamespace("content") 51 @JNINamespace("content")
52 @SuppressWarnings("SynchronizeOnNonFinalField") 52 @SuppressWarnings("SynchronizeOnNonFinalField")
53 @MainDex 53 @MainDex
54 @UsedByReflection("WebApkSandboxedProcessService") 54 @UsedByReflection("WebApkSandboxedProcessService")
55 public class ChildProcessServiceImpl { 55 public class ChildProcessServiceImpl {
56 private static final String MAIN_THREAD_NAME = "ChildProcessMain"; 56 private static final String MAIN_THREAD_NAME = "ChildProcessMain";
57 private static final String TAG = "ChildProcessService"; 57 private static final String TAG = "ChildProcessService";
58 58
59 // Lock that protects the following members. 59 // Lock that protects the following members.
60 private final Object mBinderLock = new Object(); 60 private final Object mBinderLock = new Object();
61 private IChildProcessCallback mCallback; 61 private IGpuProcessCallback mGpuCallback;
62 // PID of the client of this service, set in bindToCaller(). 62 // PID of the client of this service, set in bindToCaller().
63 private int mBoundCallingPid; 63 private int mBoundCallingPid;
64 64
65 // This is the native "Main" thread for the renderer / utility process. 65 // This is the native "Main" thread for the renderer / utility process.
66 private Thread mMainThread; 66 private Thread mMainThread;
67 // Parameters received via IPC, only accessed while holding the mMainThread monitor. 67 // Parameters received via IPC, only accessed while holding the mMainThread monitor.
68 private String[] mCommandLineParams; 68 private String[] mCommandLineParams;
69 private int mCpuCount; 69 private int mCpuCount;
70 private long mCpuFeatures; 70 private long mCpuFeatures;
71 // File descriptors that should be registered natively. 71 // File descriptors that should be registered natively.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 } else if (mBoundCallingPid != callingPid) { 117 } else if (mBoundCallingPid != callingPid) {
118 Log.e(TAG, "Service is already bound by pid %d, cannot bind for pid %d", 118 Log.e(TAG, "Service is already bound by pid %d, cannot bind for pid %d",
119 mBoundCallingPid, callingPid); 119 mBoundCallingPid, callingPid);
120 return false; 120 return false;
121 } 121 }
122 } 122 }
123 return true; 123 return true;
124 } 124 }
125 125
126 @Override 126 @Override
127 public int setupConnection(Bundle args, IChildProcessCallback callback) { 127 public int setupConnection(Bundle args, IBinder callback) {
128 int callingPid = Binder.getCallingPid(); 128 int callingPid = Binder.getCallingPid();
129 synchronized (mBinderLock) { 129 synchronized (mBinderLock) {
130 if (mBoundCallingPid != callingPid) { 130 if (mBoundCallingPid != callingPid) {
131 if (mBoundCallingPid == 0) { 131 if (mBoundCallingPid == 0) {
132 Log.e(TAG, "Service has not been bound with bindToCaller ()"); 132 Log.e(TAG, "Service has not been bound with bindToCaller ()");
133 } else { 133 } else {
134 Log.e(TAG, "Client pid %d does not match the bound pid % d", callingPid, 134 Log.e(TAG, "Client pid %d does not match the bound pid % d", callingPid,
135 mBoundCallingPid); 135 mBoundCallingPid);
136 } 136 }
137 return -1; 137 return -1;
138 } 138 }
139 139
140 mCallback = callback; 140 mGpuCallback =
141 callback != null ? IGpuProcessCallback.Stub.asInterface( callback) : null;
141 getServiceInfo(args); 142 getServiceInfo(args);
142 return Process.myPid(); 143 return Process.myPid();
143 } 144 }
144 } 145 }
145 146
146 @Override 147 @Override
147 public void crashIntentionallyForTesting() { 148 public void crashIntentionallyForTesting() {
148 Process.killProcess(Process.myPid()); 149 Process.killProcess(Process.myPid());
149 } 150 }
150 151
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 sharedRelros = null; 371 sharedRelros = null;
371 } 372 }
372 mMainThread.notifyAll(); 373 mMainThread.notifyAll();
373 } 374 }
374 } 375 }
375 376
376 @SuppressWarnings("unused") 377 @SuppressWarnings("unused")
377 @CalledByNative 378 @CalledByNative
378 private void forwardSurfaceTextureForSurfaceRequest( 379 private void forwardSurfaceTextureForSurfaceRequest(
379 UnguessableToken requestToken, SurfaceTexture surfaceTexture) { 380 UnguessableToken requestToken, SurfaceTexture surfaceTexture) {
380 if (mCallback == null) { 381 if (mGpuCallback == null) {
381 Log.e(TAG, "No callback interface has been provided."); 382 Log.e(TAG, "No callback interface has been provided.");
382 return; 383 return;
383 } 384 }
384 385
385 Surface surface = new Surface(surfaceTexture); 386 Surface surface = new Surface(surfaceTexture);
386 387
387 try { 388 try {
388 mCallback.forwardSurfaceForSurfaceRequest(requestToken, surface); 389 mGpuCallback.forwardSurfaceForSurfaceRequest(requestToken, surface);
389 } catch (RemoteException e) { 390 } catch (RemoteException e) {
390 Log.e(TAG, "Unable to call forwardSurfaceForSurfaceRequest: %s", e); 391 Log.e(TAG, "Unable to call forwardSurfaceForSurfaceRequest: %s", e);
391 return; 392 return;
392 } finally { 393 } finally {
393 surface.release(); 394 surface.release();
394 } 395 }
395 } 396 }
396 397
397 @SuppressWarnings("unused") 398 @SuppressWarnings("unused")
398 @CalledByNative 399 @CalledByNative
399 private Surface getViewSurface(int surfaceId) { 400 private Surface getViewSurface(int surfaceId) {
400 if (mCallback == null) { 401 if (mGpuCallback == null) {
401 Log.e(TAG, "No callback interface has been provided."); 402 Log.e(TAG, "No callback interface has been provided.");
402 return null; 403 return null;
403 } 404 }
404 405
405 try { 406 try {
406 SurfaceWrapper wrapper = mCallback.getViewSurface(surfaceId); 407 SurfaceWrapper wrapper = mGpuCallback.getViewSurface(surfaceId);
407 return wrapper != null ? wrapper.getSurface() : null; 408 return wrapper != null ? wrapper.getSurface() : null;
408 } catch (RemoteException e) { 409 } catch (RemoteException e) {
409 Log.e(TAG, "Unable to call getViewSurface: %s", e); 410 Log.e(TAG, "Unable to call getViewSurface: %s", e);
410 return null; 411 return null;
411 } 412 }
412 } 413 }
413 414
414 /** 415 /**
415 * Helper for registering FileDescriptorInfo objects with GlobalFileDescript ors or 416 * Helper for registering FileDescriptorInfo objects with GlobalFileDescript ors or
416 * FileDescriptorStore. 417 * FileDescriptorStore.
(...skipping 13 matching lines...) Expand all
430 private static native void nativeInitChildProcessImpl( 431 private static native void nativeInitChildProcessImpl(
431 ChildProcessServiceImpl serviceImpl, int cpuCount, long cpuFeatures) ; 432 ChildProcessServiceImpl serviceImpl, int cpuCount, long cpuFeatures) ;
432 433
433 /** 434 /**
434 * Force the child process to exit. 435 * Force the child process to exit.
435 */ 436 */
436 private static native void nativeExitChildProcess(); 437 private static native void nativeExitChildProcess();
437 438
438 private native void nativeShutdownMainThread(); 439 private native void nativeShutdownMainThread();
439 } 440 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698