| 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 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 return new ChromiumLinkerParams(sLinkerLoadAddress, | 398 return new ChromiumLinkerParams(sLinkerLoadAddress, |
| 399 waitForSharedRelros, | 399 waitForSharedRelros, |
| 400 linker.getTestRunnerClassNameForTest
ing(), | 400 linker.getTestRunnerClassNameForTest
ing(), |
| 401 linker.getImplementationForTesting()
); | 401 linker.getImplementationForTesting()
); |
| 402 } else { | 402 } else { |
| 403 return new ChromiumLinkerParams(sLinkerLoadAddress, | 403 return new ChromiumLinkerParams(sLinkerLoadAddress, |
| 404 waitForSharedRelros); | 404 waitForSharedRelros); |
| 405 } | 405 } |
| 406 } | 406 } |
| 407 | 407 |
| 408 private static Bundle createCommonParamsBundle(ChildProcessCreationParams pa
rams) { |
| 409 Bundle commonParams = new Bundle(); |
| 410 commonParams.putParcelable( |
| 411 ChildProcessConstants.EXTRA_LINKER_PARAMS, getLinkerParamsForNew
Connection()); |
| 412 final boolean bindToCallerCheck = params == null ? false : params.getBin
dToCallerCheck(); |
| 413 commonParams.putBoolean(ChildProcessConstants.EXTRA_BIND_TO_CALLER, bind
ToCallerCheck); |
| 414 return commonParams; |
| 415 } |
| 416 |
| 408 private static ChildProcessConnection allocateBoundConnection(SpawnData spaw
nData, | 417 private static ChildProcessConnection allocateBoundConnection(SpawnData spaw
nData, |
| 409 boolean alwaysInForeground, ChildProcessConnection.StartCallback sta
rtCallback) { | 418 boolean alwaysInForeground, ChildProcessConnection.StartCallback sta
rtCallback) { |
| 410 final Context context = spawnData.context(); | 419 final Context context = spawnData.context(); |
| 411 final boolean inSandbox = spawnData.inSandbox(); | 420 final boolean inSandbox = spawnData.inSandbox(); |
| 412 final ChildProcessCreationParams creationParams = spawnData.getCreationP
arams(); | 421 final ChildProcessCreationParams creationParams = spawnData.getCreationP
arams(); |
| 413 Bundle commonParams = new Bundle(); | 422 ChildProcessConnection connection = allocateConnection(spawnData, |
| 414 commonParams.putParcelable( | 423 createCommonParamsBundle(spawnData.getCreationParams()), alwaysI
nForeground); |
| 415 ChildProcessConstants.EXTRA_LINKER_PARAMS, getLinkerParamsForNew
Connection()); | |
| 416 ChildProcessConnection connection = | |
| 417 allocateConnection(spawnData, commonParams, alwaysInForeground); | |
| 418 if (connection != null) { | 424 if (connection != null) { |
| 419 connection.start(startCallback); | 425 connection.start(startCallback); |
| 420 | 426 |
| 421 String packageName = creationParams != null ? creationParams.getPack
ageName() | 427 String packageName = creationParams != null ? creationParams.getPack
ageName() |
| 422 : context.getPackageName
(); | 428 : context.getPackageName
(); |
| 423 if (inSandbox | 429 if (inSandbox |
| 424 && !getConnectionAllocator(packageName, inSandbox) | 430 && !getConnectionAllocator(packageName, inSandbox) |
| 425 .isFreeConnectionAvailable()) { | 431 .isFreeConnectionAvailable()) { |
| 426 // Proactively releases all the moderate bindings once all the s
andboxed services | 432 // Proactively releases all the moderate bindings once all the s
andboxed services |
| 427 // are allocated, which will be very likely to have some of them
killed by OOM | 433 // are allocated, which will be very likely to have some of them
killed by OOM |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 // When launching these renderer processes, {@link ChildProcessC
onnectionImpl} | 663 // When launching these renderer processes, {@link ChildProcessC
onnectionImpl} |
| 658 // requires the package name of the application which holds the
renderer process. | 664 // requires the package name of the application which holds the
renderer process. |
| 659 // Therefore, the package name in ChildProcessCreationParams cou
ld be the package | 665 // Therefore, the package name in ChildProcessCreationParams cou
ld be the package |
| 660 // name of WebViews, WebAPKs, or Chrome, depending on the host a
pplication. | 666 // name of WebViews, WebAPKs, or Chrome, depending on the host a
pplication. |
| 661 // Except renderer process, all other child processes should use
Chrome's package | 667 // Except renderer process, all other child processes should use
Chrome's package |
| 662 // name. In WebAPK, ChildProcessCreationParams are initialized w
ith WebAPK's | 668 // name. In WebAPK, ChildProcessCreationParams are initialized w
ith WebAPK's |
| 663 // package name. Make a copy of the WebAPK's params, but replace
the package with | 669 // package name. Make a copy of the WebAPK's params, but replace
the package with |
| 664 // Chrome's package to use when initializing a non-renderer proc
esses. | 670 // Chrome's package to use when initializing a non-renderer proc
esses. |
| 665 // TODO(boliu): Should fold into |paramId|. Investigate why this
is needed. | 671 // TODO(boliu): Should fold into |paramId|. Investigate why this
is needed. |
| 666 params = new ChildProcessCreationParams(context.getPackageName()
, | 672 params = new ChildProcessCreationParams(context.getPackageName()
, |
| 667 params.getIsExternalService(), params.getLibraryProcessT
ype()); | 673 params.getIsExternalService(), params.getLibraryProcessT
ype(), |
| 674 params.getBindToCallerCheck()); |
| 668 } | 675 } |
| 669 if (ContentSwitches.SWITCH_GPU_PROCESS.equals(processType)) { | 676 if (ContentSwitches.SWITCH_GPU_PROCESS.equals(processType)) { |
| 670 callbackType = CALLBACK_FOR_GPU_PROCESS; | 677 callbackType = CALLBACK_FOR_GPU_PROCESS; |
| 671 inSandbox = false; | 678 inSandbox = false; |
| 672 } else if (ContentSwitches.SWITCH_UTILITY_PROCESS.equals(processType
)) { | 679 } else if (ContentSwitches.SWITCH_UTILITY_PROCESS.equals(processType
)) { |
| 673 // We only support sandboxed right now. | 680 // We only support sandboxed right now. |
| 674 callbackType = CALLBACK_FOR_UTILITY_PROCESS; | 681 callbackType = CALLBACK_FOR_UTILITY_PROCESS; |
| 675 } else { | 682 } else { |
| 676 assert false; | 683 assert false; |
| 677 } | 684 } |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 882 static ChildProcessConnection allocateBoundConnectionForTesting(Context cont
ext, | 889 static ChildProcessConnection allocateBoundConnectionForTesting(Context cont
ext, |
| 883 ChildProcessCreationParams creationParams) { | 890 ChildProcessCreationParams creationParams) { |
| 884 return allocateBoundConnection( | 891 return allocateBoundConnection( |
| 885 new SpawnData(false /* forWarmUp */, context, null /* commandLin
e */, | 892 new SpawnData(false /* forWarmUp */, context, null /* commandLin
e */, |
| 886 0 /* childProcessId */, null /* filesToBeMapped */, 0 /*
clientContext */, | 893 0 /* childProcessId */, null /* filesToBeMapped */, 0 /*
clientContext */, |
| 887 CALLBACK_FOR_RENDERER_PROCESS, true /* inSandbox */, cre
ationParams), | 894 CALLBACK_FOR_RENDERER_PROCESS, true /* inSandbox */, cre
ationParams), |
| 888 false /* alwaysInForeground */, null); | 895 false /* alwaysInForeground */, null); |
| 889 } | 896 } |
| 890 | 897 |
| 891 @VisibleForTesting | 898 @VisibleForTesting |
| 892 static ChildProcessConnection allocateConnectionForTesting(Context context, | 899 static ChildProcessConnection allocateConnectionForTesting( |
| 893 ChildProcessCreationParams creationParams) { | 900 Context context, ChildProcessCreationParams creationParams) { |
| 894 Bundle commonParams = new Bundle(); | |
| 895 commonParams.putParcelable( | |
| 896 ChildProcessConstants.EXTRA_LINKER_PARAMS, getLinkerParamsForNew
Connection()); | |
| 897 return allocateConnection( | 901 return allocateConnection( |
| 898 new SpawnData(false /* forWarmUp */, context, null /* commandLin
e */, | 902 new SpawnData(false /* forWarmUp */, context, null /* commandLin
e */, |
| 899 0 /* childProcessId */, null /* filesToBeMapped */, 0 /*
clientContext */, | 903 0 /* childProcessId */, null /* filesToBeMapped */, 0 /*
clientContext */, |
| 900 CALLBACK_FOR_RENDERER_PROCESS, true /* inSandbox */, cre
ationParams), | 904 CALLBACK_FOR_RENDERER_PROCESS, true /* inSandbox */, cre
ationParams), |
| 901 commonParams, false); | 905 createCommonParamsBundle(creationParams), false); |
| 902 } | 906 } |
| 903 | 907 |
| 904 /** | 908 /** |
| 905 * Queue up a spawn requests for testing. | 909 * Queue up a spawn requests for testing. |
| 906 */ | 910 */ |
| 907 @VisibleForTesting | 911 @VisibleForTesting |
| 908 static void enqueuePendingSpawnForTesting(Context context, String[] commandL
ine, | 912 static void enqueuePendingSpawnForTesting(Context context, String[] commandL
ine, |
| 909 ChildProcessCreationParams creationParams, boolean inSandbox) { | 913 ChildProcessCreationParams creationParams, boolean inSandbox) { |
| 910 String packageName = creationParams != null ? creationParams.getPackageN
ame() | 914 String packageName = creationParams != null ? creationParams.getPackageN
ame() |
| 911 : context.getPackageName(); | 915 : context.getPackageName(); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 971 | 975 |
| 972 return true; | 976 return true; |
| 973 } | 977 } |
| 974 | 978 |
| 975 private static native void nativeOnChildProcessStarted(long clientContext, i
nt pid); | 979 private static native void nativeOnChildProcessStarted(long clientContext, i
nt pid); |
| 976 private static native void nativeCompleteScopedSurfaceRequest( | 980 private static native void nativeCompleteScopedSurfaceRequest( |
| 977 UnguessableToken requestToken, Surface surface); | 981 UnguessableToken requestToken, Surface surface); |
| 978 private static native boolean nativeIsSingleProcess(); | 982 private static native boolean nativeIsSingleProcess(); |
| 979 private static native Surface nativeGetViewSurface(int surfaceId); | 983 private static native Surface nativeGetViewSurface(int surfaceId); |
| 980 } | 984 } |
| OLD | NEW |