| 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.app.Service; |
| 7 import android.content.ComponentName; | 8 import android.content.ComponentName; |
| 8 import android.content.Context; | 9 import android.content.Context; |
| 9 import android.content.Intent; | 10 import android.content.Intent; |
| 10 import android.content.ServiceConnection; | 11 import android.content.ServiceConnection; |
| 11 import android.content.pm.PackageManager; | 12 import android.content.pm.PackageManager; |
| 12 import android.content.pm.ServiceInfo; | 13 import android.content.pm.ServiceInfo; |
| 13 import android.os.Bundle; | 14 import android.os.Bundle; |
| 14 import android.os.DeadObjectException; | 15 import android.os.DeadObjectException; |
| 15 import android.os.IBinder; | 16 import android.os.IBinder; |
| 16 import android.os.RemoteException; | 17 import android.os.RemoteException; |
| 17 | 18 |
| 18 import org.chromium.base.Log; | 19 import org.chromium.base.Log; |
| 19 import org.chromium.base.ThreadUtils; | 20 import org.chromium.base.ThreadUtils; |
| 20 import org.chromium.base.TraceEvent; | 21 import org.chromium.base.TraceEvent; |
| 21 import org.chromium.base.VisibleForTesting; | 22 import org.chromium.base.VisibleForTesting; |
| 22 import org.chromium.content.app.ChildProcessService; | |
| 23 import org.chromium.content.app.ChromiumLinkerParams; | 23 import org.chromium.content.app.ChromiumLinkerParams; |
| 24 import org.chromium.content.common.IChildProcessCallback; | 24 import org.chromium.content.common.IChildProcessCallback; |
| 25 import org.chromium.content.common.IChildProcessService; | 25 import org.chromium.content.common.IChildProcessService; |
| 26 | 26 |
| 27 import java.io.IOException; | 27 import java.io.IOException; |
| 28 | 28 |
| 29 /** | 29 /** |
| 30 * Manages a connection between the browser activity and a child service. | 30 * Manages a connection between the browser activity and a child service. |
| 31 */ | 31 */ |
| 32 public class ChildProcessConnectionImpl implements ChildProcessConnection { | 32 public class ChildProcessConnectionImpl implements ChildProcessConnection { |
| 33 private final Context mContext; | 33 private final Context mContext; |
| 34 private final int mServiceNumber; | 34 private final int mServiceNumber; |
| 35 private final boolean mInSandbox; | 35 private final boolean mInSandbox; |
| 36 private final ChildProcessConnection.DeathCallback mDeathCallback; | 36 private final ChildProcessConnection.DeathCallback mDeathCallback; |
| 37 private final Class<? extends ChildProcessService> mServiceClass; | 37 private final Class<? extends Service> mServiceClass; |
| 38 private final ComponentName mServiceName; | 38 private final ComponentName mServiceName; |
| 39 | 39 |
| 40 // Synchronization: While most internal flow occurs on the UI thread, the pu
blic API | 40 // Synchronization: While most internal flow occurs on the UI thread, the pu
blic API |
| 41 // (specifically start and stop) may be called from any thread, hence all en
try point methods | 41 // (specifically start and stop) may be called from any thread, hence all en
try point methods |
| 42 // into the class are synchronized on the lock to protect access to these me
mbers. | 42 // into the class are synchronized on the lock to protect access to these me
mbers. |
| 43 private final Object mLock = new Object(); | 43 private final Object mLock = new Object(); |
| 44 private IChildProcessService mService = null; | 44 private IChildProcessService mService = null; |
| 45 // Set to true when the service connected successfully. | 45 // Set to true when the service connected successfully. |
| 46 private boolean mServiceConnectComplete = false; | 46 private boolean mServiceConnectComplete = false; |
| 47 // Set to true when the service disconnects, as opposed to being properly cl
osed. This happens | 47 // Set to true when the service disconnects, as opposed to being properly cl
osed. This happens |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 if (mConnectionCallback != null) { | 204 if (mConnectionCallback != null) { |
| 205 mConnectionCallback.onConnected(0); | 205 mConnectionCallback.onConnected(0); |
| 206 } | 206 } |
| 207 mConnectionCallback = null; | 207 mConnectionCallback = null; |
| 208 } | 208 } |
| 209 } | 209 } |
| 210 } | 210 } |
| 211 | 211 |
| 212 ChildProcessConnectionImpl(Context context, int number, boolean inSandbox, | 212 ChildProcessConnectionImpl(Context context, int number, boolean inSandbox, |
| 213 ChildProcessConnection.DeathCallback deathCallback, | 213 ChildProcessConnection.DeathCallback deathCallback, |
| 214 Class<? extends ChildProcessService> serviceClass, | 214 Class<? extends Service> serviceClass, |
| 215 ChromiumLinkerParams chromiumLinkerParams, | 215 ChromiumLinkerParams chromiumLinkerParams, |
| 216 boolean alwaysInForeground, | 216 boolean alwaysInForeground, |
| 217 ChildProcessCreationParams creationParams) { | 217 ChildProcessCreationParams creationParams) { |
| 218 mContext = context; | 218 mContext = context; |
| 219 mServiceNumber = number; | 219 mServiceNumber = number; |
| 220 mInSandbox = inSandbox; | 220 mInSandbox = inSandbox; |
| 221 mDeathCallback = deathCallback; | 221 mDeathCallback = deathCallback; |
| 222 mServiceClass = serviceClass; | 222 mServiceClass = serviceClass; |
| 223 String packageName = | 223 String packageName = |
| 224 creationParams != null ? creationParams.getPackageName() : conte
xt.getPackageName(); | 224 creationParams != null ? creationParams.getPackageName() : conte
xt.getPackageName(); |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 return true; | 517 return true; |
| 518 } | 518 } |
| 519 return false; | 519 return false; |
| 520 } | 520 } |
| 521 | 521 |
| 522 @VisibleForTesting | 522 @VisibleForTesting |
| 523 public boolean isConnected() { | 523 public boolean isConnected() { |
| 524 return mService != null; | 524 return mService != null; |
| 525 } | 525 } |
| 526 } | 526 } |
| OLD | NEW |