backout 3c552ee3aa5e to fix commit message
authorWes Johnston <wjohnston@mozilla.com>
Fri, 02 Aug 2013 11:09:48 -0700
changeset 153463 8a2b3ff7906cf1567d058b1ff9d5b78d88e32353
parent 153462 a9d30334069f49bb79dab0a169235f703f42b668
child 153464 62a598857a50a5fff5853430dfb0d254b523e185
push id2859
push userakeybl@mozilla.com
push dateMon, 16 Sep 2013 19:14:59 +0000
treeherdermozilla-beta@87d3c51cd2bf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone25.0a1
backs out3c552ee3aa5e0e1f1156e16ff8b651bcb29785f9
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
backout 3c552ee3aa5e to fix commit message
mobile/android/base/BrowserApp.java
mobile/android/base/GeckoProfile.java
--- a/mobile/android/base/BrowserApp.java
+++ b/mobile/android/base/BrowserApp.java
@@ -95,19 +95,16 @@ abstract public class BrowserApp extends
 
     private static final String STATE_ABOUT_HOME_TOP_PADDING = "abouthome_top_padding";
     private static final String STATE_DYNAMIC_TOOLBAR_ENABLED = "dynamic_toolbar";
 
     public static BrowserToolbar mBrowserToolbar;
     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 {
         public int id;
         public String label;
         public String icon;
         public boolean checkable = false;
         public boolean checked = false;
@@ -392,33 +389,29 @@ abstract public class BrowserApp extends
                     mAboutHome.setLastTabsVisibility(false);
             }
         });
 
         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");
 
         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);
 
         mBrowserToolbar = (BrowserToolbar) findViewById(R.id.browser_toolbar);
 
         ((GeckoApp.MainLayout) mMainLayout).setTouchEventInterceptor(new HideTabsTouchListener());
         ((GeckoApp.MainLayout) mMainLayout).setMotionEventInterceptor(new MotionEventInterceptor() {
@@ -1816,18 +1809,16 @@ abstract public class BrowserApp extends
             @Override
             public void onPromptFinished(String result) {
                 try {
                     int itemId = new JSONObject(result).getInt("button");
                     if (itemId == 0) {
                         String args = "";
                         if (type == GuestModeDialog.ENTERING) {
                             args = "--guest-mode";
-                        } else {
-                            GeckoProfile.leaveGuestSession(BrowserApp.this);
                         }
                         doRestart(args);
                         System.exit(0);
                     }
                 } catch(JSONException ex) {
                     Log.e(LOGTAG, "Exception reading guest mode prompt result", ex);
                 }
             }
--- a/mobile/android/base/GeckoProfile.java
+++ b/mobile/android/base/GeckoProfile.java
@@ -2,17 +2,16 @@
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 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;
 import android.util.Log;
 
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.FileReader;
@@ -20,65 +19,38 @@ import java.io.IOException;
 import java.io.OutputStreamWriter;
 import java.nio.charset.Charset;
 import java.util.Enumeration;
 import java.util.HashMap;
 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;
 
     private final Context mContext;
     private final String mName;
     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();
       File mozillaDir = new File(filesDir, "mozilla");
       File profilesIni = new File(mozillaDir, "profiles.ini");
       return new INIParser(profilesIni);
     }
 
     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());
         }
 
         return get(context, "");
     }
 
     public static GeckoProfile get(Context context, String profileName) {
         synchronized (sProfileCache) {
@@ -135,74 +107,40 @@ public final class GeckoProfile {
         }
     }
 
     public static boolean removeProfile(Context context, String profileName) {
         return new GeckoProfile(context, profileName).remove();
     }
 
     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);
         }
         return null;
     }
 
-    public static void leaveGuestSession(Context context) {
-        GeckoProfile profile = getGuestProfile(context);
-        if (profile != null) {
-            profile.unlock();
-        }
-    }
-
-    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;
+    public static void removeGuestProfile(Context context) {
+        if (context == null) {
+            throw new IllegalArgumentException("context must be non-null");
         }
-
-        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);
             }
         } catch (Exception ex) {
             Log.e(LOGTAG, "Error removing guest profile", ex);
         }
     }
 
@@ -219,62 +157,16 @@ public final class GeckoProfile {
                 delete(fileDelete);
             }
         }
 
         // Even if this is a dir, it should now be empty and delete should work
         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;
     }
 
     private GeckoProfile(Context context, String profileName, File profileDir) {
         mContext = context;
         mName = profileName;
@@ -395,25 +287,20 @@ public final class GeckoProfile {
             return sb.toString();
         } finally {
             fr.close();
         }
     }
 
     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);
 
             Hashtable<String, INISection> sections = parser.getSections();
             for (Enumeration<INISection> e = sections.elements(); e.hasMoreElements();) {
                 INISection section = e.nextElement();
                 String name = section.getStringProperty("Name");