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

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: 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 88%
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..72df27b8d10cb376c96cd318c1dc5f947df4ef48 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
+ * 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,6 +69,8 @@ public class ChildProcessService extends Service {
private boolean mIsBound = false;
private final Semaphore mActivitySemaphore = new Semaphore(1);
+ private final IChildProcessService.Stub mBinder;
+ private ClassLoader mClassLoader;
// Return a Linker instance. If testing, the Linker needs special setup.
private Linker getLinker() {
@@ -88,36 +85,40 @@ public class ChildProcessService extends Service {
return Linker.getInstance();
}
- // Binder object used by clients for this service.
pkotwicz 2016/06/10 21:29:48 Why this change? I tried reverting this change and
Xi Han 2016/06/13 20:04:11 Good catch. I made this changes before introducing
- private final IChildProcessService.Stub mBinder = new IChildProcessService.Stub() {
- // NOTE: Implement any IChildProcessService methods here.
- @Override
- public int setupConnection(Bundle args, IChildProcessCallback callback) {
- mCallback = callback;
- getServiceInfo(args);
- return Process.myPid();
- }
-
- @Override
- public void crashIntentionallyForTesting() {
- Process.killProcess(Process.myPid());
- }
- };
-
/* package */ static Context getContext() {
return sContext.get();
}
- @Override
- public void onCreate() {
+ public ChildProcessServiceImpl() {
+ super();
+ mBinder = new IChildProcessService.Stub() {
+ // NOTE: Implement any IChildProcessService methods here.
+ @Override
+ public int setupConnection(Bundle args, IChildProcessCallback callback) {
+ mCallback = callback;
+ getServiceInfo(args);
+ return Process.myPid();
+ }
+
+ @Override
+ public void crashIntentionallyForTesting() {
+ Process.killProcess(Process.myPid());
+ }
+ };
+ }
+
pkotwicz 2016/06/10 21:29:48 📚 Please document this method.
Xi Han 2016/06/13 20:04:11 Done.
+ public void create(final Context context, final Context hostBrowserContext,
+ ClassLoader classLoader) {
+ //Debug.waitForDebugger();
pkotwicz 2016/06/10 21:29:47 😁
Xi Han 2016/06/13 20:04:11 Missed this, removed.
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());
+ ContextUtils.initApplicationContext(context);
+ mClassLoader = classLoader;
pkotwicz 2016/06/10 21:29:48 Nit: initialize |mClassLoader| at the top of the m
Xi Han 2016/06/13 20:04:11 Done.
+ final ChildProcessServiceImpl instance = this;
pkotwicz 2016/06/10 21:29:47 Remove line 121. You can use ChildProcessServiceIm
Xi Han 2016/06/13 20:04:11 Good to know, thanks!
mMainThread = new Thread(new Runnable() {
@Override
@@ -156,7 +157,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 +171,7 @@ public class ChildProcessService extends Service {
if (!isLoaded && requestedSharedRelro) {
linker.disableSharedRelros();
try {
- LibraryLoader.get(mLibraryProcessType).loadNow(getApplicationContext());
+ LibraryLoader.get(mLibraryProcessType).loadNow(context);
isLoaded = true;
} catch (ProcessInitException e) {
Log.e(TAG, "Failed to load native library on retry", e);
@@ -194,7 +195,7 @@ public class ChildProcessService extends Service {
nativeRegisterGlobalFileDescriptor(
fdInfo.mId, fdInfo.mFd.detachFd(), fdInfo.mOffset, fdInfo.mSize);
}
- nativeInitChildProcess(ChildProcessService.this, mCpuCount, mCpuFeatures);
+ nativeInitChildProcessImpl(instance, mCpuCount, mCpuFeatures);
if (mActivitySemaphore.tryAcquire()) {
ContentMain.start();
nativeExitChildProcess();
@@ -207,13 +208,12 @@ public class ChildProcessService extends Service {
}
}, MAIN_THREAD_NAME);
mMainThread.start();
+ Log.d(TAG, "mMainThread is started: %s", mMainThread.getName());
pkotwicz 2016/06/10 21:29:47 Log.i() to match the remainder of the file?
Xi Han 2016/06/13 20:04:11 Sorry, it was debugging log, removed.
}
- @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 +238,11 @@ public class ChildProcessService extends Service {
nativeShutdownMainThread();
}
- @Override
- public IBinder onBind(Intent intent) {
+ public IBinder bind(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.
pkotwicz 2016/06/10 21:29:47 Nit: Remove the comment w.r.t to stopSelf()
Xi Han 2016/06/13 20:04:11 Done.
- stopSelf();
initializeParams(intent);
return mBinder;
}
@@ -272,7 +270,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 +425,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