mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 11:55:49 +00:00
Bug 1259653 - Support initializing GeckoThread with a specific profile; r=snorp
Add GeckoThread.initWithProfile that make it easy to target a particular profile. The method succeeds when GeckoThread has not been initialized or is already using the specified profile. It fails when the current profile does not match the specified profile.
This commit is contained in:
parent
d255ddc8dc
commit
ef1800c548
@ -1184,8 +1184,7 @@ public abstract class GeckoApp
|
||||
GeckoProfile.getFromArgs(getApplicationContext(), args) : null;
|
||||
|
||||
sAlreadyLoaded = true;
|
||||
GeckoThread.ensureInit(profile, args, action,
|
||||
/* debugging */ ACTION_DEBUG.equals(action));
|
||||
GeckoThread.init(profile, args, action, /* debugging */ ACTION_DEBUG.equals(action));
|
||||
|
||||
// Speculatively pre-fetch the profile in the background.
|
||||
ThreadUtils.postToBackgroundThread(new Runnable() {
|
||||
|
@ -23,6 +23,7 @@ import android.os.MessageQueue;
|
||||
import android.os.SystemClock;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
@ -120,7 +121,7 @@ public class GeckoThread extends Thread {
|
||||
setName("Gecko");
|
||||
}
|
||||
|
||||
public static boolean ensureInit(GeckoProfile profile, String args, String action, boolean debugging) {
|
||||
public static boolean init(GeckoProfile profile, String args, String action, boolean debugging) {
|
||||
ThreadUtils.assertOnUiThread();
|
||||
if (isState(State.INITIAL) && sGeckoThread == null) {
|
||||
sGeckoThread = new GeckoThread(profile, args, action, debugging);
|
||||
@ -129,6 +130,29 @@ public class GeckoThread extends Thread {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean initWithProfile(String profileName, File profileDir) {
|
||||
if (profileName == null) {
|
||||
throw new IllegalArgumentException("Null profile name");
|
||||
}
|
||||
|
||||
final GeckoProfile profile = getActiveProfile();
|
||||
if (profile == null) {
|
||||
// We haven't initialized yet; okay to initialize now.
|
||||
final Context context = GeckoAppShell.getApplicationContext();
|
||||
return init(GeckoProfile.get(context, profileName, profileDir),
|
||||
/* args */ null, /* action */ null, /* debugging */ false);
|
||||
}
|
||||
|
||||
// We already initialized and have a profile; see if it matches ours.
|
||||
try {
|
||||
return profileDir == null ? profileName.equals(profile.getName()) :
|
||||
profile.getDir().getCanonicalPath().equals(profileDir.getCanonicalPath());
|
||||
} catch (final IOException e) {
|
||||
Log.e(LOGTAG, "Cannot compare profile " + profileName);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean launch() {
|
||||
ThreadUtils.assertOnUiThread();
|
||||
if (checkAndSetState(State.INITIAL, State.LAUNCHED)) {
|
||||
|
Loading…
Reference in New Issue
Block a user