| 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.DeadObjectException; | 15 import android.os.DeadObjectException; |
| 16 import android.os.IBinder; | 16 import android.os.IBinder; |
| 17 import android.os.RemoteException; | 17 import android.os.RemoteException; |
| 18 | 18 |
| 19 import org.chromium.base.Log; | 19 import org.chromium.base.Log; |
| 20 import org.chromium.base.ThreadUtils; | 20 import org.chromium.base.ThreadUtils; |
| 21 import org.chromium.base.TraceEvent; | 21 import org.chromium.base.TraceEvent; |
| 22 import org.chromium.base.VisibleForTesting; | 22 import org.chromium.base.VisibleForTesting; |
| 23 import org.chromium.base.process_launcher.ChildProcessCreationParams; | 23 import org.chromium.base.process_launcher.ChildProcessCreationParams; |
| 24 import org.chromium.content.common.FileDescriptorInfo; | 24 import org.chromium.content.common.FileDescriptorInfo; |
| 25 import org.chromium.content.common.IChildProcessCallback; | |
| 26 import org.chromium.content.common.IChildProcessService; | 25 import org.chromium.content.common.IChildProcessService; |
| 27 | 26 |
| 28 import java.io.IOException; | 27 import java.io.IOException; |
| 29 | 28 |
| 29 import javax.annotation.Nullable; |
| 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 { |
| 34 private final Context mContext; | 35 private final Context mContext; |
| 35 private final int mServiceNumber; | 36 private final int mServiceNumber; |
| 36 private final boolean mInSandbox; | 37 private final boolean mInSandbox; |
| 37 private final ChildProcessConnection.DeathCallback mDeathCallback; | 38 private final ChildProcessConnection.DeathCallback mDeathCallback; |
| 38 private final ComponentName mServiceName; | 39 private final ComponentName mServiceName; |
| 39 | 40 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 // Caches whether non-sandboxed and sandboxed services require an extra | 84 // Caches whether non-sandboxed and sandboxed services require an extra |
| 84 // binding flag provided via ChildProcessCreationParams. | 85 // binding flag provided via ChildProcessCreationParams. |
| 85 // TODO(mnaganov): Get rid of it after the release of the next Android SDK. | 86 // TODO(mnaganov): Get rid of it after the release of the next Android SDK. |
| 86 private static Boolean sNeedsExtrabindFlags[] = new Boolean[2]; | 87 private static Boolean sNeedsExtrabindFlags[] = new Boolean[2]; |
| 87 | 88 |
| 88 private static final String TAG = "ChildProcessConnect"; | 89 private static final String TAG = "ChildProcessConnect"; |
| 89 | 90 |
| 90 private static class ConnectionParams { | 91 private static class ConnectionParams { |
| 91 final String[] mCommandLine; | 92 final String[] mCommandLine; |
| 92 final FileDescriptorInfo[] mFilesToBeMapped; | 93 final FileDescriptorInfo[] mFilesToBeMapped; |
| 93 final IChildProcessCallback mCallback; | 94 final IBinder mCallback; |
| 94 final Bundle mSharedRelros; | 95 final Bundle mSharedRelros; |
| 95 | 96 |
| 96 ConnectionParams(String[] commandLine, FileDescriptorInfo[] filesToBeMap
ped, | 97 ConnectionParams(String[] commandLine, FileDescriptorInfo[] filesToBeMap
ped, |
| 97 IChildProcessCallback callback, Bundle sharedRelros) { | 98 IBinder callback, Bundle sharedRelros) { |
| 98 mCommandLine = commandLine; | 99 mCommandLine = commandLine; |
| 99 mFilesToBeMapped = filesToBeMapped; | 100 mFilesToBeMapped = filesToBeMapped; |
| 100 mCallback = callback; | 101 mCallback = callback; |
| 101 mSharedRelros = sharedRelros; | 102 mSharedRelros = sharedRelros; |
| 102 } | 103 } |
| 103 } | 104 } |
| 104 | 105 |
| 105 // This is set in start() and is used in onServiceConnected(). | 106 // This is set in start() and is used in onServiceConnected(). |
| 106 private ChildProcessConnection.StartCallback mStartCallback; | 107 private ChildProcessConnection.StartCallback mStartCallback; |
| 107 | 108 |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 } else { | 344 } else { |
| 344 mWaivedBinding.bind(); | 345 mWaivedBinding.bind(); |
| 345 } | 346 } |
| 346 } | 347 } |
| 347 } finally { | 348 } finally { |
| 348 TraceEvent.end("ChildProcessConnectionImpl.start"); | 349 TraceEvent.end("ChildProcessConnectionImpl.start"); |
| 349 } | 350 } |
| 350 } | 351 } |
| 351 | 352 |
| 352 @Override | 353 @Override |
| 353 public void setupConnection( | 354 public void setupConnection(String[] commandLine, FileDescriptorInfo[] files
ToBeMapped, |
| 354 String[] commandLine, | 355 @Nullable IBinder callback, ConnectionCallback connectionCallback, |
| 355 FileDescriptorInfo[] filesToBeMapped, | |
| 356 IChildProcessCallback processCallback, | |
| 357 ConnectionCallback connectionCallback, | |
| 358 Bundle sharedRelros) { | 356 Bundle sharedRelros) { |
| 359 synchronized (mLock) { | 357 synchronized (mLock) { |
| 360 assert mConnectionParams == null; | 358 assert mConnectionParams == null; |
| 361 if (mServiceDisconnected) { | 359 if (mServiceDisconnected) { |
| 362 Log.w(TAG, "Tried to setup a connection that already disconnecte
d."); | 360 Log.w(TAG, "Tried to setup a connection that already disconnecte
d."); |
| 363 connectionCallback.onConnected(0); | 361 connectionCallback.onConnected(0); |
| 364 return; | 362 return; |
| 365 } | 363 } |
| 366 try { | 364 try { |
| 367 TraceEvent.begin("ChildProcessConnectionImpl.setupConnection"); | 365 TraceEvent.begin("ChildProcessConnectionImpl.setupConnection"); |
| 368 mConnectionCallback = connectionCallback; | 366 mConnectionCallback = connectionCallback; |
| 369 mConnectionParams = new ConnectionParams( | 367 mConnectionParams = |
| 370 commandLine, filesToBeMapped, processCallback, sharedRel
ros); | 368 new ConnectionParams(commandLine, filesToBeMapped, callb
ack, sharedRelros); |
| 371 // Run the setup if the service is already connected. If not, | 369 // Run the setup if the service is already connected. If not, |
| 372 // doConnectionSetupLocked() will be called from onServiceConnec
ted(). | 370 // doConnectionSetupLocked() will be called from onServiceConnec
ted(). |
| 373 if (mServiceConnectComplete) { | 371 if (mServiceConnectComplete) { |
| 374 doConnectionSetupLocked(); | 372 doConnectionSetupLocked(); |
| 375 } | 373 } |
| 376 } finally { | 374 } finally { |
| 377 TraceEvent.end("ChildProcessConnectionImpl.setupConnection"); | 375 TraceEvent.end("ChildProcessConnectionImpl.setupConnection"); |
| 378 } | 376 } |
| 379 } | 377 } |
| 380 } | 378 } |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 return true; | 551 return true; |
| 554 } | 552 } |
| 555 return false; | 553 return false; |
| 556 } | 554 } |
| 557 | 555 |
| 558 @VisibleForTesting | 556 @VisibleForTesting |
| 559 public boolean isConnected() { | 557 public boolean isConnected() { |
| 560 return mService != null; | 558 return mService != null; |
| 561 } | 559 } |
| 562 } | 560 } |
| OLD | NEW |