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.app; | 5 package org.chromium.content.app; |
6 | 6 |
7 import android.app.Service; | 7 import android.app.Service; |
8 import android.content.Context; | 8 import android.content.Context; |
9 import android.content.Intent; | 9 import android.content.Intent; |
10 import android.graphics.SurfaceTexture; | 10 import android.graphics.SurfaceTexture; |
(...skipping 29 matching lines...) Expand all Loading... |
40 public class SandboxedProcessService extends Service { | 40 public class SandboxedProcessService extends Service { |
41 private static final String MAIN_THREAD_NAME = "SandboxedProcessMain"; | 41 private static final String MAIN_THREAD_NAME = "SandboxedProcessMain"; |
42 private static final String TAG = "SandboxedProcessService"; | 42 private static final String TAG = "SandboxedProcessService"; |
43 private ISandboxedProcessCallback mCallback; | 43 private ISandboxedProcessCallback mCallback; |
44 | 44 |
45 // This is the native "Main" thread for the renderer / utility process. | 45 // This is the native "Main" thread for the renderer / utility process. |
46 private Thread mSandboxMainThread; | 46 private Thread mSandboxMainThread; |
47 // Parameters received via IPC, only accessed while holding the mSandboxMain
Thread monitor. | 47 // Parameters received via IPC, only accessed while holding the mSandboxMain
Thread monitor. |
48 private String mNativeLibraryName; // Must be passed in via the bind comman
d. | 48 private String mNativeLibraryName; // Must be passed in via the bind comman
d. |
49 private String[] mCommandLineParams; | 49 private String[] mCommandLineParams; |
| 50 private int mCpuCount; |
| 51 private long mCpuFeatures; |
50 // Pairs IDs and file descriptors that should be registered natively. | 52 // Pairs IDs and file descriptors that should be registered natively. |
51 private ArrayList<Integer> mFileIds; | 53 private ArrayList<Integer> mFileIds; |
52 private ArrayList<ParcelFileDescriptor> mFileFds; | 54 private ArrayList<ParcelFileDescriptor> mFileFds; |
53 | 55 |
54 private static Context sContext = null; | 56 private static Context sContext = null; |
55 private boolean mLibraryInitialized = false; | 57 private boolean mLibraryInitialized = false; |
56 | 58 |
57 // Binder object used by clients for this service. | 59 // Binder object used by clients for this service. |
58 private final ISandboxedProcessService.Stub mBinder = new ISandboxedProcessS
ervice.Stub() { | 60 private final ISandboxedProcessService.Stub mBinder = new ISandboxedProcessS
ervice.Stub() { |
59 // NOTE: Implement any ISandboxedProcessService methods here. | 61 // NOTE: Implement any ISandboxedProcessService methods here. |
60 @Override | 62 @Override |
61 public int setupConnection(Bundle args, ISandboxedProcessCallback callba
ck) { | 63 public int setupConnection(Bundle args, ISandboxedProcessCallback callba
ck) { |
62 mCallback = callback; | 64 mCallback = callback; |
63 synchronized (mSandboxMainThread) { | 65 synchronized (mSandboxMainThread) { |
64 // Allow the command line to be set via bind() intent or setupCo
nnection, but | 66 // Allow the command line to be set via bind() intent or setupCo
nnection, but |
65 // the FD can only be transferred here. | 67 // the FD can only be transferred here. |
66 if (mCommandLineParams == null) { | 68 if (mCommandLineParams == null) { |
67 mCommandLineParams = args.getStringArray( | 69 mCommandLineParams = args.getStringArray( |
68 SandboxedProcessConnection.EXTRA_COMMAND_LINE); | 70 SandboxedProcessConnection.EXTRA_COMMAND_LINE); |
69 } | 71 } |
70 // We must have received the command line by now | 72 // We must have received the command line by now |
71 assert mCommandLineParams != null; | 73 assert mCommandLineParams != null; |
| 74 mCpuCount = args.getInt(SandboxedProcessConnection.EXTRA_CPU_COU
NT); |
| 75 mCpuFeatures = args.getLong(SandboxedProcessConnection.EXTRA_CPU
_FEATURES); |
| 76 assert mCpuCount > 0; |
72 mFileIds = new ArrayList<Integer>(); | 77 mFileIds = new ArrayList<Integer>(); |
73 mFileFds = new ArrayList<ParcelFileDescriptor>(); | 78 mFileFds = new ArrayList<ParcelFileDescriptor>(); |
74 for (int i = 0;; i++) { | 79 for (int i = 0;; i++) { |
75 String fdName = SandboxedProcessConnection.EXTRA_FILES_PREFI
X + i | 80 String fdName = SandboxedProcessConnection.EXTRA_FILES_PREFI
X + i |
76 + SandboxedProcessConnection.EXTRA_FILES_FD_SUFFIX; | 81 + SandboxedProcessConnection.EXTRA_FILES_FD_SUFFIX; |
77 ParcelFileDescriptor parcel = args.getParcelable(fdName); | 82 ParcelFileDescriptor parcel = args.getParcelable(fdName); |
78 if (parcel == null) { | 83 if (parcel == null) { |
79 // End of the file list. | 84 // End of the file list. |
80 break; | 85 break; |
81 } | 86 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 } | 136 } |
132 assert mFileIds.size() == mFileFds.size(); | 137 assert mFileIds.size() == mFileFds.size(); |
133 int[] fileIds = new int[mFileIds.size()]; | 138 int[] fileIds = new int[mFileIds.size()]; |
134 int[] fileFds = new int[mFileFds.size()]; | 139 int[] fileFds = new int[mFileFds.size()]; |
135 for (int i = 0; i < mFileIds.size(); ++i) { | 140 for (int i = 0; i < mFileIds.size(); ++i) { |
136 fileIds[i] = mFileIds.get(i); | 141 fileIds[i] = mFileIds.get(i); |
137 fileFds[i] = mFileFds.get(i).detachFd(); | 142 fileFds[i] = mFileFds.get(i).detachFd(); |
138 } | 143 } |
139 ContentMain.initApplicationContext(sContext.getApplicationCo
ntext()); | 144 ContentMain.initApplicationContext(sContext.getApplicationCo
ntext()); |
140 nativeInitSandboxedProcess(sContext.getApplicationContext(), | 145 nativeInitSandboxedProcess(sContext.getApplicationContext(), |
141 SandboxedProcessService.this, fileIds, fileFds); | 146 SandboxedProcessService.this, fileIds, fileFds, |
| 147 mCpuCount, mCpuFeatures); |
142 ContentMain.start(); | 148 ContentMain.start(); |
143 nativeExitSandboxedProcess(); | 149 nativeExitSandboxedProcess(); |
144 } catch (InterruptedException e) { | 150 } catch (InterruptedException e) { |
145 Log.w(TAG, MAIN_THREAD_NAME + " startup failed: " + e); | 151 Log.w(TAG, MAIN_THREAD_NAME + " startup failed: " + e); |
146 } | 152 } |
147 } | 153 } |
148 }, MAIN_THREAD_NAME); | 154 }, MAIN_THREAD_NAME); |
149 mSandboxMainThread.start(); | 155 mSandboxMainThread.start(); |
150 } | 156 } |
151 | 157 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 * The main entry point for a sandboxed process. This should be called from
a new thread since | 243 * The main entry point for a sandboxed process. This should be called from
a new thread since |
238 * it will not return until the sandboxed process exits. See sandboxed_proce
ss_service.{h,cc} | 244 * it will not return until the sandboxed process exits. See sandboxed_proce
ss_service.{h,cc} |
239 * | 245 * |
240 * @param applicationContext The Application Context of the current process. | 246 * @param applicationContext The Application Context of the current process. |
241 * @param service The current SandboxedProcessService object. | 247 * @param service The current SandboxedProcessService object. |
242 * @param fileIds A list of file IDs that should be registered for access by
the renderer. | 248 * @param fileIds A list of file IDs that should be registered for access by
the renderer. |
243 * @param fileFds A list of file descriptors that should be registered for a
ccess by the | 249 * @param fileFds A list of file descriptors that should be registered for a
ccess by the |
244 * renderer. | 250 * renderer. |
245 */ | 251 */ |
246 private static native void nativeInitSandboxedProcess(Context applicationCon
text, | 252 private static native void nativeInitSandboxedProcess(Context applicationCon
text, |
247 SandboxedProcessService service, int[] extraFileIds, int[] extraFile
Fds); | 253 SandboxedProcessService service, int[] extraFileIds, int[] extraFile
Fds, |
| 254 int cpuCount, long cpuFeatures); |
248 | 255 |
249 /** | 256 /** |
250 * Force the sandboxed process to exit. | 257 * Force the sandboxed process to exit. |
251 */ | 258 */ |
252 private static native void nativeExitSandboxedProcess(); | 259 private static native void nativeExitSandboxedProcess(); |
253 | 260 |
254 private native void nativeShutdownSandboxMainThread(); | 261 private native void nativeShutdownSandboxMainThread(); |
255 } | 262 } |
OLD | NEW |