Bug 708280 - delay checking checking for update until idle to avoid startup path. r=mfinkle
authorDoug Turner <dougt@dougt.org>
Mon, 12 Dec 2011 16:27:34 +0800
changeset 84116 aebdec71790ec420502bbbf255373fa383f12bde
parent 84115 05d5c4ef7efc6871a2291a4683c65d6166e9dac3
child 84117 475d66e8929d0f7ab0d87125b524695826c21845
push id519
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 00:38:35 +0000
treeherdermozilla-beta@788ea1ef610b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs708280
milestone11.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 708280 - delay checking checking for update until idle to avoid startup path. r=mfinkle
mobile/android/base/GeckoApp.java
--- a/mobile/android/base/GeckoApp.java
+++ b/mobile/android/base/GeckoApp.java
@@ -897,16 +897,17 @@ abstract public class GeckoApp
                     public void run() {
                         if (sMenu != null)
                             sMenu.findItem(R.id.preferences).setEnabled(true);
                     }
                 });
                 setLaunchState(GeckoApp.LaunchState.GeckoRunning);
                 GeckoAppShell.sendPendingEventsToGecko();
                 connectGeckoLayerClient();
+                Looper.myQueue().addIdleHandler(new UpdateIdleHandler());
             } else if (event.equals("ToggleChrome:Hide")) {
                 mMainHandler.post(new Runnable() {
                     public void run() {
                         mBrowserToolbar.setVisibility(View.GONE);
                     }
                 });
             } else if (event.equals("ToggleChrome:Show")) {
                 mMainHandler.post(new Runnable() {
@@ -1414,42 +1415,17 @@ abstract public class GeckoApp
         mBatteryReceiver = new GeckoBatteryManager();
         registerReceiver(mBatteryReceiver, batteryFilter);
 
         IntentFilter smsFilter = new IntentFilter();
         smsFilter.addAction("android.provider.Telephony.SMS_RECEIVED");
         mSmsReceiver = new GeckoSmsManager();
         registerReceiver(mSmsReceiver, smsFilter);
 
-        final GeckoApp self = this;
- 
-        mMainHandler.postDelayed(new Runnable() {
-            public void run() {
-                
-                Log.w(LOGTAG, "zerdatime " + new Date().getTime() + " - pre checkLaunchState");
-
-                /*
-                  XXXX see bug 635342
-                   We want to disable this code if possible.  It is about 145ms in runtime
-                SharedPreferences settings = getPreferences(Activity.MODE_PRIVATE);
-                String localeCode = settings.getString(getPackageName() + ".locale", "");
-                if (localeCode != null && localeCode.length() > 0)
-                    GeckoAppShell.setSelectedLocale(localeCode);
-                */
-
-                if (!checkLaunchState(LaunchState.Launched)) {
-                    return;
-                }
-
-                // it would be good only to do this if MOZ_UPDATER was defined 
-                long startTime = new Date().getTime();
-                checkAndLaunchUpdate();
-                Log.w(LOGTAG, "checking for an update took " + (new Date().getTime() - startTime) + "ms");
-            }
-        }, 50);
+        final GeckoApp self = this; 
     }
 
     /**
      * Enable Android StrictMode checks (for supported OS versions).
      * http://developer.android.com/reference/android/os/StrictMode.html
      */
     private void enableStrictMode()
     {
@@ -1705,16 +1681,31 @@ abstract public class GeckoApp
         // Give the restart process time to start before we die
         GeckoAppShell.waitForAnotherGeckoProc();
     }
 
     public void handleNotification(String action, String alertName, String alertCookie) {
         GeckoAppShell.handleNotification(action, alertName, alertCookie);
     }
 
+    // it would be good only to do this if MOZ_UPDATER was defined 
+    private class UpdateIdleHandler implements MessageQueue.IdleHandler {
+        public boolean queueIdle() {
+            mMainHandler.post(new Runnable() {
+                    public void run() {
+                        long startTime = new Date().getTime();
+                        checkAndLaunchUpdate();
+                        Log.w(LOGTAG, "checking for an update took " + (new Date().getTime() - startTime) + "ms");
+                    }
+                });
+            // only need to run this once.
+            return false;
+        }
+    }
+
     private void checkAndLaunchUpdate() {
         Log.i(LOGTAG, "Checking for an update");
 
         int statusCode = 8; // UNEXPECTED_ERROR
         File baseUpdateDir = null;
         if (Build.VERSION.SDK_INT >= 8)
             baseUpdateDir = getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS);
         else