Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package org.chromium.content.browser; | |
| 6 | |
| 7 import android.content.Context; | |
| 8 import android.os.ParcelFileDescriptor; | |
| 9 | |
| 10 import org.chromium.base.Log; | |
| 11 import org.chromium.base.annotations.CalledByNative; | |
| 12 import org.chromium.base.annotations.JNINamespace; | |
| 13 import org.chromium.base.process_launcher.FileDescriptorInfo; | |
| 14 | |
| 15 import java.io.IOException; | |
| 16 | |
| 17 /** | |
| 18 * This is the java counterpart to ChildProcessLauncherHelper. It is owned by na tive side and | |
| 19 * has an explicit destroy method. | |
| 20 * Each public or jni methods should have explicit documentation on what threads they are called. | |
| 21 */ | |
| 22 @JNINamespace("content::internal") | |
| 23 class ChildProcessLauncherHelper { | |
| 24 private static final String TAG = "ChildProcLH"; | |
| 25 | |
| 26 // 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
| |
| 27 private long mNativePointer; | |
| 28 private int mPid; | |
| 29 | |
| 30 // Called on launcher thread. | |
| 31 @CalledByNative | |
| 32 private static FileDescriptorInfo makeFdInfo( | |
| 33 int id, int fd, boolean autoClose, long offset, long size) { | |
| 34 ParcelFileDescriptor pFd; | |
| 35 if (autoClose) { | |
| 36 // Adopt the FD, it will be closed when we close the ParcelFileDescr iptor. | |
| 37 pFd = ParcelFileDescriptor.adoptFd(fd); | |
| 38 } else { | |
| 39 try { | |
| 40 pFd = ParcelFileDescriptor.fromFd(fd); | |
| 41 } catch (IOException e) { | |
| 42 Log.e(TAG, "Invalid FD provided for process connection, aborting connection.", e); | |
| 43 return null; | |
| 44 } | |
| 45 } | |
| 46 return new FileDescriptorInfo(id, pFd, offset, size); | |
| 47 } | |
| 48 | |
| 49 // Called on launcher thread. | |
| 50 @CalledByNative | |
| 51 private static ChildProcessLauncherHelper create(long nativePointer, Context context, | |
| 52 int paramId, final String[] commandLine, int childProcessId, | |
| 53 FileDescriptorInfo[] filesToBeMapped) { | |
| 54 return new ChildProcessLauncherHelper( | |
| 55 nativePointer, context, paramId, commandLine, childProcessId, fi lesToBeMapped); | |
| 56 } | |
| 57 | |
| 58 private ChildProcessLauncherHelper(long nativePointer, Context context, int paramId, | |
| 59 final String[] commandLine, int childProcessId, FileDescriptorInfo[] filesToBeMapped) { | |
| 60 mNativePointer = nativePointer; | |
| 61 | |
| 62 ChildProcessLauncher.start(context, paramId, commandLine, childProcessId , filesToBeMapped, | |
| 63 new ChildProcessLauncher.LaunchCallback() { | |
| 64 @Override | |
| 65 public void onChildProcessStarted(int pid) { | |
| 66 mPid = pid; | |
| 67 if (mNativePointer != 0) { | |
| 68 nativeOnChildProcessStarted(mNativePointer, pid); | |
| 69 } | |
| 70 mNativePointer = 0; | |
| 71 } | |
| 72 }); | |
| 73 } | |
| 74 | |
| 75 // Called on client (UI or IO) thread. | |
| 76 @CalledByNative | |
| 77 private boolean isOomProtected() { | |
| 78 return ChildProcessLauncher.getBindingManager().isOomProtected(mPid); | |
| 79 } | |
| 80 | |
| 81 // Called on launcher thread. | |
| 82 @CalledByNative | |
| 83 private void setInForeground(int pid, boolean inForeground) { | |
| 84 assert mPid == pid; | |
| 85 ChildProcessLauncher.getBindingManager().setInForeground(mPid, inForegro und); | |
| 86 } | |
| 87 | |
| 88 @CalledByNative | |
| 89 private static void stop(int pid) { | |
| 90 ChildProcessLauncher.stop(pid); | |
| 91 } | |
| 92 | |
| 93 // Can be called on a number of threads, including launcher, and binder. | |
| 94 private static native void nativeOnChildProcessStarted(long ptr, int pid); | |
| 95 } | |
| OLD | NEW |