diff --git a/mobile/android/base/BrowserApp.java b/mobile/android/base/BrowserApp.java index 2667dc0991a..f5b4ea320bd 100644 --- a/mobile/android/base/BrowserApp.java +++ b/mobile/android/base/BrowserApp.java @@ -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); } diff --git a/mobile/android/base/GeckoProfile.java b/mobile/android/base/GeckoProfile.java index cec58c13f47..870ba948bc1 100644 --- a/mobile/android/base/GeckoProfile.java +++ b/mobile/android/base/GeckoProfile.java @@ -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);