Bug 906030 - Don't create profiles when checking if they're locked. r=bnicholson
authorWes Johnston <wjohnston@mozilla.com>
Wed, 11 Sep 2013 10:10:47 -0700
changeset 146680 0b479df9a59a0a3acb7fbdccedd4b3e5dbba00c3
parent 146679 63aa3bb1a0ddb36ee4781a4faa9525c3a0cac2ae
child 146681 9929cf38b486956b530650ad2998d811218f510a
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersbnicholson
bugs906030
milestone26.0a1
Bug 906030 - Don't create profiles when checking if they're locked. r=bnicholson
mobile/android/base/GeckoProfile.java
--- a/mobile/android/base/GeckoProfile.java
+++ b/mobile/android/base/GeckoProfile.java
@@ -63,17 +63,17 @@ public final class GeckoProfile {
         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) {
                 return ((GeckoApp)context).mProfile;
             }
 
             GeckoProfile guest = GeckoProfile.getGuestProfile(context);
-            // if the guest profile exists and is locked, return it
+            // if the guest profile 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());
         }
 
@@ -226,42 +226,54 @@ public final class GeckoProfile {
     }
 
     // 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;
+        // Don't use getDir() as it will create a dir if none exists
+        if (mDir != null && mDir.exists()) {
+            File lockFile = new File(mDir, LOCK_FILE_NAME);
+            boolean res = lockFile.exists();
+            mLocked = res ? LockState.LOCKED : LockState.UNLOCKED;
+        } else {
+            mLocked = LockState.UNLOCKED;
+        }
+
+        return mLocked == LockState.LOCKED;
     }
 
     public boolean lock() {
         try {
+            // If this dir doesn't exist getDir will create it for us
             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() {
+        // Don't use getDir() as it will create a dir
+        if (mDir == null || !mDir.exists()) {
+            return true;
+        }
+
         try {
-            File lockFile = new File(getDir(), LOCK_FILE_NAME);
+            File lockFile = new File(mDir, LOCK_FILE_NAME);
             boolean result = delete(lockFile);
             if (result) {
                 mLocked = LockState.UNLOCKED;
             } else {
                 mLocked = LockState.LOCKED;
             }
             return result;
         } catch(IOException ex) {