OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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.Context; | 7 import android.content.Context; |
8 import android.os.RemoteException; | |
9 import android.util.Log; | 8 import android.util.Log; |
10 import android.view.Surface; | 9 import android.view.Surface; |
11 | 10 |
12 import java.util.Arrays; | 11 import java.util.Arrays; |
13 import java.util.ArrayList; | 12 import java.util.ArrayList; |
14 import java.util.List; | 13 import java.util.List; |
15 import java.util.Map; | 14 import java.util.Map; |
16 import java.util.concurrent.ConcurrentHashMap; | 15 import java.util.concurrent.ConcurrentHashMap; |
17 | 16 |
18 import org.chromium.base.CalledByNative; | 17 import org.chromium.base.CalledByNative; |
19 import org.chromium.base.JNINamespace; | 18 import org.chromium.base.JNINamespace; |
20 import org.chromium.base.ThreadUtils; | 19 import org.chromium.base.ThreadUtils; |
21 import org.chromium.content.app.LibraryLoader; | 20 import org.chromium.content.app.LibraryLoader; |
| 21 import org.chromium.content.app.SandboxedProcessService; |
22 import org.chromium.content.common.ISandboxedProcessCallback; | 22 import org.chromium.content.common.ISandboxedProcessCallback; |
23 import org.chromium.content.common.ISandboxedProcessService; | 23 import org.chromium.content.common.ISandboxedProcessService; |
24 | 24 |
25 /** | 25 /** |
26 * This class provides the method to start/stop SandboxedProcess called by | 26 * This class provides the method to start/stop SandboxedProcess called by |
27 * native. | 27 * native. |
28 */ | 28 */ |
29 @JNINamespace("content") | 29 @JNINamespace("content") |
30 public class SandboxedProcessLauncher { | 30 public class SandboxedProcessLauncher { |
31 private static String TAG = "SandboxedProcessLauncher"; | 31 private static String TAG = "SandboxedProcessLauncher"; |
(...skipping 18 matching lines...) Expand all Loading... |
50 // set when we don't expect them to). | 50 // set when we don't expect them to). |
51 // SHOULD BE ACCESSED WITH THE mConnections LOCK. | 51 // SHOULD BE ACCESSED WITH THE mConnections LOCK. |
52 private static final ArrayList<Integer> mFreeConnectionIndices = | 52 private static final ArrayList<Integer> mFreeConnectionIndices = |
53 new ArrayList<Integer>(MAX_REGISTERED_SERVICES); | 53 new ArrayList<Integer>(MAX_REGISTERED_SERVICES); |
54 static { | 54 static { |
55 for (int i = 0; i < MAX_REGISTERED_SERVICES; i++) { | 55 for (int i = 0; i < MAX_REGISTERED_SERVICES; i++) { |
56 mFreeConnectionIndices.add(i); | 56 mFreeConnectionIndices.add(i); |
57 } | 57 } |
58 } | 58 } |
59 | 59 |
| 60 // Service class for sandboxed process. As the default value it uses |
| 61 // SandboxedProcessService. |
| 62 private static Class<? extends SandboxedProcessService> mServiceClass = |
| 63 SandboxedProcessService.class; |
| 64 private static boolean mConnectionAllocated = false; |
| 65 |
| 66 // Sets service class for sandboxed service. |
| 67 public static void setServiceClass(Class<? extends SandboxedProcessService>
serviceClass) { |
| 68 // We should guarantee this is called before allocating connection. |
| 69 assert !mConnectionAllocated; |
| 70 mServiceClass = serviceClass; |
| 71 } |
| 72 |
60 private static SandboxedProcessConnection allocateConnection(Context context
) { | 73 private static SandboxedProcessConnection allocateConnection(Context context
) { |
61 SandboxedProcessConnection.DeathCallback deathCallback = | 74 SandboxedProcessConnection.DeathCallback deathCallback = |
62 new SandboxedProcessConnection.DeathCallback() { | 75 new SandboxedProcessConnection.DeathCallback() { |
63 @Override | 76 @Override |
64 public void onSandboxedProcessDied(int pid) { | 77 public void onSandboxedProcessDied(int pid) { |
65 stop(pid); | 78 stop(pid); |
66 } | 79 } |
67 }; | 80 }; |
68 synchronized (mConnections) { | 81 synchronized (mConnections) { |
69 if (mFreeConnectionIndices.isEmpty()) { | 82 if (mFreeConnectionIndices.isEmpty()) { |
70 Log.w(TAG, "Ran out of sandboxed services."); | 83 Log.w(TAG, "Ran out of sandboxed services."); |
71 return null; | 84 return null; |
72 } | 85 } |
73 int slot = mFreeConnectionIndices.remove(0); | 86 int slot = mFreeConnectionIndices.remove(0); |
74 assert mConnections[slot] == null; | 87 assert mConnections[slot] == null; |
75 mConnections[slot] = new SandboxedProcessConnection(context, slot, d
eathCallback); | 88 mConnections[slot] = new SandboxedProcessConnection(context, slot, d
eathCallback, |
| 89 mServiceClass); |
| 90 mConnectionAllocated = true; |
76 return mConnections[slot]; | 91 return mConnections[slot]; |
77 } | 92 } |
78 } | 93 } |
79 | 94 |
80 private static SandboxedProcessConnection allocateBoundConnection(Context co
ntext, | 95 private static SandboxedProcessConnection allocateBoundConnection(Context co
ntext, |
81 String[] commandLine) { | 96 String[] commandLine) { |
82 SandboxedProcessConnection connection = allocateConnection(context); | 97 SandboxedProcessConnection connection = allocateConnection(context); |
83 if (connection != null) { | 98 if (connection != null) { |
84 String libraryName = LibraryLoader.getLibraryToLoad(); | 99 String libraryName = LibraryLoader.getLibraryToLoad(); |
85 assert libraryName != null : "Attempting to launch a sandbox process
without first " | 100 assert libraryName != null : "Attempting to launch a sandbox process
without first " |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 return nativeGetViewSurface(surfaceId); | 324 return nativeGetViewSurface(surfaceId); |
310 } | 325 } |
311 }; | 326 }; |
312 }; | 327 }; |
313 | 328 |
314 private static native void nativeOnSandboxedProcessStarted(int clientContext
, int pid); | 329 private static native void nativeOnSandboxedProcessStarted(int clientContext
, int pid); |
315 private static native Surface nativeGetViewSurface(int surfaceId); | 330 private static native Surface nativeGetViewSurface(int surfaceId); |
316 private static native void nativeEstablishSurfacePeer( | 331 private static native void nativeEstablishSurfacePeer( |
317 int pid, Surface surface, int primaryID, int secondaryID); | 332 int pid, Surface surface, int primaryID, int secondaryID); |
318 } | 333 } |
OLD | NEW |