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.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 Loading... | |
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(Class<? extends Service > serviceClass) { | |
83 if (serviceClass != null) { | |
84 return serviceClass; | |
85 } | |
86 return mInSandbox ? SandboxedProcessService.class | |
87 : PrivilegedProcessService.class; | |
88 } | |
89 | |
85 public ChildProcessConnection allocate( | 90 public ChildProcessConnection allocate( |
86 Context context, ChildProcessConnection.DeathCallback deathCallb ack, | 91 Context context, ChildProcessConnection.DeathCallback deathCallb ack, |
87 ChromiumLinkerParams chromiumLinkerParams, | 92 ChromiumLinkerParams chromiumLinkerParams, |
88 boolean alwaysInForeground, | 93 boolean alwaysInForeground, |
89 ChildProcessCreationParams creationParams) { | 94 ChildProcessCreationParams creationParams) { |
90 synchronized (mConnectionLock) { | 95 synchronized (mConnectionLock) { |
91 if (mFreeConnectionIndices.isEmpty()) { | 96 if (mFreeConnectionIndices.isEmpty()) { |
92 Log.d(TAG, "Ran out of services to allocate."); | 97 Log.d(TAG, "Ran out of services to allocate."); |
93 return null; | 98 return null; |
94 } | 99 } |
95 int slot = mFreeConnectionIndices.remove(0); | 100 int slot = mFreeConnectionIndices.remove(0); |
96 assert mChildProcessConnections[slot] == null; | 101 assert mChildProcessConnections[slot] == null; |
102 Class<? extends Service> serviceClass = getServiceClass(creation Params != null | |
103 ? creationParams.getServiceClass() : null); | |
Maria
2016/06/17 17:09:24
I think that's an odd division of logic. Why not j
Xi Han
2016/06/17 18:35:20
It sounds good to me, since we can just pass null
| |
97 mChildProcessConnections[slot] = new ChildProcessConnectionImpl( context, slot, | 104 mChildProcessConnections[slot] = new ChildProcessConnectionImpl( context, slot, |
98 mInSandbox, deathCallback, mChildClass, chromiumLinkerPa rams, | 105 mInSandbox, deathCallback, serviceClass, chromiumLinkerP arams, |
99 alwaysInForeground, creationParams); | 106 alwaysInForeground, creationParams); |
100 Log.d(TAG, "Allocator allocated a connection, sandbox: %b, slot: %d", mInSandbox, | 107 Log.d(TAG, "Allocator allocated a connection, sandbox: %b, slot: %d", mInSandbox, |
101 slot); | 108 slot); |
102 return mChildProcessConnections[slot]; | 109 return mChildProcessConnections[slot]; |
103 } | 110 } |
104 } | 111 } |
105 | 112 |
106 public void free(ChildProcessConnection connection) { | 113 public void free(ChildProcessConnection connection) { |
107 synchronized (mConnectionLock) { | 114 synchronized (mConnectionLock) { |
108 int slot = connection.getServiceNumber(); | 115 int slot = connection.getServiceNumber(); |
(...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
937 ChildProcessCreationParams creationParams) { | 944 ChildProcessCreationParams creationParams) { |
938 return allocateBoundConnection(context, null, true, false, creationParam s); | 945 return allocateBoundConnection(context, null, true, false, creationParam s); |
939 } | 946 } |
940 | 947 |
941 /** | 948 /** |
942 * Queue up a spawn requests for testing. | 949 * Queue up a spawn requests for testing. |
943 */ | 950 */ |
944 @VisibleForTesting | 951 @VisibleForTesting |
945 static void enqueuePendingSpawnForTesting(Context context, String[] commandL ine, | 952 static void enqueuePendingSpawnForTesting(Context context, String[] commandL ine, |
946 ChildProcessCreationParams creationParams, boolean inSandbox) { | 953 ChildProcessCreationParams creationParams, boolean inSandbox) { |
954 String packageName = creationParams != null ? creationParams.getPackageN ame() | |
955 : context.getPackageName(); | |
947 PendingSpawnQueue pendingSpawnQueue = getPendingSpawnQueue(context, | 956 PendingSpawnQueue pendingSpawnQueue = getPendingSpawnQueue(context, |
948 creationParams.getPackageName(), inSandbox); | 957 packageName, inSandbox); |
949 synchronized (pendingSpawnQueue.mPendingSpawnsLock) { | 958 synchronized (pendingSpawnQueue.mPendingSpawnsLock) { |
950 pendingSpawnQueue.enqueueLocked(new PendingSpawnData(context, comman dLine, 1, | 959 pendingSpawnQueue.enqueueLocked(new PendingSpawnData(context, comman dLine, 1, |
951 new FileDescriptorInfo[0], 0, CALLBACK_FOR_RENDERER_PROCESS, true, | 960 new FileDescriptorInfo[0], 0, CALLBACK_FOR_RENDERER_PROCESS, true, |
952 creationParams)); | 961 creationParams)); |
953 } | 962 } |
954 } | 963 } |
955 | 964 |
956 /** | 965 /** |
957 * @return the number of sandboxed connections of given {@link packageName} managed by the | 966 * @return the number of sandboxed connections of given {@link packageName} managed by the |
958 * allocator. | 967 * allocator. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1000 } | 1009 } |
1001 | 1010 |
1002 return true; | 1011 return true; |
1003 } | 1012 } |
1004 | 1013 |
1005 private static native void nativeOnChildProcessStarted(long clientContext, i nt pid); | 1014 private static native void nativeOnChildProcessStarted(long clientContext, i nt pid); |
1006 private static native void nativeEstablishSurfacePeer( | 1015 private static native void nativeEstablishSurfacePeer( |
1007 int pid, Surface surface, int primaryID, int secondaryID); | 1016 int pid, Surface surface, int primaryID, int secondaryID); |
1008 private static native boolean nativeIsSingleProcess(); | 1017 private static native boolean nativeIsSingleProcess(); |
1009 } | 1018 } |
OLD | NEW |