зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1442255 - 5. Use extras bundle to initialize child processes; r=esawin
Pass the extras bundle from the main process to the child process through IChildProcess.start, instead of through the Intent, which never worked because intent extras are not passed to Service.onBind. MozReview-Commit-ID: I2EToBNE2Y6 --HG-- extra : rebase_source : e49ece736ad475468c37c5d158e013a791cf4484
This commit is contained in:
Родитель
63d04540b7
Коммит
acc5349a8d
|
@ -6,9 +6,12 @@ package org.mozilla.gecko.process;
|
|||
|
||||
import org.mozilla.gecko.process.IProcessManager;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
|
||||
interface IChildProcess {
|
||||
int getPid();
|
||||
boolean start(in IProcessManager procMan, in String[] args, in ParcelFileDescriptor crashReporterPfd, in ParcelFileDescriptor ipcPfd, in ParcelFileDescriptor crashAnnotationPfd);
|
||||
boolean start(in IProcessManager procMan, in String[] args, in Bundle extras,
|
||||
in ParcelFileDescriptor ipcPfd, in ParcelFileDescriptor crashReporterPfd,
|
||||
in ParcelFileDescriptor crashAnnotationPfd);
|
||||
}
|
||||
|
|
|
@ -34,7 +34,6 @@ public final class GeckoLoader {
|
|||
private static boolean sSQLiteLibsLoaded;
|
||||
private static boolean sNSSLibsLoaded;
|
||||
private static boolean sMozGlueLoaded;
|
||||
private static String[] sEnvList;
|
||||
|
||||
private GeckoLoader() {
|
||||
// prevent instantiation
|
||||
|
@ -91,31 +90,18 @@ public final class GeckoLoader {
|
|||
return tmpDir;
|
||||
}
|
||||
|
||||
public static void addEnvironmentToIntent(Intent intent) {
|
||||
if (sEnvList != null) {
|
||||
for (int ix = 0; ix < sEnvList.length; ix++) {
|
||||
intent.putExtra("env" + ix, sEnvList[ix]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void setupGeckoEnvironment(final Context context, final String profilePath,
|
||||
final Bundle extras) {
|
||||
// if we have an intent (we're being launched by an activity)
|
||||
// read in any environmental variables from it here
|
||||
if (extras != null) {
|
||||
final ArrayList<String> envList = new ArrayList<String>();
|
||||
String env = extras.getString("env0");
|
||||
Log.d(LOGTAG, "Gecko environment env0: " + env);
|
||||
for (int c = 1; env != null; c++) {
|
||||
envList.add(env);
|
||||
putenv(env);
|
||||
env = extras.getString("env" + c);
|
||||
Log.d(LOGTAG, "env" + c + ": " + env);
|
||||
}
|
||||
if (envList.size() > 0) {
|
||||
sEnvList = envList.toArray(new String[envList.size()]);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
|
@ -5,15 +5,16 @@
|
|||
package org.mozilla.gecko.process;
|
||||
|
||||
import org.mozilla.gecko.GeckoAppShell;
|
||||
import org.mozilla.gecko.GeckoThread;
|
||||
import org.mozilla.gecko.IGeckoEditableParent;
|
||||
import org.mozilla.gecko.annotation.WrapForJNI;
|
||||
import org.mozilla.gecko.mozglue.GeckoLoader;
|
||||
import org.mozilla.gecko.util.ThreadUtils;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.os.Process;
|
||||
|
@ -74,7 +75,6 @@ public final class GeckoProcessManager extends IProcessManager.Stub {
|
|||
final Intent intent = new Intent();
|
||||
intent.setClassName(context,
|
||||
GeckoServiceChildProcess.class.getName() + '$' + mType);
|
||||
GeckoLoader.addEnvironmentToIntent(intent);
|
||||
|
||||
if (context.bindService(intent, this, Context.BIND_AUTO_CREATE)) {
|
||||
waitForChildLocked();
|
||||
|
@ -168,13 +168,13 @@ public final class GeckoProcessManager extends IProcessManager.Stub {
|
|||
|
||||
@WrapForJNI
|
||||
private static int start(final String type, final String[] args,
|
||||
final int crashFd, final int ipcFd,
|
||||
final int ipcFd, final int crashFd,
|
||||
final int crashAnnotationFd) {
|
||||
return INSTANCE.start(type, args, crashFd, ipcFd, crashAnnotationFd, /* retry */ false);
|
||||
return INSTANCE.start(type, args, ipcFd, crashFd, crashAnnotationFd, /* retry */ false);
|
||||
}
|
||||
|
||||
private int start(final String type, final String[] args, final int crashFd,
|
||||
final int ipcFd, final int crashAnnotationFd,
|
||||
private int start(final String type, final String[] args, final int ipcFd,
|
||||
final int crashFd, final int crashAnnotationFd,
|
||||
final boolean retry) {
|
||||
final ChildConnection connection = getConnection(type);
|
||||
final IChildProcess child = connection.bind();
|
||||
|
@ -182,12 +182,13 @@ public final class GeckoProcessManager extends IProcessManager.Stub {
|
|||
return 0;
|
||||
}
|
||||
|
||||
final ParcelFileDescriptor crashPfd;
|
||||
final Bundle extras = GeckoThread.getActiveExtras();
|
||||
final ParcelFileDescriptor ipcPfd;
|
||||
final ParcelFileDescriptor crashPfd;
|
||||
final ParcelFileDescriptor crashAnnotationPfd;
|
||||
try {
|
||||
crashPfd = (crashFd >= 0) ? ParcelFileDescriptor.fromFd(crashFd) : null;
|
||||
ipcPfd = ParcelFileDescriptor.fromFd(ipcFd);
|
||||
crashPfd = (crashFd >= 0) ? ParcelFileDescriptor.fromFd(crashFd) : null;
|
||||
crashAnnotationPfd = (crashAnnotationFd >= 0) ? ParcelFileDescriptor.fromFd(crashAnnotationFd) : null;
|
||||
} catch (final IOException e) {
|
||||
Log.e(LOGTAG, "Cannot create fd for " + type, e);
|
||||
|
@ -196,7 +197,7 @@ public final class GeckoProcessManager extends IProcessManager.Stub {
|
|||
|
||||
boolean started = false;
|
||||
try {
|
||||
started = child.start(this, args, crashPfd, ipcPfd, crashAnnotationPfd);
|
||||
started = child.start(this, args, extras, ipcPfd, crashPfd, crashAnnotationPfd);
|
||||
} catch (final RemoteException e) {
|
||||
}
|
||||
|
||||
|
@ -207,10 +208,13 @@ public final class GeckoProcessManager extends IProcessManager.Stub {
|
|||
}
|
||||
Log.w(LOGTAG, "Attempting to kill running child " + type);
|
||||
connection.unbind();
|
||||
return start(type, args, crashFd, ipcFd, crashAnnotationFd, /* retry */ true);
|
||||
return start(type, args, ipcFd, crashFd, crashAnnotationFd, /* retry */ true);
|
||||
}
|
||||
|
||||
try {
|
||||
if (crashAnnotationPfd != null) {
|
||||
crashAnnotationPfd.close();
|
||||
}
|
||||
if (crashPfd != null) {
|
||||
crashPfd.close();
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import org.mozilla.gecko.util.ThreadUtils;
|
|||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.os.Binder;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.os.Process;
|
||||
|
@ -61,8 +62,9 @@ public class GeckoServiceChildProcess extends Service {
|
|||
@Override
|
||||
public boolean start(final IProcessManager procMan,
|
||||
final String[] args,
|
||||
final ParcelFileDescriptor crashReporterPfd,
|
||||
final Bundle extras,
|
||||
final ParcelFileDescriptor ipcPfd,
|
||||
final ParcelFileDescriptor crashReporterPfd,
|
||||
final ParcelFileDescriptor crashAnnotationPfd) {
|
||||
synchronized (GeckoServiceChildProcess.class) {
|
||||
if (sProcessManager != null) {
|
||||
|
@ -72,15 +74,17 @@ public class GeckoServiceChildProcess extends Service {
|
|||
sProcessManager = procMan;
|
||||
}
|
||||
|
||||
final int ipcFd = ipcPfd != null ? ipcPfd.detachFd() : -1;
|
||||
final int crashReporterFd = crashReporterPfd != null ?
|
||||
crashReporterPfd.detachFd() : -1;
|
||||
final int ipcFd = ipcPfd != null ? ipcPfd.detachFd() : -1;
|
||||
final int crashAnnotationFd = crashAnnotationPfd != null ? crashAnnotationPfd.detachFd() : -1;
|
||||
final int crashAnnotationFd = crashAnnotationPfd != null ?
|
||||
crashAnnotationPfd.detachFd() : -1;
|
||||
|
||||
ThreadUtils.postToUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (GeckoThread.initChildProcess(args, crashReporterFd, ipcFd, crashAnnotationFd)) {
|
||||
if (GeckoThread.initChildProcess(args, extras, ipcFd, crashReporterFd,
|
||||
crashAnnotationFd)) {
|
||||
GeckoThread.launch();
|
||||
}
|
||||
}
|
||||
|
@ -91,7 +95,6 @@ public class GeckoServiceChildProcess extends Service {
|
|||
|
||||
@Override
|
||||
public IBinder onBind(final Intent intent) {
|
||||
GeckoLoader.setLastIntent(new SafeIntent(intent));
|
||||
GeckoThread.launch(); // Preload Gecko.
|
||||
return mBinder;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче