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
Родитель d4179482bf
Коммит 5f5f1a9ba5
2 изменённых файлов: 33 добавлений и 8 удалений

Просмотреть файл

@ -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);
}

Просмотреть файл

@ -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);