Bug 917455 - Update top sites behaviour for about:home's Top Sites panel (r=wesj, a=lsblakk)
authorLucas Rocha <lucasr@mozilla.com>
Wed, 18 Sep 2013 17:56:32 -0400
changeset 223617 c444238cb90a011d0fa0e389e10b4d20ecba0861
parent 223616 7951523d9b542c10c7925df9e13e6b604f6b0df8
child 223618 d7e3b0bb444834ae0541193c6f71832865e31796
push id6
push userryanvm@gmail.com
push dateMon, 12 Jan 2015 22:04:06 +0000
treeherdermozilla-b2g37_v2_2@895c8fc7b734 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswesj, lsblakk
bugs917455
milestone26.0a2
Bug 917455 - Update top sites behaviour for about:home's Top Sites panel (r=wesj, a=lsblakk)
mobile/android/base/db/BrowserDB.java
--- a/mobile/android/base/db/BrowserDB.java
+++ b/mobile/android/base/db/BrowserDB.java
@@ -133,22 +133,22 @@ public class BrowserDB {
     public static void invalidateCachedState() {
         sDb.invalidateCachedState();
     }
 
     public static Cursor filter(ContentResolver cr, CharSequence constraint, int limit) {
         return sDb.filter(cr, constraint, limit);
     }
 
-    public static Cursor getTopSites(ContentResolver cr, int limit) {
-        // Note this is not a single query anymore, but actually returns a mixture of two queries, one for topSites
-        // and one for pinned sites
-        Cursor topSites = sDb.getTopSites(cr, limit);
-        Cursor pinnedSites = sDb.getPinnedSites(cr, limit);
-        return new TopSitesCursorWrapper(pinnedSites, topSites, limit);
+    public static Cursor getTopSites(ContentResolver cr, int minLimit, int maxLimit) {
+        // Note this is not a single query anymore, but actually returns a mixture
+        // of two queries, one for topSites and one for pinned sites.
+        Cursor pinnedSites = sDb.getPinnedSites(cr, minLimit);
+        Cursor topSites = sDb.getTopSites(cr, maxLimit - pinnedSites.getCount());
+        return new TopSitesCursorWrapper(pinnedSites, topSites, minLimit);
     }
 
     public static void updateVisitedHistory(ContentResolver cr, String uri) {
         if (sAreContentProvidersEnabled) {
             sDb.updateVisitedHistory(cr, uri);
         }
     }
 
@@ -337,22 +337,22 @@ public class BrowserDB {
      * will return empty strings and zero.
      */
     public static class TopSitesCursorWrapper extends CursorWrapper {
         int mIndex = -1; // Current position of the cursor
         Cursor mCursor = null;
         int mSize = 0;
         private SparseArray<PinnedSite> mPinnedSites = null;
 
-        public TopSitesCursorWrapper(Cursor pinnedCursor, Cursor normalCursor, int size) {
+        public TopSitesCursorWrapper(Cursor pinnedCursor, Cursor normalCursor, int minSize) {
             super(normalCursor);
 
             setPinnedSites(pinnedCursor);
             mCursor = normalCursor;
-            mSize = size;
+            mSize = Math.max(minSize, mPinnedSites.size() + mCursor.getCount());
         }
 
         public void setPinnedSites(Cursor c) {
             mPinnedSites = new SparseArray<PinnedSite>();
 
             if (c == null) {
                 return;
             }