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.browser; | 5 package org.chromium.content.browser; |
6 | 6 |
7 import android.os.Bundle; | |
bulach
2013/09/09 16:14:15
nit: sort order
digit1
2013/09/10 09:23:30
Done.
| |
7 import android.content.Context; | 8 import android.content.Context; |
8 import android.util.Log; | 9 import android.util.Log; |
9 import android.util.SparseIntArray; | 10 import android.util.SparseIntArray; |
10 import android.view.Surface; | 11 import android.view.Surface; |
11 | 12 |
12 import java.util.ArrayList; | 13 import java.util.ArrayList; |
13 import java.util.Map; | 14 import java.util.Map; |
14 import java.util.concurrent.ConcurrentHashMap; | 15 import java.util.concurrent.ConcurrentHashMap; |
15 | 16 |
16 import org.chromium.base.CalledByNative; | 17 import org.chromium.base.CalledByNative; |
17 import org.chromium.base.JNINamespace; | 18 import org.chromium.base.JNINamespace; |
19 import org.chromium.base.Linker; | |
18 import org.chromium.base.ThreadUtils; | 20 import org.chromium.base.ThreadUtils; |
19 import org.chromium.content.app.ChildProcessService; | 21 import org.chromium.content.app.ChildProcessService; |
22 import org.chromium.content.app.LibraryLoader; | |
20 import org.chromium.content.app.PrivilegedProcessService; | 23 import org.chromium.content.app.PrivilegedProcessService; |
21 import org.chromium.content.app.SandboxedProcessService; | 24 import org.chromium.content.app.SandboxedProcessService; |
22 import org.chromium.content.common.IChildProcessCallback; | 25 import org.chromium.content.common.IChildProcessCallback; |
23 import org.chromium.content.common.IChildProcessService; | 26 import org.chromium.content.common.IChildProcessService; |
24 | 27 |
25 /** | 28 /** |
26 * This class provides the method to start/stop ChildProcess called by native. | 29 * This class provides the method to start/stop ChildProcess called by native. |
27 */ | 30 */ |
28 @JNINamespace("content") | 31 @JNINamespace("content") |
29 public class ChildProcessLauncher { | 32 public class ChildProcessLauncher { |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
168 return; | 171 return; |
169 } | 172 } |
170 | 173 |
171 // Represents an invalid process handle; same as base/process/process.h kNul lProcessHandle. | 174 // Represents an invalid process handle; same as base/process/process.h kNul lProcessHandle. |
172 private static final int NULL_PROCESS_HANDLE = 0; | 175 private static final int NULL_PROCESS_HANDLE = 0; |
173 | 176 |
174 // Map from pid to ChildService connection. | 177 // Map from pid to ChildService connection. |
175 private static Map<Integer, ChildProcessConnection> sServiceMap = | 178 private static Map<Integer, ChildProcessConnection> sServiceMap = |
176 new ConcurrentHashMap<Integer, ChildProcessConnection>(); | 179 new ConcurrentHashMap<Integer, ChildProcessConnection>(); |
177 | 180 |
181 // Bundle from Linker.getRelroBundle(), to be sent to each service once | |
182 // setRelroBundle() is called. | |
183 private static Bundle sRelroBundle = null; | |
184 | |
178 // Map from pid to the count of oom bindings. "Oom binding" is a binding tha t raises the process | 185 // Map from pid to the count of oom bindings. "Oom binding" is a binding tha t raises the process |
179 // oom priority so that it shouldn't be killed by the OS out-of-memory kille r under normal | 186 // oom priority so that it shouldn't be killed by the OS out-of-memory kille r under normal |
180 // conditions (it can still be killed under drastic memory pressure). | 187 // conditions (it can still be killed under drastic memory pressure). |
181 private static SparseIntArray sOomBindingCount = new SparseIntArray(); | 188 private static SparseIntArray sOomBindingCount = new SparseIntArray(); |
182 | 189 |
183 // A pre-allocated and pre-bound connection ready for connection setup, or n ull. | 190 // A pre-allocated and pre-bound connection ready for connection setup, or n ull. |
184 private static ChildProcessConnection sSpareSandboxedConnection = null; | 191 private static ChildProcessConnection sSpareSandboxedConnection = null; |
185 | 192 |
186 /** | 193 /** |
187 * Returns the child process service interface for the given pid. This may b e called on | 194 * Returns the child process service interface for the given pid. This may b e called on |
(...skipping 13 matching lines...) Expand all Loading... | |
201 | 208 |
202 /** | 209 /** |
203 * Should be called early in startup so the work needed to spawn the child p rocess can be done | 210 * Should be called early in startup so the work needed to spawn the child p rocess can be done |
204 * in parallel to other startup work. Must not be called on the UI thread. S pare connection is | 211 * in parallel to other startup work. Must not be called on the UI thread. S pare connection is |
205 * created in sandboxed child process. | 212 * created in sandboxed child process. |
206 * @param context the application context used for the connection. | 213 * @param context the application context used for the connection. |
207 */ | 214 */ |
208 public static void warmUp(Context context) { | 215 public static void warmUp(Context context) { |
209 synchronized (ChildProcessLauncher.class) { | 216 synchronized (ChildProcessLauncher.class) { |
210 assert !ThreadUtils.runningOnUiThread(); | 217 assert !ThreadUtils.runningOnUiThread(); |
218 if (LibraryLoader.useCrazyLinker()) { | |
219 // Initialization of the relro sharing must happen before any pr ocess is started. | |
220 Linker.initRelroSharing(); | |
221 } | |
211 if (sSpareSandboxedConnection == null) { | 222 if (sSpareSandboxedConnection == null) { |
212 sSpareSandboxedConnection = allocateBoundConnection(context, nul l, true); | 223 sSpareSandboxedConnection = allocateBoundConnection(context, nul l, true); |
213 } | 224 } |
214 } | 225 } |
215 } | 226 } |
216 | 227 |
228 public static void setRelroBundle(Bundle bundle) { | |
229 synchronized (ChildProcessLauncher.class) { | |
230 sRelroBundle = bundle; | |
231 if (bundle != null) { | |
232 for (Map.Entry<Integer, ChildProcessConnection> entry : sService Map.entrySet()) { | |
233 ChildProcessConnection connection = entry.getValue(); | |
234 connection.applyRelro(bundle); | |
235 } | |
236 } | |
237 } | |
238 } | |
239 | |
217 private static String getSwitchValue(final String[] commandLine, String swit chKey) { | 240 private static String getSwitchValue(final String[] commandLine, String swit chKey) { |
218 if (commandLine == null || switchKey == null) { | 241 if (commandLine == null || switchKey == null) { |
219 return null; | 242 return null; |
220 } | 243 } |
221 // This format should be matched with the one defined in command_line.h. | 244 // This format should be matched with the one defined in command_line.h. |
222 final String switchKeyPrefix = "--" + switchKey + "="; | 245 final String switchKeyPrefix = "--" + switchKey + "="; |
223 for (String command : commandLine) { | 246 for (String command : commandLine) { |
224 if (command != null && command.startsWith(switchKeyPrefix)) { | 247 if (command != null && command.startsWith(switchKeyPrefix)) { |
225 return command.substring(switchKeyPrefix.length()); | 248 return command.substring(switchKeyPrefix.length()); |
226 } | 249 } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
287 final ChildProcessConnection connection = allocatedConnection; | 310 final ChildProcessConnection connection = allocatedConnection; |
288 Log.d(TAG, "Setting up connection to process: slot=" + connection.getSer viceNumber()); | 311 Log.d(TAG, "Setting up connection to process: slot=" + connection.getSer viceNumber()); |
289 | 312 |
290 ChildProcessConnection.ConnectionCallbacks connectionCallbacks = | 313 ChildProcessConnection.ConnectionCallbacks connectionCallbacks = |
291 new ChildProcessConnection.ConnectionCallbacks() { | 314 new ChildProcessConnection.ConnectionCallbacks() { |
292 public void onConnected(int pid, int oomBindingCount) { | 315 public void onConnected(int pid, int oomBindingCount) { |
293 Log.d(TAG, "on connect callback, pid=" + pid + " context=" + cli entContext); | 316 Log.d(TAG, "on connect callback, pid=" + pid + " context=" + cli entContext); |
294 if (pid != NULL_PROCESS_HANDLE) { | 317 if (pid != NULL_PROCESS_HANDLE) { |
295 sOomBindingCount.put(pid, oomBindingCount); | 318 sOomBindingCount.put(pid, oomBindingCount); |
296 sServiceMap.put(pid, connection); | 319 sServiceMap.put(pid, connection); |
320 | |
321 if (sRelroBundle != null) | |
322 connection.applyRelro(sRelroBundle); | |
297 } else { | 323 } else { |
298 freeConnection(connection); | 324 freeConnection(connection); |
299 } | 325 } |
300 nativeOnChildProcessStarted(clientContext, pid); | 326 nativeOnChildProcessStarted(clientContext, pid); |
301 } | 327 } |
302 | 328 |
303 public void onOomBindingAdded(int pid) { | 329 public void onOomBindingAdded(int pid) { |
304 if (pid != NULL_PROCESS_HANDLE) { | 330 if (pid != NULL_PROCESS_HANDLE) { |
305 sOomBindingCount.put(pid, sOomBindingCount.get(pid) + 1); | 331 sOomBindingCount.put(pid, sOomBindingCount.get(pid) + 1); |
306 } | 332 } |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
439 Log.w(TAG, message + ", pid=" + pid); | 465 Log.w(TAG, message + ", pid=" + pid); |
440 } | 466 } |
441 } | 467 } |
442 | 468 |
443 private static native void nativeOnChildProcessStarted(int clientContext, in t pid); | 469 private static native void nativeOnChildProcessStarted(int clientContext, in t pid); |
444 private static native Surface nativeGetViewSurface(int surfaceId); | 470 private static native Surface nativeGetViewSurface(int surfaceId); |
445 private static native void nativeEstablishSurfacePeer( | 471 private static native void nativeEstablishSurfacePeer( |
446 int pid, Surface surface, int primaryID, int secondaryID); | 472 int pid, Surface surface, int primaryID, int secondaryID); |
447 private static native boolean nativeIsSingleProcess(); | 473 private static native boolean nativeIsSingleProcess(); |
448 } | 474 } |
OLD | NEW |