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.ComponentName; | 7 import android.content.ComponentName; |
8 import android.content.Context; | 8 import android.content.Context; |
9 import android.content.Intent; | 9 import android.content.Intent; |
10 import android.content.ServiceConnection; | 10 import android.content.ServiceConnection; |
11 import android.os.AsyncTask; | 11 import android.os.AsyncTask; |
12 import android.os.Bundle; | 12 import android.os.Bundle; |
13 import android.os.Handler; | 13 import android.os.Handler; |
14 import android.os.IBinder; | 14 import android.os.IBinder; |
15 import android.os.Looper; | 15 import android.os.Looper; |
16 import android.os.ParcelFileDescriptor; | 16 import android.os.ParcelFileDescriptor; |
17 import android.util.Log; | 17 import android.util.Log; |
18 | 18 |
19 import java.io.IOException; | 19 import java.io.IOException; |
20 import java.util.concurrent.atomic.AtomicBoolean; | 20 import java.util.concurrent.atomic.AtomicBoolean; |
21 | 21 |
22 import org.chromium.base.CalledByNative; | 22 import org.chromium.base.CalledByNative; |
23 import org.chromium.base.CpuFeatures; | |
23 import org.chromium.base.ThreadUtils; | 24 import org.chromium.base.ThreadUtils; |
24 import org.chromium.content.common.CommandLine; | 25 import org.chromium.content.common.CommandLine; |
25 import org.chromium.content.common.ISandboxedProcessCallback; | 26 import org.chromium.content.common.ISandboxedProcessCallback; |
26 import org.chromium.content.common.ISandboxedProcessService; | 27 import org.chromium.content.common.ISandboxedProcessService; |
27 import org.chromium.content.common.TraceEvent; | 28 import org.chromium.content.common.TraceEvent; |
28 | 29 |
29 public class SandboxedProcessConnection implements ServiceConnection { | 30 public class SandboxedProcessConnection implements ServiceConnection { |
30 interface DeathCallback { | 31 interface DeathCallback { |
31 void onSandboxedProcessDied(int pid); | 32 void onSandboxedProcessDied(int pid); |
32 } | 33 } |
33 | 34 |
34 // Names of items placed in the bind intent or connection bundle. | 35 // Names of items placed in the bind intent or connection bundle. |
35 public static final String EXTRA_COMMAND_LINE = | 36 public static final String EXTRA_COMMAND_LINE = |
36 "com.google.android.apps.chrome.extra.sandbox_command_line"; | 37 "com.google.android.apps.chrome.extra.sandbox_command_line"; |
37 public static final String EXTRA_NATIVE_LIBRARY_NAME = | 38 public static final String EXTRA_NATIVE_LIBRARY_NAME = |
38 "com.google.android.apps.chrome.extra.sandbox_native_library_name"; | 39 "com.google.android.apps.chrome.extra.sandbox_native_library_name"; |
39 // Note the FDs may only be passed in the connection bundle. | 40 // Note the FDs may only be passed in the connection bundle. |
40 public static final String EXTRA_FILES_PREFIX = | 41 public static final String EXTRA_FILES_PREFIX = |
41 "com.google.android.apps.chrome.extra.sandbox_extraFile_"; | 42 "com.google.android.apps.chrome.extra.sandbox_extraFile_"; |
42 public static final String EXTRA_FILES_ID_SUFFIX = "_id"; | 43 public static final String EXTRA_FILES_ID_SUFFIX = "_id"; |
43 public static final String EXTRA_FILES_FD_SUFFIX = "_fd"; | 44 public static final String EXTRA_FILES_FD_SUFFIX = "_fd"; |
44 | 45 |
46 // Used to pass the CPU core count to sandboxed processes. | |
47 public static final String EXTRA_CPU_COUNT = | |
48 "com.google.android.apps.chrome.extra.cpu_count"; | |
49 // Used to pass the CPU features mask to sandboxed processes. | |
50 public static final String EXTRA_CPU_FEATURES = | |
51 "com.google.android.apps.chrome.extra.cpu_features"; | |
52 | |
45 private final Context mContext; | 53 private final Context mContext; |
46 private final int mServiceNumber; | 54 private final int mServiceNumber; |
47 private final SandboxedProcessConnection.DeathCallback mDeathCallback; | 55 private final SandboxedProcessConnection.DeathCallback mDeathCallback; |
48 | 56 |
49 // Synchronization: While most internal flow occurs on the UI thread, the pu blic API | 57 // Synchronization: While most internal flow occurs on the UI thread, the pu blic API |
50 // (specifically bind and unbind) may be called from any thread, hence all e ntry point methods | 58 // (specifically bind and unbind) may be called from any thread, hence all e ntry point methods |
51 // into the class are synchronized on the SandboxedProcessConnection instanc e to protect access | 59 // into the class are synchronized on the SandboxedProcessConnection instanc e to protect access |
52 // to these members. But see also the TODO where AsyncBoundServiceConnection is created. | 60 // to these members. But see also the TODO where AsyncBoundServiceConnection is created. |
53 private ISandboxedProcessService mService = null; | 61 private ISandboxedProcessService mService = null; |
54 private boolean mServiceConnectComplete = false; | 62 private boolean mServiceConnectComplete = false; |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
230 Log.e(TAG, | 238 Log.e(TAG, |
231 "Invalid FD provided for process connection, abort ing connection.", | 239 "Invalid FD provided for process connection, abort ing connection.", |
232 e); | 240 e); |
233 return; | 241 return; |
234 } | 242 } |
235 | 243 |
236 } | 244 } |
237 bundle.putParcelable(fdName, parcelFiles[i]); | 245 bundle.putParcelable(fdName, parcelFiles[i]); |
238 bundle.putInt(idName, fileInfos[i].mId); | 246 bundle.putInt(idName, fileInfos[i].mId); |
239 } | 247 } |
248 // Add the CPU properties now. | |
249 bundle.putInt(EXTRA_CPU_COUNT, CpuFeatures.getCount()); | |
250 bundle.putLong(EXTRA_CPU_FEATURES, CpuFeatures.getMask()); | |
251 Log.i(TAG, "Sending CPU features: count=" + CpuFeatures.getCount() + " features=" + CpuFeatures.getMask()); | |
bulach
2012/12/10 14:03:07
nit: >100cols
digit1
2012/12/10 14:44:56
Actually, this was a debug message that should hav
| |
252 | |
240 try { | 253 try { |
241 mPID = mService.setupConnection(bundle, mConnectionParams.mCallb ack); | 254 mPID = mService.setupConnection(bundle, mConnectionParams.mCallb ack); |
242 } catch (android.os.RemoteException re) { | 255 } catch (android.os.RemoteException re) { |
243 Log.e(TAG, "Failed to setup connection.", re); | 256 Log.e(TAG, "Failed to setup connection.", re); |
244 } | 257 } |
245 // We proactivley close the FDs rather than wait for GC & finalizer. | 258 // We proactivley close the FDs rather than wait for GC & finalizer. |
246 try { | 259 try { |
247 for (ParcelFileDescriptor parcelFile : parcelFiles) { | 260 for (ParcelFileDescriptor parcelFile : parcelFiles) { |
248 if (parcelFile != null) parcelFile.close(); | 261 if (parcelFile != null) parcelFile.close(); |
249 } | 262 } |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
332 } | 345 } |
333 } | 346 } |
334 | 347 |
335 /** | 348 /** |
336 * @return The connection PID, or 0 if not yet connected. | 349 * @return The connection PID, or 0 if not yet connected. |
337 */ | 350 */ |
338 synchronized public int getPid() { | 351 synchronized public int getPid() { |
339 return mPID; | 352 return mPID; |
340 } | 353 } |
341 } | 354 } |
OLD | NEW |