Bug 1288816 - Aurora patch - Do the RecentTabsPanel wait from a separate thread. r=jchen draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Sat, 23 Jul 2016 15:28:04 +0200
changeset 392118 c6bd9f0b88118636ad020f816d93d10c7ef9e204
parent 391868 2015718ee09726d42fe29338954627c6d5fa0f8f
child 526258 3cb72b5ad4f56752da7f724da9f9f910c3641e9a
push id23946
push usermozilla@buttercookie.de
push dateSat, 23 Jul 2016 13:28:54 +0000
reviewersjchen
bugs1288816
milestone49.0a2
Bug 1288816 - Aurora patch - Do the RecentTabsPanel wait from a separate thread. r=jchen When reading the previous session file, the RecentTabsPanel waits for GeckoApp (initialisation runs on the main thread) to have actually moved the previous session file to its correct location (happens from the background thread). Hence we can't do the wait from either of those two threads, because we risk a deadlock otherwise if the RecentTabsPanel happens to be initialised *before* GeckoApp. MozReview-Commit-ID: 54x89xHi9b9
mobile/android/base/java/org/mozilla/gecko/home/RecentTabsPanel.java
--- a/mobile/android/base/java/org/mozilla/gecko/home/RecentTabsPanel.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/RecentTabsPanel.java
@@ -214,17 +214,33 @@ public class RecentTabsPanel extends Hom
             emptyText.setText(R.string.home_last_tabs_empty);
 
             mList.setEmptyView(mEmptyView);
         }
     }
 
     @Override
     protected void load() {
-        getLoaderManager().initLoader(LOADER_ID_RECENT_TABS, null, mCursorLoaderCallbacks);
+        Thread updateCursorThread = new Thread(new Runnable() {
+            @Override
+            public void run() {
+                // We need to ensure that the session restore code has updated sessionstore.bak as necessary.
+                GeckoProfile.get(getContext()).waitForOldSessionDataProcessing();
+
+                ThreadUtils.postToUiThread(new Runnable() {
+                    @Override
+                    public void run() {
+                        // Reload the cursor to show recently closed tabs.
+                        getLoaderManager().initLoader(LOADER_ID_RECENT_TABS, null, mCursorLoaderCallbacks);
+                    }
+                });
+            }
+        });
+
+        updateCursorThread.start();
     }
 
     @Override
     public void handleMessage(String event, NativeJSObject message, EventCallback callback) {
         final NativeJSObject[] tabs = message.getObjectArray("tabs");
         final int length = tabs.length;
 
         final ClosedTab[] closedTabs = new ClosedTab[length];
@@ -237,18 +253,33 @@ public class RecentTabsPanel extends Hom
         ThreadUtils.postToUiThread(new Runnable() {
             @Override
             public void run() {
                 mClosedTabs = closedTabs;
 
                 // The fragment might have been detached before this code
                 // runs in the UI thread.
                 if (getActivity() != null) {
-                    // Reload the cursor to show recently closed tabs.
-                    getLoaderManager().restartLoader(LOADER_ID_RECENT_TABS, null, mCursorLoaderCallbacks);
+                    Thread updateCursorThread = new Thread(new Runnable() {
+                        @Override
+                        public void run() {
+                            // We need to ensure that the session restore code has updated sessionstore.bak as necessary.
+                            GeckoProfile.get(getContext()).waitForOldSessionDataProcessing();
+
+                            ThreadUtils.postToUiThread(new Runnable() {
+                                @Override
+                                public void run() {
+                                    // Reload the cursor to show recently closed tabs.
+                                    getLoaderManager().restartLoader(LOADER_ID_RECENT_TABS, null, mCursorLoaderCallbacks);
+                                }
+                            });
+                        }
+                    });
+
+                    updateCursorThread.start();
                 }
             }
         });
     }
 
     private void openTabsWithType(int type) {
         final Cursor c = mAdapter.getCursor();
         if (c == null || !c.moveToFirst()) {
@@ -324,19 +355,16 @@ public class RecentTabsPanel extends Hom
                 }
 
                 // Add an "Open all" button if more than 2 tabs were added to the list.
                 if (visibleClosedTabs > 1) {
                     addRow(c, null, null, RecentTabs.TYPE_OPEN_ALL_CLOSED, null);
                 }
             }
 
-            // We need to ensure that the session restore code has updated sessionstore.bak as necessary.
-            GeckoProfile.get(context).waitForOldSessionDataProcessing();
-
             final String jsonString = GeckoProfile.get(context).readSessionFile(true);
             if (jsonString == null) {
                 // No previous session data
                 return c;
             }
 
             final int count = c.getCount();