Bug 895709 - Kill guest mode profile when we start in non-guest mode. r=blassey
authorWes Johnston <wjohnston@mozilla.com>
Tue, 30 Jul 2013 09:05:25 -0700
changeset 152853 17773671a1f3ec9a74360ee1249020122be112d6
parent 152852 47b0b4f9debf407f168a484f042221b59cf8cdd8
child 152854 db8581f995e9681b3ee468ae1df4f1624b1e36ea
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)
reviewersblassey
bugs895709
milestone25.0a1
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
Bug 895709 - Kill guest mode profile when we start in non-guest mode. r=blassey
mobile/android/base/BrowserApp.java
mobile/android/base/GeckoProfile.java
--- a/mobile/android/base/BrowserApp.java
+++ b/mobile/android/base/BrowserApp.java
@@ -395,16 +395,23 @@ abstract public class BrowserApp extends
 
     @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 {
+            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() {
--- a/mobile/android/base/GeckoProfile.java
+++ b/mobile/android/base/GeckoProfile.java
@@ -111,29 +111,62 @@ public final class GeckoProfile {
         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);
+
             File guestDir = context.getDir("guest", Context.MODE_PRIVATE);
-            if (guestDir.exists())
-                guestDir.delete();
             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 removeGuestProfile(Context context) {
+        if (context == null) {
+            throw new IllegalArgumentException("context must be non-null");
+        }
+        try {
+            File guestDir = context.getDir("guest", Context.MODE_PRIVATE);
+            if (guestDir.exists()) {
+                delete(guestDir);
+            }
+        } catch (Exception ex) {
+            Log.e(LOGTAG, "Error removing guest profile", ex);
+        }
+    }
+
+    public static boolean delete(File file) throws IOException {
+        // Try to do a quick initial delete
+        if (file.delete())
+            return true;
+
+        if (file.isDirectory()) {
+            // If the quick delete failed and this is a dir, recursively delete the contents of the dir
+            String files[] = file.list();
+            for (String temp : files) {
+                File fileDelete = new File(file, temp);
+                delete(fileDelete);
+            }
+        }
+
+        // Even if this is a dir, it should now be empty and delete should work
+        return file.delete();
+    }
+
     private GeckoProfile(Context context, String profileName) {
         mContext = context;
         mName = profileName;
     }
 
     private GeckoProfile(Context context, String profileName, File profileDir) {
         mContext = context;
         mName = profileName;