Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.content.browser; | 5 package org.chromium.content.browser; |
| 6 | 6 |
| 7 import android.content.ComponentName; | 7 import android.content.ComponentName; |
| 8 import android.content.Context; | 8 import android.content.Context; |
| 9 import android.content.Intent; | 9 import android.content.Intent; |
| 10 import android.content.ServiceConnection; | 10 import android.content.ServiceConnection; |
| 11 import android.content.pm.PackageManager; | 11 import android.content.pm.PackageManager; |
| 12 import android.content.pm.ServiceInfo; | 12 import android.content.pm.ServiceInfo; |
| 13 import android.os.Build; | 13 import android.os.Build; |
| 14 import android.os.Bundle; | 14 import android.os.Bundle; |
| 15 import android.os.IBinder; | 15 import android.os.IBinder; |
| 16 import android.os.RemoteException; | 16 import android.os.RemoteException; |
| 17 | 17 |
| 18 import org.chromium.base.Log; | 18 import org.chromium.base.Log; |
| 19 import org.chromium.base.ThreadUtils; | 19 import org.chromium.base.ThreadUtils; |
| 20 import org.chromium.base.TraceEvent; | 20 import org.chromium.base.TraceEvent; |
| 21 import org.chromium.base.VisibleForTesting; | 21 import org.chromium.base.VisibleForTesting; |
| 22 import org.chromium.base.process_launcher.ChildProcessCreationParams; | 22 import org.chromium.base.process_launcher.ChildProcessCreationParams; |
| 23 import org.chromium.base.process_launcher.FileDescriptorInfo; | 23 import org.chromium.base.process_launcher.FileDescriptorInfo; |
| 24 import org.chromium.base.process_launcher.ICallbackInt; | |
| 24 import org.chromium.base.process_launcher.IChildProcessService; | 25 import org.chromium.base.process_launcher.IChildProcessService; |
| 25 | 26 |
| 26 import java.io.IOException; | 27 import java.io.IOException; |
| 27 | 28 |
| 28 import javax.annotation.Nullable; | 29 import javax.annotation.Nullable; |
| 29 | 30 |
| 30 /** | 31 /** |
| 31 * Manages a connection between the browser activity and a child service. | 32 * Manages a connection between the browser activity and a child service. |
| 32 */ | 33 */ |
| 33 public class ChildProcessConnectionImpl implements ChildProcessConnection { | 34 public class ChildProcessConnectionImpl implements ChildProcessConnection { |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 382 mWaivedBinding.unbind(); | 383 mWaivedBinding.unbind(); |
| 383 mModerateBinding.unbind(); | 384 mModerateBinding.unbind(); |
| 384 mStrongBindingCount = 0; | 385 mStrongBindingCount = 0; |
| 385 if (mService != null) { | 386 if (mService != null) { |
| 386 mService = null; | 387 mService = null; |
| 387 } | 388 } |
| 388 mConnectionParams = null; | 389 mConnectionParams = null; |
| 389 } | 390 } |
| 390 } | 391 } |
| 391 | 392 |
| 393 private void onSetupConnectionResult(int pid) { | |
| 394 synchronized (mLock) { | |
| 395 mPid = pid; | |
| 396 assert mPid != 0 : "Child service claims to be run by a process of p id=0."; | |
| 397 // We proactively close the FDs rather than wait for GC & finalizer. | |
| 398 try { | |
| 399 for (FileDescriptorInfo fileInfo : mConnectionParams.mFilesToBeM apped) { | |
| 400 fileInfo.fd.close(); | |
| 401 } | |
| 402 } catch (IOException ioe) { | |
| 403 Log.w(TAG, "Failed to close FD.", ioe); | |
| 404 } | |
| 405 mConnectionParams = null; | |
| 406 | |
| 407 if (mConnectionCallback != null) { | |
| 408 mConnectionCallback.onConnected(mPid); | |
| 409 } | |
| 410 mConnectionCallback = null; | |
| 411 } | |
| 412 } | |
| 413 | |
| 392 /** | 414 /** |
| 393 * Called after the connection parameters have been set (in setupConnection( )) *and* a | 415 * Called after the connection parameters have been set (in setupConnection( )) *and* a |
| 394 * connection has been established (as signaled by onServiceConnected()). Th ese two events can | 416 * connection has been established (as signaled by onServiceConnected()). Th ese two events can |
| 395 * happen in any order. Has to be called with mLock. | 417 * happen in any order. Has to be called with mLock. |
| 396 */ | 418 */ |
| 397 private void doConnectionSetupLocked() { | 419 private void doConnectionSetupLocked() { |
| 398 try { | 420 try { |
| 399 TraceEvent.begin("ChildProcessConnectionImpl.doConnectionSetupLocked "); | 421 TraceEvent.begin("ChildProcessConnectionImpl.doConnectionSetupLocked "); |
| 400 assert mServiceConnectComplete && mService != null; | 422 assert mServiceConnectComplete && mService != null; |
| 401 assert mConnectionParams != null; | 423 assert mConnectionParams != null; |
| 402 | 424 |
| 403 Bundle bundle = ChildProcessLauncher.createsServiceBundle( | 425 Bundle bundle = ChildProcessLauncher.createsServiceBundle( |
| 404 mConnectionParams.mCommandLine, mConnectionParams.mFilesToBe Mapped); | 426 mConnectionParams.mCommandLine, mConnectionParams.mFilesToBe Mapped); |
| 427 ICallbackInt pidCallback = new ICallbackInt.Stub() { | |
| 428 @Override | |
| 429 public void call(final int pid) { | |
| 430 LauncherThread.post(new Runnable() { | |
| 431 @Override | |
| 432 public void run() { | |
| 433 onSetupConnectionResult(pid); | |
| 434 } | |
| 435 }); | |
| 436 } | |
| 437 }; | |
| 405 try { | 438 try { |
| 406 mPid = mService.setupConnection(bundle, mConnectionParams.mCallb ack); | 439 mService.setupConnection(bundle, pidCallback, mConnectionParams. mCallback); |
| 407 assert mPid != 0 : "Child service claims to be run by a process of pid=0."; | 440 } catch (RemoteException re) { |
| 408 } catch (android.os.RemoteException re) { | |
| 409 Log.e(TAG, "Failed to setup connection.", re); | 441 Log.e(TAG, "Failed to setup connection.", re); |
| 410 } | 442 } |
| 411 // 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.
| |
| 412 try { | |
| 413 for (FileDescriptorInfo fileInfo : mConnectionParams.mFilesToBeM apped) { | |
| 414 fileInfo.fd.close(); | |
| 415 } | |
| 416 } catch (IOException ioe) { | |
| 417 Log.w(TAG, "Failed to close FD.", ioe); | |
| 418 } | |
| 419 mConnectionParams = null; | |
| 420 | |
| 421 if (mConnectionCallback != null) { | |
| 422 mConnectionCallback.onConnected(mPid); | |
| 423 } | |
| 424 mConnectionCallback = null; | |
| 425 } finally { | 443 } finally { |
| 426 TraceEvent.end("ChildProcessConnectionImpl.doConnectionSetupLocked") ; | 444 TraceEvent.end("ChildProcessConnectionImpl.doConnectionSetupLocked") ; |
| 427 } | 445 } |
| 428 } | 446 } |
| 429 | 447 |
| 430 @Override | 448 @Override |
| 431 public boolean isInitialBindingBound() { | 449 public boolean isInitialBindingBound() { |
| 432 synchronized (mLock) { | 450 synchronized (mLock) { |
| 433 return mInitialBinding.isBound(); | 451 return mInitialBinding.isBound(); |
| 434 } | 452 } |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 542 @VisibleForTesting | 560 @VisibleForTesting |
| 543 public void crashServiceForTesting() throws RemoteException { | 561 public void crashServiceForTesting() throws RemoteException { |
| 544 mService.crashIntentionallyForTesting(); | 562 mService.crashIntentionallyForTesting(); |
| 545 } | 563 } |
| 546 | 564 |
| 547 @VisibleForTesting | 565 @VisibleForTesting |
| 548 public boolean isConnected() { | 566 public boolean isConnected() { |
| 549 return mService != null; | 567 return mService != null; |
| 550 } | 568 } |
| 551 } | 569 } |
| OLD | NEW |