| 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.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 Loading... |
| 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 static FileDescriptorInfo makeFdInfo(int id, int fd, boolean autoClose, long
offset, |
| 490 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 static void start( |
| 502 Context context, | 519 Context context, |
| 503 final String[] commandLine, | 520 final String[] commandLine, |
| 504 int childProcessId, | 521 int childProcessId, |
| 505 int[] fileIds, | 522 FileDescriptorInfo[] filesToBeMapped, |
| 506 int[] fileFds, | |
| 507 boolean[] fileAutoClose, | |
| 508 long clientContext) { | 523 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; | 524 assert clientContext != 0; |
| 516 | 525 |
| 517 int callbackType = CALLBACK_FOR_UNKNOWN_PROCESS; | 526 int callbackType = CALLBACK_FOR_UNKNOWN_PROCESS; |
| 518 boolean inSandbox = true; | 527 boolean inSandbox = true; |
| 519 String processType = getSwitchValue(commandLine, SWITCH_PROCESS_TYPE); | 528 String processType = getSwitchValue(commandLine, SWITCH_PROCESS_TYPE); |
| 520 if (SWITCH_RENDERER_PROCESS.equals(processType)) { | 529 if (SWITCH_RENDERER_PROCESS.equals(processType)) { |
| 521 callbackType = CALLBACK_FOR_RENDERER_PROCESS; | 530 callbackType = CALLBACK_FOR_RENDERER_PROCESS; |
| 522 } else if (SWITCH_GPU_PROCESS.equals(processType)) { | 531 } else if (SWITCH_GPU_PROCESS.equals(processType)) { |
| 523 callbackType = CALLBACK_FOR_GPU_PROCESS; | 532 callbackType = CALLBACK_FOR_GPU_PROCESS; |
| 524 inSandbox = false; | 533 inSandbox = false; |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 760 } | 769 } |
| 761 | 770 |
| 762 return true; | 771 return true; |
| 763 } | 772 } |
| 764 | 773 |
| 765 private static native void nativeOnChildProcessStarted(long clientContext, i
nt pid); | 774 private static native void nativeOnChildProcessStarted(long clientContext, i
nt pid); |
| 766 private static native void nativeEstablishSurfacePeer( | 775 private static native void nativeEstablishSurfacePeer( |
| 767 int pid, Surface surface, int primaryID, int secondaryID); | 776 int pid, Surface surface, int primaryID, int secondaryID); |
| 768 private static native boolean nativeIsSingleProcess(); | 777 private static native boolean nativeIsSingleProcess(); |
| 769 } | 778 } |
| OLD | NEW |