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 |
| index 9d8845b8cdd94d1298bd3731463b596a6f64ec6b..942f53b1b2a1c47a13c96db02d872ddb809864ba 100644 |
| --- a/content/public/android/java/src/org/chromium/content/browser/ChildProcessLauncherHelper.java |
| +++ b/content/public/android/java/src/org/chromium/content/browser/ChildProcessLauncherHelper.java |
| @@ -25,9 +25,12 @@ import java.io.IOException; |
| class ChildProcessLauncherHelper { |
| private static final String TAG = "ChildProcLH"; |
| + // Represents an invalid process handle; same as base/process/process.h kNullProcessHandle. |
| + private static final int NULL_PROCESS_HANDLE = 0; |
| + |
| // Note native pointer is only guaranteed live until nativeOnChildProcessStarted. |
| private long mNativeChildProcessLauncherHelper; |
| - private int mPid; |
| + private BaseChildProcessConnection mChildProcessConnection; |
| @CalledByNative |
| private static FileDescriptorInfo makeFdInfo( |
| @@ -65,27 +68,44 @@ class ChildProcessLauncherHelper { |
| ChildProcessLauncher.start(context, paramId, commandLine, childProcessId, filesToBeMapped, |
| new ChildProcessLauncher.LaunchCallback() { |
| @Override |
| - public void onChildProcessStarted(int pid) { |
| - mPid = pid; |
| + public void onChildProcessStarted(BaseChildProcessConnection connection) { |
| + mChildProcessConnection = connection; |
| if (mNativeChildProcessLauncherHelper != 0) { |
| - nativeOnChildProcessStarted(mNativeChildProcessLauncherHelper, pid); |
| + nativeOnChildProcessStarted( |
| + mNativeChildProcessLauncherHelper, getPid()); |
| } |
| mNativeChildProcessLauncherHelper = 0; |
| } |
| }); |
| } |
| + private int getPid() { |
| + return mChildProcessConnection == null ? NULL_PROCESS_HANDLE |
| + : mChildProcessConnection.getPid(); |
| + } |
| // Called on client (UI or IO) thread. |
| @CalledByNative |
| private boolean isOomProtected() { |
| - return ChildProcessLauncher.getBindingManager().isOomProtected(mPid); |
| + if (mChildProcessConnection == null) { |
|
boliu
2017/04/20 22:33:34
hmm, this is "kind of" thread safe, only because m
Jay Civelli
2017/04/25 06:02:46
As you mentioned before, reference assignation are
|
| + return false; |
| + } |
| + |
| + if (mChildProcessConnection instanceof ImportantChildProcessConnection) { |
| + // The connection was bound as BIND_IMPORTANT. This should prevent it from being killed |
| + // when the app is on the foreground (that's our best guess, but there is no absolute |
| + // guarantee). |
| + return ChildProcessLauncher.isApplicationInForeground(); |
| + } |
| + |
| + return ((ManagedChildProcessConnection) mChildProcessConnection) |
| + .isOomProtectedOrWasWhenDied(); |
| } |
| @CalledByNative |
| private void setInForeground(int pid, boolean inForeground) { |
| assert LauncherThread.runningOnLauncherThread(); |
| - assert mPid == pid; |
| - ChildProcessLauncher.getBindingManager().setInForeground(mPid, inForeground); |
| + assert getPid() == pid; |
| + ChildProcessLauncher.getBindingManager().setInForeground(pid, inForeground); |
| } |
| @CalledByNative |