Bug 1262625 - Only call getDir to initialize profile. r=jchen
authorMichael Comella <michael.l.comella@gmail.com>
Wed, 13 Apr 2016 16:12:14 -0700
changeset 293205 6b0f8e84b00ceb8db88665a00c0089f467f9136d
parent 293204 acaefde5bf02467bf2000059ab4cd2cd23dba0a2
child 293206 3e85a84c7d68632e1098cc9374787dc8f54ce24f
push id30177
push usercbook@mozilla.com
push dateFri, 15 Apr 2016 09:40:05 +0000
treeherdermozilla-central@755a175b3cc7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjchen
bugs1262625
milestone48.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 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();
                 }