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

Side by Side Diff: content/public/android/java/src/org/chromium/content/app/ChildProcessService.java

Issue 23717023: Android: Add chrome-specific dynamic linker. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix base_unittests_apk Created 7 years, 3 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 (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;
11 import android.os.Bundle; 11 import android.os.Bundle;
12 import android.os.IBinder; 12 import android.os.IBinder;
13 import android.os.ParcelFileDescriptor; 13 import android.os.ParcelFileDescriptor;
14 import android.os.Process; 14 import android.os.Process;
15 import android.os.RemoteException; 15 import android.os.RemoteException;
16 import android.util.Log; 16 import android.util.Log;
17 import android.view.Surface; 17 import android.view.Surface;
18 18
19 import org.chromium.base.CalledByNative; 19 import org.chromium.base.CalledByNative;
20 import org.chromium.base.JNINamespace; 20 import org.chromium.base.JNINamespace;
21 import org.chromium.content.browser.ChildProcessConnection; 21 import org.chromium.content.browser.ChildProcessConnection;
22 import org.chromium.content.common.IChildProcessCallback; 22 import org.chromium.content.common.IChildProcessCallback;
23 import org.chromium.content.common.IChildProcessService; 23 import org.chromium.content.common.IChildProcessService;
24 import org.chromium.content.browser.ChildProcessLauncher;
25 import org.chromium.content.common.ProcessInitException; 24 import org.chromium.content.common.ProcessInitException;
26 25
27 import java.util.ArrayList; 26 import java.util.ArrayList;
28 import java.util.concurrent.atomic.AtomicReference; 27 import java.util.concurrent.atomic.AtomicReference;
29 28
30 /** 29 /**
31 * This is the base class for child services; the [Non]SandboxedProcessService0, 1.. etc 30 * This is the base class for child services; the [Non]SandboxedProcessService0, 1.. etc
32 * subclasses provide the concrete service entry points, to enable the browser t o connect 31 * subclasses provide the concrete service entry points, to enable the browser t o connect
33 * to more than one distinct process (i.e. one process per service number, up to limit of N). 32 * to more than one distinct process (i.e. one process per service number, up to limit of N).
34 * The embedding application must declare these service instances in the applica tion section 33 * The embedding application must declare these service instances in the applica tion section
(...skipping 10 matching lines...) Expand all
45 44
46 // This is the native "Main" thread for the renderer / utility process. 45 // This is the native "Main" thread for the renderer / utility process.
47 private Thread mMainThread; 46 private Thread mMainThread;
48 // Parameters received via IPC, only accessed while holding the mMainThread monitor. 47 // Parameters received via IPC, only accessed while holding the mMainThread monitor.
49 private String[] mCommandLineParams; 48 private String[] mCommandLineParams;
50 private int mCpuCount; 49 private int mCpuCount;
51 private long mCpuFeatures; 50 private long mCpuFeatures;
52 // Pairs IDs and file descriptors that should be registered natively. 51 // Pairs IDs and file descriptors that should be registered natively.
53 private ArrayList<Integer> mFileIds; 52 private ArrayList<Integer> mFileIds;
54 private ArrayList<ParcelFileDescriptor> mFileFds; 53 private ArrayList<ParcelFileDescriptor> mFileFds;
54 // Linker-specific parameters for this child process service.
55 private LinkerParams mLinkerParams;
55 56
56 private static AtomicReference<Context> sContext = new AtomicReference<Conte xt>(null); 57 private static AtomicReference<Context> sContext = new AtomicReference<Conte xt>(null);
57 private boolean mLibraryInitialized = false; 58 private boolean mLibraryInitialized = false;
59 // Becomes true once the service is bound.
60 private boolean mIsBound = false;
58 61
59 // Binder object used by clients for this service. 62 // Binder object used by clients for this service.
60 private final IChildProcessService.Stub mBinder = new IChildProcessService.S tub() { 63 private final IChildProcessService.Stub mBinder = new IChildProcessService.S tub() {
61 // NOTE: Implement any IChildProcessService methods here. 64 // NOTE: Implement any IChildProcessService methods here.
62 @Override 65 @Override
63 public int setupConnection(Bundle args, IChildProcessCallback callback) { 66 public int setupConnection(Bundle args, IChildProcessCallback callback) {
64 mCallback = callback; 67 mCallback = callback;
65 synchronized (mMainThread) { 68 synchronized (mMainThread) {
66 // Allow the command line to be set via bind() intent or setupCo nnection, but 69 // Allow the command line to be set via bind() intent or setupCo nnection, but
67 // the FD can only be transferred here. 70 // the FD can only be transferred here.
(...skipping 14 matching lines...) Expand all
82 ParcelFileDescriptor parcel = args.getParcelable(fdName); 85 ParcelFileDescriptor parcel = args.getParcelable(fdName);
83 if (parcel == null) { 86 if (parcel == null) {
84 // End of the file list. 87 // End of the file list.
85 break; 88 break;
86 } 89 }
87 mFileFds.add(parcel); 90 mFileFds.add(parcel);
88 String idName = ChildProcessConnection.EXTRA_FILES_PREFIX + i 91 String idName = ChildProcessConnection.EXTRA_FILES_PREFIX + i
89 + ChildProcessConnection.EXTRA_FILES_ID_SUFFIX; 92 + ChildProcessConnection.EXTRA_FILES_ID_SUFFIX;
90 mFileIds.add(args.getInt(idName)); 93 mFileIds.add(args.getInt(idName));
91 } 94 }
95 Bundle sharedRelros = args.getBundle(Linker.EXTRA_LINKER_SHARED_ RELROS);
96 if (sharedRelros != null) {
97 Linker.useSharedRelros(sharedRelros);
palmer 2013/10/01 00:11:22 How sure are we that only the browser could invoke
digit1 2013/10/01 15:40:20 Yes, this is part of the existing code for startin
98 sharedRelros = null;
99 }
92 mMainThread.notifyAll(); 100 mMainThread.notifyAll();
93 } 101 }
94 return Process.myPid(); 102 return Process.myPid();
95 } 103 }
96 }; 104 };
97 105
98 /* package */ static Context getContext() { 106 /* package */ static Context getContext() {
99 return sContext.get(); 107 return sContext.get();
100 } 108 }
101 109
102 @Override 110 @Override
103 public void onCreate() { 111 public void onCreate() {
104 Log.i(TAG, "Creating new ChildProcessService pid=" + Process.myPid()); 112 Log.i(TAG, "Creating new ChildProcessService pid=" + Process.myPid());
105 if (sContext.get() != null) { 113 if (sContext.get() != null) {
106 Log.e(TAG, "ChildProcessService created again in process!"); 114 Log.e(TAG, "ChildProcessService created again in process!");
107 } 115 }
108 sContext.set(this); 116 sContext.set(this);
109 super.onCreate(); 117 super.onCreate();
110 118
111 mMainThread = new Thread(new Runnable() { 119 mMainThread = new Thread(new Runnable() {
112 @Override 120 @Override
113 public void run() { 121 public void run() {
114 try { 122 try {
123 boolean useLinker = Linker.isUsed();
124
125 if (useLinker) {
126 synchronized (mMainThread) {
127 while (!mIsBound)
128 mMainThread.wait();
129 }
130 if (mLinkerParams != null && mLinkerParams.mWaitForShare dRelro)
131 Linker.initServiceProcess(mLinkerParams.mBaseLoadAdd ress);
132 else
133 Linker.disableSharedRelros();
134 }
115 try { 135 try {
116 LibraryLoader.loadNow(); 136 LibraryLoader.loadNow();
117 } catch (ProcessInitException e) { 137 } catch (ProcessInitException e) {
118 Log.e(TAG, "Failed to load native library, exiting child process", e); 138 Log.e(TAG, "Failed to load native library, exiting child process", e);
119 return; 139 return;
120 } 140 }
121 synchronized (mMainThread) { 141 synchronized (mMainThread) {
122 while (mCommandLineParams == null) { 142 while (mCommandLineParams == null) {
123 mMainThread.wait(); 143 mMainThread.wait();
124 } 144 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 public IBinder onBind(Intent intent) { 201 public IBinder onBind(Intent intent) {
182 // We call stopSelf() to request that this service be stopped as soon as the client 202 // We call stopSelf() to request that this service be stopped as soon as the client
183 // unbinds. Otherwise the system may keep it around and available for a reconnect. The 203 // unbinds. Otherwise the system may keep it around and available for a reconnect. The
184 // child processes do not currently support reconnect; they must be init ialized from 204 // child processes do not currently support reconnect; they must be init ialized from
185 // scratch every time. 205 // scratch every time.
186 stopSelf(); 206 stopSelf();
187 207
188 synchronized (mMainThread) { 208 synchronized (mMainThread) {
189 mCommandLineParams = intent.getStringArrayExtra( 209 mCommandLineParams = intent.getStringArrayExtra(
190 ChildProcessConnection.EXTRA_COMMAND_LINE); 210 ChildProcessConnection.EXTRA_COMMAND_LINE);
211 mLinkerParams = null;
212 if (Linker.isUsed())
213 mLinkerParams = new LinkerParams(intent);
214 mIsBound = true;
191 mMainThread.notifyAll(); 215 mMainThread.notifyAll();
192 } 216 }
193 217
194 return mBinder; 218 return mBinder;
195 } 219 }
196 220
197 /** 221 /**
198 * Called from native code to share a surface texture with another child pro cess. 222 * Called from native code to share a surface texture with another child pro cess.
199 * Through using the callback object the browser is used as a proxy to route the 223 * Through using the callback object the browser is used as a proxy to route the
200 * call to the correct process. 224 * call to the correct process.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 ChildProcessService service, int[] extraFileIds, int[] extraFileFds, 290 ChildProcessService service, int[] extraFileIds, int[] extraFileFds,
267 int cpuCount, long cpuFeatures); 291 int cpuCount, long cpuFeatures);
268 292
269 /** 293 /**
270 * Force the child process to exit. 294 * Force the child process to exit.
271 */ 295 */
272 private static native void nativeExitChildProcess(); 296 private static native void nativeExitChildProcess();
273 297
274 private native void nativeShutdownMainThread(); 298 private native void nativeShutdownMainThread();
275 } 299 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698