Bug 1339160 - 3. Use GeckoService to warm up Gecko from custom tabs service; r=snorp
authorJim Chen <nchen@mozilla.com>
Wed, 15 Feb 2017 17:12:59 -0500
changeset 485022 8620e18b5878bdf7f9169364503aff9a910afa47
parent 485021 26359cfd0d245637ff7efc288098d07f1652d417
child 485023 427fd576729151744a2bdd7f433cdf78c0ba3015
push id45611
push userbmo:gasolin@mozilla.com
push dateThu, 16 Feb 2017 01:39:57 +0000
reviewerssnorp
bugs1339160
milestone54.0a1
Bug 1339160 - 3. Use GeckoService to warm up Gecko from custom tabs service; r=snorp Use the GeckoService load-gecko action to warm up Gecko instead of using a separate method.
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
@@ -228,35 +228,9 @@ 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
@@ -1,15 +1,16 @@
 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.customtabs;
 
+import android.content.Intent;
 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;
@@ -33,18 +34,25 @@ public class GeckoCustomTabsService exte
     }
 
     @Override
     protected boolean warmup(long flags) {
         if (DEBUG) {
             Log.v(LOGTAG, "warming up...");
         }
 
-        GeckoService.startGecko(GeckoProfile.initFromArgs(this, null), null, getApplicationContext());
+        if (GeckoThread.isRunning()) {
+            return true;
+        }
 
+        final Intent intent = GeckoService.getIntentToStartGecko(this);
+        // Use a default profile for warming up Gecko.
+        final GeckoProfile profile = GeckoProfile.get(this);
+        GeckoService.setIntentProfile(intent, profile.getName(), profile.getDir().getAbsolutePath());
+        startService(intent);
         return true;
     }
 
     @Override
     protected boolean newSession(CustomTabsSessionToken sessionToken) {
         Log.v(LOGTAG, "newSession()");
 
         // Pretend session has been started