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.base.process_launcher.FileDescriptorInfo; | 24 import org.chromium.base.process_launcher.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 | 95 |
95 ConnectionParams(String[] commandLine, FileDescriptorInfo[] filesToBeMap
ped, | 96 ConnectionParams( |
96 IChildProcessCallback callback) { | 97 String[] commandLine, FileDescriptorInfo[] filesToBeMapped, IBin
der callback) { |
97 mCommandLine = commandLine; | 98 mCommandLine = commandLine; |
98 mFilesToBeMapped = filesToBeMapped; | 99 mFilesToBeMapped = filesToBeMapped; |
99 mCallback = callback; | 100 mCallback = callback; |
100 } | 101 } |
101 } | 102 } |
102 | 103 |
103 // This is set in start() and is used in onServiceConnected(). | 104 // This is set in start() and is used in onServiceConnected(). |
104 private ChildProcessConnection.StartCallback mStartCallback; | 105 private ChildProcessConnection.StartCallback mStartCallback; |
105 | 106 |
106 // This is set in setupConnection() and is later used in doConnectionSetupLo
cked(), after which | 107 // This is set in setupConnection() and is later used in doConnectionSetupLo
cked(), after which |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 mWaivedBinding.bind(); | 343 mWaivedBinding.bind(); |
343 } | 344 } |
344 } | 345 } |
345 } finally { | 346 } finally { |
346 TraceEvent.end("ChildProcessConnectionImpl.start"); | 347 TraceEvent.end("ChildProcessConnectionImpl.start"); |
347 } | 348 } |
348 } | 349 } |
349 | 350 |
350 @Override | 351 @Override |
351 public void setupConnection(String[] commandLine, FileDescriptorInfo[] files
ToBeMapped, | 352 public void setupConnection(String[] commandLine, FileDescriptorInfo[] files
ToBeMapped, |
352 IChildProcessCallback processCallback, ConnectionCallback connection
Callback) { | 353 @Nullable IBinder callback, ConnectionCallback connectionCallback) { |
353 synchronized (mLock) { | 354 synchronized (mLock) { |
354 assert mConnectionParams == null; | 355 assert mConnectionParams == null; |
355 if (mServiceDisconnected) { | 356 if (mServiceDisconnected) { |
356 Log.w(TAG, "Tried to setup a connection that already disconnecte
d."); | 357 Log.w(TAG, "Tried to setup a connection that already disconnecte
d."); |
357 connectionCallback.onConnected(0); | 358 connectionCallback.onConnected(0); |
358 return; | 359 return; |
359 } | 360 } |
360 try { | 361 try { |
361 TraceEvent.begin("ChildProcessConnectionImpl.setupConnection"); | 362 TraceEvent.begin("ChildProcessConnectionImpl.setupConnection"); |
362 mConnectionCallback = connectionCallback; | 363 mConnectionCallback = connectionCallback; |
363 mConnectionParams = | 364 mConnectionParams = new ConnectionParams(commandLine, filesToBeM
apped, callback); |
364 new ConnectionParams(commandLine, filesToBeMapped, proce
ssCallback); | |
365 // Run the setup if the service is already connected. If not, | 365 // Run the setup if the service is already connected. If not, |
366 // doConnectionSetupLocked() will be called from onServiceConnec
ted(). | 366 // doConnectionSetupLocked() will be called from onServiceConnec
ted(). |
367 if (mServiceConnectComplete) { | 367 if (mServiceConnectComplete) { |
368 doConnectionSetupLocked(); | 368 doConnectionSetupLocked(); |
369 } | 369 } |
370 } finally { | 370 } finally { |
371 TraceEvent.end("ChildProcessConnectionImpl.setupConnection"); | 371 TraceEvent.end("ChildProcessConnectionImpl.setupConnection"); |
372 } | 372 } |
373 } | 373 } |
374 } | 374 } |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 return true; | 546 return true; |
547 } | 547 } |
548 return false; | 548 return false; |
549 } | 549 } |
550 | 550 |
551 @VisibleForTesting | 551 @VisibleForTesting |
552 public boolean isConnected() { | 552 public boolean isConnected() { |
553 return mService != null; | 553 return mService != null; |
554 } | 554 } |
555 } | 555 } |
OLD | NEW |