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.os.Bundle; | 11 import android.os.Bundle; |
12 import android.os.DeadObjectException; | 12 import android.os.DeadObjectException; |
13 import android.os.IBinder; | 13 import android.os.IBinder; |
14 import android.os.ParcelFileDescriptor; | |
15 import android.os.RemoteException; | 14 import android.os.RemoteException; |
16 import android.util.Log; | 15 import android.util.Log; |
17 | 16 |
18 import org.chromium.base.CpuFeatures; | 17 import org.chromium.base.CpuFeatures; |
19 import org.chromium.base.ThreadUtils; | 18 import org.chromium.base.ThreadUtils; |
20 import org.chromium.base.TraceEvent; | 19 import org.chromium.base.TraceEvent; |
21 import org.chromium.base.VisibleForTesting; | 20 import org.chromium.base.VisibleForTesting; |
22 import org.chromium.base.library_loader.Linker; | 21 import org.chromium.base.library_loader.Linker; |
23 import org.chromium.content.app.ChildProcessService; | 22 import org.chromium.content.app.ChildProcessService; |
24 import org.chromium.content.app.ChromiumLinkerParams; | 23 import org.chromium.content.app.ChromiumLinkerParams; |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 */ | 312 */ |
314 private void doConnectionSetupLocked() { | 313 private void doConnectionSetupLocked() { |
315 try { | 314 try { |
316 TraceEvent.begin("ChildProcessConnectionImpl.doConnectionSetupLocked
"); | 315 TraceEvent.begin("ChildProcessConnectionImpl.doConnectionSetupLocked
"); |
317 assert mServiceConnectComplete && mService != null; | 316 assert mServiceConnectComplete && mService != null; |
318 assert mConnectionParams != null; | 317 assert mConnectionParams != null; |
319 | 318 |
320 Bundle bundle = new Bundle(); | 319 Bundle bundle = new Bundle(); |
321 bundle.putStringArray(EXTRA_COMMAND_LINE, mConnectionParams.mCommand
Line); | 320 bundle.putStringArray(EXTRA_COMMAND_LINE, mConnectionParams.mCommand
Line); |
322 | 321 |
323 FileDescriptorInfo[] fileInfos = mConnectionParams.mFilesToBeMapped; | 322 bundle.putParcelableArray(EXTRA_FILES, mConnectionParams.mFilesToBeM
apped); |
324 ParcelFileDescriptor[] parcelFiles = new ParcelFileDescriptor[fileIn
fos.length]; | |
325 for (int i = 0; i < fileInfos.length; i++) { | |
326 if (fileInfos[i].mFd == -1) { | |
327 // If someone provided an invalid FD, they are doing somethi
ng wrong. | |
328 Log.e(TAG, "Invalid FD (id=" + fileInfos[i].mId + ") for pro
cess connection, " | |
329 + "aborting connection."); | |
330 return; | |
331 } | |
332 String idName = EXTRA_FILES_PREFIX + i + EXTRA_FILES_ID_SUFFIX; | |
333 String fdName = EXTRA_FILES_PREFIX + i + EXTRA_FILES_FD_SUFFIX; | |
334 if (fileInfos[i].mAutoClose) { | |
335 // Adopt the FD, it will be closed when we close the ParcelF
ileDescriptor. | |
336 parcelFiles[i] = ParcelFileDescriptor.adoptFd(fileInfos[i].m
Fd); | |
337 } else { | |
338 try { | |
339 parcelFiles[i] = ParcelFileDescriptor.fromFd(fileInfos[i
].mFd); | |
340 } catch (IOException e) { | |
341 Log.e(TAG, | |
342 "Invalid FD provided for process connection, abo
rting connection.", | |
343 e); | |
344 return; | |
345 } | |
346 | |
347 } | |
348 bundle.putParcelable(fdName, parcelFiles[i]); | |
349 bundle.putInt(idName, fileInfos[i].mId); | |
350 } | |
351 // Add the CPU properties now. | 323 // Add the CPU properties now. |
352 bundle.putInt(EXTRA_CPU_COUNT, CpuFeatures.getCount()); | 324 bundle.putInt(EXTRA_CPU_COUNT, CpuFeatures.getCount()); |
353 bundle.putLong(EXTRA_CPU_FEATURES, CpuFeatures.getMask()); | 325 bundle.putLong(EXTRA_CPU_FEATURES, CpuFeatures.getMask()); |
354 | 326 |
355 bundle.putBundle(Linker.EXTRA_LINKER_SHARED_RELROS, | 327 bundle.putBundle(Linker.EXTRA_LINKER_SHARED_RELROS, |
356 mConnectionParams.mSharedRelros); | 328 mConnectionParams.mSharedRelros); |
357 | 329 |
358 try { | 330 try { |
359 mPid = mService.setupConnection(bundle, mConnectionParams.mCallb
ack); | 331 mPid = mService.setupConnection(bundle, mConnectionParams.mCallb
ack); |
360 assert mPid != 0 : "Child service claims to be run by a process
of pid=0."; | 332 assert mPid != 0 : "Child service claims to be run by a process
of pid=0."; |
361 } catch (android.os.RemoteException re) { | 333 } catch (android.os.RemoteException re) { |
362 Log.e(TAG, "Failed to setup connection.", re); | 334 Log.e(TAG, "Failed to setup connection.", re); |
363 } | 335 } |
364 // We proactively close the FDs rather than wait for GC & finalizer. | 336 // We proactively close the FDs rather than wait for GC & finalizer. |
365 try { | 337 try { |
366 for (ParcelFileDescriptor parcelFile : parcelFiles) { | 338 for (FileDescriptorInfo fileInfo : mConnectionParams.mFilesToBeM
apped) { |
367 if (parcelFile != null) parcelFile.close(); | 339 fileInfo.mFd.close(); |
368 } | 340 } |
369 } catch (IOException ioe) { | 341 } catch (IOException ioe) { |
370 Log.w(TAG, "Failed to close FD.", ioe); | 342 Log.w(TAG, "Failed to close FD.", ioe); |
371 } | 343 } |
372 mConnectionParams = null; | 344 mConnectionParams = null; |
373 | 345 |
374 if (mConnectionCallback != null) { | 346 if (mConnectionCallback != null) { |
375 mConnectionCallback.onConnected(mPid); | 347 mConnectionCallback.onConnected(mPid); |
376 } | 348 } |
377 mConnectionCallback = null; | 349 mConnectionCallback = null; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 return true; | 441 return true; |
470 } | 442 } |
471 return false; | 443 return false; |
472 } | 444 } |
473 | 445 |
474 @VisibleForTesting | 446 @VisibleForTesting |
475 public boolean isConnected() { | 447 public boolean isConnected() { |
476 return mService != null; | 448 return mService != null; |
477 } | 449 } |
478 } | 450 } |
OLD | NEW |