Bug 1074340 - Don't initialize guest profile more than once. r=wesj
--- a/mobile/android/base/BrowserApp.java
+++ b/mobile/android/base/BrowserApp.java
@@ -515,21 +515,22 @@ public class BrowserApp extends GeckoApp
}).execute();
}
@Override
public void onCreate(Bundle savedInstanceState) {
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);
}
// This has to be prepared prior to calling GeckoApp.onCreate, because
// widget code and BrowserToolbar need it, and they're created by the
// layout, which GeckoApp takes care of.
((GeckoApplication) getApplication()).prepareLightweightTheme();
super.onCreate(savedInstanceState);
--- a/mobile/android/base/GeckoProfile.java
+++ b/mobile/android/base/GeckoProfile.java
@@ -18,16 +18,17 @@ import java.util.Hashtable;
import org.mozilla.gecko.GeckoProfileDirectories.NoMozillaDirectoryException;
import org.mozilla.gecko.GeckoProfileDirectories.NoSuchProfileException;
import org.mozilla.gecko.db.LocalBrowserDB;
import org.mozilla.gecko.distribution.Distribution;
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;
import android.support.v4.content.LocalBroadcastManager;
import android.text.TextUtils;
import android.util.Log;
public final class GeckoProfile {
@@ -85,19 +86,29 @@ public final class GeckoProfile {
// Check for a cached profile on this context already
// TODO: We should not be caching profile information on the Activity context
final GeckoApp geckoApp = (GeckoApp) context;
if (geckoApp.mProfile != null) {
return geckoApp.mProfile;
}
}
- // 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) {
final GeckoApp geckoApp = (GeckoApp) context;
String defaultProfileName;
try {
defaultProfileName = geckoApp.getDefaultProfileName();
} catch (NoMozillaDirectoryException e) {
@@ -186,16 +197,17 @@ public final class GeckoProfile {
// Clear all shared prefs for the given profile.
GeckoSharedPrefs.forProfileName(context, profileName)
.edit().clear().apply();
}
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,
// otherwise GeckoProfile.getDir will try to be smart and build it for us in the normal profiles dir.
getGuestDir(context).mkdir();
GeckoProfile profile = getGuestProfile(context);
// If we're creating this guest session over the keyguard, don't lock it.
@@ -227,16 +239,28 @@ public final class GeckoProfile {
private static File getGuestDir(Context context) {
if (sGuestDir == null) {
sGuestDir = context.getFileStreamPath("guest");
}
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);
if (guestDir.exists()) {
sGuestProfile = get(context, GUEST_PROFILE, guestDir);
sGuestProfile.mInGuestMode = true;
}
}