Bug 866150 - Revert TopSitesView cleaup changes from bug 865060. r=bnicholson
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Mon, 29 Apr 2013 17:18:26 -0700
changeset 141248 d44d0b5590b7f07f45ce2ea44b3da9c2116a1246
parent 141247 f3daae8f8041d194b88b2c54236618a694b04c07
child 141249 2d02910b859e77cd165b13179eda6e398e3bfb6f
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbnicholson
bugs866150, 865060
milestone23.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 866150 - Revert TopSitesView cleaup changes from bug 865060. r=bnicholson
mobile/android/base/widget/TopSitesView.java
--- a/mobile/android/base/widget/TopSitesView.java
+++ b/mobile/android/base/widget/TopSitesView.java
@@ -189,53 +189,56 @@ public class TopSitesView extends GridVi
         int w = getColumnWidth(measuredWidth);
         ThumbnailHelper.getInstance().setThumbnailWidth(w);
         heightMeasureSpec = MeasureSpec.makeMeasureSpec((int)(w*ThumbnailHelper.THUMBNAIL_ASPECT_RATIO*numRows) + getPaddingTop() + getPaddingBottom(),
                                                              MeasureSpec.EXACTLY);
         super.onMeasure(widthMeasureSpec, heightMeasureSpec);
     }
 
     public void loadTopSites() {
-        final ContentResolver resolver = mContext.getContentResolver();
-        final Cursor oldCursor = (mTopSitesAdapter != null) ? mTopSitesAdapter.getCursor() : null;
+        ThreadUtils.postToBackgroundThread(new Runnable() {
+            @Override
+            public void run() {
+                final ContentResolver resolver = mContext.getContentResolver();
 
-        new UiAsyncTask<Void, Void, Cursor>(ThreadUtils.getBackgroundHandler()) {
-            @Override
-            protected Cursor doInBackground(Void... params) {
-                return BrowserDB.getTopSites(resolver, mNumberOfTopSites);
-            }
+                // Swap in the new cursor.
+                final Cursor oldCursor = (mTopSitesAdapter != null) ? mTopSitesAdapter.getCursor() : null;
+                final Cursor newCursor = BrowserDB.getTopSites(resolver, mNumberOfTopSites);
 
-            @Override
-            protected void onPostExecute(Cursor newCursor) {
-                if (mTopSitesAdapter == null) {
-                    mTopSitesAdapter = new TopSitesCursorAdapter(mContext,
-                                                                 R.layout.abouthome_topsite_item,
-                                                                 newCursor,
-                                                                 new String[] { URLColumns.TITLE },
-                                                                 new int[] { R.id.title });
+                post(new Runnable() {
+                    @Override
+                    public void run() {
+                        if (mTopSitesAdapter == null) {
+                            mTopSitesAdapter = new TopSitesCursorAdapter(mContext,
+                                                                         R.layout.abouthome_topsite_item,
+                                                                         newCursor,
+                                                                         new String[] { URLColumns.TITLE },
+                                                                         new int[] { R.id.title });
 
-                    setAdapter(mTopSitesAdapter);
-                } else {
-                    mTopSitesAdapter.changeCursor(newCursor);
-                }
+                            setAdapter(mTopSitesAdapter);
+                        } else {
+                            mTopSitesAdapter.changeCursor(newCursor);
+                        }
 
-                if (mTopSitesAdapter.getCount() > 0)
-                    loadTopSitesThumbnails(resolver);
+                        if (mTopSitesAdapter.getCount() > 0)
+                            loadTopSitesThumbnails(resolver);
 
-                // Free the old Cursor in the right thread now.
-                if (oldCursor != null && !oldCursor.isClosed())
-                    oldCursor.close();
+                        // Free the old Cursor in the right thread now.
+                        if (oldCursor != null && !oldCursor.isClosed())
+                            oldCursor.close();
 
-                // Even if AboutHome isn't necessarily entirely loaded if we
-                // get here, for phones this is the part the user initially sees,
-                // so it's the one we will care about for now.
-                if (mLoadCompleteListener != null)
-                    mLoadCompleteListener.onAboutHomeLoadComplete();
+                        // Even if AboutHome isn't necessarily entirely loaded if we
+                        // get here, for phones this is the part the user initially sees,
+                        // so it's the one we will care about for now.
+                        if (mLoadCompleteListener != null)
+                            mLoadCompleteListener.onAboutHomeLoadComplete();
+                    }
+                });
             }
-        }.execute();
+        });
     }
 
     @Override
     protected void onLayout(boolean changed, int l, int t, int r, int b) {
         super.onLayout(changed, l, t, r, b);
 
         if (mPendingThumbnails != null) {
             updateTopSitesThumbnails(mPendingThumbnails);
@@ -323,33 +326,28 @@ public class TopSitesView extends GridVi
             if (c != null)
                 c.close();
         }
 
         return thumbnails;
     }
 
     private void loadTopSitesThumbnails(final ContentResolver cr) {
+        final List<String> urls = getTopSitesUrls();
+        if (urls.size() == 0)
+            return;
+
         (new UiAsyncTask<Void, Void, Map<String, Bitmap> >(ThreadUtils.getBackgroundHandler()) {
             @Override
             public Map<String, Bitmap> doInBackground(Void... params) {
-                final List<String> urls = getTopSitesUrls();
-                if (urls.size() == 0) {
-                    return null;
-                }
-
                 return getThumbnailsFromCursor(BrowserDB.getThumbnailsForUrls(cr, urls));
             }
 
             @Override
             public void onPostExecute(Map<String, Bitmap> thumbnails) {
-                if (thumbnails == null) {
-                    return;
-                }
-
                 // If we're waiting for a layout to happen, the GridView may be
                 // stale, so store the pending thumbnails here. They will be
                 // shown on the next layout pass.
                 if (isLayoutRequested()) {
                     mPendingThumbnails = thumbnails;
                 } else {
                     updateTopSitesThumbnails(thumbnails);
                 }