Bug 1266104 - Ensure SavedReaderViewHelper is loaded for recent tabs panel draft
authorAndrzej Hunt <ahunt@mozilla.com>
Wed, 20 Apr 2016 22:02:49 +0200
changeset 354420 68b338c6f7782a7ab42d9f79f25fa624826310db
parent 354403 8682bfc4ba849853ececcc9838a9ba5d100180bf
child 518994 00f0f4699d014532b4c35fa9c0e8d1d4d33930a2
push id16068
push userahunt@mozilla.com
push dateWed, 20 Apr 2016 20:03:14 +0000
bugs1266104
milestone48.0a1
Bug 1266104 - Ensure SavedReaderViewHelper is loaded for recent tabs panel I wonder if there is a better solution to guarantee we have the necessary data loaded, however this seems to be the only special case (i.e. the only place we use TwoLinePageRow without the DB having been loaded first). MozReview-Commit-ID: F4iAIpe87IY
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
@@ -17,16 +17,17 @@ import org.mozilla.gecko.GeckoAppShell;
 import org.mozilla.gecko.GeckoEvent;
 import org.mozilla.gecko.GeckoProfile;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.SessionParser;
 import org.mozilla.gecko.Telemetry;
 import org.mozilla.gecko.TelemetryContract;
 import org.mozilla.gecko.db.BrowserContract.CommonColumns;
 import org.mozilla.gecko.db.BrowserContract.URLColumns;
+import org.mozilla.gecko.reader.SavedReaderViewHelper;
 import org.mozilla.gecko.util.EventCallback;
 import org.mozilla.gecko.util.NativeEventListener;
 import org.mozilla.gecko.util.NativeJSObject;
 import org.mozilla.gecko.util.ThreadUtils;
 
 import android.content.Context;
 import android.database.Cursor;
 import android.database.MatrixCursor;
@@ -281,16 +282,25 @@ public class RecentTabsPanel extends Hom
             row.add(url);
             row.add(title);
             row.add(type);
             row.add(data);
         }
 
         @Override
         public Cursor loadCursor() {
+            // TwoLinePageRow requires the SavedReaderViewHelper to be initialised. Usually this is
+            // done as part of BrowserDatabaseHelper.onOpen(), however we don't actually access
+            // the DB when showing the Recent Tabs panel, hence it's possible that the SavedReaderViewHelper
+            // isn't loaded. Therefore we need to explicitly force loading here.
+            // Note: loadCursor is run on a background thread, hence it's safe to do this here.
+            // (loading time is a few ms, and hence shouldn't impact overall loading time for this
+            // panel in any significant way).
+            SavedReaderViewHelper.getSavedReaderViewHelper(getContext()).loadItems();
+
             final Context context = getContext();
 
             final MatrixCursor c = new MatrixCursor(new String[] { RecentTabs._ID,
                                                                    RecentTabs.URL,
                                                                    RecentTabs.TITLE,
                                                                    RecentTabs.TYPE,
                                                                    RecentTabs.DATA});