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

Unified Diff: content/public/android/java/src/org/chromium/content/browser/ChildProcessLauncher.java

Issue 1622743005: Introduce background Download process to android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moving away from ChildProcessLauncher Created 4 years, 11 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/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 71ad6d0861afde9d741aa6760acd8d16de411a65..2acde4f0156830abdceb7f3a9cd4a1c05a1d089e 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
@@ -4,10 +4,14 @@
package org.chromium.content.browser;
+import android.annotation.SuppressLint;
import android.content.Context;
+import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.graphics.SurfaceTexture;
+import android.os.Build;
+import android.os.Bundle;
import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
import android.text.TextUtils;
@@ -15,6 +19,7 @@ import android.util.Pair;
import android.view.Surface;
import org.chromium.base.CommandLine;
+import org.chromium.base.CpuFeatures;
import org.chromium.base.Log;
import org.chromium.base.ThreadUtils;
import org.chromium.base.TraceEvent;
@@ -24,6 +29,7 @@ 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;
import org.chromium.content.app.SandboxedProcessService;
import org.chromium.content.common.IChildProcessCallback;
@@ -32,6 +38,7 @@ import org.chromium.content.common.SurfaceWrapper;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedList;
+import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.concurrent.ConcurrentHashMap;
@@ -47,11 +54,13 @@ public class ChildProcessLauncher {
static final int CALLBACK_FOR_GPU_PROCESS = 1;
static final int CALLBACK_FOR_RENDERER_PROCESS = 2;
static final int CALLBACK_FOR_UTILITY_PROCESS = 3;
+ static final int CALLBACK_FOR_DOWNLOAD_PROCESS = 4;
private static final String SWITCH_PROCESS_TYPE = "type";
private static final String SWITCH_RENDERER_PROCESS = "renderer";
private static final String SWITCH_UTILITY_PROCESS = "utility";
private static final String SWITCH_GPU_PROCESS = "gpu-process";
+ private static final String SWITCH_DOWNLOAD_PROCESS = "download";
/**
* Allows specifying the package name for looking up child services
@@ -110,7 +119,7 @@ public class ChildProcessLauncher {
mFreeConnectionIndices.add(i);
}
mChildClass =
- inSandbox ? SandboxedProcessService.class : PrivilegedProcessService.class;
+ inSandbox ? SandboxedProcessService.class : PrivilegedProcessService.class;
mInSandbox = inSandbox;
}
@@ -437,6 +446,10 @@ public class ChildProcessLauncher {
private static Map<Pair<Integer, Integer>, Surface> sSurfaceTextureSurfaceMap =
new ConcurrentHashMap<Pair<Integer, Integer>, Surface>();
+ // Map from channel id to a list of FileDescriptorInfo for download child process.
+ private static Map<String, List<FileDescriptorInfo>> sDownloadFilesMap =
no sievers 2016/02/02 01:37:38 unused?
qinmin 2016/02/02 20:51:41 Removed.
+ new ConcurrentHashMap<String, List<FileDescriptorInfo>>();
+
// Whether the main application is currently brought to the foreground.
private static boolean sApplicationInForeground = true;
@@ -626,6 +639,9 @@ public class ChildProcessLauncher {
} else if (SWITCH_UTILITY_PROCESS.equals(processType)) {
// We only support sandboxed right now.
callbackType = CALLBACK_FOR_UTILITY_PROCESS;
+ } else if (SWITCH_DOWNLOAD_PROCESS.equals(processType)) {
+ callbackType = CALLBACK_FOR_DOWNLOAD_PROCESS;
+ inSandbox = false;
} else {
assert false;
}
@@ -645,6 +661,12 @@ public class ChildProcessLauncher {
try {
TraceEvent.begin("ChildProcessLauncher.startInternal");
+ if (callbackType == CALLBACK_FOR_DOWNLOAD_PROCESS) {
+ ChromiumLinkerParams chromiumLinkerParams = getLinkerParamsForNewConnection();
+ startDownloadProcess(context, commandLine, chromiumLinkerParams, clientContext);
+ return;
+ }
+
ChildProcessConnection allocatedConnection = null;
synchronized (ChildProcessLauncher.class) {
if (inSandbox) {
@@ -675,6 +697,54 @@ public class ChildProcessLauncher {
}
}
+ /**
+ * Create the common bundle to be passed to child processes.
+ * @param context Application context.
+ * @param commandLine Command line params to be passed to the service.
+ * @param linkerParams Linker params to start the service.
+ */
+ protected static Bundle createsServiceBundle(
+ String[] commandLine, FileDescriptorInfo[] filesToBeMapped, Bundle sharedRelros) {
+ Bundle bundle = new Bundle();
+ bundle.putStringArray(ChildProcessConstants.EXTRA_COMMAND_LINE, commandLine);
+ bundle.putParcelableArray(ChildProcessConstants.EXTRA_FILES, filesToBeMapped);
+ bundle.putInt(ChildProcessConstants.EXTRA_CPU_COUNT, CpuFeatures.getCount());
+ bundle.putLong(ChildProcessConstants.EXTRA_CPU_FEATURES, CpuFeatures.getMask());
+ bundle.putBundle(Linker.EXTRA_LINKER_SHARED_RELROS, sharedRelros);
+ return bundle;
+ }
+
+ /**
+ * Create the background download service. The download service controls its own life
+ * time and may out live chrome.
+ * @param context Application context.
+ * @param commandLine Command line params to be passed to the service.
+ * @param linkerParams Linker params to start the service.
+ * @param clientContext Arbitrary parameter used by the client to distinguish this connection.
+ */
+ @SuppressLint("NewApi")
+ private static void startDownloadProcess(Context context, final String[] commandLine,
+ final ChromiumLinkerParams linkerParams, final long clientContext) {
+ assert Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2;
+ Intent intent = new Intent();
+ intent.setClass(context, DownloadProcessService.class);
+ intent.setPackage(context.getPackageName());
+ // TODO(qinmin): pass in download params from command line.
+ if (commandLine != null) {
+ intent.putExtra(ChildProcessConstants.EXTRA_COMMAND_LINE, commandLine);
+ }
+ Bundle bundle =
+ createsServiceBundle(commandLine, null, Linker.getInstance().getSharedRelros());
+ // Pid doesn't matter for download process.
+ bundle.putBinder(ChildProcessConstants.EXTRA_CHILD_PROCESS_CALLBACK,
+ createCallback(0, CALLBACK_FOR_DOWNLOAD_PROCESS).asBinder());
+ intent.putExtras(bundle);
+ if (linkerParams != null) {
+ linkerParams.addIntentExtras(intent);
+ }
+ context.startService(intent);
+ }
+
@VisibleForTesting
static void triggerConnectionSetup(
final ChildProcessConnection connection,
@@ -806,6 +876,15 @@ public class ChildProcessLauncher {
return ChildProcessLauncher.getSurfaceTextureSurface(surfaceTextureId,
childProcessId);
}
+
+ @Override
+ public void onDownloadStarted(boolean started, int downloadId) {
+ // TODO(qinmin): call native to cancel or proceed with the download.
+ if (callbackType != CALLBACK_FOR_DOWNLOAD_PROCESS) {
+ Log.e(TAG, "Illegal callback for non-download process.");
+ return;
+ }
+ }
};
}

Powered by Google App Engine
This is Rietveld 408576698