OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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.base.library_loader.LibraryLoader; |
| 22 import org.chromium.base.library_loader.Linker; |
| 23 import org.chromium.base.library_loader.ProcessInitException; |
21 import org.chromium.content.browser.ChildProcessConnection; | 24 import org.chromium.content.browser.ChildProcessConnection; |
22 import org.chromium.content.browser.ChildProcessLauncher; | 25 import org.chromium.content.browser.ChildProcessLauncher; |
23 import org.chromium.content.common.IChildProcessCallback; | 26 import org.chromium.content.common.IChildProcessCallback; |
24 import org.chromium.content.common.IChildProcessService; | 27 import org.chromium.content.common.IChildProcessService; |
25 import org.chromium.content.common.ProcessInitException; | |
26 | 28 |
27 import java.util.ArrayList; | 29 import java.util.ArrayList; |
28 import java.util.concurrent.atomic.AtomicReference; | 30 import java.util.concurrent.atomic.AtomicReference; |
29 | 31 |
30 /** | 32 /** |
31 * This is the base class for child services; the [Non]SandboxedProcessService0,
1.. etc | 33 * 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 | 34 * 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). | 35 * 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 | 36 * The embedding application must declare these service instances in the applica
tion section |
35 * of its AndroidManifest.xml, for example with N entries of the form:- | 37 * of its AndroidManifest.xml, for example with N entries of the form:- |
(...skipping 10 matching lines...) Expand all Loading... |
46 // This is the native "Main" thread for the renderer / utility process. | 48 // This is the native "Main" thread for the renderer / utility process. |
47 private Thread mMainThread; | 49 private Thread mMainThread; |
48 // Parameters received via IPC, only accessed while holding the mMainThread
monitor. | 50 // Parameters received via IPC, only accessed while holding the mMainThread
monitor. |
49 private String[] mCommandLineParams; | 51 private String[] mCommandLineParams; |
50 private int mCpuCount; | 52 private int mCpuCount; |
51 private long mCpuFeatures; | 53 private long mCpuFeatures; |
52 // Pairs IDs and file descriptors that should be registered natively. | 54 // Pairs IDs and file descriptors that should be registered natively. |
53 private ArrayList<Integer> mFileIds; | 55 private ArrayList<Integer> mFileIds; |
54 private ArrayList<ParcelFileDescriptor> mFileFds; | 56 private ArrayList<ParcelFileDescriptor> mFileFds; |
55 // Linker-specific parameters for this child process service. | 57 // Linker-specific parameters for this child process service. |
56 private LinkerParams mLinkerParams; | 58 private ChromiumLinkerParams mLinkerParams; |
57 | 59 |
58 private static AtomicReference<Context> sContext = new AtomicReference<Conte
xt>(null); | 60 private static AtomicReference<Context> sContext = new AtomicReference<Conte
xt>(null); |
59 private boolean mLibraryInitialized = false; | 61 private boolean mLibraryInitialized = false; |
60 // Becomes true once the service is bound. Access must synchronize around mM
ainThread. | 62 // Becomes true once the service is bound. Access must synchronize around mM
ainThread. |
61 private boolean mIsBound = false; | 63 private boolean mIsBound = false; |
62 | 64 |
63 // Binder object used by clients for this service. | 65 // Binder object used by clients for this service. |
64 private final IChildProcessService.Stub mBinder = new IChildProcessService.S
tub() { | 66 private final IChildProcessService.Stub mBinder = new IChildProcessService.S
tub() { |
65 // NOTE: Implement any IChildProcessService methods here. | 67 // NOTE: Implement any IChildProcessService methods here. |
66 @Override | 68 @Override |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 return; | 191 return; |
190 } | 192 } |
191 synchronized (mMainThread) { | 193 synchronized (mMainThread) { |
192 try { | 194 try { |
193 while (!mLibraryInitialized) { | 195 while (!mLibraryInitialized) { |
194 // Avoid a potential race in calling through to native code
before the library | 196 // Avoid a potential race in calling through to native code
before the library |
195 // has loaded. | 197 // has loaded. |
196 mMainThread.wait(); | 198 mMainThread.wait(); |
197 } | 199 } |
198 } catch (InterruptedException e) { | 200 } catch (InterruptedException e) { |
| 201 // Ignore |
199 } | 202 } |
200 } | 203 } |
201 // Try to shutdown the MainThread gracefully, but it might not | 204 // Try to shutdown the MainThread gracefully, but it might not |
202 // have chance to exit normally. | 205 // have chance to exit normally. |
203 nativeShutdownMainThread(); | 206 nativeShutdownMainThread(); |
204 } | 207 } |
205 | 208 |
206 @Override | 209 @Override |
207 public IBinder onBind(Intent intent) { | 210 public IBinder onBind(Intent intent) { |
208 // We call stopSelf() to request that this service be stopped as soon as
the client | 211 // We call stopSelf() to request that this service be stopped as soon as
the client |
209 // unbinds. Otherwise the system may keep it around and available for a
reconnect. The | 212 // unbinds. Otherwise the system may keep it around and available for a
reconnect. The |
210 // child processes do not currently support reconnect; they must be init
ialized from | 213 // child processes do not currently support reconnect; they must be init
ialized from |
211 // scratch every time. | 214 // scratch every time. |
212 stopSelf(); | 215 stopSelf(); |
213 | 216 |
214 synchronized (mMainThread) { | 217 synchronized (mMainThread) { |
215 mCommandLineParams = intent.getStringArrayExtra( | 218 mCommandLineParams = intent.getStringArrayExtra( |
216 ChildProcessConnection.EXTRA_COMMAND_LINE); | 219 ChildProcessConnection.EXTRA_COMMAND_LINE); |
217 mLinkerParams = null; | 220 mLinkerParams = null; |
218 if (Linker.isUsed()) | 221 if (Linker.isUsed()) |
219 mLinkerParams = new LinkerParams(intent); | 222 mLinkerParams = new ChromiumLinkerParams(intent); |
220 mIsBound = true; | 223 mIsBound = true; |
221 mMainThread.notifyAll(); | 224 mMainThread.notifyAll(); |
222 } | 225 } |
223 | 226 |
224 return mBinder; | 227 return mBinder; |
225 } | 228 } |
226 | 229 |
227 /** | 230 /** |
228 * Called from native code to share a surface texture with another child pro
cess. | 231 * Called from native code to share a surface texture with another child pro
cess. |
229 * Through using the callback object the browser is used as a proxy to route
the | 232 * Through using the callback object the browser is used as a proxy to route
the |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 ChildProcessService service, int[] extraFileIds, int[] extraFileFds, | 299 ChildProcessService service, int[] extraFileIds, int[] extraFileFds, |
297 int cpuCount, long cpuFeatures); | 300 int cpuCount, long cpuFeatures); |
298 | 301 |
299 /** | 302 /** |
300 * Force the child process to exit. | 303 * Force the child process to exit. |
301 */ | 304 */ |
302 private static native void nativeExitChildProcess(); | 305 private static native void nativeExitChildProcess(); |
303 | 306 |
304 private native void nativeShutdownMainThread(); | 307 private native void nativeShutdownMainThread(); |
305 } | 308 } |
OLD | NEW |