Commit 9348eeca authored by pkotwicz's avatar pkotwicz Committed by Commit bot

Move WebApkSandboxedProcessService to webapk/shell_apk

BUG=None

Review-Url: https://codereview.chromium.org/2107573002
Cr-Commit-Position: refs/heads/master@{#403330}
parent c110f185
...@@ -7,10 +7,6 @@ import("//build/config/android/rules.gni") ...@@ -7,10 +7,6 @@ import("//build/config/android/rules.gni")
android_library("common_java") { android_library("common_java") {
java_files = [ java_files = [
"src/org/chromium/webapk/lib/common/WebApkConstants.java", "src/org/chromium/webapk/lib/common/WebApkConstants.java",
"src/org/chromium/webapk/lib/common/WebApkSandboxedProcessService.java",
"src/org/chromium/webapk/lib/common/WebApkSandboxedProcessService0.java",
"src/org/chromium/webapk/lib/common/WebApkSandboxedProcessService1.java",
"src/org/chromium/webapk/lib/common/WebApkSandboxedProcessService2.java",
"src/org/chromium/webapk/lib/common/WebApkUtils.java", "src/org/chromium/webapk/lib/common/WebApkUtils.java",
] ]
} }
...@@ -51,18 +51,18 @@ ...@@ -51,18 +51,18 @@
<meta-data android:name="org.chromium.content.browser.NUM_SANDBOXED_SERVICES" <meta-data android:name="org.chromium.content.browser.NUM_SANDBOXED_SERVICES"
android:value="3"/> android:value="3"/>
<meta-data android:name="org.chromium.content.browser.SANDBOXED_SERVICES_NAME" <meta-data android:name="org.chromium.content.browser.SANDBOXED_SERVICES_NAME"
android:value="org.chromium.webapk.lib.common.WebApkSandboxedProcessService"/> android:value="org.chromium.webapk.shell_apk.WebApkSandboxedProcessService"/>
<service android:name="org.chromium.webapk.lib.common.WebApkSandboxedProcessService0" <service android:name="org.chromium.webapk.shell_apk.WebApkSandboxedProcessService0"
android:isolatedProcess="true" android:isolatedProcess="true"
android:process=":webapk_sandboxed_process0" android:process=":webapk_sandboxed_process0"
android:exported="true" android:exported="true"
tools:ignore="ExportedService"/> tools:ignore="ExportedService"/>
<service android:name="org.chromium.webapk.lib.common.WebApkSandboxedProcessService1" <service android:name="org.chromium.webapk.shell_apk.WebApkSandboxedProcessService1"
android:isolatedProcess="true" android:isolatedProcess="true"
android:process=":webapk_sandboxed_process1" android:process=":webapk_sandboxed_process1"
android:exported="true" android:exported="true"
tools:ignore="ExportedService"/> tools:ignore="ExportedService"/>
<service android:name="org.chromium.webapk.lib.common.WebApkSandboxedProcessService2" <service android:name="org.chromium.webapk.shell_apk.WebApkSandboxedProcessService2"
android:isolatedProcess="true" android:isolatedProcess="true"
android:process=":webapk_sandboxed_process2" android:process=":webapk_sandboxed_process2"
android:exported="true" android:exported="true"
......
...@@ -72,6 +72,10 @@ android_apk("webapk") { ...@@ -72,6 +72,10 @@ android_apk("webapk") {
apk_name = "WebApk.$webapk_manifest_package_origin" apk_name = "WebApk.$webapk_manifest_package_origin"
java_files = [ java_files = [
"src/org/chromium/webapk/shell_apk/MainActivity.java", "src/org/chromium/webapk/shell_apk/MainActivity.java",
"src/org/chromium/webapk/shell_apk/WebApkSandboxedProcessService.java",
"src/org/chromium/webapk/shell_apk/WebApkSandboxedProcessService0.java",
"src/org/chromium/webapk/shell_apk/WebApkSandboxedProcessService1.java",
"src/org/chromium/webapk/shell_apk/WebApkSandboxedProcessService2.java",
"src/org/chromium/webapk/shell_apk/WebApkServiceFactory.java", "src/org/chromium/webapk/shell_apk/WebApkServiceFactory.java",
] ]
deps = [ deps = [
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
package org.chromium.webapk.lib.common; package org.chromium.webapk.shell_apk;
import android.app.Service; import android.app.Service;
import android.content.Context; import android.content.Context;
...@@ -10,6 +10,8 @@ import android.content.Intent; ...@@ -10,6 +10,8 @@ import android.content.Intent;
import android.os.IBinder; import android.os.IBinder;
import android.util.Log; import android.util.Log;
import org.chromium.webapk.lib.common.WebApkUtils;
import java.lang.reflect.Method; import java.lang.reflect.Method;
/** /**
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
package org.chromium.webapk.lib.common; package org.chromium.webapk.shell_apk;
/** /**
* This is needed to register multiple SandboxedProcess services so that we can have * This is needed to register multiple SandboxedProcess services so that we can have
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
package org.chromium.webapk.lib.common; package org.chromium.webapk.shell_apk;
/** /**
* This is needed to register multiple SandboxedProcess services so that we can have * This is needed to register multiple SandboxedProcess services so that we can have
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
package org.chromium.webapk.lib.common; package org.chromium.webapk.shell_apk;
/** /**
* This is needed to register multiple SandboxedProcess services so that we can have * This is needed to register multiple SandboxedProcess services so that we can have
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
package org.chromium.content.browser; package org.chromium.content.browser;
import android.app.Service;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
...@@ -34,7 +33,6 @@ public class ChildProcessConnectionImpl implements ChildProcessConnection { ...@@ -34,7 +33,6 @@ public class ChildProcessConnectionImpl implements ChildProcessConnection {
private final int mServiceNumber; private final int mServiceNumber;
private final boolean mInSandbox; private final boolean mInSandbox;
private final ChildProcessConnection.DeathCallback mDeathCallback; private final ChildProcessConnection.DeathCallback mDeathCallback;
private final Class<? extends Service> mServiceClass;
private final ComponentName mServiceName; private final ComponentName mServiceName;
// Synchronization: While most internal flow occurs on the UI thread, the public API // Synchronization: While most internal flow occurs on the UI thread, the public API
...@@ -211,7 +209,7 @@ public class ChildProcessConnectionImpl implements ChildProcessConnection { ...@@ -211,7 +209,7 @@ public class ChildProcessConnectionImpl implements ChildProcessConnection {
ChildProcessConnectionImpl(Context context, int number, boolean inSandbox, ChildProcessConnectionImpl(Context context, int number, boolean inSandbox,
ChildProcessConnection.DeathCallback deathCallback, ChildProcessConnection.DeathCallback deathCallback,
Class<? extends Service> serviceClass, String serviceClassName,
ChromiumLinkerParams chromiumLinkerParams, ChromiumLinkerParams chromiumLinkerParams,
boolean alwaysInForeground, boolean alwaysInForeground,
ChildProcessCreationParams creationParams) { ChildProcessCreationParams creationParams) {
...@@ -219,10 +217,9 @@ public class ChildProcessConnectionImpl implements ChildProcessConnection { ...@@ -219,10 +217,9 @@ public class ChildProcessConnectionImpl implements ChildProcessConnection {
mServiceNumber = number; mServiceNumber = number;
mInSandbox = inSandbox; mInSandbox = inSandbox;
mDeathCallback = deathCallback; mDeathCallback = deathCallback;
mServiceClass = serviceClass;
String packageName = String packageName =
creationParams != null ? creationParams.getPackageName() : context.getPackageName(); creationParams != null ? creationParams.getPackageName() : context.getPackageName();
mServiceName = new ComponentName(packageName, mServiceClass.getName() + mServiceNumber); mServiceName = new ComponentName(packageName, serviceClassName + mServiceNumber);
mLinkerParams = chromiumLinkerParams; mLinkerParams = chromiumLinkerParams;
mAlwaysInForeground = alwaysInForeground; mAlwaysInForeground = alwaysInForeground;
mCreationParams = creationParams; mCreationParams = creationParams;
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
package org.chromium.content.browser; package org.chromium.content.browser;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Service; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo;
...@@ -65,20 +65,20 @@ public class ChildProcessLauncher { ...@@ -65,20 +65,20 @@ public class ChildProcessLauncher {
private final ArrayList<Integer> mFreeConnectionIndices; private final ArrayList<Integer> mFreeConnectionIndices;
private final Object mConnectionLock = new Object(); private final Object mConnectionLock = new Object();
private final Class<? extends Service> mChildClass; private final String mChildClassName;
private final boolean mInSandbox; private final boolean mInSandbox;
// Each Allocator keeps a queue for the pending spawn data. Once a connection is free, we // 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. // dequeue the pending spawn data from the same allocator as the connection.
private final PendingSpawnQueue mPendingSpawnQueue = new PendingSpawnQueue(); private final PendingSpawnQueue mPendingSpawnQueue = new PendingSpawnQueue();
public ChildConnectionAllocator(boolean inSandbox, int numChildServices, public ChildConnectionAllocator(boolean inSandbox, int numChildServices,
Class<? extends Service> serviceClass) { String serviceClassName) {
mChildProcessConnections = new ChildProcessConnectionImpl[numChildServices]; mChildProcessConnections = new ChildProcessConnectionImpl[numChildServices];
mFreeConnectionIndices = new ArrayList<Integer>(numChildServices); mFreeConnectionIndices = new ArrayList<Integer>(numChildServices);
for (int i = 0; i < numChildServices; i++) { for (int i = 0; i < numChildServices; i++) {
mFreeConnectionIndices.add(i); mFreeConnectionIndices.add(i);
} }
mChildClass = serviceClass; mChildClassName = serviceClassName;
mInSandbox = inSandbox; mInSandbox = inSandbox;
} }
...@@ -95,7 +95,7 @@ public class ChildProcessLauncher { ...@@ -95,7 +95,7 @@ public class ChildProcessLauncher {
int slot = mFreeConnectionIndices.remove(0); int slot = mFreeConnectionIndices.remove(0);
assert mChildProcessConnections[slot] == null; assert mChildProcessConnections[slot] == null;
mChildProcessConnections[slot] = new ChildProcessConnectionImpl(context, slot, mChildProcessConnections[slot] = new ChildProcessConnectionImpl(context, slot,
mInSandbox, deathCallback, mChildClass, chromiumLinkerParams, mInSandbox, deathCallback, mChildClassName, chromiumLinkerParams,
alwaysInForeground, creationParams); alwaysInForeground, creationParams);
Log.d(TAG, "Allocator allocated a connection, sandbox: %b, slot: %d", mInSandbox, Log.d(TAG, "Allocator allocated a connection, sandbox: %b, slot: %d", mInSandbox,
slot); slot);
...@@ -277,38 +277,42 @@ public class ChildProcessLauncher { ...@@ -277,38 +277,42 @@ public class ChildProcessLauncher {
return numServices; return numServices;
} }
private static Class<? extends Service> getClassOfService(Context context, boolean inSandbox, private static String getClassNameOfService(Context context, boolean inSandbox,
String packageName) { String packageName) {
if (!inSandbox) { if (!inSandbox) {
return PrivilegedProcessService.class; return PrivilegedProcessService.class.getName();
} }
String serviceName = null;
if (CommandLine.getInstance().hasSwitch(SWITCH_SANDBOXED_SERVICES_NAME_FOR_TESTING)) { if (CommandLine.getInstance().hasSwitch(SWITCH_SANDBOXED_SERVICES_NAME_FOR_TESTING)) {
serviceName = CommandLine.getInstance().getSwitchValue( return CommandLine.getInstance().getSwitchValue(
SWITCH_SANDBOXED_SERVICES_NAME_FOR_TESTING); SWITCH_SANDBOXED_SERVICES_NAME_FOR_TESTING);
} else { }
try {
PackageManager packageManager = context.getPackageManager(); String serviceName = null;
ApplicationInfo appInfo = packageManager.getApplicationInfo(packageName, try {
PackageManager.GET_META_DATA); PackageManager packageManager = context.getPackageManager();
if (appInfo.metaData != null) { ApplicationInfo appInfo =
serviceName = appInfo.metaData.getString(SANDBOXED_SERVICES_NAME_KEY); packageManager.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
} if (appInfo.metaData != null) {
} catch (PackageManager.NameNotFoundException e) { serviceName = appInfo.metaData.getString(SANDBOXED_SERVICES_NAME_KEY);
throw new RuntimeException("Could not get application info.");
} }
} catch (PackageManager.NameNotFoundException e) {
throw new RuntimeException("Could not get application info.");
} }
if (serviceName != null) { if (serviceName != null) {
// Check that the service exists.
try { try {
Class<? extends Service> service = PackageManager packageManager = context.getPackageManager();
(Class<? extends Service>) Class.forName(serviceName); // PackageManager#getServiceInfo() throws an exception if the service does not
return service; // exist.
} catch (ClassNotFoundException e) { packageManager.getServiceInfo(new ComponentName(packageName, serviceName + "0"), 0);
return serviceName;
} catch (PackageManager.NameNotFoundException e) {
throw new RuntimeException( throw new RuntimeException(
"Illegal meta data value: the child service class doesn't exist"); "Illegal meta data value: the child service doesn't exist");
} }
} }
return SandboxedProcessService.class; return SandboxedProcessService.class.getName();
} }
private static void initConnectionAllocatorsIfNecessary( private static void initConnectionAllocatorsIfNecessary(
...@@ -327,12 +331,12 @@ public class ChildProcessLauncher { ...@@ -327,12 +331,12 @@ public class ChildProcessLauncher {
sSandboxedChildConnectionAllocatorMap.put(packageName, sSandboxedChildConnectionAllocatorMap.put(packageName,
new ChildConnectionAllocator(true, new ChildConnectionAllocator(true,
getNumberOfServices(context, true, packageName), getNumberOfServices(context, true, packageName),
getClassOfService(context, true, packageName))); getClassNameOfService(context, true, packageName)));
} }
} else if (sPrivilegedChildConnectionAllocator == null) { } else if (sPrivilegedChildConnectionAllocator == null) {
sPrivilegedChildConnectionAllocator = new ChildConnectionAllocator( sPrivilegedChildConnectionAllocator = new ChildConnectionAllocator(false,
false, getNumberOfServices(context, false, packageName), getNumberOfServices(context, false, packageName),
getClassOfService(context, false, packageName)); getClassNameOfService(context, false, packageName));
} }
// TODO(pkotwicz|hanxi): Figure out when old allocators should be removed from // TODO(pkotwicz|hanxi): Figure out when old allocators should be removed from
// {@code sSandboxedChildConnectionAllocatorMap}. // {@code sSandboxedChildConnectionAllocatorMap}.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment