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

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

Issue 2049843004: Upstream: Renderers are running in WebAPKs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Always check command line flags in getNum(Class)ofService(). Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
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 87%
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 ee6dba468e9f21ee694edda873268829e2d91f6e..a022eb45f1b372ed238f6958b4dd5d2da14781e1 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,16 +99,28 @@ public class ChildProcessService extends Service {
}
};
- @Override
- public void onCreate() {
+ // The ClassLoader for the host browser context.
+ private ClassLoader mHostClassLoader;
+
+ /* package */ static Context getContext() {
+ return sContext.get();
+ }
+
+ /**
+ * Loads Chrome's native libraries and initializes a ChildProcessServiceImpl.
+ * @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
@@ -152,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) {
@@ -166,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);
@@ -190,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();
@@ -205,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).
@@ -234,22 +240,12 @@ 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;
}
- /**
- * Helper method to initialize the params from intent.
- * @param intent Intent to launch the service.
- */
- protected void initializeParams(Intent intent) {
+ void initializeParams(Intent intent) {
synchronized (mMainThread) {
mCommandLineParams =
intent.getStringArrayExtra(ChildProcessConstants.EXTRA_COMMAND_LINE);
@@ -262,13 +258,9 @@ public class ChildProcessService extends Service {
}
}
- /**
- * Helper method to get the information about the service from a given bundle.
- * @param bundle Bundle that contains the information to start the 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.
@@ -423,11 +415,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.

Powered by Google App Engine
This is Rietveld 408576698