| Index: content/public/android/java/src/org/chromium/content/browser/ChildProcessLauncher.java
|
| diff --git a/content/public/android/java/src/org/chromium/content/browser/ChildProcessLauncher.java b/content/public/android/java/src/org/chromium/content/browser/ChildProcessLauncher.java
|
| index daa8aef6caa8d07814f24bbe61e1f2349597d96e..4230113d16f2375b353d915ced8a23c662a98034 100644
|
| --- a/content/public/android/java/src/org/chromium/content/browser/ChildProcessLauncher.java
|
| +++ b/content/public/android/java/src/org/chromium/content/browser/ChildProcessLauncher.java
|
| @@ -5,6 +5,7 @@
|
| package org.chromium.content.browser;
|
|
|
| import android.annotation.SuppressLint;
|
| +import android.app.Service;
|
| import android.content.Context;
|
| import android.content.Intent;
|
| import android.content.pm.ApplicationInfo;
|
| @@ -27,7 +28,6 @@ import org.chromium.base.VisibleForTesting;
|
| import org.chromium.base.annotations.CalledByNative;
|
| import org.chromium.base.annotations.JNINamespace;
|
| import org.chromium.base.library_loader.Linker;
|
| -import org.chromium.content.app.ChildProcessService;
|
| import org.chromium.content.app.ChromiumLinkerParams;
|
| import org.chromium.content.app.DownloadProcessService;
|
| import org.chromium.content.app.PrivilegedProcessService;
|
| @@ -65,20 +65,25 @@ public class ChildProcessLauncher {
|
| private final ArrayList<Integer> mFreeConnectionIndices;
|
| private final Object mConnectionLock = new Object();
|
|
|
| - private Class<? extends ChildProcessService> mChildClass;
|
| + private Class<? extends Service> mChildClass;
|
| private final boolean mInSandbox;
|
| // Each Allocator keeps a queue for the pending spawn data. Once a connection is free, we
|
| // dequeue the pending spawn data from the same allocator as the connection.
|
| private final PendingSpawnQueue mPendingSpawnQueue = new PendingSpawnQueue();
|
|
|
| - public ChildConnectionAllocator(boolean inSandbox, int numChildServices) {
|
| + public ChildConnectionAllocator(boolean inSandbox, int numChildServices,
|
| + Class<? extends Service> serviceName) {
|
| mChildProcessConnections = new ChildProcessConnectionImpl[numChildServices];
|
| mFreeConnectionIndices = new ArrayList<Integer>(numChildServices);
|
| for (int i = 0; i < numChildServices; i++) {
|
| mFreeConnectionIndices.add(i);
|
| }
|
| - mChildClass =
|
| - inSandbox ? SandboxedProcessService.class : PrivilegedProcessService.class;
|
| + if (serviceName == null) {
|
| + mChildClass = inSandbox ? SandboxedProcessService.class
|
| + : PrivilegedProcessService.class;
|
| + } else {
|
| + mChildClass = serviceName;
|
| + }
|
| mInSandbox = inSandbox;
|
| }
|
|
|
| @@ -273,7 +278,8 @@ public class ChildProcessLauncher {
|
| }
|
|
|
| private static void initConnectionAllocatorsIfNecessary(
|
| - Context context, boolean inSandbox, String packageName) {
|
| + Context context, boolean inSandbox, String packageName,
|
| + Class<? extends Service> serviceName) {
|
| // TODO(mariakhomenko): Uses an Object to lock the access.
|
| synchronized (ChildProcessLauncher.class) {
|
| if (inSandbox) {
|
| @@ -287,11 +293,11 @@ public class ChildProcessLauncher {
|
| packageName);
|
| sSandboxedChildConnectionAllocatorMap.put(packageName,
|
| new ChildConnectionAllocator(true,
|
| - getNumberOfServices(context, true, packageName)));
|
| + getNumberOfServices(context, true, packageName), serviceName));
|
| }
|
| } else if (sPrivilegedChildConnectionAllocator == null) {
|
| sPrivilegedChildConnectionAllocator = new ChildConnectionAllocator(
|
| - false, getNumberOfServices(context, false, packageName));
|
| + false, getNumberOfServices(context, false, packageName), serviceName);
|
| }
|
| // TODO(pkotwicz|hanxi): Figure out when old allocators should be removed from
|
| // {@code sSandboxedChildConnectionAllocatorMap}.
|
| @@ -314,8 +320,8 @@ public class ChildProcessLauncher {
|
| * Get the PendingSpawnQueue of the Allocator. Initialize the Allocator if needed.
|
| */
|
| private static PendingSpawnQueue getPendingSpawnQueue(Context context, String packageName,
|
| - boolean inSandbox) {
|
| - initConnectionAllocatorsIfNecessary(context, inSandbox, packageName);
|
| + boolean inSandbox, Class<? extends Service> serviceName) {
|
| + initConnectionAllocatorsIfNecessary(context, inSandbox, packageName, serviceName);
|
| return getConnectionAllocator(packageName, inSandbox).getPendingSpawnQueue();
|
| }
|
|
|
| @@ -335,10 +341,12 @@ public class ChildProcessLauncher {
|
| };
|
| String packageName = creationParams != null ? creationParams.getPackageName()
|
| : context.getPackageName();
|
| - initConnectionAllocatorsIfNecessary(context, inSandbox, packageName);
|
| - return getConnectionAllocator(packageName, inSandbox)
|
| - .allocate(context, deathCallback, chromiumLinkerParams, alwaysInForeground,
|
| - creationParams);
|
| + Class<? extends Service> serviceName = creationParams != null
|
| + ? creationParams.getServiceName() : null;
|
| + initConnectionAllocatorsIfNecessary(context, inSandbox, packageName, serviceName);
|
| + return getConnectionAllocator(packageName, inSandbox).allocate(
|
| + context, deathCallback, chromiumLinkerParams, alwaysInForeground,
|
| + creationParams);
|
| }
|
|
|
| private static boolean sLinkerInitialized = false;
|
| @@ -730,8 +738,10 @@ public class ChildProcessLauncher {
|
| if (allocatedConnection == null) {
|
| boolean alwaysInForeground = false;
|
| if (callbackType == CALLBACK_FOR_GPU_PROCESS) alwaysInForeground = true;
|
| + Class<? extends Service> serviceName = creationParams != null
|
| + ? creationParams.getServiceName() : null;
|
| PendingSpawnQueue pendingSpawnQueue = getPendingSpawnQueue(
|
| - context, packageName, inSandbox);
|
| + context, packageName, inSandbox, serviceName);
|
| synchronized (pendingSpawnQueue.mPendingSpawnsLock) {
|
| allocatedConnection = allocateBoundConnection(
|
| context, commandLine, inSandbox, alwaysInForeground, creationParams);
|
| @@ -927,8 +937,12 @@ public class ChildProcessLauncher {
|
| @VisibleForTesting
|
| static void enqueuePendingSpawnForTesting(Context context, String[] commandLine,
|
| ChildProcessCreationParams creationParams, boolean inSandbox) {
|
| + String packageName = creationParams != null ? creationParams.getPackageName()
|
| + : context.getPackageName();
|
| + Class<? extends Service> serviceName = creationParams != null
|
| + ? creationParams.getServiceName() : null;
|
| PendingSpawnQueue pendingSpawnQueue = getPendingSpawnQueue(context,
|
| - creationParams.getPackageName(), inSandbox);
|
| + packageName, inSandbox, serviceName);
|
| synchronized (pendingSpawnQueue.mPendingSpawnsLock) {
|
| pendingSpawnQueue.enqueueLocked(new PendingSpawnData(context, commandLine, 1,
|
| new FileDescriptorInfo[0], 0, CALLBACK_FOR_RENDERER_PROCESS, true,
|
| @@ -942,7 +956,7 @@ public class ChildProcessLauncher {
|
| */
|
| @VisibleForTesting
|
| static int allocatedSandboxedConnectionsCountForTesting(Context context, String packageName) {
|
| - initConnectionAllocatorsIfNecessary(context, true, packageName);
|
| + initConnectionAllocatorsIfNecessary(context, true, packageName, null);
|
| return sSandboxedChildConnectionAllocatorMap.get(packageName)
|
| .allocatedConnectionsCountForTesting();
|
| }
|
| @@ -962,7 +976,8 @@ public class ChildProcessLauncher {
|
| @VisibleForTesting
|
| static int pendingSpawnsCountForTesting(Context context, String packageName,
|
| boolean inSandbox) {
|
| - PendingSpawnQueue pendingSpawnQueue = getPendingSpawnQueue(context, packageName, inSandbox);
|
| + PendingSpawnQueue pendingSpawnQueue = getPendingSpawnQueue(context, packageName, inSandbox,
|
| + null);
|
| synchronized (pendingSpawnQueue.mPendingSpawnsLock) {
|
| return pendingSpawnQueue.sizeLocked();
|
| }
|
|
|