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; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 // binding flag provided via ChildProcessCreationParams. | 84 // binding flag provided via ChildProcessCreationParams. |
85 // TODO(mnaganov): Get rid of it after the release of the next Android SDK. | 85 // TODO(mnaganov): Get rid of it after the release of the next Android SDK. |
86 private static Boolean sNeedsExtrabindFlags[] = new Boolean[2]; | 86 private static Boolean sNeedsExtrabindFlags[] = new Boolean[2]; |
87 | 87 |
88 private static final String TAG = "ChildProcessConnect"; | 88 private static final String TAG = "ChildProcessConnect"; |
89 | 89 |
90 private static class ConnectionParams { | 90 private static class ConnectionParams { |
91 final String[] mCommandLine; | 91 final String[] mCommandLine; |
92 final FileDescriptorInfo[] mFilesToBeMapped; | 92 final FileDescriptorInfo[] mFilesToBeMapped; |
93 final IChildProcessCallback mCallback; | 93 final IChildProcessCallback mCallback; |
94 final Bundle mSharedRelros; | |
95 | 94 |
96 ConnectionParams(String[] commandLine, FileDescriptorInfo[] filesToBeMap
ped, | 95 ConnectionParams(String[] commandLine, FileDescriptorInfo[] filesToBeMap
ped, |
97 IChildProcessCallback callback, Bundle sharedRelros) { | 96 IChildProcessCallback callback) { |
98 mCommandLine = commandLine; | 97 mCommandLine = commandLine; |
99 mFilesToBeMapped = filesToBeMapped; | 98 mFilesToBeMapped = filesToBeMapped; |
100 mCallback = callback; | 99 mCallback = callback; |
101 mSharedRelros = sharedRelros; | |
102 } | 100 } |
103 } | 101 } |
104 | 102 |
105 // This is set in start() and is used in onServiceConnected(). | 103 // This is set in start() and is used in onServiceConnected(). |
106 private ChildProcessConnection.StartCallback mStartCallback; | 104 private ChildProcessConnection.StartCallback mStartCallback; |
107 | 105 |
108 // This is set in setupConnection() and is later used in doConnectionSetupLo
cked(), after which | 106 // This is set in setupConnection() and is later used in doConnectionSetupLo
cked(), after which |
109 // the variable is cleared. Therefore this is only valid while the connectio
n is being set up. | 107 // the variable is cleared. Therefore this is only valid while the connectio
n is being set up. |
110 private ConnectionParams mConnectionParams; | 108 private ConnectionParams mConnectionParams; |
111 | 109 |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 } else { | 341 } else { |
344 mWaivedBinding.bind(); | 342 mWaivedBinding.bind(); |
345 } | 343 } |
346 } | 344 } |
347 } finally { | 345 } finally { |
348 TraceEvent.end("ChildProcessConnectionImpl.start"); | 346 TraceEvent.end("ChildProcessConnectionImpl.start"); |
349 } | 347 } |
350 } | 348 } |
351 | 349 |
352 @Override | 350 @Override |
353 public void setupConnection( | 351 public void setupConnection(String[] commandLine, FileDescriptorInfo[] files
ToBeMapped, |
354 String[] commandLine, | 352 IChildProcessCallback processCallback, ConnectionCallback connection
Callback) { |
355 FileDescriptorInfo[] filesToBeMapped, | |
356 IChildProcessCallback processCallback, | |
357 ConnectionCallback connectionCallback, | |
358 Bundle sharedRelros) { | |
359 synchronized (mLock) { | 353 synchronized (mLock) { |
360 assert mConnectionParams == null; | 354 assert mConnectionParams == null; |
361 if (mServiceDisconnected) { | 355 if (mServiceDisconnected) { |
362 Log.w(TAG, "Tried to setup a connection that already disconnecte
d."); | 356 Log.w(TAG, "Tried to setup a connection that already disconnecte
d."); |
363 connectionCallback.onConnected(0); | 357 connectionCallback.onConnected(0); |
364 return; | 358 return; |
365 } | 359 } |
366 try { | 360 try { |
367 TraceEvent.begin("ChildProcessConnectionImpl.setupConnection"); | 361 TraceEvent.begin("ChildProcessConnectionImpl.setupConnection"); |
368 mConnectionCallback = connectionCallback; | 362 mConnectionCallback = connectionCallback; |
369 mConnectionParams = new ConnectionParams( | 363 mConnectionParams = |
370 commandLine, filesToBeMapped, processCallback, sharedRel
ros); | 364 new ConnectionParams(commandLine, filesToBeMapped, proce
ssCallback); |
371 // Run the setup if the service is already connected. If not, | 365 // Run the setup if the service is already connected. If not, |
372 // doConnectionSetupLocked() will be called from onServiceConnec
ted(). | 366 // doConnectionSetupLocked() will be called from onServiceConnec
ted(). |
373 if (mServiceConnectComplete) { | 367 if (mServiceConnectComplete) { |
374 doConnectionSetupLocked(); | 368 doConnectionSetupLocked(); |
375 } | 369 } |
376 } finally { | 370 } finally { |
377 TraceEvent.end("ChildProcessConnectionImpl.setupConnection"); | 371 TraceEvent.end("ChildProcessConnectionImpl.setupConnection"); |
378 } | 372 } |
379 } | 373 } |
380 } | 374 } |
(...skipping 17 matching lines...) Expand all Loading... |
398 * Called after the connection parameters have been set (in setupConnection(
)) *and* a | 392 * Called after the connection parameters have been set (in setupConnection(
)) *and* a |
399 * connection has been established (as signaled by onServiceConnected()). Th
ese two events can | 393 * connection has been established (as signaled by onServiceConnected()). Th
ese two events can |
400 * happen in any order. Has to be called with mLock. | 394 * happen in any order. Has to be called with mLock. |
401 */ | 395 */ |
402 private void doConnectionSetupLocked() { | 396 private void doConnectionSetupLocked() { |
403 try { | 397 try { |
404 TraceEvent.begin("ChildProcessConnectionImpl.doConnectionSetupLocked
"); | 398 TraceEvent.begin("ChildProcessConnectionImpl.doConnectionSetupLocked
"); |
405 assert mServiceConnectComplete && mService != null; | 399 assert mServiceConnectComplete && mService != null; |
406 assert mConnectionParams != null; | 400 assert mConnectionParams != null; |
407 | 401 |
408 Bundle bundle = | 402 Bundle bundle = ChildProcessLauncher.createsServiceBundle( |
409 ChildProcessLauncher.createsServiceBundle(mConnectionParams.
mCommandLine, | 403 mConnectionParams.mCommandLine, mConnectionParams.mFilesToBe
Mapped); |
410 mConnectionParams.mFilesToBeMapped, mConnectionParam
s.mSharedRelros); | |
411 try { | 404 try { |
412 mPid = mService.setupConnection(bundle, mConnectionParams.mCallb
ack); | 405 mPid = mService.setupConnection(bundle, mConnectionParams.mCallb
ack); |
413 assert mPid != 0 : "Child service claims to be run by a process
of pid=0."; | 406 assert mPid != 0 : "Child service claims to be run by a process
of pid=0."; |
414 } catch (android.os.RemoteException re) { | 407 } catch (android.os.RemoteException re) { |
415 Log.e(TAG, "Failed to setup connection.", re); | 408 Log.e(TAG, "Failed to setup connection.", re); |
416 } | 409 } |
417 // We proactively close the FDs rather than wait for GC & finalizer. | 410 // We proactively close the FDs rather than wait for GC & finalizer. |
418 try { | 411 try { |
419 for (FileDescriptorInfo fileInfo : mConnectionParams.mFilesToBeM
apped) { | 412 for (FileDescriptorInfo fileInfo : mConnectionParams.mFilesToBeM
apped) { |
420 fileInfo.mFd.close(); | 413 fileInfo.mFd.close(); |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 return true; | 546 return true; |
554 } | 547 } |
555 return false; | 548 return false; |
556 } | 549 } |
557 | 550 |
558 @VisibleForTesting | 551 @VisibleForTesting |
559 public boolean isConnected() { | 552 public boolean isConnected() { |
560 return mService != null; | 553 return mService != null; |
561 } | 554 } |
562 } | 555 } |
OLD | NEW |