Bug 1262625 - Only call getDir to initialize profile. r=jchen
MozReview-Commit-ID: F8ky8G9QhUT
--- 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();
}