Chromium Code Reviews| Index: content/public/android/java/src/org/chromium/content/app/ChildProcessServiceImpl.java |
| diff --git a/content/public/android/java/src/org/chromium/content/app/ChildProcessService.java b/content/public/android/java/src/org/chromium/content/app/ChildProcessServiceImpl.java |
| similarity index 89% |
| copy from content/public/android/java/src/org/chromium/content/app/ChildProcessService.java |
| copy to content/public/android/java/src/org/chromium/content/app/ChildProcessServiceImpl.java |
| index ef97d8384eca21d157ee5b9ac9a1bd4614c64454..2c9c5996a7047c45afd167f68c3e79ebe643374b 100644 |
| --- a/content/public/android/java/src/org/chromium/content/app/ChildProcessService.java |
| +++ b/content/public/android/java/src/org/chromium/content/app/ChildProcessServiceImpl.java |
| @@ -1,10 +1,9 @@ |
| -// Copyright 2012 The Chromium Authors. All rights reserved. |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| package org.chromium.content.app; |
| -import android.app.Service; |
| import android.content.Context; |
| import android.content.Intent; |
| import android.graphics.SurfaceTexture; |
| @@ -27,7 +26,6 @@ import org.chromium.base.library_loader.Linker; |
| import org.chromium.base.library_loader.ProcessInitException; |
| import org.chromium.content.browser.ChildProcessConstants; |
| import org.chromium.content.browser.ChildProcessCreationParams; |
| -import org.chromium.content.browser.ChildProcessLauncher; |
| import org.chromium.content.browser.FileDescriptorInfo; |
| import org.chromium.content.common.ContentSwitches; |
| import org.chromium.content.common.IChildProcessCallback; |
| @@ -38,18 +36,15 @@ import java.util.concurrent.Semaphore; |
| import java.util.concurrent.atomic.AtomicReference; |
| /** |
| - * This is the base class for child services; the [Non]SandboxedProcessService0, 1.. etc |
| - * subclasses provide the concrete service entry points, to enable the browser to connect |
| - * to more than one distinct process (i.e. one process per service number, up to limit of N). |
| - * The embedding application must declare these service instances in the application section |
| - * of its AndroidManifest.xml, for example with N entries of the form:- |
| - * <service android:name="org.chromium.content.app.[Non]SandboxedProcessServiceX" |
| - * android:process=":[non]sandboxed_processX" /> |
| - * for X in 0...N-1 (where N is {@link ChildProcessLauncher#MAX_REGISTERED_SERVICES}) |
| + * This class provides all the implementations for {@link ChildProcessService} which owns an |
|
pkotwicz
2016/06/14 01:19:48
How about: "This class implements all of the funct
Xi Han
2016/06/14 21:55:04
Done.
|
| + * object of {@link ChildProcessServiceImpl}. |
| + * It makes possible that WebAPK's ChildProcessService owns a ChildProcessServiceImpl object |
| + * and uses the same functionalities to create renderer process for WebAPKs when "--enable-webapk" |
| + * flag is turned on. |
| */ |
| @JNINamespace("content") |
| @SuppressWarnings("SynchronizeOnNonFinalField") |
| -public class ChildProcessService extends Service { |
| +public class ChildProcessServiceImpl { |
| private static final String MAIN_THREAD_NAME = "ChildProcessMain"; |
| private static final String TAG = "ChildProcessService"; |
| protected static final FileDescriptorInfo[] EMPTY_FILE_DESCRIPTOR_INFO = {}; |
| @@ -74,21 +69,6 @@ public class ChildProcessService extends Service { |
| private boolean mIsBound = false; |
| private final Semaphore mActivitySemaphore = new Semaphore(1); |
| - |
| - // Return a Linker instance. If testing, the Linker needs special setup. |
| - private Linker getLinker() { |
| - if (Linker.areTestsEnabled()) { |
| - // For testing, set the Linker implementation and the test runner |
| - // class name to match those used by the parent. |
| - assert mLinkerParams != null; |
| - Linker.setupForTesting( |
| - mLinkerParams.mLinkerImplementationForTesting, |
| - mLinkerParams.mTestRunnerClassNameForTesting); |
| - } |
| - return Linker.getInstance(); |
| - } |
| - |
| - // Binder object used by clients for this service. |
| private final IChildProcessService.Stub mBinder = new IChildProcessService.Stub() { |
| // NOTE: Implement any IChildProcessService methods here. |
| @Override |
| @@ -104,20 +84,39 @@ public class ChildProcessService extends Service { |
| } |
| }; |
|
pkotwicz
2016/06/14 01:19:48
Can you please add a comment to |mClassLoader| and
Xi Han
2016/06/14 21:55:03
Done.
|
| + private ClassLoader mClassLoader; |
| + |
| + // Return a Linker instance. If testing, the Linker needs special setup. |
|
pkotwicz
2016/06/14 01:19:48
Nit: Can you move this function so that gerrit doe
Xi Han
2016/06/14 21:55:03
Done.
|
| + private Linker getLinker() { |
| + if (Linker.areTestsEnabled()) { |
| + // For testing, set the Linker implementation and the test runner |
| + // class name to match those used by the parent. |
| + assert mLinkerParams != null; |
| + Linker.setupForTesting( |
| + mLinkerParams.mLinkerImplementationForTesting, |
| + mLinkerParams.mTestRunnerClassNameForTesting); |
| + } |
| + return Linker.getInstance(); |
| + } |
| + |
| /* package */ static Context getContext() { |
|
pkotwicz
2016/06/14 01:19:48
This function seems unused. I posted a CL to remov
Xi Han
2016/06/14 21:55:04
Thanks for creating the clean up CL!
pkotwicz
2016/06/15 14:13:50
It looks like dtrainor@ is at Blimpcon. We'll prob
|
| return sContext.get(); |
| } |
| - @Override |
| - public void onCreate() { |
| + /** |
| + * Loads Chrome's native libraries and initializes a ChildProcessServiceImapl. |
| + * @param context The application context. |
| + * @param hostBrowserContext The context of the Host Browser (i.e. Chrome). |
| + */ |
| + public void create(final Context context, final Context hostBrowserContext) { |
| + mClassLoader = hostBrowserContext.getClassLoader(); |
| Log.i(TAG, "Creating new ChildProcessService pid=%d", Process.myPid()); |
| if (sContext.get() != null) { |
| throw new RuntimeException("Illegal child process reuse."); |
| } |
| - sContext.set(this); |
| - super.onCreate(); |
| + sContext.set(context); |
|
pkotwicz
2016/06/14 01:19:48
Can you please add a comment about which context t
Xi Han
2016/06/14 21:55:03
Done.
|
| - ContextUtils.initApplicationContext(getApplicationContext()); |
| + ContextUtils.initApplicationContext(context); |
| mMainThread = new Thread(new Runnable() { |
| @Override |
| @@ -156,7 +155,7 @@ public class ChildProcessService extends Service { |
| boolean loadAtFixedAddressFailed = false; |
| try { |
| - LibraryLoader.get(mLibraryProcessType).loadNow(getApplicationContext()); |
| + LibraryLoader.get(mLibraryProcessType).loadNow(hostBrowserContext); |
| isLoaded = true; |
| } catch (ProcessInitException e) { |
| if (requestedSharedRelro) { |
| @@ -170,7 +169,7 @@ public class ChildProcessService extends Service { |
| if (!isLoaded && requestedSharedRelro) { |
| linker.disableSharedRelros(); |
| try { |
| - LibraryLoader.get(mLibraryProcessType).loadNow(getApplicationContext()); |
| + LibraryLoader.get(mLibraryProcessType).loadNow(context); |
|
pkotwicz
2016/06/14 01:19:48
Should this be |hostBrowserContext|? (I am unsure
Xi Han
2016/06/14 21:55:04
It looks like we should use |hostBrowserContext| t
|
| isLoaded = true; |
| } catch (ProcessInitException e) { |
| Log.e(TAG, "Failed to load native library on retry", e); |
| @@ -194,7 +193,8 @@ public class ChildProcessService extends Service { |
| nativeRegisterGlobalFileDescriptor( |
| fdInfo.mId, fdInfo.mFd.detachFd(), fdInfo.mOffset, fdInfo.mSize); |
| } |
| - nativeInitChildProcess(ChildProcessService.this, mCpuCount, mCpuFeatures); |
| + nativeInitChildProcessImpl(ChildProcessServiceImpl.this, mCpuCount, |
| + mCpuFeatures); |
| if (mActivitySemaphore.tryAcquire()) { |
| ContentMain.start(); |
| nativeExitChildProcess(); |
| @@ -209,11 +209,9 @@ public class ChildProcessService extends Service { |
| mMainThread.start(); |
| } |
| - @Override |
| @SuppressFBWarnings("DM_EXIT") |
| - public void onDestroy() { |
| + public void destroy() { |
| Log.i(TAG, "Destroying ChildProcessService pid=%d", Process.myPid()); |
| - super.onDestroy(); |
| if (mActivitySemaphore.tryAcquire()) { |
| // TODO(crbug.com/457406): This is a bit hacky, but there is no known better solution |
| // as this service will get reused (at least if not sandboxed). |
| @@ -238,13 +236,7 @@ public class ChildProcessService extends Service { |
| nativeShutdownMainThread(); |
| } |
| - @Override |
| - public IBinder onBind(Intent intent) { |
| - // We call stopSelf() to request that this service be stopped as soon as the client |
| - // unbinds. Otherwise the system may keep it around and available for a reconnect. The |
| - // child processes do not currently support reconnect; they must be initialized from |
| - // scratch every time. |
| - stopSelf(); |
| + public IBinder bind(Intent intent) { |
| initializeParams(intent); |
| return mBinder; |
| } |
| @@ -272,7 +264,7 @@ public class ChildProcessService extends Service { |
| */ |
| void getServiceInfo(Bundle bundle) { |
| // Required to unparcel FileDescriptorInfo. |
| - bundle.setClassLoader(getClassLoader()); |
| + bundle.setClassLoader(mClassLoader); |
| synchronized (mMainThread) { |
| // Allow the command line to be set via bind() intent or setupConnection, but |
| // the FD can only be transferred here. |
| @@ -427,11 +419,11 @@ public class ChildProcessService extends Service { |
| * The main entry point for a child process. This should be called from a new thread since |
| * it will not return until the child process exits. See child_process_service.{h,cc} |
| * |
| - * @param service The current ChildProcessService object. |
| + * @param serviceImpl The current ChildProcessServiceImpl object. |
| * renderer. |
| */ |
| - private static native void nativeInitChildProcess( |
| - ChildProcessService service, int cpuCount, long cpuFeatures); |
| + private static native void nativeInitChildProcessImpl( |
| + ChildProcessServiceImpl serviceImpl, int cpuCount, long cpuFeatures); |
| /** |
| * Force the child process to exit. |