Bug 826639 - Force pending about:home updates to happen onDraw. r=lucasr
☠☠ backed out by 5bf175669197 ☠ ☠
authorWes Johnston <wjohnston@mozilla.com>
Tue, 02 Apr 2013 10:54:48 -0700
changeset 126963 6a57e0f94616f013e5c3b172f3866981293be588
parent 126962 505afb5e85712e0932339898c963ee5424c4c4e1
child 126964 57a3afad9252b02fefcd6f34bdd33d5d9b452812
push id25758
push userwjohnston@mozilla.com
push dateTue, 02 Apr 2013 17:55:29 +0000
treeherdermozilla-inbound@57a3afad9252 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslucasr
bugs826639
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 826639 - Force pending about:home updates to happen onDraw. r=lucasr
mobile/android/base/widget/AboutHomeContent.java
mobile/android/base/widget/TopSitesView.java
--- a/mobile/android/base/widget/AboutHomeContent.java
+++ b/mobile/android/base/widget/AboutHomeContent.java
@@ -9,16 +9,17 @@ import org.mozilla.gecko.BrowserApp;
 import org.mozilla.gecko.LightweightTheme;
 import org.mozilla.gecko.LightweightThemeDrawable;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.db.BrowserContract;
 import org.mozilla.gecko.util.ThreadUtils;
 
 import android.content.Context;
 import android.database.ContentObserver;
+import android.graphics.Canvas;
 import android.util.AttributeSet;
 import android.view.ContextMenu.ContextMenuInfo;
 import android.view.ContextMenu.ContextMenuInfo;
 import android.view.LayoutInflater;
 import android.widget.AdapterView.AdapterContextMenuInfo;
 import android.widget.ScrollView;
 import android.widget.Toast;
 
@@ -40,16 +41,17 @@ public class AboutHomeContent extends Sc
         REMOTE_TABS;
 
         public static final EnumSet<UpdateFlags> ALL = EnumSet.allOf(UpdateFlags.class);
     }
 
     private Context mContext;
     private BrowserApp mActivity;
     private UriLoadCallback mUriLoadCallback = null;
+    private EnumSet<UpdateFlags> mPendingUpdates = EnumSet.noneOf(UpdateFlags.class);
 
     private ContentObserver mTabsContentObserver = null;
 
     protected TopSitesView mTopSites;
     protected AddonsSection mAddons;
     protected LastTabsSection mLastTabs;
     protected RemoteTabsSection mRemoteTabs;
     private PromoBox mPromoBox;
@@ -150,29 +152,54 @@ public class AboutHomeContent extends Sc
         mTopSites.unpinSite(info, flags);
     }
 
     public void editSite(ContextMenuInfo info) {
         mTopSites.editSite(info);
     }
 
     public void update(final EnumSet<UpdateFlags> flags) {
-        ThreadUtils.postToBackgroundThread(new Runnable() {
+        synchronized (mPendingUpdates) {
+            for (UpdateFlags flag : flags) {
+                if (!mPendingUpdates.contains(flag))
+                    mPendingUpdates.add(flag);
+            }
+        }
+    }
+
+    @Override
+    protected void dispatchDraw(Canvas canvas) {
+        super.dispatchDraw(canvas);
+        // if any updates are pending, process them on a background thread
+        processPendingUpdates();
+    }
+
+    void processPendingUpdates() {
+        // during startup, this may be called before init()
+        final EnumSet<UpdateFlags> copiedUpdates;
+        synchronized (mPendingUpdates) {
+            if (mPendingUpdates.isEmpty())
+                return;
+            copiedUpdates = mPendingUpdates.clone();
+            mPendingUpdates = EnumSet.noneOf(UpdateFlags.class);
+        }
+
+        ThreadUtils.getBackgroundHandler().post(new Runnable() {
             @Override
             public void run() {
-                if (flags.contains(UpdateFlags.TOP_SITES))
+                if (copiedUpdates.contains(UpdateFlags.TOP_SITES))
                     loadTopSites();
 
-                if (flags.contains(UpdateFlags.PREVIOUS_TABS))
+                if (copiedUpdates.contains(UpdateFlags.PREVIOUS_TABS))
                     readLastTabs();
 
-                if (flags.contains(UpdateFlags.RECOMMENDED_ADDONS))
+                if (copiedUpdates.contains(UpdateFlags.RECOMMENDED_ADDONS))
                     readRecommendedAddons();
 
-                if (flags.contains(UpdateFlags.REMOTE_TABS))
+                if (copiedUpdates.contains(UpdateFlags.REMOTE_TABS))
                     loadRemoteTabs();
             }
         });
     }
 
     public void setUriLoadCallback(UriLoadCallback uriLoadCallback) {
         mUriLoadCallback = uriLoadCallback;
         mTopSites.setUriLoadCallback(uriLoadCallback);
--- a/mobile/android/base/widget/TopSitesView.java
+++ b/mobile/android/base/widget/TopSitesView.java
@@ -250,16 +250,17 @@ public class TopSitesView extends GridVi
         } else {
             try {
                 thumbnailView.setImageBitmap(thumbnail);
                 thumbnailView.setBackgroundColor(0x0);
                 thumbnailView.setScaleType(ImageView.ScaleType.CENTER_CROP);
             } catch (OutOfMemoryError oom) {
                 Log.e(LOGTAG, "Unable to load thumbnail bitmap", oom);
                 thumbnailView.setImageResource(R.drawable.abouthome_thumbnail_bg);
+                thumbnailView.setBackgroundColor(mThumbnailBackground);
                 thumbnailView.setScaleType(ImageView.ScaleType.FIT_CENTER);
             }
         }
     }
 
     private void updateTopSitesThumbnails(Map<String, Bitmap> thumbnails) {
         for (int i = 0; i < mTopSitesAdapter.getCount(); i++) {
             final View view = getChildAt(i);
@@ -269,16 +270,17 @@ public class TopSitesView extends GridVi
             if (view == null)
                 continue;
 
             TopSitesViewHolder holder = (TopSitesViewHolder)view.getTag();
             final String url = holder.getUrl();
             if (TextUtils.isEmpty(url)) {
                 holder.thumbnailView.setImageResource(R.drawable.abouthome_thumbnail_add);
                 holder.thumbnailView.setScaleType(ImageView.ScaleType.FIT_CENTER);
+                holder.thumbnailView.setBackgroundColor(mThumbnailBackground);
             } else {
                 displayThumbnail(view, thumbnails.get(url));
             }
         }
 
         invalidate();
     }