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

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

Issue 2809293005: android: assert runningOnLauncherThread (Closed)
Patch Set: assert Created 3 years, 8 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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.ParcelFileDescriptor; 8 import android.os.ParcelFileDescriptor;
9 9
10 import org.chromium.base.ContextUtils; 10 import org.chromium.base.ContextUtils;
(...skipping 11 matching lines...) Expand all
22 * Each public or jni methods should have explicit documentation on what threads they are called. 22 * Each public or jni methods should have explicit documentation on what threads they are called.
23 */ 23 */
24 @JNINamespace("content::internal") 24 @JNINamespace("content::internal")
25 class ChildProcessLauncherHelper { 25 class ChildProcessLauncherHelper {
26 private static final String TAG = "ChildProcLH"; 26 private static final String TAG = "ChildProcLH";
27 27
28 // Note native pointer is only guaranteed live until nativeOnChildProcessSta rted. 28 // Note native pointer is only guaranteed live until nativeOnChildProcessSta rted.
29 private long mNativeChildProcessLauncherHelper; 29 private long mNativeChildProcessLauncherHelper;
30 private int mPid; 30 private int mPid;
31 31
32 // Called on launcher thread.
33 @CalledByNative 32 @CalledByNative
34 private static FileDescriptorInfo makeFdInfo( 33 private static FileDescriptorInfo makeFdInfo(
35 int id, int fd, boolean autoClose, long offset, long size) { 34 int id, int fd, boolean autoClose, long offset, long size) {
35 assert LauncherThread.runningOnLauncherThread();
36 ParcelFileDescriptor pFd; 36 ParcelFileDescriptor pFd;
37 if (autoClose) { 37 if (autoClose) {
38 // Adopt the FD, it will be closed when we close the ParcelFileDescr iptor. 38 // Adopt the FD, it will be closed when we close the ParcelFileDescr iptor.
39 pFd = ParcelFileDescriptor.adoptFd(fd); 39 pFd = ParcelFileDescriptor.adoptFd(fd);
40 } else { 40 } else {
41 try { 41 try {
42 pFd = ParcelFileDescriptor.fromFd(fd); 42 pFd = ParcelFileDescriptor.fromFd(fd);
43 } catch (IOException e) { 43 } catch (IOException e) {
44 Log.e(TAG, "Invalid FD provided for process connection, aborting connection.", e); 44 Log.e(TAG, "Invalid FD provided for process connection, aborting connection.", e);
45 return null; 45 return null;
46 } 46 }
47 } 47 }
48 return new FileDescriptorInfo(id, pFd, offset, size); 48 return new FileDescriptorInfo(id, pFd, offset, size);
49 } 49 }
50 50
51 // Called on launcher thread.
52 @CalledByNative 51 @CalledByNative
53 private static ChildProcessLauncherHelper create(long nativePointer, Context context, 52 private static ChildProcessLauncherHelper create(long nativePointer, Context context,
54 int paramId, final String[] commandLine, int childProcessId, 53 int paramId, final String[] commandLine, int childProcessId,
55 FileDescriptorInfo[] filesToBeMapped) { 54 FileDescriptorInfo[] filesToBeMapped) {
55 assert LauncherThread.runningOnLauncherThread();
56 return new ChildProcessLauncherHelper( 56 return new ChildProcessLauncherHelper(
57 nativePointer, context, paramId, commandLine, childProcessId, fi lesToBeMapped); 57 nativePointer, context, paramId, commandLine, childProcessId, fi lesToBeMapped);
58 } 58 }
59 59
60 private ChildProcessLauncherHelper(long nativePointer, Context context, int paramId, 60 private ChildProcessLauncherHelper(long nativePointer, Context context, int paramId,
61 final String[] commandLine, int childProcessId, FileDescriptorInfo[] filesToBeMapped) { 61 final String[] commandLine, int childProcessId, FileDescriptorInfo[] filesToBeMapped) {
62 assert LauncherThread.runningOnLauncherThread();
62 mNativeChildProcessLauncherHelper = nativePointer; 63 mNativeChildProcessLauncherHelper = nativePointer;
63 64
64 ChildProcessLauncher.start(context, paramId, commandLine, childProcessId , filesToBeMapped, 65 ChildProcessLauncher.start(context, paramId, commandLine, childProcessId , filesToBeMapped,
65 new ChildProcessLauncher.LaunchCallback() { 66 new ChildProcessLauncher.LaunchCallback() {
66 @Override 67 @Override
67 public void onChildProcessStarted(int pid) { 68 public void onChildProcessStarted(int pid) {
68 mPid = pid; 69 mPid = pid;
69 if (mNativeChildProcessLauncherHelper != 0) { 70 if (mNativeChildProcessLauncherHelper != 0) {
70 nativeOnChildProcessStarted(mNativeChildProcessLaunc herHelper, pid); 71 nativeOnChildProcessStarted(mNativeChildProcessLaunc herHelper, pid);
71 } 72 }
72 mNativeChildProcessLauncherHelper = 0; 73 mNativeChildProcessLauncherHelper = 0;
73 } 74 }
74 }); 75 });
75 } 76 }
76 77
77 // Called on client (UI or IO) thread. 78 // Called on client (UI or IO) thread.
78 @CalledByNative 79 @CalledByNative
79 private boolean isOomProtected() { 80 private boolean isOomProtected() {
80 return ChildProcessLauncher.getBindingManager().isOomProtected(mPid); 81 return ChildProcessLauncher.getBindingManager().isOomProtected(mPid);
81 } 82 }
82 83
83 // Called on launcher thread.
84 @CalledByNative 84 @CalledByNative
85 private void setInForeground(int pid, boolean inForeground) { 85 private void setInForeground(int pid, boolean inForeground) {
86 assert LauncherThread.runningOnLauncherThread();
86 assert mPid == pid; 87 assert mPid == pid;
87 ChildProcessLauncher.getBindingManager().setInForeground(mPid, inForegro und); 88 ChildProcessLauncher.getBindingManager().setInForeground(mPid, inForegro und);
88 } 89 }
89 90
91 // Called on client (UI or IO) thread and launcher thread.
90 @CalledByNative 92 @CalledByNative
91 private static void stop(int pid) { 93 private static void stop(int pid) {
92 ChildProcessLauncher.stop(pid); 94 ChildProcessLauncher.stop(pid);
93 } 95 }
94 96
95 // Called on UI thread. 97 // Called on UI thread.
96 @CalledByNative 98 @CalledByNative
97 private static int getNumberOfRendererSlots() { 99 private static int getNumberOfRendererSlots() {
98 final ChildProcessCreationParams params = ChildProcessCreationParams.get Default(); 100 final ChildProcessCreationParams params = ChildProcessCreationParams.get Default();
99 final Context context = ContextUtils.getApplicationContext(); 101 final Context context = ContextUtils.getApplicationContext();
100 final boolean inSandbox = true; 102 final boolean inSandbox = true;
101 final String packageName = 103 final String packageName =
102 params == null ? context.getPackageName() : params.getPackageNam e(); 104 params == null ? context.getPackageName() : params.getPackageNam e();
103 try { 105 try {
104 return ChildConnectionAllocator.getNumberOfServices(context, inSandb ox, packageName); 106 return ChildConnectionAllocator.getNumberOfServices(context, inSandb ox, packageName);
105 } catch (RuntimeException e) { 107 } catch (RuntimeException e) {
106 // Unittest packages do not declare services. Some tests require a r ealistic number 108 // Unittest packages do not declare services. Some tests require a r ealistic number
107 // to test child process policies, so pick a high-ish number here. 109 // to test child process policies, so pick a high-ish number here.
108 return 65535; 110 return 65535;
109 } 111 }
110 } 112 }
111 113
112 // Can be called on a number of threads, including launcher, and binder. 114 // Can be called on a number of threads, including launcher, and binder.
113 private static native void nativeOnChildProcessStarted( 115 private static native void nativeOnChildProcessStarted(
114 long nativeChildProcessLauncherHelper, int pid); 116 long nativeChildProcessLauncherHelper, int pid);
115 } 117 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698