Bug 1339160 - 2. Add GeckoService actions for loading libs and starting Gecko; r=snorp
authorJim Chen <nchen@mozilla.com>
Wed, 15 Feb 2017 17:12:56 -0500
changeset 485021 26359cfd0d245637ff7efc288098d07f1652d417
parent 485020 c80d17b6ea4897766816f0f3ac9b005ce551cbd3
child 485022 8620e18b5878bdf7f9169364503aff9a910afa47
push id45611
push userbmo:gasolin@mozilla.com
push dateThu, 16 Feb 2017 01:39:57 +0000
reviewerssnorp
bugs1339160
milestone54.0a1
Bug 1339160 - 2. Add GeckoService actions for loading libs and starting Gecko; r=snorp Add two actions to GeckoService to load libs only, and to load libs plus start Gecko, respectively.
mobile/android/base/java/org/mozilla/gecko/GeckoService.java
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoService.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoService.java
@@ -26,16 +26,18 @@ public class GeckoService extends Servic
     private static final String LOGTAG = "GeckoService";
     private static final boolean DEBUG = false;
 
     private static final String INTENT_PROFILE_NAME = "org.mozilla.gecko.intent.PROFILE_NAME";
     private static final String INTENT_PROFILE_DIR = "org.mozilla.gecko.intent.PROFILE_DIR";
 
     private static final String INTENT_ACTION_UPDATE_ADDONS = "update-addons";
     private static final String INTENT_ACTION_CREATE_SERVICES = "create-services";
+    private static final String INTENT_ACTION_LOAD_LIBS = "load-libs";
+    private static final String INTENT_ACTION_START_GECKO = "start-gecko";
 
     private static final String INTENT_SERVICE_CATEGORY = "category";
     private static final String INTENT_SERVICE_DATA = "data";
 
     private static class EventListener implements BundleEventListener {
         @Override // BundleEventListener
         public void handleMessage(final String event,
                                   final GeckoBundle message,
@@ -127,25 +129,34 @@ public class GeckoService extends Servic
         intent.putExtra(INTENT_SERVICE_DATA, data);
         return intent;
     }
 
     public static Intent getIntentToCreateServices(final Context context, final String category) {
         return getIntentToCreateServices(context, category, /* data */ null);
     }
 
+    public static Intent getIntentToLoadLibs(final Context context) {
+        return getIntentForAction(context, INTENT_ACTION_LOAD_LIBS);
+    }
+
+    public static Intent getIntentToStartGecko(final Context context) {
+        return getIntentForAction(context, INTENT_ACTION_START_GECKO);
+    }
+
     public static void setIntentProfile(final Intent intent, final String profileName,
                                         final String profileDir) {
         intent.putExtra(INTENT_PROFILE_NAME, profileName);
         intent.putExtra(INTENT_PROFILE_DIR, profileDir);
     }
 
-    private int handleIntent(final Intent intent, final int startId) {
-        if (DEBUG) {
-            Log.d(LOGTAG, "Handling " + intent.getAction());
+    private boolean initGecko(final Intent intent) {
+        if (INTENT_ACTION_LOAD_LIBS.equals(intent.getAction())) {
+            // Intentionally not initialize Gecko when only loading libs.
+            return true;
         }
 
         final String profileName = intent.getStringExtra(INTENT_PROFILE_NAME);
         final String profileDir = intent.getStringExtra(INTENT_PROFILE_DIR);
 
         if (profileName == null) {
             throw new IllegalArgumentException("Intent must specify profile.");
         }
@@ -155,26 +166,41 @@ public class GeckoService extends Servic
             Log.w(LOGTAG, "Ignoring due to profile mismatch: " +
                           profileName + " [" + profileDir + ']');
 
             final GeckoProfile profile = GeckoThread.getActiveProfile();
             if (profile != null) {
                 Log.w(LOGTAG, "Current profile is " + profile.getName() +
                               " [" + profile.getDir().getAbsolutePath() + ']');
             }
+            return false;
+        }
+        return true;
+    }
+
+    private int handleIntent(final Intent intent, final int startId) {
+        if (DEBUG) {
+            Log.d(LOGTAG, "Handling " + intent.getAction());
+        }
+
+        if (!initGecko(intent)) {
             stopSelf(startId);
             return Service.START_NOT_STICKY;
         }
 
         GeckoThread.launch();
 
         switch (intent.getAction()) {
         case INTENT_ACTION_UPDATE_ADDONS:
             // Run the add-on update service. Because the service is automatically invoked
             // when loading Gecko, we don't have to do anything else here.
+        case INTENT_ACTION_LOAD_LIBS:
+            // Load libs only. Don't take any additional actions.
+        case INTENT_ACTION_START_GECKO:
+            // Load libs and start Gecko. Don't take any additional actions.
             break;
 
         case INTENT_ACTION_CREATE_SERVICES:
             final String category = intent.getStringExtra(INTENT_SERVICE_CATEGORY);
             final String data = intent.getStringExtra(INTENT_SERVICE_DATA);
 
             if (category == null) {
                 break;