| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 * Tests cleanup for a connection that terminates before setup. | 95 * Tests cleanup for a connection that terminates before setup. |
| 96 */ | 96 */ |
| 97 @Test | 97 @Test |
| 98 @MediumTest | 98 @MediumTest |
| 99 @Feature({"ProcessManagement"}) | 99 @Feature({"ProcessManagement"}) |
| 100 public void testServiceCrashedBeforeSetup() throws RemoteException { | 100 public void testServiceCrashedBeforeSetup() throws RemoteException { |
| 101 Assert.assertEquals(0, allocatedChromeSandboxedConnectionsCount()); | 101 Assert.assertEquals(0, allocatedChromeSandboxedConnectionsCount()); |
| 102 Assert.assertEquals(0, ChildProcessLauncher.connectedServicesCountForTes
ting()); | 102 Assert.assertEquals(0, ChildProcessLauncher.connectedServicesCountForTes
ting()); |
| 103 | 103 |
| 104 // Start and connect to a new service. | 104 // Start and connect to a new service. |
| 105 final ChildProcessConnectionImpl connection = startConnection(); | 105 final BaseChildProcessConnection connection = startConnection(); |
| 106 Assert.assertEquals(1, allocatedChromeSandboxedConnectionsCount()); | 106 Assert.assertEquals(1, allocatedChromeSandboxedConnectionsCount()); |
| 107 | 107 |
| 108 // Verify that the service is not yet set up. | 108 // Verify that the service is not yet set up. |
| 109 Assert.assertEquals(0, connection.getPid()); | 109 Assert.assertEquals(0, connection.getPid()); |
| 110 Assert.assertEquals(0, ChildProcessLauncher.connectedServicesCountForTes
ting()); | 110 Assert.assertEquals(0, ChildProcessLauncher.connectedServicesCountForTes
ting()); |
| 111 | 111 |
| 112 // Crash the service. | 112 // Crash the service. |
| 113 connection.crashServiceForTesting(); | 113 connection.crashServiceForTesting(); |
| 114 | 114 |
| 115 // Verify that the connection gets cleaned-up. | 115 // Verify that the connection gets cleaned-up. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 131 /** | 131 /** |
| 132 * Tests cleanup for a connection that terminates after setup. | 132 * Tests cleanup for a connection that terminates after setup. |
| 133 */ | 133 */ |
| 134 @Test | 134 @Test |
| 135 @MediumTest | 135 @MediumTest |
| 136 @Feature({"ProcessManagement"}) | 136 @Feature({"ProcessManagement"}) |
| 137 public void testServiceCrashedAfterSetup() throws RemoteException { | 137 public void testServiceCrashedAfterSetup() throws RemoteException { |
| 138 Assert.assertEquals(0, allocatedChromeSandboxedConnectionsCount()); | 138 Assert.assertEquals(0, allocatedChromeSandboxedConnectionsCount()); |
| 139 | 139 |
| 140 // Start and connect to a new service. | 140 // Start and connect to a new service. |
| 141 final ChildProcessConnectionImpl connection = startConnection(); | 141 final BaseChildProcessConnection connection = startConnection(); |
| 142 Assert.assertEquals(1, allocatedChromeSandboxedConnectionsCount()); | 142 Assert.assertEquals(1, allocatedChromeSandboxedConnectionsCount()); |
| 143 | 143 |
| 144 // Initiate the connection setup. | 144 // Initiate the connection setup. |
| 145 triggerConnectionSetup(connection); | 145 triggerConnectionSetup(connection); |
| 146 | 146 |
| 147 // Verify that the connection completes the setup. | 147 // Verify that the connection completes the setup. |
| 148 CriteriaHelper.pollInstrumentationThread(Criteria.equals(1, new Callable
<Integer>() { | 148 CriteriaHelper.pollInstrumentationThread(Criteria.equals(1, new Callable
<Integer>() { |
| 149 @Override | 149 @Override |
| 150 public Integer call() { | 150 public Integer call() { |
| 151 return ChildProcessLauncher.connectedServicesCountForTesting(); | 151 return ChildProcessLauncher.connectedServicesCountForTesting(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 * Tests spawning a pending process from queue. | 186 * Tests spawning a pending process from queue. |
| 187 */ | 187 */ |
| 188 @Test | 188 @Test |
| 189 @MediumTest | 189 @MediumTest |
| 190 @Feature({"ProcessManagement"}) | 190 @Feature({"ProcessManagement"}) |
| 191 public void testPendingSpawnQueue() throws RemoteException { | 191 public void testPendingSpawnQueue() throws RemoteException { |
| 192 final Context appContext = InstrumentationRegistry.getInstrumentation().
getTargetContext(); | 192 final Context appContext = InstrumentationRegistry.getInstrumentation().
getTargetContext(); |
| 193 Assert.assertEquals(0, allocatedChromeSandboxedConnectionsCount()); | 193 Assert.assertEquals(0, allocatedChromeSandboxedConnectionsCount()); |
| 194 | 194 |
| 195 // Start and connect to a new service. | 195 // Start and connect to a new service. |
| 196 final ChildProcessConnectionImpl connection = startConnection(); | 196 final BaseChildProcessConnection connection = startConnection(); |
| 197 Assert.assertEquals(1, allocatedChromeSandboxedConnectionsCount()); | 197 Assert.assertEquals(1, allocatedChromeSandboxedConnectionsCount()); |
| 198 | 198 |
| 199 // Queue up a new spawn request. There is no way to kill the pending con
nection, leak it | 199 // Queue up a new spawn request. There is no way to kill the pending con
nection, leak it |
| 200 // until the browser restart. | 200 // until the browser restart. |
| 201 final String packageName = appContext.getPackageName(); | 201 final String packageName = appContext.getPackageName(); |
| 202 final boolean inSandbox = true; | 202 final boolean inSandbox = true; |
| 203 enqueuePendingSpawnForTesting(appContext, sProcessWaitArguments, | 203 enqueuePendingSpawnForTesting(appContext, sProcessWaitArguments, |
| 204 getDefaultChildProcessCreationParams(packageName), inSandbox); | 204 getDefaultChildProcessCreationParams(packageName), inSandbox); |
| 205 Assert.assertEquals(1, pendingSpawnsCountForTesting(appContext, packageN
ame, inSandbox)); | 205 Assert.assertEquals(1, pendingSpawnsCountForTesting(appContext, packageN
ame, inSandbox)); |
| 206 | 206 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 @ChildProcessAllocatorSettings( | 262 @ChildProcessAllocatorSettings( |
| 263 sandboxedServiceCount = 4, sandboxedServiceName = DEFAULT_SANDBOXED_
PROCESS_SERVICE) | 263 sandboxedServiceCount = 4, sandboxedServiceName = DEFAULT_SANDBOXED_
PROCESS_SERVICE) |
| 264 public void testServiceNumberAllocation() { | 264 public void testServiceNumberAllocation() { |
| 265 Context appContext = InstrumentationRegistry.getInstrumentation().getTar
getContext(); | 265 Context appContext = InstrumentationRegistry.getInstrumentation().getTar
getContext(); |
| 266 Assert.assertEquals(0, | 266 Assert.assertEquals(0, |
| 267 allocatedSandboxedConnectionsCountForTesting( | 267 allocatedSandboxedConnectionsCountForTesting( |
| 268 appContext, EXTERNAL_APK_PACKAGE_NAME)); | 268 appContext, EXTERNAL_APK_PACKAGE_NAME)); |
| 269 Assert.assertEquals(0, allocatedChromeSandboxedConnectionsCount()); | 269 Assert.assertEquals(0, allocatedChromeSandboxedConnectionsCount()); |
| 270 | 270 |
| 271 // Start and connect to a new service of an external APK. | 271 // Start and connect to a new service of an external APK. |
| 272 ChildProcessConnectionImpl externalApkConnection = | 272 BaseChildProcessConnection externalApkConnection = |
| 273 allocateConnection(EXTERNAL_APK_PACKAGE_NAME); | 273 allocateConnection(EXTERNAL_APK_PACKAGE_NAME); |
| 274 // Start and connect to a new service for a regular tab. | 274 // Start and connect to a new service for a regular tab. |
| 275 ChildProcessConnectionImpl tabConnection = allocateConnection(appContext
.getPackageName()); | 275 BaseChildProcessConnection tabConnection = allocateConnection(appContext
.getPackageName()); |
| 276 | 276 |
| 277 // Verify that one connection is allocated for an external APK and a reg
ular tab | 277 // Verify that one connection is allocated for an external APK and a reg
ular tab |
| 278 // respectively. | 278 // respectively. |
| 279 Assert.assertEquals(1, | 279 Assert.assertEquals(1, |
| 280 allocatedSandboxedConnectionsCountForTesting( | 280 allocatedSandboxedConnectionsCountForTesting( |
| 281 appContext, EXTERNAL_APK_PACKAGE_NAME)); | 281 appContext, EXTERNAL_APK_PACKAGE_NAME)); |
| 282 Assert.assertEquals(1, allocatedChromeSandboxedConnectionsCount()); | 282 Assert.assertEquals(1, allocatedChromeSandboxedConnectionsCount()); |
| 283 | 283 |
| 284 // Verify that connections allocated for an external APK and the regular
tab are from | 284 // Verify that connections allocated for an external APK and the regular
tab are from |
| 285 // different ChildConnectionAllocators, since both ChildConnectionAlloca
tors start | 285 // different ChildConnectionAllocators, since both ChildConnectionAlloca
tors start |
| (...skipping 12 matching lines...) Expand all Loading... |
| 298 @Feature({"ProcessManagement"}) | 298 @Feature({"ProcessManagement"}) |
| 299 @ChildProcessAllocatorSettings( | 299 @ChildProcessAllocatorSettings( |
| 300 sandboxedServiceCount = 1, sandboxedServiceName = DEFAULT_SANDBOXED_
PROCESS_SERVICE) | 300 sandboxedServiceCount = 1, sandboxedServiceName = DEFAULT_SANDBOXED_
PROCESS_SERVICE) |
| 301 public void testExceedMaximumConnectionNumber() { | 301 public void testExceedMaximumConnectionNumber() { |
| 302 Context appContext = InstrumentationRegistry.getInstrumentation().getTar
getContext(); | 302 Context appContext = InstrumentationRegistry.getInstrumentation().getTar
getContext(); |
| 303 Assert.assertEquals(0, | 303 Assert.assertEquals(0, |
| 304 allocatedSandboxedConnectionsCountForTesting( | 304 allocatedSandboxedConnectionsCountForTesting( |
| 305 appContext, EXTERNAL_APK_PACKAGE_NAME)); | 305 appContext, EXTERNAL_APK_PACKAGE_NAME)); |
| 306 | 306 |
| 307 // Setup a connection for an external APK to reach the maximum allowed c
onnection number. | 307 // Setup a connection for an external APK to reach the maximum allowed c
onnection number. |
| 308 ChildProcessConnectionImpl externalApkConnection = | 308 BaseChildProcessConnection externalApkConnection = |
| 309 allocateConnection(EXTERNAL_APK_PACKAGE_NAME); | 309 allocateConnection(EXTERNAL_APK_PACKAGE_NAME); |
| 310 Assert.assertNotNull(externalApkConnection); | 310 Assert.assertNotNull(externalApkConnection); |
| 311 | 311 |
| 312 // Verify that there isn't any connection available for the external APK
. | 312 // Verify that there isn't any connection available for the external APK
. |
| 313 ChildProcessConnectionImpl exceedNumberExternalApkConnection = | 313 BaseChildProcessConnection exceedNumberExternalApkConnection = |
| 314 allocateConnection(EXTERNAL_APK_PACKAGE_NAME); | 314 allocateConnection(EXTERNAL_APK_PACKAGE_NAME); |
| 315 Assert.assertNull(exceedNumberExternalApkConnection); | 315 Assert.assertNull(exceedNumberExternalApkConnection); |
| 316 | 316 |
| 317 // Verify that we can still allocate connection for a regular tab. | 317 // Verify that we can still allocate connection for a regular tab. |
| 318 ChildProcessConnectionImpl tabConnection = allocateConnection(appContext
.getPackageName()); | 318 BaseChildProcessConnection tabConnection = allocateConnection(appContext
.getPackageName()); |
| 319 Assert.assertNotNull(tabConnection); | 319 Assert.assertNotNull(tabConnection); |
| 320 } | 320 } |
| 321 | 321 |
| 322 /** | 322 /** |
| 323 * Tests binding to the same sandboxed service process from multiple process
es in the | 323 * Tests binding to the same sandboxed service process from multiple process
es in the |
| 324 * same package. This uses the ChildProcessLauncherTestHelperService declare
d in | 324 * same package. This uses the ChildProcessLauncherTestHelperService declare
d in |
| 325 * ContentShell.apk as a separate android:process to bind the first (slot 0)
service. The | 325 * ContentShell.apk as a separate android:process to bind the first (slot 0)
service. The |
| 326 * instrumentation test then tries to bind the same slot, which fails, so th
e | 326 * instrumentation test then tries to bind the same slot, which fails, so th
e |
| 327 * ChildProcessLauncher retries on a new connection. | 327 * ChildProcessLauncher retries on a new connection. |
| 328 */ | 328 */ |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 "Connection slot from helper service is not 0", 0, replyHandler.
mMessage.arg2); | 398 "Connection slot from helper service is not 0", 0, replyHandler.
mMessage.arg2); |
| 399 | 399 |
| 400 final int helperConnPid = replyHandler.mMessage.arg1; | 400 final int helperConnPid = replyHandler.mMessage.arg1; |
| 401 Assert.assertTrue(helperConnPid > 0); | 401 Assert.assertTrue(helperConnPid > 0); |
| 402 | 402 |
| 403 // Launch a service from this process. Since slot 0 is already bound by
the Helper, it | 403 // Launch a service from this process. Since slot 0 is already bound by
the Helper, it |
| 404 // will fail to start and the ChildProcessLauncher will retry. | 404 // will fail to start and the ChildProcessLauncher will retry. |
| 405 final ChildProcessCreationParams creationParams = new ChildProcessCreati
onParams( | 405 final ChildProcessCreationParams creationParams = new ChildProcessCreati
onParams( |
| 406 context.getPackageName(), false /* isExternalService */, | 406 context.getPackageName(), false /* isExternalService */, |
| 407 LibraryProcessType.PROCESS_CHILD, true /* bindToCallerCheck */); | 407 LibraryProcessType.PROCESS_CHILD, true /* bindToCallerCheck */); |
| 408 final ChildProcessConnection conn = | 408 final BaseChildProcessConnection conn = |
| 409 ChildProcessLauncherTestHelperService.startInternalForTesting( | 409 ChildProcessLauncherTestHelperService.startInternalForTesting( |
| 410 context, sProcessWaitArguments, new FileDescriptorInfo[0
], creationParams); | 410 context, sProcessWaitArguments, new FileDescriptorInfo[0
], creationParams); |
| 411 | 411 |
| 412 CriteriaHelper.pollInstrumentationThread( | 412 CriteriaHelper.pollInstrumentationThread( |
| 413 new Criteria("Failed waiting for instrumentation-bound service")
{ | 413 new Criteria("Failed waiting for instrumentation-bound service")
{ |
| 414 @Override | 414 @Override |
| 415 public boolean isSatisfied() { | 415 public boolean isSatisfied() { |
| 416 return conn.getService() != null; | 416 return conn.getService() != null; |
| 417 } | 417 } |
| 418 }); | 418 }); |
| 419 | 419 |
| 420 Assert.assertEquals(0, conn.getServiceNumber()); | 420 Assert.assertEquals(0, conn.getServiceNumber()); |
| 421 | 421 |
| 422 final ChildProcessConnection[] sandboxedConnections = | 422 final BaseChildProcessConnection[] sandboxedConnections = |
| 423 getSandboxedConnectionArrayForTesting(context, context.getPackag
eName()); | 423 getSandboxedConnectionArrayForTesting(context, context.getPackag
eName()); |
| 424 | 424 |
| 425 // Wait for the retry to succeed. | 425 // Wait for the retry to succeed. |
| 426 CriteriaHelper.pollInstrumentationThread( | 426 CriteriaHelper.pollInstrumentationThread( |
| 427 new Criteria("Failed waiting for both child process services") { | 427 new Criteria("Failed waiting for both child process services") { |
| 428 @Override | 428 @Override |
| 429 public boolean isSatisfied() { | 429 public boolean isSatisfied() { |
| 430 boolean allChildrenConnected = true; | 430 boolean allChildrenConnected = true; |
| 431 for (int i = 0; i <= 1; ++i) { | 431 for (int i = 0; i <= 1; ++i) { |
| 432 ChildProcessConnection conn = sandboxedConnections[i
]; | 432 BaseChildProcessConnection conn = sandboxedConnectio
ns[i]; |
| 433 allChildrenConnected &= conn != null && conn.getServ
ice() != null; | 433 allChildrenConnected &= conn != null && conn.getServ
ice() != null; |
| 434 } | 434 } |
| 435 return allChildrenConnected; | 435 return allChildrenConnected; |
| 436 } | 436 } |
| 437 }); | 437 }); |
| 438 | 438 |
| 439 // Check that only two connections are created. | 439 // Check that only two connections are created. |
| 440 for (int i = 0; i < sandboxedConnections.length; ++i) { | 440 for (int i = 0; i < sandboxedConnections.length; ++i) { |
| 441 ChildProcessConnection sandboxedConn = sandboxedConnections[i]; | 441 BaseChildProcessConnection sandboxedConn = sandboxedConnections[i]; |
| 442 if (i <= 1) { | 442 if (i <= 1) { |
| 443 Assert.assertNotNull(sandboxedConn); | 443 Assert.assertNotNull(sandboxedConn); |
| 444 Assert.assertNotNull(sandboxedConn.getService()); | 444 Assert.assertNotNull(sandboxedConn.getService()); |
| 445 } else { | 445 } else { |
| 446 Assert.assertNull(sandboxedConn); | 446 Assert.assertNull(sandboxedConn); |
| 447 } | 447 } |
| 448 } | 448 } |
| 449 | 449 |
| 450 Assert.assertTrue(conn == sandboxedConnections[0]); | 450 Assert.assertTrue(conn == sandboxedConnections[0]); |
| 451 final ChildProcessConnection retryConn = sandboxedConnections[1]; | 451 final BaseChildProcessConnection retryConn = sandboxedConnections[1]; |
| 452 | 452 |
| 453 Assert.assertFalse(conn == retryConn); | 453 Assert.assertFalse(conn == retryConn); |
| 454 | 454 |
| 455 Assert.assertEquals(0, conn.getServiceNumber()); | 455 Assert.assertEquals(0, conn.getServiceNumber()); |
| 456 Assert.assertEquals(0, conn.getPid()); | 456 Assert.assertEquals(0, conn.getPid()); |
| 457 Assert.assertFalse(conn.getService().bindToCaller()); | 457 Assert.assertFalse(conn.getService().bindToCaller()); |
| 458 | 458 |
| 459 Assert.assertEquals(1, retryConn.getServiceNumber()); | 459 Assert.assertEquals(1, retryConn.getServiceNumber()); |
| 460 CriteriaHelper.pollInstrumentationThread( | 460 CriteriaHelper.pollInstrumentationThread( |
| 461 new Criteria("Failed waiting retry connection to get pid") { | 461 new Criteria("Failed waiting retry connection to get pid") { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 481 @MediumTest | 481 @MediumTest |
| 482 @Feature({"ProcessManagement"}) | 482 @Feature({"ProcessManagement"}) |
| 483 public void testWarmUp() { | 483 public void testWarmUp() { |
| 484 final Context context = InstrumentationRegistry.getInstrumentation().get
TargetContext(); | 484 final Context context = InstrumentationRegistry.getInstrumentation().get
TargetContext(); |
| 485 warmUpOnUiThreadBlocking(context); | 485 warmUpOnUiThreadBlocking(context); |
| 486 ChildProcessLauncherTestHelperService.runOnLauncherThreadBlocking(new Ru
nnable() { | 486 ChildProcessLauncherTestHelperService.runOnLauncherThreadBlocking(new Ru
nnable() { |
| 487 @Override | 487 @Override |
| 488 public void run() { | 488 public void run() { |
| 489 Assert.assertEquals(1, allocatedChromeSandboxedConnectionsCount(
)); | 489 Assert.assertEquals(1, allocatedChromeSandboxedConnectionsCount(
)); |
| 490 | 490 |
| 491 final ChildProcessConnection conn = | 491 final BaseChildProcessConnection conn = |
| 492 ChildProcessLauncherTestHelperService.startInternalForTe
sting( | 492 ChildProcessLauncherTestHelperService.startInternalForTe
sting( |
| 493 context, new String[0], new FileDescriptorInfo[0
], null); | 493 context, new String[0], new FileDescriptorInfo[0
], null); |
| 494 Assert.assertEquals( | 494 Assert.assertEquals( |
| 495 1, allocatedChromeSandboxedConnectionsCount()); // Used
warmup connection. | 495 1, allocatedChromeSandboxedConnectionsCount()); // Used
warmup connection. |
| 496 | 496 |
| 497 ChildProcessLauncher.stop(conn.getPid()); | 497 ChildProcessLauncher.stop(conn.getPid()); |
| 498 } | 498 } |
| 499 }); | 499 }); |
| 500 } | 500 } |
| 501 | 501 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 523 | 523 |
| 524 startRendererProcess( | 524 startRendererProcess( |
| 525 context, ChildProcessCreationParams.DEFAULT_ID, new File
DescriptorInfo[0]); | 525 context, ChildProcessCreationParams.DEFAULT_ID, new File
DescriptorInfo[0]); |
| 526 Assert.assertEquals(2, allocatedChromeSandboxedConnectionsCount(
)); // Warmup used. | 526 Assert.assertEquals(2, allocatedChromeSandboxedConnectionsCount(
)); // Warmup used. |
| 527 | 527 |
| 528 ChildProcessCreationParams.unregister(paramId); | 528 ChildProcessCreationParams.unregister(paramId); |
| 529 } | 529 } |
| 530 }); | 530 }); |
| 531 } | 531 } |
| 532 | 532 |
| 533 private ChildProcessConnectionImpl startConnection() { | 533 private BaseChildProcessConnection startConnection() { |
| 534 // Allocate a new connection. | 534 // Allocate a new connection. |
| 535 Context context = InstrumentationRegistry.getInstrumentation().getTarget
Context(); | 535 Context context = InstrumentationRegistry.getInstrumentation().getTarget
Context(); |
| 536 final ChildProcessConnectionImpl connection = | 536 final BaseChildProcessConnection connection = allocateBoundConnectionFor
Testing( |
| 537 (ChildProcessConnectionImpl) allocateBoundConnectionForTesting( | 537 context, getDefaultChildProcessCreationParams(context.getPackage
Name())); |
| 538 context, getDefaultChildProcessCreationParams(context.ge
tPackageName())); | |
| 539 | 538 |
| 540 // Wait for the service to connect. | 539 // Wait for the service to connect. |
| 541 CriteriaHelper.pollInstrumentationThread( | 540 CriteriaHelper.pollInstrumentationThread( |
| 542 new Criteria("The connection wasn't established.") { | 541 new Criteria("The connection wasn't established.") { |
| 543 @Override | 542 @Override |
| 544 public boolean isSatisfied() { | 543 public boolean isSatisfied() { |
| 545 return connection.isConnected(); | 544 return connection.isConnected(); |
| 546 } | 545 } |
| 547 }); | 546 }); |
| 548 return connection; | 547 return connection; |
| 549 } | 548 } |
| 550 | 549 |
| 551 private static void startRendererProcess( | 550 private static void startRendererProcess( |
| 552 Context context, int paramId, FileDescriptorInfo[] filesToMap) { | 551 Context context, int paramId, FileDescriptorInfo[] filesToMap) { |
| 553 assert LauncherThread.runningOnLauncherThread(); | 552 assert LauncherThread.runningOnLauncherThread(); |
| 554 ChildProcessLauncher.start(context, paramId, | 553 ChildProcessLauncher.start(context, paramId, |
| 555 new String[] {"--" + ContentSwitches.SWITCH_PROCESS_TYPE + "=" | 554 new String[] {"--" + ContentSwitches.SWITCH_PROCESS_TYPE + "=" |
| 556 + ContentSwitches.SWITCH_RENDERER_PROCESS}, | 555 + ContentSwitches.SWITCH_RENDERER_PROCESS}, |
| 557 0 /* childProcessId */, filesToMap, null /* launchCallback */); | 556 0 /* childProcessId */, filesToMap, null /* launchCallback */); |
| 558 } | 557 } |
| 559 | 558 |
| 560 private static ChildProcessConnection allocateBoundConnectionForTesting( | 559 private static BaseChildProcessConnection allocateBoundConnectionForTesting( |
| 561 final Context context, final ChildProcessCreationParams creationPara
ms) { | 560 final Context context, final ChildProcessCreationParams creationPara
ms) { |
| 562 return ChildProcessLauncherTestHelperService.runOnLauncherAndGetResult( | 561 return ChildProcessLauncherTestHelperService.runOnLauncherAndGetResult( |
| 563 new Callable<ChildProcessConnection>() { | 562 new Callable<BaseChildProcessConnection>() { |
| 564 @Override | 563 @Override |
| 565 public ChildProcessConnection call() { | 564 public BaseChildProcessConnection call() { |
| 566 return ChildProcessLauncher.allocateBoundConnection( | 565 return ChildProcessLauncher.allocateBoundConnection( |
| 567 new ChildSpawnData(context, null /* commandLine
*/, | 566 new ChildSpawnData(context, null /* commandLine
*/, |
| 568 0 /* childProcessId */, null /* filesToB
eMapped */, | 567 0 /* childProcessId */, null /* filesToB
eMapped */, |
| 569 null /* LaunchCallback */, null /* child
ProcessCallback */, | 568 null /* LaunchCallback */, null /* child
ProcessCallback */, |
| 570 true /* inSandbox */, false /* alwaysInF
oreground */, | 569 true /* inSandbox */, false /* alwaysInF
oreground */, |
| 571 creationParams), | 570 creationParams), |
| 572 null /* startCallback */, false /* forWarmUp */)
; | 571 null /* startCallback */, false /* forWarmUp */)
; |
| 573 } | 572 } |
| 574 }); | 573 }); |
| 575 } | 574 } |
| 576 | 575 |
| 577 /** | 576 /** |
| 578 * Returns a new connection if it is allocated. Note this function only allo
cates a connection | 577 * Returns a new connection if it is allocated. Note this function only allo
cates a connection |
| 579 * but doesn't really start the connection to bind a service. It is for test
ing whether the | 578 * but doesn't really start the connection to bind a service. It is for test
ing whether the |
| 580 * connection is allocated properly for different application packages. | 579 * connection is allocated properly for different application packages. |
| 581 */ | 580 */ |
| 582 private ChildProcessConnectionImpl allocateConnection(final String packageNa
me) { | 581 private BaseChildProcessConnection allocateConnection(final String packageNa
me) { |
| 583 return ChildProcessLauncherTestHelperService.runOnLauncherAndGetResult( | 582 return ChildProcessLauncherTestHelperService.runOnLauncherAndGetResult( |
| 584 new Callable<ChildProcessConnectionImpl>() { | 583 new Callable<BaseChildProcessConnection>() { |
| 585 @Override | 584 @Override |
| 586 public ChildProcessConnectionImpl call() { | 585 public BaseChildProcessConnection call() { |
| 587 // Allocate a new connection. | 586 // Allocate a new connection. |
| 588 Context context = InstrumentationRegistry.getTargetConte
xt(); | 587 Context context = InstrumentationRegistry.getTargetConte
xt(); |
| 589 ChildProcessCreationParams creationParams = | 588 ChildProcessCreationParams creationParams = |
| 590 getDefaultChildProcessCreationParams(packageName
); | 589 getDefaultChildProcessCreationParams(packageName
); |
| 591 return (ChildProcessConnectionImpl) ChildProcessLauncher
.allocateConnection( | 590 return ChildProcessLauncher.allocateConnection( |
| 592 new ChildSpawnData(context, null /* commandLine
*/, | 591 new ChildSpawnData(context, null /* commandLine
*/, |
| 593 0 /* childProcessId */, null /* filesToB
eMapped */, | 592 0 /* childProcessId */, null /* filesToB
eMapped */, |
| 594 null /* launchCallback */, null /* child
ProcessCallback */, | 593 null /* launchCallback */, null /* child
ProcessCallback */, |
| 595 true /* inSandbox */, false /* alwaysInF
oreground */, | 594 true /* inSandbox */, false /* alwaysInF
oreground */, |
| 596 creationParams), | 595 creationParams), |
| 597 ChildProcessLauncher.createCommonParamsBundle(cr
eationParams), | 596 ChildProcessLauncher.createCommonParamsBundle(cr
eationParams), |
| 598 false /* forWarmUp */); | 597 false /* forWarmUp */); |
| 599 } | 598 } |
| 600 }); | 599 }); |
| 601 } | 600 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 624 new Callable<Integer>() { | 623 new Callable<Integer>() { |
| 625 @Override | 624 @Override |
| 626 public Integer call() { | 625 public Integer call() { |
| 627 return ChildConnectionAllocator | 626 return ChildConnectionAllocator |
| 628 .getAllocator(context, packageName, true /*isSan
dboxed */) | 627 .getAllocator(context, packageName, true /*isSan
dboxed */) |
| 629 .allocatedConnectionsCountForTesting(); | 628 .allocatedConnectionsCountForTesting(); |
| 630 } | 629 } |
| 631 }); | 630 }); |
| 632 } | 631 } |
| 633 | 632 |
| 634 private static ChildProcessConnection[] getSandboxedConnectionArrayForTestin
g( | 633 private static BaseChildProcessConnection[] getSandboxedConnectionArrayForTe
sting( |
| 635 final Context context, final String packageName) { | 634 final Context context, final String packageName) { |
| 636 return ChildProcessLauncherTestHelperService.runOnLauncherAndGetResult( | 635 return ChildProcessLauncherTestHelperService.runOnLauncherAndGetResult( |
| 637 new Callable<ChildProcessConnection[]>() { | 636 new Callable<BaseChildProcessConnection[]>() { |
| 638 @Override | 637 @Override |
| 639 public ChildProcessConnection[] call() { | 638 public BaseChildProcessConnection[] call() { |
| 640 return ChildConnectionAllocator | 639 return ChildConnectionAllocator |
| 641 .getAllocator(context, packageName, true /*isSan
dboxed */) | 640 .getAllocator(context, packageName, true /*isSan
dboxed */) |
| 642 .connectionArrayForTesting(); | 641 .connectionArrayForTesting(); |
| 643 } | 642 } |
| 644 }); | 643 }); |
| 645 } | 644 } |
| 646 | 645 |
| 647 private static int pendingSpawnsCountForTesting( | 646 private static int pendingSpawnsCountForTesting( |
| 648 final Context context, final String packageName, final boolean inSan
dbox) { | 647 final Context context, final String packageName, final boolean inSan
dbox) { |
| 649 return ChildProcessLauncherTestHelperService.runOnLauncherAndGetResult( | 648 return ChildProcessLauncherTestHelperService.runOnLauncherAndGetResult( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 663 private int allocatedChromeSandboxedConnectionsCount() { | 662 private int allocatedChromeSandboxedConnectionsCount() { |
| 664 Context context = InstrumentationRegistry.getInstrumentation().getTarget
Context(); | 663 Context context = InstrumentationRegistry.getInstrumentation().getTarget
Context(); |
| 665 return allocatedSandboxedConnectionsCountForTesting(context, context.get
PackageName()); | 664 return allocatedSandboxedConnectionsCountForTesting(context, context.get
PackageName()); |
| 666 } | 665 } |
| 667 | 666 |
| 668 private ChildProcessCreationParams getDefaultChildProcessCreationParams(Stri
ng packageName) { | 667 private ChildProcessCreationParams getDefaultChildProcessCreationParams(Stri
ng packageName) { |
| 669 return new ChildProcessCreationParams(packageName, false /* isExternalSe
rvice */, | 668 return new ChildProcessCreationParams(packageName, false /* isExternalSe
rvice */, |
| 670 LibraryProcessType.PROCESS_CHILD, false /* bindToCallerCheck */)
; | 669 LibraryProcessType.PROCESS_CHILD, false /* bindToCallerCheck */)
; |
| 671 } | 670 } |
| 672 | 671 |
| 673 private void triggerConnectionSetup(final ChildProcessConnectionImpl connect
ion) { | 672 private void triggerConnectionSetup(final BaseChildProcessConnection connect
ion) { |
| 674 ChildProcessLauncherTestHelperService.runOnLauncherThreadBlocking(new Ru
nnable() { | 673 ChildProcessLauncherTestHelperService.runOnLauncherThreadBlocking(new Ru
nnable() { |
| 675 @Override | 674 @Override |
| 676 public void run() { | 675 public void run() { |
| 677 ChildProcessLauncher.triggerConnectionSetup(connection, sProcess
WaitArguments, | 676 ChildProcessLauncher.triggerConnectionSetup(connection, sProcess
WaitArguments, |
| 678 1 /* childProcessId */, new FileDescriptorInfo[0], | 677 1 /* childProcessId */, new FileDescriptorInfo[0], |
| 679 null /* launchCallback */, null /* childProcessCallback
*/); | 678 null /* launchCallback */, null /* childProcessCallback
*/); |
| 680 } | 679 } |
| 681 }); | 680 }); |
| 682 } | 681 } |
| 683 } | 682 } |
| OLD | NEW |