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

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

Issue 2845243002: Moving BindingManager and ChildProcessConnection to base/.
Patch Set: Moving BindingManager and ChildProcessConnection to base/. Created 3 years, 7 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.os.Bundle; 8 import android.os.Bundle;
9 import android.os.IBinder; 9 import android.os.IBinder;
10 import android.os.RemoteException; 10 import android.os.RemoteException;
11 11
12 import org.chromium.base.CpuFeatures; 12 import org.chromium.base.CpuFeatures;
13 import org.chromium.base.Log; 13 import org.chromium.base.Log;
14 import org.chromium.base.ThreadUtils; 14 import org.chromium.base.ThreadUtils;
15 import org.chromium.base.TraceEvent; 15 import org.chromium.base.TraceEvent;
16 import org.chromium.base.VisibleForTesting; 16 import org.chromium.base.VisibleForTesting;
17 import org.chromium.base.library_loader.Linker; 17 import org.chromium.base.library_loader.Linker;
18 import org.chromium.base.process_launcher.BaseChildProcessConnection;
19 import org.chromium.base.process_launcher.BindingManager;
20 import org.chromium.base.process_launcher.BindingManagerImpl;
18 import org.chromium.base.process_launcher.ChildProcessCreationParams; 21 import org.chromium.base.process_launcher.ChildProcessCreationParams;
19 import org.chromium.base.process_launcher.FileDescriptorInfo; 22 import org.chromium.base.process_launcher.FileDescriptorInfo;
23 import org.chromium.base.process_launcher.ManagedChildProcessConnection;
20 import org.chromium.content.app.ChromiumLinkerParams; 24 import org.chromium.content.app.ChromiumLinkerParams;
21 import org.chromium.content.common.ContentSwitches; 25 import org.chromium.content.common.ContentSwitches;
22 26
23 import java.util.Map; 27 import java.util.Map;
24 import java.util.concurrent.ConcurrentHashMap; 28 import java.util.concurrent.ConcurrentHashMap;
25 29
26 /** 30 /**
27 * This class provides the method to start/stop ChildProcess called by native. 31 * This class provides the method to start/stop ChildProcess called by native.
28 * 32 *
29 * Note about threading. The threading here is complicated and not well document ed. 33 * Note about threading. The threading here is complicated and not well document ed.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 linker.getImplementationForTesting() ); 97 linker.getImplementationForTesting() );
94 } else { 98 } else {
95 return new ChromiumLinkerParams(sLinkerLoadAddress, 99 return new ChromiumLinkerParams(sLinkerLoadAddress,
96 waitForSharedRelros); 100 waitForSharedRelros);
97 } 101 }
98 } 102 }
99 103
100 @VisibleForTesting 104 @VisibleForTesting
101 static Bundle createCommonParamsBundle(ChildProcessCreationParams params) { 105 static Bundle createCommonParamsBundle(ChildProcessCreationParams params) {
102 Bundle commonParams = new Bundle(); 106 Bundle commonParams = new Bundle();
103 commonParams.putParcelable( 107 commonParams.putParcelable(ContentChildProcessConstants.EXTRA_LINKER_PAR AMS,
104 ChildProcessConstants.EXTRA_LINKER_PARAMS, getLinkerParamsForNew Connection()); 108 getLinkerParamsForNewConnection());
105 final boolean bindToCallerCheck = params == null ? false : params.getBin dToCallerCheck(); 109 final boolean bindToCallerCheck = params == null ? false : params.getBin dToCallerCheck();
106 commonParams.putBoolean(ChildProcessConstants.EXTRA_BIND_TO_CALLER, bind ToCallerCheck); 110 commonParams.putBoolean(
111 ContentChildProcessConstants.EXTRA_BIND_TO_CALLER, bindToCallerC heck);
107 return commonParams; 112 return commonParams;
108 } 113 }
109 114
110 @VisibleForTesting 115 @VisibleForTesting
111 static BaseChildProcessConnection allocateBoundConnection(ChildSpawnData spa wnData, 116 static BaseChildProcessConnection allocateBoundConnection(ChildSpawnData spa wnData,
112 BaseChildProcessConnection.StartCallback startCallback, boolean forW armUp) { 117 BaseChildProcessConnection.StartCallback startCallback, boolean forW armUp) {
113 assert LauncherThread.runningOnLauncherThread(); 118 assert LauncherThread.runningOnLauncherThread();
114 final Context context = spawnData.getContext(); 119 final Context context = spawnData.getContext();
115 final boolean inSandbox = spawnData.isInSandbox(); 120 final boolean inSandbox = spawnData.isInSandbox();
116 final ChildProcessCreationParams creationParams = spawnData.getCreationP arams(); 121 final ChildProcessCreationParams creationParams = spawnData.getCreationP arams();
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 private static BindingManager sBindingManager; 205 private static BindingManager sBindingManager;
201 206
202 // Whether the main application is currently brought to the foreground. 207 // Whether the main application is currently brought to the foreground.
203 private static boolean sApplicationInForeground = true; 208 private static boolean sApplicationInForeground = true;
204 209
205 // Lazy initialize sBindingManager 210 // Lazy initialize sBindingManager
206 // TODO(boliu): This should be internal to content. 211 // TODO(boliu): This should be internal to content.
207 public static BindingManager getBindingManager() { 212 public static BindingManager getBindingManager() {
208 synchronized (sBindingManagerLock) { 213 synchronized (sBindingManagerLock) {
209 if (sBindingManager == null) { 214 if (sBindingManager == null) {
210 sBindingManager = BindingManagerImpl.createBindingManager(); 215 sBindingManager =
216 BindingManagerImpl.createBindingManager(LauncherThread.g etHandler());
211 } 217 }
212 return sBindingManager; 218 return sBindingManager;
213 } 219 }
214 } 220 }
215 221
216 @VisibleForTesting 222 @VisibleForTesting
217 public static void setBindingManagerForTesting(BindingManager manager) { 223 public static void setBindingManagerForTesting(BindingManager manager) {
218 sBindingManager = manager; 224 sBindingManager = manager;
219 } 225 }
220 226
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 } 468 }
463 469
464 triggerConnectionSetup(allocatedConnection, commandLine, childProces sId, 470 triggerConnectionSetup(allocatedConnection, commandLine, childProces sId,
465 filesToBeMapped, childProcessCallback, launchCallback); 471 filesToBeMapped, childProcessCallback, launchCallback);
466 return allocatedConnection; 472 return allocatedConnection;
467 } finally { 473 } finally {
468 TraceEvent.end("ChildProcessLauncher.startInternal"); 474 TraceEvent.end("ChildProcessLauncher.startInternal");
469 } 475 }
470 } 476 }
471 477
472 /**
473 * Create the common bundle to be passed to child processes.
474 * @param context Application context.
475 * @param commandLine Command line params to be passed to the service.
476 * @param linkerParams Linker params to start the service.
477 */
478 protected static Bundle createsServiceBundle(
479 String[] commandLine, FileDescriptorInfo[] filesToBeMapped) {
480 Bundle bundle = new Bundle();
481 bundle.putStringArray(ChildProcessConstants.EXTRA_COMMAND_LINE, commandL ine);
482 bundle.putParcelableArray(ChildProcessConstants.EXTRA_FILES, filesToBeMa pped);
483 bundle.putInt(ChildProcessConstants.EXTRA_CPU_COUNT, CpuFeatures.getCoun t());
484 bundle.putLong(ChildProcessConstants.EXTRA_CPU_FEATURES, CpuFeatures.get Mask());
485 bundle.putBundle(Linker.EXTRA_LINKER_SHARED_RELROS, Linker.getInstance() .getSharedRelros());
486 return bundle;
487 }
488
489 @VisibleForTesting 478 @VisibleForTesting
490 static void triggerConnectionSetup(final BaseChildProcessConnection connecti on, 479 static void triggerConnectionSetup(final BaseChildProcessConnection connecti on,
491 String[] commandLine, int childProcessId, FileDescriptorInfo[] files ToBeMapped, 480 String[] commandLine, int childProcessId, FileDescriptorInfo[] files ToBeMapped,
492 final IBinder childProcessCallback, final LaunchCallback launchCallb ack) { 481 final IBinder childProcessCallback, final LaunchCallback launchCallb ack) {
493 assert LauncherThread.runningOnLauncherThread(); 482 assert LauncherThread.runningOnLauncherThread();
494 Log.d(TAG, "Setting up connection to process: slot=%d", connection.getSe rviceNumber()); 483 Log.d(TAG, "Setting up connection to process: slot=%d", connection.getSe rviceNumber());
495 BaseChildProcessConnection.ConnectionCallback connectionCallback = 484 BaseChildProcessConnection.ConnectionCallback connectionCallback =
496 new BaseChildProcessConnection.ConnectionCallback() { 485 new BaseChildProcessConnection.ConnectionCallback() {
497 @Override 486 @Override
487 public void onConnectionSetup(Bundle params) {
488 params.putInt(ContentChildProcessConstants.EXTRA_CPU_COU NT,
489 CpuFeatures.getCount());
490 params.putLong(ContentChildProcessConstants.EXTRA_CPU_FE ATURES,
491 CpuFeatures.getMask());
492 params.putBundle(Linker.EXTRA_LINKER_SHARED_RELROS,
493 Linker.getInstance().getSharedRelros());
494 }
495
496 @Override
498 public void onConnected(BaseChildProcessConnection connectio n) { 497 public void onConnected(BaseChildProcessConnection connectio n) {
499 assert LauncherThread.runningOnLauncherThread(); 498 assert LauncherThread.runningOnLauncherThread();
500 if (connection != null) { 499 if (connection != null) {
501 int pid = connection.getPid(); 500 int pid = connection.getPid();
502 Log.d(TAG, "on connect callback, pid=%d", pid); 501 Log.d(TAG, "on connect callback, pid=%d", pid);
503 if (connection instanceof ManagedChildProcessConnect ion) { 502 if (connection instanceof ManagedChildProcessConnect ion) {
504 getBindingManager().addNewConnection( 503 getBindingManager().addNewConnection(
505 pid, (ManagedChildProcessConnection) con nection); 504 pid, (ManagedChildProcessConnection) con nection);
506 } 505 }
507 sServiceMap.put(pid, connection); 506 sServiceMap.put(pid, connection);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 552
554 try { 553 try {
555 ((ManagedChildProcessConnection) sServiceMap.get(pid)).crashServiceF orTesting(); 554 ((ManagedChildProcessConnection) sServiceMap.get(pid)).crashServiceF orTesting();
556 } catch (RemoteException ex) { 555 } catch (RemoteException ex) {
557 return false; 556 return false;
558 } 557 }
559 558
560 return true; 559 return true;
561 } 560 }
562 } 561 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698