Bug 1288186 - Do the RecentTabsAdapter wait from a separate thread. r=jchen
authorJan Henning <jh+bugzilla@buttercookie.de>
Fri, 22 Jul 2016 19:07:41 +0200
changeset 348755 6f1eb74d5648596470e7a2e3f21606b1f12d055c
parent 348754 6348d34d8643769a3c5d59e52dbb1701d79374d8
child 348756 b6ebadfc57ba4755498651503c6db48d32489c16
push id1230
push userjlund@mozilla.com
push dateMon, 31 Oct 2016 18:13:35 +0000
treeherdermozilla-release@5e06e3766db2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjchen
bugs1288186
milestone50.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 1288186 - Do the RecentTabsAdapter wait from a separate thread. r=jchen When reading the previous session file, the RecentTabsAdapter 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 RecentTabsAdapter happens to be initialised *before* GeckoApp. MozReview-Commit-ID: 3GBeReP2iQW
mobile/android/base/java/org/mozilla/gecko/home/RecentTabsAdapter.java
--- a/mobile/android/base/java/org/mozilla/gecko/home/RecentTabsAdapter.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/RecentTabsAdapter.java
@@ -118,22 +118,24 @@ public class RecentTabsAdapter extends R
 
                 // Update the "Recently closed" part of the tab list.
                 updateTabsList(prevClosedTabsCount, recentlyClosedTabs.length, getFirstRecentTabIndex(), getLastRecentTabIndex());
             }
         });
     }
 
     private void readPreviousSessionData() {
-        // Make sure that the start up code has had a chance to update sessionstore.bak as necessary.
-        GeckoProfile.get(context).waitForOldSessionDataProcessing();
-
-        ThreadUtils.postToBackgroundThread(new Runnable() {
+        // If we happen to initialise before GeckoApp, waiting on either the main or the background
+        // thread can lead to a deadlock, so we have to run on a separate thread instead.
+        final Thread parseThread = new Thread(new Runnable() {
             @Override
             public void run() {
+                // Make sure that the start up code has had a chance to update sessionstore.bak as necessary.
+                GeckoProfile.get(context).waitForOldSessionDataProcessing();
+
                 final String jsonString = GeckoProfile.get(context).readSessionFile(true);
                 if (jsonString == null) {
                     // No previous session data.
                     return;
                 }
 
                 final List<ClosedTab> parsedTabs = new ArrayList<>();
 
@@ -170,17 +172,19 @@ public class RecentTabsAdapter extends R
                         // Handle the section header hiding/unhiding.
                         updateHeaderVisibility(prevSectionHeaderVisibility, prevSectionHeaderIndex);
 
                         // Update the "Tabs from last time" part of the tab list.
                         updateTabsList(prevClosedTabsCount, lastSessionTabs.length, getFirstLastSessionTabIndex(), getLastLastSessionTabIndex());
                     }
                 });
             }
-        });
+        }, "LastSessionTabsThread");
+
+        parseThread.start();
     }
 
     public void clearLastSessionData() {
         final ClosedTab[] emptyLastSessionTabs = new ClosedTab[0];
 
         // Only modify mLastSessionTabs on the UI thread.
         ThreadUtils.postToUiThread(new Runnable() {
             @Override