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 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
563 /** | 563 /** |
564 * Should be called early in startup so the work needed to spawn the child p rocess can be done | 564 * Should be called early in startup so the work needed to spawn the child p rocess can be done |
565 * in parallel to other startup work. Must not be called on the UI thread. S pare connection is | 565 * in parallel to other startup work. Must not be called on the UI thread. S pare connection is |
566 * created in sandboxed child process. | 566 * created in sandboxed child process. |
567 * @param context the application context used for the connection. | 567 * @param context the application context used for the connection. |
568 */ | 568 */ |
569 public static void warmUp(Context context) { | 569 public static void warmUp(Context context) { |
570 synchronized (sSpareConnectionLock) { | 570 synchronized (sSpareConnectionLock) { |
571 assert !ThreadUtils.runningOnUiThread(); | 571 assert !ThreadUtils.runningOnUiThread(); |
572 if (sSpareSandboxedConnection == null) { | 572 if (sSpareSandboxedConnection == null) { |
573 ChildProcessCreationParams params = ChildProcessCreationParams.g et(); | 573 ChildProcessCreationParams params = ChildProcessCreationParams.g etDefault(); |
574 if (params != null) { | |
575 params = params.copy(); | |
576 } | |
577 | |
578 sSpareConnectionStarting = true; | 574 sSpareConnectionStarting = true; |
579 | 575 |
580 ChildProcessConnection.StartCallback startCallback = | 576 ChildProcessConnection.StartCallback startCallback = |
581 new ChildProcessConnection.StartCallback() { | 577 new ChildProcessConnection.StartCallback() { |
582 @Override | 578 @Override |
583 public void onChildStarted() { | 579 public void onChildStarted() { |
584 synchronized (sSpareConnectionLock) { | 580 synchronized (sSpareConnectionLock) { |
585 sSpareConnectionStarting = false; | 581 sSpareConnectionStarting = false; |
586 sSpareConnectionLock.notify(); | 582 sSpareConnectionLock.notify(); |
587 } | 583 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
625 return new FileDescriptorInfo(id, pFd, offset, size); | 621 return new FileDescriptorInfo(id, pFd, offset, size); |
626 } | 622 } |
627 | 623 |
628 /** | 624 /** |
629 * Spawns and connects to a child process. May be called on any thread. It w ill not block, but | 625 * Spawns and connects to a child process. May be called on any thread. It w ill not block, but |
630 * will instead callback to {@link #nativeOnChildProcessStarted} when the co nnection is | 626 * will instead callback to {@link #nativeOnChildProcessStarted} when the co nnection is |
631 * established. Note this callback will not necessarily be from the same thr ead (currently it | 627 * established. Note this callback will not necessarily be from the same thr ead (currently it |
632 * always comes from the main thread). | 628 * always comes from the main thread). |
633 * | 629 * |
634 * @param context Context used to obtain the application context. | 630 * @param context Context used to obtain the application context. |
631 * @param paramId Key used to retrieve ChildProcessCreationParams. | |
635 * @param commandLine The child process command line argv. | 632 * @param commandLine The child process command line argv. |
636 * @param filesToBeMapped File IDs, FDs, offsets, and lengths to pass throug h. | 633 * @param filesToBeMapped File IDs, FDs, offsets, and lengths to pass throug h. |
637 * @param clientContext Arbitrary parameter used by the client to distinguis h this connection. | 634 * @param clientContext Arbitrary parameter used by the client to distinguis h this connection. |
638 */ | 635 */ |
636 // TODO(boliu): All tests should use this over startForTesting. | |
637 @VisibleForTesting | |
639 @CalledByNative | 638 @CalledByNative |
640 private static void start(Context context, final String[] commandLine, int c hildProcessId, | 639 static void start(Context context, int paramId, final String[] commandLine, int childProcessId, |
641 FileDescriptorInfo[] filesToBeMapped, long clientContext) { | 640 FileDescriptorInfo[] filesToBeMapped, long clientContext) { |
642 assert clientContext != 0; | |
643 | |
644 int callbackType = CALLBACK_FOR_UNKNOWN_PROCESS; | 641 int callbackType = CALLBACK_FOR_UNKNOWN_PROCESS; |
645 boolean inSandbox = true; | 642 boolean inSandbox = true; |
646 String processType = | 643 String processType = |
647 ContentSwitches.getSwitchValue(commandLine, ContentSwitches.SWIT CH_PROCESS_TYPE); | 644 ContentSwitches.getSwitchValue(commandLine, ContentSwitches.SWIT CH_PROCESS_TYPE); |
648 ChildProcessCreationParams params = ChildProcessCreationParams.get(); | 645 ChildProcessCreationParams params = ChildProcessCreationParams.get(param Id); |
649 if (params != null) { | 646 if (paramId != ChildProcessCreationParams.DEFAULT_ID && params == null) { |
Ted C
2017/02/27 22:25:17
why do we want to allow DEFAULT_ID not to exist in
boliu
2017/02/27 23:43:02
regular chrome (ie not monochrome) doesn't need it
| |
650 params = params.copy(); | 647 throw new RuntimeException("CreationParams id " + paramId + " not fo und"); |
651 } | 648 } |
652 if (ContentSwitches.SWITCH_RENDERER_PROCESS.equals(processType)) { | 649 if (ContentSwitches.SWITCH_RENDERER_PROCESS.equals(processType)) { |
653 callbackType = CALLBACK_FOR_RENDERER_PROCESS; | 650 callbackType = CALLBACK_FOR_RENDERER_PROCESS; |
654 } else { | 651 } else { |
655 if (params != null && !params.getPackageName().equals(context.getPac kageName())) { | 652 if (params != null && !params.getPackageName().equals(context.getPac kageName())) { |
656 // WebViews and WebAPKs have renderer processes running in their applications. | 653 // WebViews and WebAPKs have renderer processes running in their applications. |
657 // When launching these renderer processes, {@link ChildProcessC onnectionImpl} | 654 // When launching these renderer processes, {@link ChildProcessC onnectionImpl} |
658 // requires the package name of the application which holds the renderer process. | 655 // requires the package name of the application which holds the renderer process. |
659 // Therefore, the package name in ChildProcessCreationParams cou ld be the package | 656 // Therefore, the package name in ChildProcessCreationParams cou ld be the package |
660 // name of WebViews, WebAPKs, or Chrome, depending on the host a pplication. | 657 // 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 | 658 // Except renderer process, all other child processes should use Chrome's package |
662 // name. In WebAPK, ChildProcessCreationParams are initialized w ith WebAPK's | 659 // 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 | 660 // 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. | 661 // Chrome's package to use when initializing a non-renderer proc esses. |
662 // TODO(boliu): Should fold into |paramId|. Investigate why this is needed. | |
665 params = new ChildProcessCreationParams(context.getPackageName() , | 663 params = new ChildProcessCreationParams(context.getPackageName() , |
666 params.getIsExternalService(), params.getLibraryProcessT ype()); | 664 params.getIsExternalService(), params.getLibraryProcessT ype()); |
667 } | 665 } |
668 if (ContentSwitches.SWITCH_GPU_PROCESS.equals(processType)) { | 666 if (ContentSwitches.SWITCH_GPU_PROCESS.equals(processType)) { |
669 callbackType = CALLBACK_FOR_GPU_PROCESS; | 667 callbackType = CALLBACK_FOR_GPU_PROCESS; |
670 inSandbox = false; | 668 inSandbox = false; |
671 } else if (ContentSwitches.SWITCH_UTILITY_PROCESS.equals(processType )) { | 669 } else if (ContentSwitches.SWITCH_UTILITY_PROCESS.equals(processType )) { |
672 // We only support sandboxed right now. | 670 // We only support sandboxed right now. |
673 callbackType = CALLBACK_FOR_UTILITY_PROCESS; | 671 callbackType = CALLBACK_FOR_UTILITY_PROCESS; |
674 } else { | 672 } else { |
(...skipping 15 matching lines...) Expand all Loading... | |
690 final boolean inSandbox, | 688 final boolean inSandbox, |
691 final ChildProcessCreationParams creationParams) { | 689 final ChildProcessCreationParams creationParams) { |
692 try { | 690 try { |
693 TraceEvent.begin("ChildProcessLauncher.startInternal"); | 691 TraceEvent.begin("ChildProcessLauncher.startInternal"); |
694 | 692 |
695 ChildProcessConnection allocatedConnection = null; | 693 ChildProcessConnection allocatedConnection = null; |
696 String packageName = creationParams != null ? creationParams.getPack ageName() | 694 String packageName = creationParams != null ? creationParams.getPack ageName() |
697 : context.getPackageName(); | 695 : context.getPackageName(); |
698 synchronized (sSpareConnectionLock) { | 696 synchronized (sSpareConnectionLock) { |
699 if (inSandbox && sSpareSandboxedConnection != null | 697 if (inSandbox && sSpareSandboxedConnection != null |
700 && sSpareSandboxedConnection.getPackageName().equals(pac kageName)) { | 698 && sSpareSandboxedConnection.getPackageName().equals(pac kageName) |
699 // Object identity check for getDefault should be enough . The default is | |
700 // not supposed to change once set. | |
701 && creationParams == ChildProcessCreationParams.getDefau lt()) { | |
701 while (sSpareConnectionStarting) { | 702 while (sSpareConnectionStarting) { |
702 try { | 703 try { |
703 sSpareConnectionLock.wait(); | 704 sSpareConnectionLock.wait(); |
704 } catch (InterruptedException ex) { | 705 } catch (InterruptedException ex) { |
705 } | 706 } |
706 } | 707 } |
707 allocatedConnection = sSpareSandboxedConnection; | 708 allocatedConnection = sSpareSandboxedConnection; |
708 sSpareSandboxedConnection = null; | 709 sSpareSandboxedConnection = null; |
709 } | 710 } |
710 } | 711 } |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
964 | 965 |
965 return true; | 966 return true; |
966 } | 967 } |
967 | 968 |
968 private static native void nativeOnChildProcessStarted(long clientContext, i nt pid); | 969 private static native void nativeOnChildProcessStarted(long clientContext, i nt pid); |
969 private static native void nativeCompleteScopedSurfaceRequest( | 970 private static native void nativeCompleteScopedSurfaceRequest( |
970 UnguessableToken requestToken, Surface surface); | 971 UnguessableToken requestToken, Surface surface); |
971 private static native boolean nativeIsSingleProcess(); | 972 private static native boolean nativeIsSingleProcess(); |
972 private static native Surface nativeGetViewSurface(int surfaceId); | 973 private static native Surface nativeGetViewSurface(int surfaceId); |
973 } | 974 } |
OLD | NEW |