Bug 823550 - Ensure saving favicons to DB happens on the GeckoBackgroundThread r=kats
authorMark Finkle <mfinkle@mozilla.com>
Sat, 22 Dec 2012 00:27:41 -0500
changeset 125972 be3375d887c61a36826efcd642a1f72597864368
parent 125959 77d65b2c81c809d3f0342181ea3baf2693b0a576
child 125973 948ae77e36d6f12e65b46037636349e26ceeb38a
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats
bugs823550
milestone20.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 823550 - Ensure saving favicons to DB happens on the GeckoBackgroundThread r=kats
mobile/android/base/Favicons.java
--- a/mobile/android/base/Favicons.java
+++ b/mobile/android/base/Favicons.java
@@ -1,16 +1,17 @@
 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko;
 
 import org.mozilla.gecko.db.BrowserDB;
+import org.mozilla.gecko.util.GeckoBackgroundThread;
 import org.mozilla.gecko.util.GeckoJarReader;
 
 import org.apache.http.HttpEntity;
 import org.apache.http.client.methods.HttpGet;
 import org.apache.http.entity.BufferedHttpEntity;
 
 import android.content.ContentResolver;
 import android.content.ContentValues;
@@ -200,27 +201,30 @@ public class Favicons {
 
         // Runs in background thread
         private Bitmap loadFaviconFromDb() {
             ContentResolver resolver = mContext.getContentResolver();
             return BrowserDB.getFaviconForUrl(resolver, mPageUrl);
         }
 
         // Runs in background thread
-        private void saveFaviconToDb(Bitmap favicon) {
+        private void saveFaviconToDb(final Bitmap favicon) {
             if (!mPersist) {
                 return;
             }
 
-            // since the Async task can run this on any number of threads in the
-            // pool, we need to protect against inserting the same url twice
-            synchronized(Favicons.this) {
-                ContentResolver resolver = mContext.getContentResolver();
-                BrowserDB.updateFaviconForUrl(resolver, mPageUrl, favicon, mFaviconUrl);
-            }
+            // Even though this code is in a background thread, all DB writes
+            // should happen in GeckoBackgroundThread or we could get locked
+            // databases.
+            GeckoBackgroundThread.post(new Runnable() {
+                public void run() {
+                    ContentResolver resolver = mContext.getContentResolver();
+                    BrowserDB.updateFaviconForUrl(resolver, mPageUrl, favicon, mFaviconUrl);
+                }
+            });
         }
 
         // Runs in background thread
         private Bitmap downloadFavicon(URL faviconUrl) {
             if (mFaviconUrl.startsWith("jar:jar:")) {
                 BitmapDrawable d = GeckoJarReader.getBitmapDrawable(mContext.getResources(), mFaviconUrl);
                 return d.getBitmap();
             }