Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(149)

Side by Side Diff: content/public/android/java/src/org/chromium/content/browser/ChildProcessLauncher.java

Issue 2049843004: Upstream: Renderers are running in WebAPKs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Maria's comments. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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.annotation.SuppressLint; 7 import android.annotation.SuppressLint;
8 import android.app.Service;
8 import android.content.Context; 9 import android.content.Context;
9 import android.content.Intent; 10 import android.content.Intent;
10 import android.content.pm.ApplicationInfo; 11 import android.content.pm.ApplicationInfo;
11 import android.content.pm.PackageManager; 12 import android.content.pm.PackageManager;
12 import android.graphics.SurfaceTexture; 13 import android.graphics.SurfaceTexture;
13 import android.os.Build; 14 import android.os.Build;
14 import android.os.Bundle; 15 import android.os.Bundle;
15 import android.os.ParcelFileDescriptor; 16 import android.os.ParcelFileDescriptor;
16 import android.os.RemoteException; 17 import android.os.RemoteException;
17 import android.text.TextUtils; 18 import android.text.TextUtils;
18 import android.util.Pair; 19 import android.util.Pair;
19 import android.view.Surface; 20 import android.view.Surface;
20 21
21 import org.chromium.base.CommandLine; 22 import org.chromium.base.CommandLine;
22 import org.chromium.base.CpuFeatures; 23 import org.chromium.base.CpuFeatures;
23 import org.chromium.base.Log; 24 import org.chromium.base.Log;
24 import org.chromium.base.ThreadUtils; 25 import org.chromium.base.ThreadUtils;
25 import org.chromium.base.TraceEvent; 26 import org.chromium.base.TraceEvent;
26 import org.chromium.base.VisibleForTesting; 27 import org.chromium.base.VisibleForTesting;
27 import org.chromium.base.annotations.CalledByNative; 28 import org.chromium.base.annotations.CalledByNative;
28 import org.chromium.base.annotations.JNINamespace; 29 import org.chromium.base.annotations.JNINamespace;
29 import org.chromium.base.library_loader.Linker; 30 import org.chromium.base.library_loader.Linker;
30 import org.chromium.content.app.ChildProcessService;
31 import org.chromium.content.app.ChromiumLinkerParams; 31 import org.chromium.content.app.ChromiumLinkerParams;
32 import org.chromium.content.app.DownloadProcessService; 32 import org.chromium.content.app.DownloadProcessService;
33 import org.chromium.content.app.PrivilegedProcessService; 33 import org.chromium.content.app.PrivilegedProcessService;
34 import org.chromium.content.app.SandboxedProcessService; 34 import org.chromium.content.app.SandboxedProcessService;
35 import org.chromium.content.common.ContentSwitches; 35 import org.chromium.content.common.ContentSwitches;
36 import org.chromium.content.common.IChildProcessCallback; 36 import org.chromium.content.common.IChildProcessCallback;
37 import org.chromium.content.common.SurfaceWrapper; 37 import org.chromium.content.common.SurfaceWrapper;
38 38
39 import java.io.IOException; 39 import java.io.IOException;
40 import java.util.ArrayList; 40 import java.util.ArrayList;
(...skipping 17 matching lines...) Expand all
58 58
59 private static class ChildConnectionAllocator { 59 private static class ChildConnectionAllocator {
60 // Connections to services. Indices of the array correspond to the servi ce numbers. 60 // Connections to services. Indices of the array correspond to the servi ce numbers.
61 private final ChildProcessConnection[] mChildProcessConnections; 61 private final ChildProcessConnection[] mChildProcessConnections;
62 62
63 // The list of free (not bound) service indices. 63 // The list of free (not bound) service indices.
64 // SHOULD BE ACCESSED WITH mConnectionLock. 64 // SHOULD BE ACCESSED WITH mConnectionLock.
65 private final ArrayList<Integer> mFreeConnectionIndices; 65 private final ArrayList<Integer> mFreeConnectionIndices;
66 private final Object mConnectionLock = new Object(); 66 private final Object mConnectionLock = new Object();
67 67
68 private Class<? extends ChildProcessService> mChildClass;
69 private final boolean mInSandbox; 68 private final boolean mInSandbox;
70 // Each Allocator keeps a queue for the pending spawn data. Once a conne ction is free, we 69 // Each Allocator keeps a queue for the pending spawn data. Once a conne ction is free, we
71 // dequeue the pending spawn data from the same allocator as the connect ion. 70 // dequeue the pending spawn data from the same allocator as the connect ion.
72 private final PendingSpawnQueue mPendingSpawnQueue = new PendingSpawnQue ue(); 71 private final PendingSpawnQueue mPendingSpawnQueue = new PendingSpawnQue ue();
73 72
74 public ChildConnectionAllocator(boolean inSandbox, int numChildServices) { 73 public ChildConnectionAllocator(boolean inSandbox, int numChildServices) {
75 mChildProcessConnections = new ChildProcessConnectionImpl[numChildSe rvices]; 74 mChildProcessConnections = new ChildProcessConnectionImpl[numChildSe rvices];
76 mFreeConnectionIndices = new ArrayList<Integer>(numChildServices); 75 mFreeConnectionIndices = new ArrayList<Integer>(numChildServices);
77 for (int i = 0; i < numChildServices; i++) { 76 for (int i = 0; i < numChildServices; i++) {
78 mFreeConnectionIndices.add(i); 77 mFreeConnectionIndices.add(i);
79 } 78 }
80 mChildClass =
81 inSandbox ? SandboxedProcessService.class : PrivilegedProces sService.class;
82 mInSandbox = inSandbox; 79 mInSandbox = inSandbox;
83 } 80 }
84 81
82 private Class<? extends Service> getServiceClass(ChildProcessCreationPar ams params) {
83 Class<? extends Service> serviceClass = null;
84 if (params != null) {
85 serviceClass = params.getServiceClass();
86 }
87 if (serviceClass != null) {
88 return serviceClass;
89 }
90 return mInSandbox ? SandboxedProcessService.class
91 : PrivilegedProcessService.class;
92 }
93
85 public ChildProcessConnection allocate( 94 public ChildProcessConnection allocate(
86 Context context, ChildProcessConnection.DeathCallback deathCallb ack, 95 Context context, ChildProcessConnection.DeathCallback deathCallb ack,
87 ChromiumLinkerParams chromiumLinkerParams, 96 ChromiumLinkerParams chromiumLinkerParams,
88 boolean alwaysInForeground, 97 boolean alwaysInForeground,
89 ChildProcessCreationParams creationParams) { 98 ChildProcessCreationParams creationParams) {
90 synchronized (mConnectionLock) { 99 synchronized (mConnectionLock) {
91 if (mFreeConnectionIndices.isEmpty()) { 100 if (mFreeConnectionIndices.isEmpty()) {
92 Log.d(TAG, "Ran out of services to allocate."); 101 Log.d(TAG, "Ran out of services to allocate.");
93 return null; 102 return null;
94 } 103 }
95 int slot = mFreeConnectionIndices.remove(0); 104 int slot = mFreeConnectionIndices.remove(0);
96 assert mChildProcessConnections[slot] == null; 105 assert mChildProcessConnections[slot] == null;
97 mChildProcessConnections[slot] = new ChildProcessConnectionImpl( context, slot, 106 mChildProcessConnections[slot] = new ChildProcessConnectionImpl( context, slot,
98 mInSandbox, deathCallback, mChildClass, chromiumLinkerPa rams, 107 mInSandbox, deathCallback, getServiceClass(creationParam s),
99 alwaysInForeground, creationParams); 108 chromiumLinkerParams, alwaysInForeground, creationParams );
100 Log.d(TAG, "Allocator allocated a connection, sandbox: %b, slot: %d", mInSandbox, 109 Log.d(TAG, "Allocator allocated a connection, sandbox: %b, slot: %d", mInSandbox,
101 slot); 110 slot);
102 return mChildProcessConnections[slot]; 111 return mChildProcessConnections[slot];
103 } 112 }
104 } 113 }
105 114
106 public void free(ChildProcessConnection connection) { 115 public void free(ChildProcessConnection connection) {
107 synchronized (mConnectionLock) { 116 synchronized (mConnectionLock) {
108 int slot = connection.getServiceNumber(); 117 int slot = connection.getServiceNumber();
109 if (mChildProcessConnections[slot] != connection) { 118 if (mChildProcessConnections[slot] != connection) {
(...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after
937 ChildProcessCreationParams creationParams) { 946 ChildProcessCreationParams creationParams) {
938 return allocateBoundConnection(context, null, true, false, creationParam s); 947 return allocateBoundConnection(context, null, true, false, creationParam s);
939 } 948 }
940 949
941 /** 950 /**
942 * Queue up a spawn requests for testing. 951 * Queue up a spawn requests for testing.
943 */ 952 */
944 @VisibleForTesting 953 @VisibleForTesting
945 static void enqueuePendingSpawnForTesting(Context context, String[] commandL ine, 954 static void enqueuePendingSpawnForTesting(Context context, String[] commandL ine,
946 ChildProcessCreationParams creationParams, boolean inSandbox) { 955 ChildProcessCreationParams creationParams, boolean inSandbox) {
956 String packageName = creationParams != null ? creationParams.getPackageN ame()
957 : context.getPackageName();
947 PendingSpawnQueue pendingSpawnQueue = getPendingSpawnQueue(context, 958 PendingSpawnQueue pendingSpawnQueue = getPendingSpawnQueue(context,
948 creationParams.getPackageName(), inSandbox); 959 packageName, inSandbox);
949 synchronized (pendingSpawnQueue.mPendingSpawnsLock) { 960 synchronized (pendingSpawnQueue.mPendingSpawnsLock) {
950 pendingSpawnQueue.enqueueLocked(new PendingSpawnData(context, comman dLine, 1, 961 pendingSpawnQueue.enqueueLocked(new PendingSpawnData(context, comman dLine, 1,
951 new FileDescriptorInfo[0], 0, CALLBACK_FOR_RENDERER_PROCESS, true, 962 new FileDescriptorInfo[0], 0, CALLBACK_FOR_RENDERER_PROCESS, true,
952 creationParams)); 963 creationParams));
953 } 964 }
954 } 965 }
955 966
956 /** 967 /**
957 * @return the number of sandboxed connections of given {@link packageName} managed by the 968 * @return the number of sandboxed connections of given {@link packageName} managed by the
958 * allocator. 969 * allocator.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1000 } 1011 }
1001 1012
1002 return true; 1013 return true;
1003 } 1014 }
1004 1015
1005 private static native void nativeOnChildProcessStarted(long clientContext, i nt pid); 1016 private static native void nativeOnChildProcessStarted(long clientContext, i nt pid);
1006 private static native void nativeEstablishSurfacePeer( 1017 private static native void nativeEstablishSurfacePeer(
1007 int pid, Surface surface, int primaryID, int secondaryID); 1018 int pid, Surface surface, int primaryID, int secondaryID);
1008 private static native boolean nativeIsSingleProcess(); 1019 private static native boolean nativeIsSingleProcess();
1009 } 1020 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698