Backed out 3 changesets (bug 1075644) for Android build bustage on a CLOSED TREE
authorWes Kocher <wkocher@mozilla.com>
Fri, 17 Oct 2014 11:33:15 -0700
changeset 210900 c8a9a49c5c100a8c79a82c9f7669caf1b620acc7
parent 210899 043792c7257a9a8a31b99f4f35393e20b0285a7d
child 210901 92c87e95915ee687ce58a7342db2bb1a9c230a8f
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
bugs1075644
milestone36.0a1
backs outc44f001ea6c196717b09dcdf7ec9e1279fe04209
ca0dfff936c2e330fde5857edb9d144acd842755
47264e561dce89866d70eabe8423381730ede251
Backed out 3 changesets (bug 1075644) for Android build bustage on a CLOSED TREE Backed out changeset c44f001ea6c1 (bug 1075644) Backed out changeset ca0dfff936c2 (bug 1075644) Backed out changeset 47264e561dce (bug 1075644)
mobile/android/base/GeckoApp.java
mobile/android/base/GeckoThread.java
mobile/android/base/home/TopSitesPanel.java
mobile/android/base/tests/testLinkContextMenu.java
mobile/android/base/tests/testMailToContextMenu.java
mobile/android/base/util/ThreadUtils.java
--- a/mobile/android/base/GeckoApp.java
+++ b/mobile/android/base/GeckoApp.java
@@ -1185,25 +1185,34 @@ public abstract class GeckoApp
             }
         });
 
         // Workaround for <http://code.google.com/p/android/issues/detail?id=20915>.
         try {
             Class.forName("android.os.AsyncTask");
         } catch (ClassNotFoundException e) {}
 
+        MemoryMonitor.getInstance().init(getApplicationContext());
+
         // GeckoAppShell is tightly coupled to us, rather than
         // the app context, because various parts of Fennec (e.g.,
         // GeckoScreenOrientation) use GAS to access the Activity in
         // the guise of fetching a Context.
         // When that's fixed, `this` can change to
         // `(GeckoApplication) getApplication()` here.
         GeckoAppShell.setContextGetter(this);
         GeckoAppShell.setGeckoInterface(this);
 
+        Tabs.getInstance().attachToContext(this);
+        try {
+            Favicons.initializeWithContext(this);
+        } catch (Exception e) {
+            Log.e(LOGTAG, "Exception starting favicon cache. Corrupt resources?", e);
+        }
+
         // Did the OS locale change while we were backgrounded? If so,
         // we need to die so that Gecko will re-init add-ons that touch
         // the UI.
         // This is using a sledgehammer to crack a nut, but it'll do for
         // now.
         // Our OS locale pref will be detected as invalid after the
         // restart, and will be propagated to Gecko accordingly, so there's
         // no need to touch that here.
@@ -1240,30 +1249,16 @@ public abstract class GeckoApp
                 @Override
                 public void run() {
                     GeckoThread.setLaunchState(GeckoThread.LaunchState.Launched);
                     GeckoThread.createAndStart();
                 }
             }, 1000 * 5 /* 5 seconds */);
         }
 
-        // Heavy load on the Gecko thread can slow down the time it takes for UI to appear on
-        // single-core devices. By minimizing the Gecko thread priority, we ensure that the UI
-        // appears quickly. The priority is reset to normal once thumbnails are loaded.
-        ThreadUtils.reduceGeckoPriority();
-
-        MemoryMonitor.getInstance().init(getApplicationContext());
-
-        Tabs.getInstance().attachToContext(this);
-        try {
-            Favicons.initializeWithContext(this);
-        } catch (Exception e) {
-            Log.e(LOGTAG, "Exception starting favicon cache. Corrupt resources?", e);
-        }
-
         Bundle stateBundle = getIntent().getBundleExtra(EXTRA_STATE_BUNDLE);
         if (stateBundle != null) {
             // Use the state bundle if it was given as an intent extra. This is
             // only intended to be used internally via Robocop, so a boolean
             // is read from a private shared pref to prevent other apps from
             // injecting states.
             final SharedPreferences prefs = getSharedPreferences();
             if (prefs.getBoolean(PREFS_ALLOW_STATE_BUNDLE, false)) {
@@ -1630,20 +1625,16 @@ public abstract class GeckoApp
             GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Viewport:Flush", null));
         }
 
         if (ACTION_ALERT_CALLBACK.equals(action)) {
             processAlertCallback(intent);
         } else if (NotificationHelper.HELPER_BROADCAST_ACTION.equals(action)) {
             NotificationHelper.getInstance(getApplicationContext()).handleNotificationIntent(intent);
         }
-
-        // Reset Gecko to normal priority. We may reduce the
-        // priority again later, e.g. for loading thumbnails.
-        ThreadUtils.resetGeckoPriority();
     }
 
     private String restoreSessionTabs(final boolean isExternalURL) throws SessionRestoreException {
         try {
             String sessionString = getProfile().readSessionFile(false);
             if (sessionString == null) {
                 throw new SessionRestoreException("Could not read from session file");
             }
--- a/mobile/android/base/GeckoThread.java
+++ b/mobile/android/base/GeckoThread.java
@@ -46,17 +46,16 @@ public class GeckoThread extends Thread 
     private final String mAction;
     private final String mUri;
 
     public static boolean ensureInit() {
         ThreadUtils.assertOnUiThread();
         if (isCreated())
             return false;
         sGeckoThread = new GeckoThread(sArgs, sAction, sUri);
-        ThreadUtils.sGeckoThread = sGeckoThread;
         return true;
     }
 
     public static String sArgs;
     public static String sAction;
     public static String sUri;
 
     public static void setArgs(String args) {
@@ -160,16 +159,17 @@ public class GeckoThread extends Thread 
         }
 
         return (args != null ? args : "") + profileArg + guestArg;
     }
 
     @Override
     public void run() {
         Looper.prepare();
+        ThreadUtils.sGeckoThread = this;
         ThreadUtils.sGeckoHandler = new Handler();
         ThreadUtils.sGeckoQueue = Looper.myQueue();
 
         String path = initGeckoEnvironment();
 
         // This can only happen after the call to initGeckoEnvironment
         // above, because otherwise the JNI code hasn't been loaded yet.
         ThreadUtils.postToUiThread(new Runnable() {
--- a/mobile/android/base/home/TopSitesPanel.java
+++ b/mobile/android/base/home/TopSitesPanel.java
@@ -93,16 +93,19 @@ public class TopSitesPanel extends HomeF
     private ThumbnailsLoaderCallbacks mThumbnailsLoaderCallbacks;
 
     // Listener for editing pinned sites.
     private EditPinnedSiteListener mEditPinnedSiteListener;
 
     // Max number of entries shown in the grid from the cursor.
     private int mMaxGridEntries;
 
+    // Time in ms until the Gecko thread is reset to normal priority.
+    private static final long PRIORITY_RESET_TIMEOUT = 10000;
+
     public static TopSitesPanel newInstance() {
         return new TopSitesPanel();
     }
 
     private static final boolean logDebug = Log.isLoggable(LOGTAG, Log.DEBUG);
     private static final boolean logVerbose = Log.isLoggable(LOGTAG, Log.VERBOSE);
 
     private static void debug(final String message) {
@@ -339,17 +342,17 @@ public class TopSitesPanel extends HomeF
         getLoaderManager().initLoader(LOADER_ID_TOP_SITES, null, mCursorLoaderCallbacks);
 
         // Since this is the primary fragment that loads whenever about:home is
         // visited, we want to load it as quickly as possible. Heavy load on
         // the Gecko thread can slow down the time it takes for thumbnails to
         // appear, especially during startup (bug 897162). By minimizing the
         // Gecko thread priority, we ensure that the UI appears quickly. The
         // priority is reset to normal once thumbnails are loaded.
-        ThreadUtils.reduceGeckoPriority();
+        ThreadUtils.reduceGeckoPriority(PRIORITY_RESET_TIMEOUT);
     }
 
     /**
      * Listener for editing pinned sites.
      */
     private class EditPinnedSiteListener implements OnEditPinnedSiteListener,
                                                     OnSiteSelectedListener {
         // Tag for the PinSiteDialog fragment.
--- a/mobile/android/base/tests/testLinkContextMenu.java
+++ b/mobile/android/base/tests/testLinkContextMenu.java
@@ -9,18 +9,18 @@ public class testLinkContextMenu extends
     private static final String LINK_PAGE_TITLE = "Big Link";
     private static final String linkMenuItems [] = StringHelper.CONTEXT_MENU_ITEMS_IN_NORMAL_TAB;
 
     public void testLinkContextMenu() {
         blockForGeckoReady();
 
         LINK_PAGE_URL=getAbsoluteUrl(StringHelper.ROBOCOP_BIG_LINK_URL);
         BLANK_PAGE_URL=getAbsoluteUrl(StringHelper.ROBOCOP_BLANK_PAGE_01_URL);
-        loadAndPaint(LINK_PAGE_URL);
-        verifyPageTitle(LINK_PAGE_TITLE);
+        inputAndLoadUrl(LINK_PAGE_URL);
+        waitForText(LINK_PAGE_TITLE);
 
         verifyContextMenuItems(linkMenuItems); // Verify context menu items are correct
         openTabFromContextMenu(linkMenuItems[0],2); // Test the "Open in New Tab" option - expecting 2 tabs: the original and the new one
         openTabFromContextMenu(linkMenuItems[1],2); // Test the "Open in Private Tab" option - expecting only 2 tabs in normal mode
         verifyCopyOption(linkMenuItems[2], BLANK_PAGE_URL); // Test the "Copy Link" option
         verifyShareOption(linkMenuItems[3], LINK_PAGE_TITLE); // Test the "Share Link" option
         verifyBookmarkLinkOption(linkMenuItems[4], BLANK_PAGE_URL); // Test the "Bookmark Link" option
     }
--- a/mobile/android/base/tests/testMailToContextMenu.java
+++ b/mobile/android/base/tests/testMailToContextMenu.java
@@ -7,16 +7,16 @@ public class testMailToContextMenu exten
     private static String MAILTO_PAGE_URL;
     private static final String MAILTO_PAGE_TITLE = StringHelper.ROBOCOP_BIG_MAILTO_TITLE;
     private static final String mailtoMenuItems [] = {"Copy Email Address", "Share Email Address"};
 
     public void testMailToContextMenu() {
         blockForGeckoReady();
 
         MAILTO_PAGE_URL=getAbsoluteUrl(StringHelper.ROBOCOP_BIG_MAILTO_URL);
-        loadAndPaint(MAILTO_PAGE_URL);
-        verifyPageTitle(MAILTO_PAGE_TITLE);
+        inputAndLoadUrl(MAILTO_PAGE_URL);
+        waitForText(MAILTO_PAGE_TITLE);
 
         verifyContextMenuItems(mailtoMenuItems);
         verifyCopyOption(mailtoMenuItems[0], "foo.bar@example.com"); // Test the "Copy Email Address" option
         verifyShareOption(mailtoMenuItems[1], MAILTO_PAGE_TITLE); // Test the "Share Email Address" option
     }
 }
--- a/mobile/android/base/util/ThreadUtils.java
+++ b/mobile/android/base/util/ThreadUtils.java
@@ -12,19 +12,16 @@ import java.util.Map;
 import android.os.Handler;
 import android.os.Looper;
 import android.os.MessageQueue;
 import android.util.Log;
 
 public final class ThreadUtils {
     private static final String LOGTAG = "ThreadUtils";
 
-    // Time in ms until the Gecko thread is reset to normal priority.
-    private static final long PRIORITY_RESET_TIMEOUT = 10000;
-
     /**
      * Controls the action taken when a method like
      * {@link ThreadUtils#assertOnUiThread(AssertBehavior)} detects a problem.
      */
     public static enum AssertBehavior {
         NONE,
         THROW,
     }
@@ -207,28 +204,30 @@ public final class ThreadUtils {
     }
 
     /**
      * Reduces the priority of the Gecko thread, allowing other operations
      * (such as those related to the UI and database) to take precedence.
      *
      * Note that there are no guards in place to prevent multiple calls
      * to this method from conflicting with each other.
+     *
+     * @param timeout Timeout in ms after which the priority will be reset
      */
-    public static void reduceGeckoPriority() {
+    public static void reduceGeckoPriority(long timeout) {
         if (Runtime.getRuntime().availableProcessors() > 1) {
             // Don't reduce priority for multicore devices. We use availableProcessors()
             // for its fast performance. It may give false negatives (i.e. multicore
             // detected as single-core), but we can tolerate this behavior.
             return;
         }
         if (!sIsGeckoPriorityReduced && sGeckoThread != null) {
             sIsGeckoPriorityReduced = true;
             sGeckoThread.setPriority(Thread.MIN_PRIORITY);
-            getUiHandler().postDelayed(sPriorityResetRunnable, PRIORITY_RESET_TIMEOUT);
+            getUiHandler().postDelayed(sPriorityResetRunnable, timeout);
         }
     }
 
     /**
      * Resets the priority of a thread whose priority has been reduced
      * by reduceGeckoPriority.
      */
     public static void resetGeckoPriority() {