Chromium Code Reviews| Index: content/public/android/java/src/org/chromium/content/browser/ChildProcessConnectionImpl.java |
| diff --git a/content/public/android/java/src/org/chromium/content/browser/ChildProcessConnectionImpl.java b/content/public/android/java/src/org/chromium/content/browser/ChildProcessConnectionImpl.java |
| index 2ad7b8aeb369b0d06f63816d03cd423df204ecc1..5e378cc9de51e568a6e34ea955c152a4b17aa07f 100644 |
| --- a/content/public/android/java/src/org/chromium/content/browser/ChildProcessConnectionImpl.java |
| +++ b/content/public/android/java/src/org/chromium/content/browser/ChildProcessConnectionImpl.java |
| @@ -21,6 +21,7 @@ import org.chromium.base.TraceEvent; |
| import org.chromium.base.VisibleForTesting; |
| import org.chromium.base.process_launcher.ChildProcessCreationParams; |
| import org.chromium.base.process_launcher.FileDescriptorInfo; |
| +import org.chromium.base.process_launcher.ICallbackInt; |
| import org.chromium.base.process_launcher.IChildProcessService; |
| import java.io.IOException; |
| @@ -389,6 +390,27 @@ public class ChildProcessConnectionImpl implements ChildProcessConnection { |
| } |
| } |
| + private void onSetupConnectionResult(int pid) { |
| + synchronized (mLock) { |
| + mPid = pid; |
| + assert mPid != 0 : "Child service claims to be run by a process of pid=0."; |
| + // We proactively close the FDs rather than wait for GC & finalizer. |
| + try { |
| + for (FileDescriptorInfo fileInfo : mConnectionParams.mFilesToBeMapped) { |
| + fileInfo.fd.close(); |
| + } |
| + } catch (IOException ioe) { |
| + Log.w(TAG, "Failed to close FD.", ioe); |
| + } |
| + mConnectionParams = null; |
| + |
| + if (mConnectionCallback != null) { |
| + mConnectionCallback.onConnected(mPid); |
| + } |
| + mConnectionCallback = null; |
| + } |
| + } |
| + |
| /** |
| * Called after the connection parameters have been set (in setupConnection()) *and* a |
| * connection has been established (as signaled by onServiceConnected()). These two events can |
| @@ -402,26 +424,22 @@ public class ChildProcessConnectionImpl implements ChildProcessConnection { |
| Bundle bundle = ChildProcessLauncher.createsServiceBundle( |
| mConnectionParams.mCommandLine, mConnectionParams.mFilesToBeMapped); |
| + ICallbackInt pidCallback = new ICallbackInt.Stub() { |
| + @Override |
| + public void call(final int pid) { |
| + LauncherThread.post(new Runnable() { |
| + @Override |
| + public void run() { |
| + onSetupConnectionResult(pid); |
| + } |
| + }); |
| + } |
| + }; |
| try { |
| - mPid = mService.setupConnection(bundle, mConnectionParams.mCallback); |
| - assert mPid != 0 : "Child service claims to be run by a process of pid=0."; |
| - } catch (android.os.RemoteException re) { |
| + mService.setupConnection(bundle, pidCallback, mConnectionParams.mCallback); |
| + } catch (RemoteException re) { |
| Log.e(TAG, "Failed to setup connection.", re); |
| } |
| - // We proactively close the FDs rather than wait for GC & finalizer. |
|
Robert Sesek
2017/04/10 16:17:58
Closing the FDs should still be possible after cal
boliu
2017/04/10 16:56:29
Done.
|
| - try { |
| - for (FileDescriptorInfo fileInfo : mConnectionParams.mFilesToBeMapped) { |
| - fileInfo.fd.close(); |
| - } |
| - } catch (IOException ioe) { |
| - Log.w(TAG, "Failed to close FD.", ioe); |
| - } |
| - mConnectionParams = null; |
| - |
| - if (mConnectionCallback != null) { |
| - mConnectionCallback.onConnected(mPid); |
| - } |
| - mConnectionCallback = null; |
| } finally { |
| TraceEvent.end("ChildProcessConnectionImpl.doConnectionSetupLocked"); |
| } |