OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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.pm.ApplicationInfo; | 9 import android.content.pm.ApplicationInfo; |
10 import android.content.pm.PackageManager; | 10 import android.content.pm.PackageManager; |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 return new ChromiumLinkerParams(sLinkerLoadAddress, | 397 return new ChromiumLinkerParams(sLinkerLoadAddress, |
398 waitForSharedRelros, | 398 waitForSharedRelros, |
399 linker.getTestRunnerClassNameForTest
ing(), | 399 linker.getTestRunnerClassNameForTest
ing(), |
400 linker.getImplementationForTesting()
); | 400 linker.getImplementationForTesting()
); |
401 } else { | 401 } else { |
402 return new ChromiumLinkerParams(sLinkerLoadAddress, | 402 return new ChromiumLinkerParams(sLinkerLoadAddress, |
403 waitForSharedRelros); | 403 waitForSharedRelros); |
404 } | 404 } |
405 } | 405 } |
406 | 406 |
| 407 private static Bundle createCommonParamsBundle(ChildProcessCreationParams pa
rams) { |
| 408 Bundle commonParams = new Bundle(); |
| 409 commonParams.putParcelable( |
| 410 ChildProcessConstants.EXTRA_LINKER_PARAMS, getLinkerParamsForNew
Connection()); |
| 411 final boolean bindToCallerCheck = params == null ? false : params.getBin
dToCallerCheck(); |
| 412 commonParams.putBoolean(ChildProcessConstants.EXTRA_BIND_TO_CALLER, bind
ToCallerCheck); |
| 413 return commonParams; |
| 414 } |
| 415 |
407 private static ChildProcessConnection allocateBoundConnection( | 416 private static ChildProcessConnection allocateBoundConnection( |
408 SpawnData spawnData, ChildProcessConnection.StartCallback startCallb
ack) { | 417 SpawnData spawnData, ChildProcessConnection.StartCallback startCallb
ack) { |
409 final Context context = spawnData.getContext(); | 418 final Context context = spawnData.getContext(); |
410 final boolean inSandbox = spawnData.isInSandbox(); | 419 final boolean inSandbox = spawnData.isInSandbox(); |
411 final ChildProcessCreationParams creationParams = spawnData.getCreationP
arams(); | 420 final ChildProcessCreationParams creationParams = spawnData.getCreationP
arams(); |
412 Bundle commonParams = new Bundle(); | 421 ChildProcessConnection connection = allocateConnection( |
413 commonParams.putParcelable( | 422 spawnData, createCommonParamsBundle(spawnData.getCreationParams(
))); |
414 ChildProcessConstants.EXTRA_LINKER_PARAMS, getLinkerParamsForNew
Connection()); | |
415 ChildProcessConnection connection = allocateConnection(spawnData, common
Params); | |
416 if (connection != null) { | 423 if (connection != null) { |
417 connection.start(startCallback); | 424 connection.start(startCallback); |
418 | 425 |
419 String packageName = creationParams != null ? creationParams.getPack
ageName() | 426 String packageName = creationParams != null ? creationParams.getPack
ageName() |
420 : context.getPackageName
(); | 427 : context.getPackageName
(); |
421 if (inSandbox | 428 if (inSandbox |
422 && !getConnectionAllocator(packageName, inSandbox) | 429 && !getConnectionAllocator(packageName, inSandbox) |
423 .isFreeConnectionAvailable()) { | 430 .isFreeConnectionAvailable()) { |
424 // Proactively releases all the moderate bindings once all the s
andboxed services | 431 // Proactively releases all the moderate bindings once all the s
andboxed services |
425 // are allocated, which will be very likely to have some of them
killed by OOM | 432 // are allocated, which will be very likely to have some of them
killed by OOM |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 // When launching these renderer processes, {@link ChildProcessC
onnectionImpl} | 631 // When launching these renderer processes, {@link ChildProcessC
onnectionImpl} |
625 // requires the package name of the application which holds the
renderer process. | 632 // requires the package name of the application which holds the
renderer process. |
626 // Therefore, the package name in ChildProcessCreationParams cou
ld be the package | 633 // Therefore, the package name in ChildProcessCreationParams cou
ld be the package |
627 // name of WebViews, WebAPKs, or Chrome, depending on the host a
pplication. | 634 // name of WebViews, WebAPKs, or Chrome, depending on the host a
pplication. |
628 // Except renderer process, all other child processes should use
Chrome's package | 635 // Except renderer process, all other child processes should use
Chrome's package |
629 // name. In WebAPK, ChildProcessCreationParams are initialized w
ith WebAPK's | 636 // name. In WebAPK, ChildProcessCreationParams are initialized w
ith WebAPK's |
630 // package name. Make a copy of the WebAPK's params, but replace
the package with | 637 // package name. Make a copy of the WebAPK's params, but replace
the package with |
631 // Chrome's package to use when initializing a non-renderer proc
esses. | 638 // Chrome's package to use when initializing a non-renderer proc
esses. |
632 // TODO(boliu): Should fold into |paramId|. Investigate why this
is needed. | 639 // TODO(boliu): Should fold into |paramId|. Investigate why this
is needed. |
633 params = new ChildProcessCreationParams(context.getPackageName()
, | 640 params = new ChildProcessCreationParams(context.getPackageName()
, |
634 params.getIsExternalService(), params.getLibraryProcessT
ype()); | 641 params.getIsExternalService(), params.getLibraryProcessT
ype(), |
| 642 params.getBindToCallerCheck()); |
635 } | 643 } |
636 if (ContentSwitches.SWITCH_GPU_PROCESS.equals(processType)) { | 644 if (ContentSwitches.SWITCH_GPU_PROCESS.equals(processType)) { |
637 childProcessCallback = new GpuProcessCallback(); | 645 childProcessCallback = new GpuProcessCallback(); |
638 inSandbox = false; | 646 inSandbox = false; |
639 alwaysInForeground = true; | 647 alwaysInForeground = true; |
640 } else { | 648 } else { |
641 // We only support sandboxed utility processes now. | 649 // We only support sandboxed utility processes now. |
642 assert ContentSwitches.SWITCH_UTILITY_PROCESS.equals(processType
); | 650 assert ContentSwitches.SWITCH_UTILITY_PROCESS.equals(processType
); |
643 } | 651 } |
644 } | 652 } |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
793 ChildProcessCreationParams creationParams) { | 801 ChildProcessCreationParams creationParams) { |
794 return allocateBoundConnection( | 802 return allocateBoundConnection( |
795 new SpawnData(false /* forWarmUp */, context, null /* commandLin
e */, | 803 new SpawnData(false /* forWarmUp */, context, null /* commandLin
e */, |
796 0 /* childProcessId */, null /* filesToBeMapped */, | 804 0 /* childProcessId */, null /* filesToBeMapped */, |
797 null /* LaunchCallback */, null /* childProcessCallback
*/, | 805 null /* LaunchCallback */, null /* childProcessCallback
*/, |
798 true /* inSandbox */, false /* alwaysInForeground */, cr
eationParams), | 806 true /* inSandbox */, false /* alwaysInForeground */, cr
eationParams), |
799 null /* startCallback */); | 807 null /* startCallback */); |
800 } | 808 } |
801 | 809 |
802 @VisibleForTesting | 810 @VisibleForTesting |
803 static ChildProcessConnection allocateConnectionForTesting(Context context, | 811 static ChildProcessConnection allocateConnectionForTesting( |
804 ChildProcessCreationParams creationParams) { | 812 Context context, ChildProcessCreationParams creationParams) { |
805 Bundle commonParams = new Bundle(); | |
806 commonParams.putParcelable( | |
807 ChildProcessConstants.EXTRA_LINKER_PARAMS, getLinkerParamsForNew
Connection()); | |
808 return allocateConnection( | 813 return allocateConnection( |
809 new SpawnData(false /* forWarmUp */, context, null /* commandLin
e */, | 814 new SpawnData(false /* forWarmUp */, context, null /* commandLin
e */, |
810 0 /* childProcessId */, null /* filesToBeMapped */, | 815 0 /* childProcessId */, null /* filesToBeMapped */, |
811 null /* launchCallback */, null /* childProcessCallback
*/, | 816 null /* launchCallback */, null /* childProcessCallback
*/, |
812 true /* inSandbox */, false /* alwaysInForeground */, cr
eationParams), | 817 true /* inSandbox */, false /* alwaysInForeground */, cr
eationParams), |
813 commonParams); | 818 createCommonParamsBundle(creationParams)); |
814 } | 819 } |
815 | 820 |
816 /** | 821 /** |
817 * Queue up a spawn requests for testing. | 822 * Queue up a spawn requests for testing. |
818 */ | 823 */ |
819 @VisibleForTesting | 824 @VisibleForTesting |
820 static void enqueuePendingSpawnForTesting(Context context, String[] commandL
ine, | 825 static void enqueuePendingSpawnForTesting(Context context, String[] commandL
ine, |
821 ChildProcessCreationParams creationParams, boolean inSandbox) { | 826 ChildProcessCreationParams creationParams, boolean inSandbox) { |
822 String packageName = creationParams != null ? creationParams.getPackageN
ame() | 827 String packageName = creationParams != null ? creationParams.getPackageN
ame() |
823 : context.getPackageName(); | 828 : context.getPackageName(); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
878 | 883 |
879 try { | 884 try { |
880 ((ChildProcessConnectionImpl) sServiceMap.get(pid)).crashServiceForT
esting(); | 885 ((ChildProcessConnectionImpl) sServiceMap.get(pid)).crashServiceForT
esting(); |
881 } catch (RemoteException ex) { | 886 } catch (RemoteException ex) { |
882 return false; | 887 return false; |
883 } | 888 } |
884 | 889 |
885 return true; | 890 return true; |
886 } | 891 } |
887 } | 892 } |
OLD | NEW |