Bug 898276: HistoryPage should use FaviconsLoader. [r=lucasr]
authorSriram Ramasubramanian <sriram@mozilla.com>
Fri, 26 Jul 2013 14:55:20 -0700
changeset 143465 008632d5460705de6ae26aa47db503e732758735
parent 143464 6b0ef2ef3b953eedb8ff84f0b0dfda7038ab68c7
child 143466 c183395271416d3b96ebcded68fac6c31f9dc3a8
push id25130
push userlrocha@mozilla.com
push dateWed, 21 Aug 2013 09:41:27 +0000
treeherdermozilla-central@b2486721572e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslucasr
bugs898276
milestone25.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 898276: HistoryPage should use FaviconsLoader. [r=lucasr]
mobile/android/base/db/LocalBrowserDB.java
mobile/android/base/home/MostRecentPage.java
--- a/mobile/android/base/db/LocalBrowserDB.java
+++ b/mobile/android/base/db/LocalBrowserDB.java
@@ -322,17 +322,16 @@ public class LocalBrowserDB implements B
     @Override
     public Cursor getRecentHistory(ContentResolver cr, int limit) {
         Cursor c = cr.query(combinedUriWithLimit(limit),
                             new String[] { Combined._ID,
                                            Combined.BOOKMARK_ID,
                                            Combined.HISTORY_ID,
                                            Combined.URL,
                                            Combined.TITLE,
-                                           Combined.FAVICON,
                                            Combined.DISPLAY,
                                            Combined.DATE_LAST_VISITED,
                                            Combined.VISITS },
                             History.DATE_LAST_VISITED + " > 0",
                             null,
                             History.DATE_LAST_VISITED + " DESC");
 
         return new LocalDBCursor(c);
--- a/mobile/android/base/home/MostRecentPage.java
+++ b/mobile/android/base/home/MostRecentPage.java
@@ -35,16 +35,19 @@ import java.util.Date;
  */
 public class MostRecentPage extends HomeFragment {
     // Logging tag name
     private static final String LOGTAG = "GeckoMostRecentPage";
 
     // Cursor loader ID for history query
     private static final int HISTORY_LOADER_ID = 0;
 
+    // Cursor loader ID for favicons query
+    private static final int FAVICONS_LOADER_ID = 1;
+
     // For the time sections in history
     private static final long MS_PER_DAY = 86400000;
     private static final long MS_PER_WEEK = MS_PER_DAY * 7;
 
     // The time ranges for each section
     private static enum MostRecentSection {
         TODAY,
         YESTERDAY,
@@ -343,23 +346,53 @@ public class MostRecentPage extends Home
                 return row;
             }
         }
     }
 
     private class CursorLoaderCallbacks implements LoaderCallbacks<Cursor> {
         @Override
         public Loader<Cursor> onCreateLoader(int id, Bundle args) {
-            return new MostRecentCursorLoader(getActivity());
+            switch(id) {
+                case HISTORY_LOADER_ID:
+                    return new MostRecentCursorLoader(getActivity());
+            
+                case FAVICONS_LOADER_ID:
+                    return FaviconsLoader.createInstance(getActivity(), args);
+            }
+
+            return null;
         }
 
         @Override
         public void onLoadFinished(Loader<Cursor> loader, Cursor c) {
-            loadMostRecentSections(c);
-            mAdapter.swapCursor(c);
+            final int loaderId = loader.getId();
+            switch(loaderId) {
+                case HISTORY_LOADER_ID:
+                    loadMostRecentSections(c);
+                    mAdapter.swapCursor(c);
+                    FaviconsLoader.restartFromCursor(getLoaderManager(), FAVICONS_LOADER_ID,
+                            mCursorLoaderCallbacks, c);
+                    break;
+            
+                case FAVICONS_LOADER_ID:
+                    // Causes the listview to recreate its children and use the
+                    // now in-memory favicons.
+                    mAdapter.notifyDataSetChanged();
+                    break;
+            }
         }
 
         @Override
         public void onLoaderReset(Loader<Cursor> loader) {
-            mAdapter.swapCursor(null);
+            final int loaderId = loader.getId();
+            switch(loaderId) {
+                case HISTORY_LOADER_ID:
+                    mAdapter.swapCursor(null);
+                    break;
+
+                case FAVICONS_LOADER_ID:
+                    // Do nothing
+                    break;
+            }
         }
     }
 }