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..74b95c6ca1b7cf9a3f4fe93bb289d1389ff4c073 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 implements all of the functionality for {@link ChildProcessService} which owns an |
| + * 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 = {}; |
| @@ -104,20 +99,28 @@ public class ChildProcessService extends Service { |
| } |
| }; |
| + // The ClassLoader for the host browser context. |
| + private ClassLoader mHostClassLoader; |
|
Maria
2016/06/17 17:09:24
final?
Xi Han
2016/06/17 18:35:20
It is still because |mHostClassLoader| isn't initi
|
| + |
| /* package */ static Context getContext() { |
| return sContext.get(); |
| } |
| - @Override |
| - public void onCreate() { |
| + /** |
| + * Loads Chrome's native libraries and initializes a ChildProcessServiceImapl. |
|
Maria
2016/06/17 17:09:24
nit: Iampl -> Impl
Xi Han
2016/06/17 18:35:20
Sorry.
|
| + * @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) { |
| + mHostClassLoader = 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); |
| - ContextUtils.initApplicationContext(getApplicationContext()); |
| + // Initialize the context for the application that owns this ChildProcessServiceImpl object. |
| + ContextUtils.initApplicationContext(context); |
| mMainThread = new Thread(new Runnable() { |
| @Override |
| @@ -156,7 +159,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 +173,7 @@ public class ChildProcessService extends Service { |
| if (!isLoaded && requestedSharedRelro) { |
| linker.disableSharedRelros(); |
| try { |
| - LibraryLoader.get(mLibraryProcessType).loadNow(getApplicationContext()); |
| + LibraryLoader.get(mLibraryProcessType).loadNow(hostBrowserContext); |
| isLoaded = true; |
| } catch (ProcessInitException e) { |
| Log.e(TAG, "Failed to load native library on retry", e); |
| @@ -194,7 +197,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 +213,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 +240,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 +268,7 @@ public class ChildProcessService extends Service { |
| */ |
| void getServiceInfo(Bundle bundle) { |
| // Required to unparcel FileDescriptorInfo. |
| - bundle.setClassLoader(getClassLoader()); |
| + bundle.setClassLoader(mHostClassLoader); |
| synchronized (mMainThread) { |
| // Allow the command line to be set via bind() intent or setupConnection, but |
| // the FD can only be transferred here. |
| @@ -427,11 +423,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. |