Bug 1262625 - Only call getDir to initialize profile. r=jchen draft
authorMichael Comella <michael.l.comella@gmail.com>
Wed, 13 Apr 2016 16:12:14 -0700
changeset 350495 4478ae1ecb0b72915af5bd4df6118beefb78f76f
parent 349534 5b37f138e5bfdb84fe3460dd115ec225933e0f5f
child 518357 5f1f1858b81647cf35e73993a54640ab9fb18d9d
push id15365
push usermichael.l.comella@gmail.com
push dateWed, 13 Apr 2016 23:12:24 +0000
reviewersjchen
bugs1262625
milestone48.0a1
Bug 1262625 - Only call getDir to initialize profile. r=jchen MozReview-Commit-ID: F8ky8G9QhUT
mobile/android/base/java/org/mozilla/gecko/GeckoProfile.java
mobile/android/base/java/org/mozilla/gecko/GeckoThread.java
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoProfile.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoProfile.java
@@ -552,23 +552,31 @@ public final class GeckoProfile {
     public String getName() {
         return mName;
     }
 
     public boolean isCustomProfile() {
         return CUSTOM_PROFILE.equals(mName);
     }
 
+    /**
+     * Retrieves the directory backing the profile. This method acts
+     * as a lazy initializer for the GeckoProfile instance.
+     */
     @RobocopTarget
     public synchronized File getDir() {
         forceCreate();
         return mProfileDir;
     }
 
-    public synchronized GeckoProfile forceCreate() {
+    /**
+     * Forces profile creation. Consider using {@link #getDir()} to initialize the profile instead - it is the
+     * lazy initializer and, for our code reasoning abilities, we should initialize the profile in one place.
+     */
+    private synchronized GeckoProfile forceCreate() {
         if (mProfileDir != null) {
             return this;
         }
 
         try {
             // Check if a profile with this name already exists.
             try {
                 mProfileDir = findProfileDir();
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoThread.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoThread.java
@@ -372,17 +372,17 @@ public class GeckoThread extends Thread 
 
             if (args == null || !args.contains(BrowserApp.GUEST_BROWSING_ARG)) {
                 profileArg += " " + BrowserApp.GUEST_BROWSING_ARG;
             }
 
         } else {
             // Make sure a profile exists.
             final GeckoProfile profile = getProfile();
-            profile.forceCreate();
+            profile.getDir(); // call the lazy initializer
 
             // If args don't include the profile, make sure it's included.
             if (args == null || !args.matches(".*\\B-(P|profile)\\s+\\S+.*")) {
                 if (profile.isCustomProfile()) {
                     profileArg = " -profile " + profile.getDir().getAbsolutePath();
                 } else {
                     profileArg = " -P " + profile.getName();
                 }