Bug 1252650 - Add GeckoThread.canUseProfile; r=snorp
authorJim Chen <nchen@mozilla.com>
Wed, 20 Apr 2016 15:06:13 -0400
changeset 294086 3fc77a3172823ddddf2646c8bb4325f9063cb346
parent 294085 ca46a5d6f50d85924e59a63a189b17ee49510975
child 294087 1573298fe6c2f66f91f3d7aac41446a517e3d382
push id75428
push usernchen@mozilla.com
push dateWed, 20 Apr 2016 19:07:08 +0000
treeherdermozilla-inbound@f69911bd0bc2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1252650
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 1252650 - Add GeckoThread.canUseProfile; r=snorp canUseProfile returns whether we're currently using the given profile or we can potentially start Gecko with the given profile.
mobile/android/base/java/org/mozilla/gecko/GeckoThread.java
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoThread.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoThread.java
@@ -125,39 +125,55 @@ public class GeckoThread extends Thread 
         ThreadUtils.assertOnUiThread();
         if (isState(State.INITIAL) && sGeckoThread == null) {
             sGeckoThread = new GeckoThread(profile, args, action, debugging);
             return true;
         }
         return false;
     }
 
-    public static boolean initWithProfile(String profileName, File profileDir) {
-        if (profileName == null) {
-            throw new IllegalArgumentException("Null profile name");
-        }
-
-        final GeckoProfile profile = getActiveProfile();
+    private static boolean canUseProfile(final GeckoProfile profile, final String profileName,
+                                         final File profileDir) {
         if (profile == null) {
-            // We haven't initialized yet; okay to initialize now.
-            final Context context = GeckoAppShell.getApplicationContext();
-            return init(GeckoProfile.get(context, profileName, profileDir),
-                        /* args */ null, /* action */ null, /* debugging */ false);
+            return true;
         }
 
         // We already initialized and have a profile; see if it matches ours.
         try {
             return profileDir == null ? profileName.equals(profile.getName()) :
                     profile.getDir().getCanonicalPath().equals(profileDir.getCanonicalPath());
         } catch (final IOException e) {
             Log.e(LOGTAG, "Cannot compare profile " + profileName);
             return false;
         }
     }
 
+    public static boolean canUseProfile(final String profileName, final File profileDir) {
+        if (profileName == null) {
+            throw new IllegalArgumentException("Null profile name");
+        }
+        return canUseProfile(getActiveProfile(), profileName, profileDir);
+    }
+
+    public static boolean initWithProfile(final String profileName, final File profileDir) {
+        if (profileName == null) {
+            throw new IllegalArgumentException("Null profile name");
+        }
+
+        final GeckoProfile profile = getActiveProfile();
+        if (profile != null) {
+            return canUseProfile(profile, profileName, profileDir);
+        }
+
+        // We haven't initialized yet; okay to initialize now.
+        final Context context = GeckoAppShell.getApplicationContext();
+        return init(GeckoProfile.get(context, profileName, profileDir),
+                    /* args */ null, /* action */ null, /* debugging */ false);
+    }
+
     public static boolean launch() {
         ThreadUtils.assertOnUiThread();
         if (checkAndSetState(State.INITIAL, State.LAUNCHED)) {
             sGeckoThread.start();
             return true;
         }
         return false;
     }