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

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

Issue 1156183003: Pass file Regions along with FDs to child processes on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: actual fix Created 5 years, 6 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 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.content.Context; 7 import android.content.Context;
8 import android.content.pm.ApplicationInfo; 8 import android.content.pm.ApplicationInfo;
9 import android.content.pm.PackageManager; 9 import android.content.pm.PackageManager;
10 import android.graphics.SurfaceTexture; 10 import android.graphics.SurfaceTexture;
11 import android.os.ParcelFileDescriptor;
11 import android.os.RemoteException; 12 import android.os.RemoteException;
12 import android.util.Pair; 13 import android.util.Pair;
13 import android.view.Surface; 14 import android.view.Surface;
14 15
15 import org.chromium.base.CalledByNative; 16 import org.chromium.base.CalledByNative;
16 import org.chromium.base.JNINamespace; 17 import org.chromium.base.JNINamespace;
17 import org.chromium.base.Log; 18 import org.chromium.base.Log;
18 import org.chromium.base.ThreadUtils; 19 import org.chromium.base.ThreadUtils;
19 import org.chromium.base.TraceEvent; 20 import org.chromium.base.TraceEvent;
20 import org.chromium.base.VisibleForTesting; 21 import org.chromium.base.VisibleForTesting;
21 import org.chromium.base.library_loader.Linker; 22 import org.chromium.base.library_loader.Linker;
22 import org.chromium.content.app.ChildProcessService; 23 import org.chromium.content.app.ChildProcessService;
23 import org.chromium.content.app.ChromiumLinkerParams; 24 import org.chromium.content.app.ChromiumLinkerParams;
24 import org.chromium.content.app.PrivilegedProcessService; 25 import org.chromium.content.app.PrivilegedProcessService;
25 import org.chromium.content.app.SandboxedProcessService; 26 import org.chromium.content.app.SandboxedProcessService;
26 import org.chromium.content.common.IChildProcessCallback; 27 import org.chromium.content.common.IChildProcessCallback;
27 import org.chromium.content.common.SurfaceWrapper; 28 import org.chromium.content.common.SurfaceWrapper;
28 29
30 import java.io.IOException;
29 import java.util.ArrayList; 31 import java.util.ArrayList;
30 import java.util.LinkedList; 32 import java.util.LinkedList;
31 import java.util.Map; 33 import java.util.Map;
32 import java.util.Queue; 34 import java.util.Queue;
33 import java.util.concurrent.ConcurrentHashMap; 35 import java.util.concurrent.ConcurrentHashMap;
34 36
35 /** 37 /**
36 * This class provides the method to start/stop ChildProcess called by native. 38 * This class provides the method to start/stop ChildProcess called by native.
37 */ 39 */
38 @JNINamespace("content") 40 @JNINamespace("content")
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 // This format should be matched with the one defined in command_line.h. 478 // This format should be matched with the one defined in command_line.h.
477 final String switchKeyPrefix = "--" + switchKey + "="; 479 final String switchKeyPrefix = "--" + switchKey + "=";
478 for (String command : commandLine) { 480 for (String command : commandLine) {
479 if (command != null && command.startsWith(switchKeyPrefix)) { 481 if (command != null && command.startsWith(switchKeyPrefix)) {
480 return command.substring(switchKeyPrefix.length()); 482 return command.substring(switchKeyPrefix.length());
481 } 483 }
482 } 484 }
483 return null; 485 return null;
484 } 486 }
485 487
488 @CalledByNative
489 private static FileDescriptorInfo makeFdInfo(
490 int id, int fd, boolean autoClose, long offset, long size) {
491 ParcelFileDescriptor pFd;
492 if (autoClose) {
493 // Adopt the FD, it will be closed when we close the ParcelFileDescr iptor.
494 pFd = ParcelFileDescriptor.adoptFd(fd);
495 } else {
496 try {
497 pFd = ParcelFileDescriptor.fromFd(fd);
498 } catch (IOException e) {
499 Log.e(TAG, "Invalid FD provided for process connection, aborting connection.", e);
500 return null;
501 }
502 }
503 return new FileDescriptorInfo(id, pFd, offset, size);
504 }
505
486 /** 506 /**
487 * Spawns and connects to a child process. May be called on any thread. It w ill not block, but 507 * Spawns and connects to a child process. May be called on any thread. It w ill not block, but
488 * will instead callback to {@link #nativeOnChildProcessStarted} when the co nnection is 508 * will instead callback to {@link #nativeOnChildProcessStarted} when the co nnection is
489 * established. Note this callback will not necessarily be from the same thr ead (currently it 509 * established. Note this callback will not necessarily be from the same thr ead (currently it
490 * always comes from the main thread). 510 * always comes from the main thread).
491 * 511 *
492 * @param context Context used to obtain the application context. 512 * @param context Context used to obtain the application context.
493 * @param commandLine The child process command line argv. 513 * @param commandLine The child process command line argv.
494 * @param fileIds The ID that should be used when mapping files in the creat ed process. 514 * @param filesToBeMapped File IDs, FDs, offsets, and lengths to pass throug h.
495 * @param fileFds The file descriptors that should be mapped in the created process.
496 * @param fileAutoClose Whether the file descriptors should be closed once t hey were passed to
497 * the created process.
498 * @param clientContext Arbitrary parameter used by the client to distinguis h this connection. 515 * @param clientContext Arbitrary parameter used by the client to distinguis h this connection.
499 */ 516 */
500 @CalledByNative 517 @CalledByNative
501 static void start( 518 private static void start(Context context, final String[] commandLine, int c hildProcessId,
502 Context context, 519 FileDescriptorInfo[] filesToBeMapped, long clientContext) {
503 final String[] commandLine,
504 int childProcessId,
505 int[] fileIds,
506 int[] fileFds,
507 boolean[] fileAutoClose,
508 long clientContext) {
509 assert fileIds.length == fileFds.length && fileFds.length == fileAutoClo se.length;
510 FileDescriptorInfo[] filesToBeMapped = new FileDescriptorInfo[fileFds.le ngth];
511 for (int i = 0; i < fileFds.length; i++) {
512 filesToBeMapped[i] =
513 new FileDescriptorInfo(fileIds[i], fileFds[i], fileAutoClose [i]);
514 }
515 assert clientContext != 0; 520 assert clientContext != 0;
516 521
517 int callbackType = CALLBACK_FOR_UNKNOWN_PROCESS; 522 int callbackType = CALLBACK_FOR_UNKNOWN_PROCESS;
518 boolean inSandbox = true; 523 boolean inSandbox = true;
519 String processType = getSwitchValue(commandLine, SWITCH_PROCESS_TYPE); 524 String processType = getSwitchValue(commandLine, SWITCH_PROCESS_TYPE);
520 if (SWITCH_RENDERER_PROCESS.equals(processType)) { 525 if (SWITCH_RENDERER_PROCESS.equals(processType)) {
521 callbackType = CALLBACK_FOR_RENDERER_PROCESS; 526 callbackType = CALLBACK_FOR_RENDERER_PROCESS;
522 } else if (SWITCH_GPU_PROCESS.equals(processType)) { 527 } else if (SWITCH_GPU_PROCESS.equals(processType)) {
523 callbackType = CALLBACK_FOR_GPU_PROCESS; 528 callbackType = CALLBACK_FOR_GPU_PROCESS;
524 inSandbox = false; 529 inSandbox = false;
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 } 765 }
761 766
762 return true; 767 return true;
763 } 768 }
764 769
765 private static native void nativeOnChildProcessStarted(long clientContext, i nt pid); 770 private static native void nativeOnChildProcessStarted(long clientContext, i nt pid);
766 private static native void nativeEstablishSurfacePeer( 771 private static native void nativeEstablishSurfacePeer(
767 int pid, Surface surface, int primaryID, int secondaryID); 772 int pid, Surface surface, int primaryID, int secondaryID);
768 private static native boolean nativeIsSingleProcess(); 773 private static native boolean nativeIsSingleProcess();
769 } 774 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698