Bug 892500/905286 - Use FaviconsLoader in LastTabsPage (r=sriram)
authorLucas Rocha <lucasr@mozilla.com>
Sat, 17 Aug 2013 01:47:42 +0100
changeset 143554 061fed4327f86bec7a2542a4bdb1a18e65054878
parent 143553 d423d46e50a9056ce058f99e6e356d40a3b676f5
child 143555 45ed1f18184f947c0ed5c174ee9dcbc5949c8ffb
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)
reviewerssriram
bugs892500, 905286
milestone26.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 892500/905286 - Use FaviconsLoader in LastTabsPage (r=sriram)
mobile/android/base/home/LastTabsPage.java
--- a/mobile/android/base/home/LastTabsPage.java
+++ b/mobile/android/base/home/LastTabsPage.java
@@ -14,16 +14,17 @@ import org.mozilla.gecko.home.HomePager.
 
 import android.app.Activity;
 import android.content.ContentResolver;
 import android.content.Context;
 import android.database.Cursor;
 import android.database.MatrixCursor;
 import android.database.MatrixCursor.RowBuilder;
 import android.os.Bundle;
+import android.support.v4.app.LoaderManager;
 import android.support.v4.app.LoaderManager.LoaderCallbacks;
 import android.support.v4.content.Loader;
 import android.support.v4.widget.CursorAdapter;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewStub;
 import android.view.ViewGroup;
 import android.widget.AdapterView;
@@ -135,22 +136,24 @@ public class LastTabsPage extends HomeFr
         mEmptyView = null;
         mRestoreButton = null;
     }
 
     @Override
     public void onActivityCreated(Bundle savedInstanceState) {
         super.onActivityCreated(savedInstanceState);
 
+        final Activity activity = getActivity();
+
         // Intialize adapter
-        mAdapter = new LastTabsAdapter(getActivity());
+        mAdapter = new LastTabsAdapter(activity);
         mList.setAdapter(mAdapter);
 
         // Create callbacks before the initial loader is started
-        mCursorLoaderCallbacks = new CursorLoaderCallbacks();
+        mCursorLoaderCallbacks = new CursorLoaderCallbacks(activity, getLoaderManager());
         loadIfVisible();
     }
 
     private void updateUiFromCursor(Cursor c) {
         if (c != null && c.getCount() > 0) {
             if (mTitle != null) {
                 mTitle.setVisibility(View.VISIBLE);
             }
@@ -212,18 +215,17 @@ public class LastTabsPage extends HomeFr
             final String jsonString = GeckoProfile.get(context).readSessionFile(true);
             if (jsonString == null) {
                 // No previous session data
                 return null;
             }
 
             final MatrixCursor c = new MatrixCursor(new String[] { Combined._ID,
                                                                    Combined.URL,
-                                                                   Combined.TITLE,
-                                                                   Combined.FAVICON });
+                                                                   Combined.TITLE });
 
             new SessionParser() {
                 @Override
                 public void onTabRead(SessionTab tab) {
                     final String url = tab.getUrl();
 
                     // Don't show last tabs for about:home
                     if (url.equals("about:home")) {
@@ -231,20 +233,16 @@ public class LastTabsPage extends HomeFr
                     }
 
                     final RowBuilder row = c.newRow();
                     row.add(-1);
                     row.add(url);
 
                     final String title = tab.getTitle();
                     row.add(title);
-
-                    final ContentResolver cr = context.getContentResolver();
-                    final byte[] favicon = BrowserDB.getFaviconBytesForUrl(cr, url);
-                    row.add(favicon);
                 }
             }.parse(jsonString);
 
             return c;
         }
     }
 
     private static class LastTabsAdapter extends CursorAdapter {
@@ -258,26 +256,48 @@ public class LastTabsPage extends HomeFr
         }
 
         @Override
         public View newView(Context context, Cursor cursor, ViewGroup parent) {
             return LayoutInflater.from(context).inflate(R.layout.home_item_row, parent, false);
         }
     }
 
-    private class CursorLoaderCallbacks implements LoaderCallbacks<Cursor> {
+    private class CursorLoaderCallbacks extends HomeCursorLoaderCallbacks {
+        public CursorLoaderCallbacks(Context context, LoaderManager loaderManager) {
+            super(context, loaderManager);
+        }
+
         @Override
         public Loader<Cursor> onCreateLoader(int id, Bundle args) {
-            return new LastTabsCursorLoader(getActivity());
+            if (id == LOADER_ID_LAST_TABS) {
+                return new LastTabsCursorLoader(getActivity());
+            } else {
+                return super.onCreateLoader(id, args);
+            }
         }
 
         @Override
         public void onLoadFinished(Loader<Cursor> loader, Cursor c) {
-            mAdapter.swapCursor(c);
-            updateUiFromCursor(c);
+            if (loader.getId() == LOADER_ID_LAST_TABS) {
+                mAdapter.swapCursor(c);
+                updateUiFromCursor(c);
+                loadFavicons(c);
+            } else {
+                super.onLoadFinished(loader, c);
+            }
         }
 
         @Override
         public void onLoaderReset(Loader<Cursor> loader) {
-            mAdapter.swapCursor(null);
+            if (loader.getId() == LOADER_ID_LAST_TABS) {
+                mAdapter.swapCursor(null);
+            } else {
+                super.onLoaderReset(loader);
+            }
+        }
+
+        @Override
+        public void onFaviconsLoaded() {
+            mAdapter.notifyDataSetChanged();
         }
     }
 }