| OLD | NEW |
| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 IChildProcessCallback mCallback; |
| 62 // PID of the client of this service, set in bindToCaller(). | 62 private boolean mBindToCallerCheck; |
| 63 // PID of the client of this service, set in bindToCaller(), if mBindToCalle
rCheck is true. |
| 63 private int mBoundCallingPid; | 64 private int mBoundCallingPid; |
| 64 | 65 |
| 65 // This is the native "Main" thread for the renderer / utility process. | 66 // This is the native "Main" thread for the renderer / utility process. |
| 66 private Thread mMainThread; | 67 private Thread mMainThread; |
| 67 // Parameters received via IPC, only accessed while holding the mMainThread
monitor. | 68 // Parameters received via IPC, only accessed while holding the mMainThread
monitor. |
| 68 private String[] mCommandLineParams; | 69 private String[] mCommandLineParams; |
| 69 private int mCpuCount; | 70 private int mCpuCount; |
| 70 private long mCpuFeatures; | 71 private long mCpuFeatures; |
| 71 // File descriptors that should be registered natively. | 72 // File descriptors that should be registered natively. |
| 72 private FileDescriptorInfo[] mFdInfos; | 73 private FileDescriptorInfo[] mFdInfos; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 103 mLinkerParams.mTestRunnerClassNameForTesting); | 104 mLinkerParams.mTestRunnerClassNameForTesting); |
| 104 } | 105 } |
| 105 return Linker.getInstance(); | 106 return Linker.getInstance(); |
| 106 } | 107 } |
| 107 | 108 |
| 108 // Binder object used by clients for this service. | 109 // Binder object used by clients for this service. |
| 109 private final IChildProcessService.Stub mBinder = new IChildProcessService.S
tub() { | 110 private final IChildProcessService.Stub mBinder = new IChildProcessService.S
tub() { |
| 110 // NOTE: Implement any IChildProcessService methods here. | 111 // NOTE: Implement any IChildProcessService methods here. |
| 111 @Override | 112 @Override |
| 112 public boolean bindToCaller() { | 113 public boolean bindToCaller() { |
| 114 assert mBindToCallerCheck; |
| 113 synchronized (mBinderLock) { | 115 synchronized (mBinderLock) { |
| 114 int callingPid = Binder.getCallingPid(); | 116 int callingPid = Binder.getCallingPid(); |
| 115 if (mBoundCallingPid == 0) { | 117 if (mBoundCallingPid == 0) { |
| 116 mBoundCallingPid = callingPid; | 118 mBoundCallingPid = callingPid; |
| 117 } else if (mBoundCallingPid != callingPid) { | 119 } else if (mBoundCallingPid != callingPid) { |
| 118 Log.e(TAG, "Service is already bound by pid %d, cannot bind
for pid %d", | 120 Log.e(TAG, "Service is already bound by pid %d, cannot bind
for pid %d", |
| 119 mBoundCallingPid, callingPid); | 121 mBoundCallingPid, callingPid); |
| 120 return false; | 122 return false; |
| 121 } | 123 } |
| 122 } | 124 } |
| 123 return true; | 125 return true; |
| 124 } | 126 } |
| 125 | 127 |
| 126 @Override | 128 @Override |
| 127 public int setupConnection(Bundle args, IChildProcessCallback callback)
{ | 129 public int setupConnection(Bundle args, IChildProcessCallback callback)
{ |
| 128 int callingPid = Binder.getCallingPid(); | 130 int callingPid = Binder.getCallingPid(); |
| 129 synchronized (mBinderLock) { | 131 synchronized (mBinderLock) { |
| 130 if (mBoundCallingPid != callingPid) { | 132 if (mBindToCallerCheck && mBoundCallingPid != callingPid) { |
| 131 if (mBoundCallingPid == 0) { | 133 if (mBoundCallingPid == 0) { |
| 132 Log.e(TAG, "Service has not been bound with bindToCaller
()"); | 134 Log.e(TAG, "Service has not been bound with bindToCaller
()"); |
| 133 } else { | 135 } else { |
| 134 Log.e(TAG, "Client pid %d does not match the bound pid %
d", callingPid, | 136 Log.e(TAG, "Client pid %d does not match the bound pid %
d", callingPid, |
| 135 mBoundCallingPid); | 137 mBoundCallingPid); |
| 136 } | 138 } |
| 137 return -1; | 139 return -1; |
| 138 } | 140 } |
| 139 | |
| 140 mCallback = callback; | |
| 141 getServiceInfo(args); | |
| 142 return Process.myPid(); | |
| 143 } | 141 } |
| 142 mCallback = callback; |
| 143 getServiceInfo(args); |
| 144 return Process.myPid(); |
| 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 |
| 151 @Override | 152 @Override |
| 152 public boolean onTransact(int arg0, Parcel arg1, Parcel arg2, int arg3) | 153 public boolean onTransact(int arg0, Parcel arg1, Parcel arg2, int arg3) |
| 153 throws RemoteException { | 154 throws RemoteException { |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 | 334 |
| 334 private void initializeParams(Intent intent) { | 335 private void initializeParams(Intent intent) { |
| 335 synchronized (mMainThread) { | 336 synchronized (mMainThread) { |
| 336 // mLinkerParams is never used if Linker.isUsed() returns false. | 337 // mLinkerParams is never used if Linker.isUsed() returns false. |
| 337 // See onCreate(). | 338 // See onCreate(). |
| 338 mLinkerParams = (ChromiumLinkerParams) intent.getParcelableExtra( | 339 mLinkerParams = (ChromiumLinkerParams) intent.getParcelableExtra( |
| 339 ChildProcessConstants.EXTRA_LINKER_PARAMS); | 340 ChildProcessConstants.EXTRA_LINKER_PARAMS); |
| 340 mLibraryProcessType = ChildProcessCreationParams.getLibraryProcessTy
pe(intent); | 341 mLibraryProcessType = ChildProcessCreationParams.getLibraryProcessTy
pe(intent); |
| 341 mMainThread.notifyAll(); | 342 mMainThread.notifyAll(); |
| 342 } | 343 } |
| 344 synchronized (mBinderLock) { |
| 345 mBindToCallerCheck = |
| 346 intent.getBooleanExtra(ChildProcessConstants.EXTRA_BIND_TO_C
ALLER, false); |
| 347 } |
| 343 } | 348 } |
| 344 | 349 |
| 345 private void getServiceInfo(Bundle bundle) { | 350 private void getServiceInfo(Bundle bundle) { |
| 346 // Required to unparcel FileDescriptorInfo. | 351 // Required to unparcel FileDescriptorInfo. |
| 347 bundle.setClassLoader(mHostClassLoader); | 352 bundle.setClassLoader(mHostClassLoader); |
| 348 synchronized (mMainThread) { | 353 synchronized (mMainThread) { |
| 349 if (mCommandLineParams == null) { | 354 if (mCommandLineParams == null) { |
| 350 mCommandLineParams = | 355 mCommandLineParams = |
| 351 bundle.getStringArray(ChildProcessConstants.EXTRA_COMMAN
D_LINE); | 356 bundle.getStringArray(ChildProcessConstants.EXTRA_COMMAN
D_LINE); |
| 352 mMainThread.notifyAll(); | 357 mMainThread.notifyAll(); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 private static native void nativeInitChildProcessImpl( | 435 private static native void nativeInitChildProcessImpl( |
| 431 ChildProcessServiceImpl serviceImpl, int cpuCount, long cpuFeatures)
; | 436 ChildProcessServiceImpl serviceImpl, int cpuCount, long cpuFeatures)
; |
| 432 | 437 |
| 433 /** | 438 /** |
| 434 * Force the child process to exit. | 439 * Force the child process to exit. |
| 435 */ | 440 */ |
| 436 private static native void nativeExitChildProcess(); | 441 private static native void nativeExitChildProcess(); |
| 437 | 442 |
| 438 private native void nativeShutdownMainThread(); | 443 private native void nativeShutdownMainThread(); |
| 439 } | 444 } |
| OLD | NEW |