backout 3c552ee3aa5e to fix commit message

This commit is contained in:
Wes Johnston 2013-08-02 11:09:48 -07:00
parent 0588403e08
commit cba955e2e0
2 changed files with 22 additions and 144 deletions

View File

@ -100,9 +100,6 @@ abstract public class BrowserApp extends GeckoApp
private AboutHome mAboutHome;
protected Telemetry.Timer mAboutHomeStartupTimer = null;
// Set the default session restore value
private int mSessionRestore = -1;
private static final int GECKO_TOOLS_MENU = -1;
private static final int ADDON_MENU_OFFSET = 1000;
private class MenuItemInfo {
@ -396,15 +393,6 @@ abstract public class BrowserApp extends GeckoApp
super.onStatePurged();
}
@Override
protected int getSessionRestoreState(Bundle savedInstanceState) {
if (mSessionRestore > -1) {
return mSessionRestore;
}
return super.getSessionRestoreState(savedInstanceState);
}
@Override
public void onCreate(Bundle savedInstanceState) {
mAboutHomeStartupTimer = new Telemetry.Timer("FENNEC_STARTUP_TIME_ABOUTHOME");
@ -412,8 +400,13 @@ abstract public class BrowserApp extends GeckoApp
String args = getIntent().getStringExtra("args");
if (args != null && args.contains("--guest-mode")) {
mProfile = GeckoProfile.createGuestProfile(this);
} else if (GeckoProfile.maybeCleanupGuestProfile(this)) {
mSessionRestore = RESTORE_NORMAL;
} else {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
GeckoProfile.removeGuestProfile(BrowserApp.this);
}
});
}
super.onCreate(savedInstanceState);
@ -1821,8 +1814,6 @@ abstract public class BrowserApp extends GeckoApp
String args = "";
if (type == GuestModeDialog.ENTERING) {
args = "--guest-mode";
} else {
GeckoProfile.leaveGuestSession(BrowserApp.this);
}
doRestart(args);
System.exit(0);

View File

@ -7,7 +7,6 @@ package org.mozilla.gecko;
import org.mozilla.gecko.util.INIParser;
import org.mozilla.gecko.util.INISection;
import org.mozilla.gecko.util.ThreadUtils;
import android.content.Context;
import android.text.TextUtils;
@ -25,8 +24,6 @@ import java.util.Hashtable;
public final class GeckoProfile {
private static final String LOGTAG = "GeckoProfile";
// Used to "lock" the guest profile, so that we'll always restart in it
private static final String LOCK_FILE_NAME = ".active_lock";
private static HashMap<String, GeckoProfile> sProfileCache = new HashMap<String, GeckoProfile>();
private static String sDefaultProfileName = null;
@ -36,21 +33,7 @@ public final class GeckoProfile {
private File mMozDir;
private File mDir;
// Constants to cache whether or not a profile is "locked".
private enum LockState {
LOCKED,
UNLOCKED,
UNDEFINED
};
// Caches whether or not a profile is "locked". Only used by the guest profile to determine if it should
// be reused or deleted on startup
private LockState mLocked = LockState.UNDEFINED;
// Caches the guest profile dir
private static File mGuestDir = null;
private boolean mInGuestMode = false;
private static GeckoProfile mGuestProfile = null;
static private INIParser getProfilesINI(Context context) {
File filesDir = context.getFilesDir();
@ -61,19 +44,8 @@ public final class GeckoProfile {
public static GeckoProfile get(Context context) {
if (context instanceof GeckoApp) {
// Check for a cached profile on this context already
// TODO: We should not be caching profile information on the Activity context
if (((GeckoApp)context).mProfile != null) {
if (((GeckoApp)context).mProfile != null)
return ((GeckoApp)context).mProfile;
}
GeckoProfile guest = GeckoProfile.getGuestProfile(context);
// if the guest profile exists and is locked, return it
if (guest != null && guest.locked()) {
return guest;
}
// Otherwise, get the default profile for the Activity
return get(context, ((GeckoApp)context).getDefaultProfileName());
}
@ -140,13 +112,17 @@ public final class GeckoProfile {
}
public static GeckoProfile createGuestProfile(Context context) {
if (context == null) {
throw new IllegalArgumentException("context must be non-null");
}
try {
removeGuestProfile(context);
// 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);
profile.lock();
File guestDir = context.getDir("guest", Context.MODE_PRIVATE);
guestDir.mkdir();
GeckoProfile profile = get(context, "guest", guestDir);
profile.mInGuestMode = true;
return profile;
} catch (Exception ex) {
Log.e(LOGTAG, "Error creating guest profile", ex);
@ -154,50 +130,12 @@ public final class GeckoProfile {
return null;
}
public static void leaveGuestSession(Context context) {
GeckoProfile profile = getGuestProfile(context);
if (profile != null) {
profile.unlock();
public static void removeGuestProfile(Context context) {
if (context == null) {
throw new IllegalArgumentException("context must be non-null");
}
}
private static File getGuestDir(Context context) {
if (mGuestDir == null) {
mGuestDir = context.getDir("guest", Context.MODE_PRIVATE);
}
return mGuestDir;
}
private static GeckoProfile getGuestProfile(Context context) {
if (mGuestProfile == null) {
File guestDir = getGuestDir(context);
mGuestProfile = get(context, "guest", guestDir);
mGuestProfile.mInGuestMode = true;
}
return mGuestProfile;
}
public static boolean maybeCleanupGuestProfile(final Context context) {
// Don't use profile.getDir() here, so that we don't accidently create the dir
File guestDir = getGuestDir(context);
final GeckoProfile profile = getGuestProfile(context);
if (guestDir.exists() && !profile.locked()) {
// if the guest dir exists, but its unlocked, delete it
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
removeGuestProfile(context);
}
});
return true;
}
return false;
}
private static void removeGuestProfile(Context context) {
try {
File guestDir = getGuestDir(context);
File guestDir = context.getDir("guest", Context.MODE_PRIVATE);
if (guestDir.exists()) {
delete(guestDir);
}
@ -224,52 +162,6 @@ public final class GeckoProfile {
return file.delete();
}
// Warning, Changing the lock file state from outside apis will cause this to become out of sync
public boolean locked() {
if (mLocked != LockState.UNDEFINED) {
return mLocked == LockState.LOCKED;
}
File lockFile = new File(getDir(), LOCK_FILE_NAME);
boolean res = lockFile.exists();
mLocked = res ? LockState.LOCKED : LockState.UNLOCKED;
return res;
}
public boolean lock() {
try {
File lockFile = new File(getDir(), LOCK_FILE_NAME);
boolean result = lockFile.createNewFile();
if (result) {
mLocked = LockState.LOCKED;
} else {
mLocked = LockState.UNLOCKED;
}
return result;
} catch(IOException ex) {
Log.e(LOGTAG, "Error locking profile", ex);
}
mLocked = LockState.UNLOCKED;
return false;
}
public boolean unlock() {
try {
File lockFile = new File(getDir(), LOCK_FILE_NAME);
boolean result = delete(lockFile);
if (result) {
mLocked = LockState.UNLOCKED;
} else {
mLocked = LockState.LOCKED;
}
return result;
} catch(IOException ex) {
Log.e(LOGTAG, "Error unlocking profile", ex);
}
mLocked = LockState.LOCKED;
return false;
}
private GeckoProfile(Context context, String profileName) {
mContext = context;
mName = profileName;
@ -400,15 +292,10 @@ public final class GeckoProfile {
private boolean remove() {
try {
File dir = getDir();
if (dir.exists())
delete(dir);
File mozillaDir = ensureMozillaDirectory(mContext);
mDir = findProfileDir(mozillaDir);
if (mDir == null) {
if (mDir == null)
return false;
}
INIParser parser = getProfilesINI(mContext);