| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 package org.chromium.content.app; | 5 package org.chromium.content.app; |
| 6 | 6 |
| 7 import android.app.Service; | 7 import android.app.Service; |
| 8 import android.content.Context; | 8 import android.content.Context; |
| 9 import android.content.Intent; | 9 import android.content.Intent; |
| 10 import android.graphics.SurfaceTexture; | 10 import android.graphics.SurfaceTexture; |
| 11 import android.os.Bundle; | 11 import android.os.Bundle; |
| 12 import android.os.IBinder; | 12 import android.os.IBinder; |
| 13 import android.os.Parcelable; | 13 import android.os.Parcelable; |
| 14 import android.os.Process; | 14 import android.os.Process; |
| 15 import android.os.RemoteException; | 15 import android.os.RemoteException; |
| 16 import android.view.Surface; | 16 import android.view.Surface; |
| 17 | 17 |
| 18 import org.chromium.base.BaseSwitches; | 18 import org.chromium.base.BaseSwitches; |
| 19 import org.chromium.base.CommandLine; | 19 import org.chromium.base.CommandLine; |
| 20 import org.chromium.base.ContextUtils; | 20 import org.chromium.base.ContextUtils; |
| 21 import org.chromium.base.Log; | 21 import org.chromium.base.Log; |
| 22 import org.chromium.base.annotations.CalledByNative; | 22 import org.chromium.base.annotations.CalledByNative; |
| 23 import org.chromium.base.annotations.JNINamespace; | 23 import org.chromium.base.annotations.JNINamespace; |
| 24 import org.chromium.base.annotations.SuppressFBWarnings; | 24 import org.chromium.base.annotations.SuppressFBWarnings; |
| 25 import org.chromium.base.library_loader.LibraryLoader; | 25 import org.chromium.base.library_loader.LibraryLoader; |
| 26 import org.chromium.base.library_loader.LibraryProcessType; | 26 import org.chromium.base.library_loader.LibraryProcessType; |
| 27 import org.chromium.base.library_loader.Linker; | 27 import org.chromium.base.library_loader.Linker; |
| 28 import org.chromium.base.library_loader.ProcessInitException; | 28 import org.chromium.base.library_loader.ProcessInitException; |
| 29 import org.chromium.content.browser.ChildProcessConstants; | 29 import org.chromium.content.browser.ChildProcessConstants; |
| 30 import org.chromium.content.browser.ChildProcessLauncher; | |
| 31 import org.chromium.content.browser.FileDescriptorInfo; | 30 import org.chromium.content.browser.FileDescriptorInfo; |
| 31 import org.chromium.content.common.ContentSwitches; |
| 32 import org.chromium.content.common.IChildProcessCallback; | 32 import org.chromium.content.common.IChildProcessCallback; |
| 33 import org.chromium.content.common.IChildProcessService; | 33 import org.chromium.content.common.IChildProcessService; |
| 34 import org.chromium.content.common.SurfaceWrapper; | 34 import org.chromium.content.common.SurfaceWrapper; |
| 35 | 35 |
| 36 import java.util.concurrent.Semaphore; | 36 import java.util.concurrent.Semaphore; |
| 37 import java.util.concurrent.atomic.AtomicReference; | 37 import java.util.concurrent.atomic.AtomicReference; |
| 38 | 38 |
| 39 /** | 39 /** |
| 40 * This is the base class for child services; the [Non]SandboxedProcessService0,
1.. etc | 40 * This is the base class for child services; the [Non]SandboxedProcessService0,
1.. etc |
| 41 * subclasses provide the concrete service entry points, to enable the browser t
o connect | 41 * subclasses provide the concrete service entry points, to enable the browser t
o connect |
| 42 * to more than one distinct process (i.e. one process per service number, up to
limit of N). | 42 * to more than one distinct process (i.e. one process per service number, up to
limit of N). |
| 43 * The embedding application must declare these service instances in the applica
tion section | 43 * The embedding application must declare these service instances in the applica
tion section |
| 44 * of its AndroidManifest.xml, for example with N entries of the form:- | 44 * of its AndroidManifest.xml, for example with N entries of the form:- |
| 45 * <service android:name="org.chromium.content.app.[Non]SandboxedProcessServ
iceX" | 45 * <service android:name="org.chromium.content.app.[Non]SandboxedProcessServ
iceX" |
| 46 * android:process=":[non]sandboxed_processX" /> | 46 * android:process=":[non]sandboxed_processX" /> |
| 47 * for X in 0...N-1 (where N is {@link ChildProcessLauncher#MAX_REGISTERED_SERVI
CES}) | 47 * for X in 0...N-1 (where N is {@link ChildProcessLauncher#MAX_REGISTERED_SERVI
CES}) |
| 48 */ | 48 */ |
| 49 @JNINamespace("content") | 49 @JNINamespace("content") |
| 50 @SuppressWarnings("SynchronizeOnNonFinalField") | 50 @SuppressWarnings("SynchronizeOnNonFinalField") |
| 51 public class ChildProcessService extends Service { | 51 public class ChildProcessService extends Service { |
| 52 private static final String MAIN_THREAD_NAME = "ChildProcessMain"; | 52 private static final String MAIN_THREAD_NAME = "ChildProcessMain"; |
| 53 private static final String TAG = "ChildProcessService"; | 53 private static final String TAG = "ChildProcessService"; |
| 54 protected static final FileDescriptorInfo[] EMPTY_FILE_DESCRIPTOR_INFO = {}; |
| 54 private IChildProcessCallback mCallback; | 55 private IChildProcessCallback mCallback; |
| 55 | 56 |
| 56 // This is the native "Main" thread for the renderer / utility process. | 57 // This is the native "Main" thread for the renderer / utility process. |
| 57 private Thread mMainThread; | 58 private Thread mMainThread; |
| 58 // Parameters received via IPC, only accessed while holding the mMainThread
monitor. | 59 // Parameters received via IPC, only accessed while holding the mMainThread
monitor. |
| 59 private String[] mCommandLineParams; | 60 private String[] mCommandLineParams; |
| 60 private int mCpuCount; | 61 private int mCpuCount; |
| 61 private long mCpuFeatures; | 62 private long mCpuFeatures; |
| 62 // File descriptors that should be registered natively. | 63 // File descriptors that should be registered natively. |
| 63 private FileDescriptorInfo[] mFdInfos; | 64 private FileDescriptorInfo[] mFdInfos; |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 mCpuFeatures = bundle.getLong(ChildProcessConstants.EXTRA_CPU_FEATUR
ES); | 283 mCpuFeatures = bundle.getLong(ChildProcessConstants.EXTRA_CPU_FEATUR
ES); |
| 283 assert mCpuCount > 0; | 284 assert mCpuCount > 0; |
| 284 Parcelable[] fdInfosAsParcelable = | 285 Parcelable[] fdInfosAsParcelable = |
| 285 bundle.getParcelableArray(ChildProcessConstants.EXTRA_FILES)
; | 286 bundle.getParcelableArray(ChildProcessConstants.EXTRA_FILES)
; |
| 286 if (fdInfosAsParcelable != null) { | 287 if (fdInfosAsParcelable != null) { |
| 287 // For why this arraycopy is necessary: | 288 // For why this arraycopy is necessary: |
| 288 // http://stackoverflow.com/questions/8745893/i-dont-get-why-thi
s-classcastexception-occurs | 289 // http://stackoverflow.com/questions/8745893/i-dont-get-why-thi
s-classcastexception-occurs |
| 289 mFdInfos = new FileDescriptorInfo[fdInfosAsParcelable.length]; | 290 mFdInfos = new FileDescriptorInfo[fdInfosAsParcelable.length]; |
| 290 System.arraycopy(fdInfosAsParcelable, 0, mFdInfos, 0, fdInfosAsP
arcelable.length); | 291 System.arraycopy(fdInfosAsParcelable, 0, mFdInfos, 0, fdInfosAsP
arcelable.length); |
| 291 } else { | 292 } else { |
| 292 // TODO(qinmin): On earlier androird versions, a started service
running in another | 293 String processType = ContentSwitches.getSwitchValue( |
| 293 // process can get killed after Chrome is killed. To work around
this issue, client | 294 mCommandLineParams, ContentSwitches.SWITCH_PROCESS_TYPE)
; |
| 294 // will never bind to the service. As a result, the file descrip
tors needs to be | 295 assert ContentSwitches.SWITCH_DOWNLOAD_PROCESS.equals(processTyp
e); |
| 295 // passed through an intent when starting the service. | 296 mFdInfos = EMPTY_FILE_DESCRIPTOR_INFO; |
| 296 } | 297 } |
| 297 Bundle sharedRelros = bundle.getBundle(Linker.EXTRA_LINKER_SHARED_RE
LROS); | 298 Bundle sharedRelros = bundle.getBundle(Linker.EXTRA_LINKER_SHARED_RE
LROS); |
| 298 if (sharedRelros != null) { | 299 if (sharedRelros != null) { |
| 299 getLinker().useSharedRelros(sharedRelros); | 300 getLinker().useSharedRelros(sharedRelros); |
| 300 sharedRelros = null; | 301 sharedRelros = null; |
| 301 } | 302 } |
| 302 mMainThread.notifyAll(); | 303 mMainThread.notifyAll(); |
| 303 } | 304 } |
| 304 } | 305 } |
| 305 | 306 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 private static native void nativeInitChildProcess( | 430 private static native void nativeInitChildProcess( |
| 430 ChildProcessService service, int cpuCount, long cpuFeatures); | 431 ChildProcessService service, int cpuCount, long cpuFeatures); |
| 431 | 432 |
| 432 /** | 433 /** |
| 433 * Force the child process to exit. | 434 * Force the child process to exit. |
| 434 */ | 435 */ |
| 435 private static native void nativeExitChildProcess(); | 436 private static native void nativeExitChildProcess(); |
| 436 | 437 |
| 437 private native void nativeShutdownMainThread(); | 438 private native void nativeShutdownMainThread(); |
| 438 } | 439 } |
| OLD | NEW |