Chromium Code Reviews| Index: content/public/android/java/src/org/chromium/content/browser/ChildProcessLauncherHelper.java |
| diff --git a/content/public/android/java/src/org/chromium/content/browser/ChildProcessLauncherHelper.java b/content/public/android/java/src/org/chromium/content/browser/ChildProcessLauncherHelper.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..23d92d74d6c3d5312142ac850f49eee43aecec2c |
| --- /dev/null |
| +++ b/content/public/android/java/src/org/chromium/content/browser/ChildProcessLauncherHelper.java |
| @@ -0,0 +1,95 @@ |
| +// Copyright 2017 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.browser; |
| + |
| +import android.content.Context; |
| +import android.os.ParcelFileDescriptor; |
| + |
| +import org.chromium.base.Log; |
| +import org.chromium.base.annotations.CalledByNative; |
| +import org.chromium.base.annotations.JNINamespace; |
| +import org.chromium.base.process_launcher.FileDescriptorInfo; |
| + |
| +import java.io.IOException; |
| + |
| +/** |
| + * This is the java counterpart to ChildProcessLauncherHelper. It is owned by native side and |
| + * has an explicit destroy method. |
| + * Each public or jni methods should have explicit documentation on what threads they are called. |
| + */ |
| +@JNINamespace("content::internal") |
| +class ChildProcessLauncherHelper { |
| + private static final String TAG = "ChildProcLH"; |
| + |
| + // Note this is not the actual native pointer to ChildProcessLauncherHelper. |
|
Maria
2017/03/27 19:22:51
It might be nice to say what it IS in addition to
|
| + private long mNativePointer; |
| + private int mPid; |
| + |
| + // Called on launcher thread. |
| + @CalledByNative |
| + private static FileDescriptorInfo makeFdInfo( |
| + int id, int fd, boolean autoClose, long offset, long size) { |
| + ParcelFileDescriptor pFd; |
| + if (autoClose) { |
| + // Adopt the FD, it will be closed when we close the ParcelFileDescriptor. |
| + pFd = ParcelFileDescriptor.adoptFd(fd); |
| + } else { |
| + try { |
| + pFd = ParcelFileDescriptor.fromFd(fd); |
| + } catch (IOException e) { |
| + Log.e(TAG, "Invalid FD provided for process connection, aborting connection.", e); |
| + return null; |
| + } |
| + } |
| + return new FileDescriptorInfo(id, pFd, offset, size); |
| + } |
| + |
| + // Called on launcher thread. |
| + @CalledByNative |
| + private static ChildProcessLauncherHelper create(long nativePointer, Context context, |
| + int paramId, final String[] commandLine, int childProcessId, |
| + FileDescriptorInfo[] filesToBeMapped) { |
| + return new ChildProcessLauncherHelper( |
| + nativePointer, context, paramId, commandLine, childProcessId, filesToBeMapped); |
| + } |
| + |
| + private ChildProcessLauncherHelper(long nativePointer, Context context, int paramId, |
| + final String[] commandLine, int childProcessId, FileDescriptorInfo[] filesToBeMapped) { |
| + mNativePointer = nativePointer; |
| + |
| + ChildProcessLauncher.start(context, paramId, commandLine, childProcessId, filesToBeMapped, |
| + new ChildProcessLauncher.LaunchCallback() { |
| + @Override |
| + public void onChildProcessStarted(int pid) { |
| + mPid = pid; |
| + if (mNativePointer != 0) { |
| + nativeOnChildProcessStarted(mNativePointer, pid); |
| + } |
| + mNativePointer = 0; |
| + } |
| + }); |
| + } |
| + |
| + // Called on client (UI or IO) thread. |
| + @CalledByNative |
| + private boolean isOomProtected() { |
| + return ChildProcessLauncher.getBindingManager().isOomProtected(mPid); |
| + } |
| + |
| + // Called on launcher thread. |
| + @CalledByNative |
| + private void setInForeground(int pid, boolean inForeground) { |
| + assert mPid == pid; |
| + ChildProcessLauncher.getBindingManager().setInForeground(mPid, inForeground); |
| + } |
| + |
| + @CalledByNative |
| + private static void stop(int pid) { |
| + ChildProcessLauncher.stop(pid); |
| + } |
| + |
| + // Can be called on a number of threads, including launcher, and binder. |
| + private static native void nativeOnChildProcessStarted(long ptr, int pid); |
| +} |