Bug 1225980 - Add a startGecko static method to GeckoService, to be used for GeckoCustomTabsService.warmup() r=rbarker
authorDylan Roeh <droeh@mozilla.com>
Wed, 09 Nov 2016 11:22:45 -0600
changeset 351993 aff695846bfdb339c3bc64001ae8dfe7a5f5e819
parent 351992 2d76c0ab3a375e9e89094ea993755dac8a932f81
child 351994 72436161232cf13ed9fca41ecca8fa0db11c3738
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrbarker
bugs1225980
milestone52.0a1
Bug 1225980 - Add a startGecko static method to GeckoService, to be used for GeckoCustomTabsService.warmup() r=rbarker
mobile/android/base/java/org/mozilla/gecko/GeckoService.java
mobile/android/base/java/org/mozilla/gecko/customtabs/GeckoCustomTabsService.java
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoService.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoService.java
@@ -6,16 +6,18 @@
 package org.mozilla.gecko;
 
 import android.app.AlarmManager;
 import android.app.Service;
 import android.app.PendingIntent;
 import android.content.Context;
 import android.content.Intent;
 import android.os.IBinder;
+import android.os.Handler;
+import android.os.Looper;
 import android.util.Log;
 
 import java.io.File;
 
 import org.mozilla.gecko.util.NativeEventListener;
 import org.mozilla.gecko.util.NativeJSObject;
 import org.mozilla.gecko.util.EventCallback;
 
@@ -200,9 +202,35 @@ public class GeckoService extends Servic
             return Service.START_NOT_STICKY;
         }
     }
 
     @Override // Service
     public IBinder onBind(final Intent intent) {
         return null;
     }
+
+    public static void startGecko(final GeckoProfile profile, final String args, final Context context) {
+        if (GeckoThread.isLaunched()) {
+            if (DEBUG) {
+                Log.v(LOGTAG, "already launched");
+            }
+            return;
+        }
+
+        Handler handler = new Handler(Looper.getMainLooper());
+        handler.post(new Runnable() {
+            @Override
+            public void run() {
+                GeckoAppShell.ensureCrashHandling();
+                GeckoAppShell.setApplicationContext(context);
+                GeckoThread.onResume();
+
+                GeckoThread.init(profile, args, null, false);
+                GeckoThread.launch();
+
+                if (DEBUG) {
+                    Log.v(LOGTAG, "warmed up (launched)");
+                }
+            }
+        });
+    }
 }
--- a/mobile/android/base/java/org/mozilla/gecko/customtabs/GeckoCustomTabsService.java
+++ b/mobile/android/base/java/org/mozilla/gecko/customtabs/GeckoCustomTabsService.java
@@ -6,36 +6,43 @@
 package org.mozilla.gecko.customtabs;
 
 import android.net.Uri;
 import android.os.Bundle;
 import android.support.customtabs.CustomTabsService;
 import android.support.customtabs.CustomTabsSessionToken;
 import android.util.Log;
 
+import org.mozilla.gecko.GeckoProfile;
+import org.mozilla.gecko.GeckoService;
+
 import java.util.List;
 
 /**
  * Custom tabs service external, third-party apps connect to.
  */
 public class GeckoCustomTabsService extends CustomTabsService {
     private static final String LOGTAG = "GeckoCustomTabsService";
+    private static final boolean DEBUG = false;
 
     @Override
     protected boolean updateVisuals(CustomTabsSessionToken sessionToken, Bundle bundle) {
         Log.v(LOGTAG, "updateVisuals()");
 
         return false;
     }
 
     @Override
     protected boolean warmup(long flags) {
-        Log.v(LOGTAG, "warmup()");
+        if (DEBUG) {
+            Log.v(LOGTAG, "warming up...");
+        }
 
-        // Pretend warmup was successful
+        GeckoService.startGecko(GeckoProfile.initFromArgs(this, null), null, getApplicationContext());
+
         return true;
     }
 
     @Override
     protected boolean newSession(CustomTabsSessionToken sessionToken) {
         Log.v(LOGTAG, "newSession()");
 
         // Pretend session has been started