Bug 1074340 - Don't initialize guest profile more than once. r=wesj

This commit is contained in:
Richard Newman 2014-10-08 11:43:14 -07:00
parent 7ebb7ddc42
commit 475aadc119
2 changed files with 33 additions and 8 deletions

View File

@ -520,11 +520,12 @@ public class BrowserApp extends GeckoApp
mAboutHomeStartupTimer = new Telemetry.UptimeTimer("FENNEC_STARTUP_TIME_ABOUTHOME");
final Intent intent = getIntent();
final String args = intent.getStringExtra("args");
if (GuestSession.shouldUse(this, args)) {
mProfile = GeckoProfile.createGuestProfile(this);
} else {
final GeckoProfile p = GeckoProfile.get(this);
if (p != null && !p.inGuestMode()) {
// This is *only* valid because we never want to use the guest mode
// profile concurrently with a normal profile -- no syncing to it,
// no dual-profile usage, nothing. BrowserApp startup with a conventional
// GeckoProfile will cause the guest profile to be deleted.
GeckoProfile.maybeCleanupGuestProfile(this);
}

View File

@ -23,6 +23,7 @@ import org.mozilla.gecko.mozglue.RobocopTarget;
import org.mozilla.gecko.util.INIParser;
import org.mozilla.gecko.util.INISection;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
@ -90,9 +91,19 @@ public final class GeckoProfile {
}
}
// If the guest profile should be used return it.
if (GuestSession.shouldUse(context, "")) {
return GeckoProfile.getGuestProfile(context);
final String args;
if (context instanceof Activity) {
args = ((Activity) context).getIntent().getStringExtra("args");
} else {
args = null;
}
if (GuestSession.shouldUse(context, args)) {
GeckoProfile p = GeckoProfile.getOrCreateGuestProfile(context);
if (isGeckoApp) {
((GeckoApp) context).mProfile = p;
}
return p;
}
if (isGeckoApp) {
@ -191,6 +202,7 @@ public final class GeckoProfile {
return success;
}
// Only public for access from tests.
public static GeckoProfile createGuestProfile(Context context) {
try {
// We need to force the creation of a new guest profile if we want it outside of the normal profile path,
@ -232,6 +244,18 @@ public final class GeckoProfile {
return sGuestDir;
}
/**
* Performs IO. Be careful of using this on the main thread.
*/
public static GeckoProfile getOrCreateGuestProfile(Context context) {
GeckoProfile p = getGuestProfile(context);
if (p == null) {
return createGuestProfile(context);
}
return p;
}
public static GeckoProfile getGuestProfile(Context context) {
if (sGuestProfile == null) {
File guestDir = getGuestDir(context);