Bug 919645 - crash in android.os.NetworkOnMainThreadException. r=bnicholson, a=lsblakk
authorRichard Newman <rnewman@mozilla.com>
Mon, 07 Oct 2013 12:54:41 -0700
changeset 160671 2a1d0c72e8649cab23073365ad38d241c733e307
parent 160670 b7f30d84fa9f64dee9786a5762d178d1c3c9155f
child 160672 7c4e44bb22344a5e0f6e3a7572c35288d495f75d
push id2961
push userlsblakk@mozilla.com
push dateMon, 28 Oct 2013 21:59:28 +0000
treeherdermozilla-beta@73ef4f13486f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbnicholson, lsblakk
bugs919645
milestone26.0a2
Bug 919645 - crash in android.os.NetworkOnMainThreadException. r=bnicholson, a=lsblakk
mobile/android/base/favicons/LoadFaviconTask.java
--- a/mobile/android/base/favicons/LoadFaviconTask.java
+++ b/mobile/android/base/favicons/LoadFaviconTask.java
@@ -13,16 +13,17 @@ import android.util.Log;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpResponse;
 import org.apache.http.client.methods.HttpGet;
 import org.apache.http.entity.BufferedHttpEntity;
 import org.mozilla.gecko.GeckoAppShell;
 import org.mozilla.gecko.db.BrowserDB;
 import org.mozilla.gecko.gfx.BitmapUtils;
 import org.mozilla.gecko.util.GeckoJarReader;
+import org.mozilla.gecko.util.ThreadUtils;
 import org.mozilla.gecko.util.UiAsyncTask;
 import static org.mozilla.gecko.favicons.Favicons.sContext;
 
 import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
@@ -207,13 +208,26 @@ public class LoadFaviconTask extends UiA
         // favicon load is cancelled.
     }
 
     int getId() {
         return mId;
     }
 
     static void closeHTTPClient() {
-        if (sHttpClient != null) {
-            sHttpClient.close();
+        // This work must be done on a background thread because it shuts down
+        // the connection pool, which typically involves closing a connection --
+        // which counts as network activity.
+        if (ThreadUtils.isOnBackgroundThread()) {
+            if (sHttpClient != null) {
+                sHttpClient.close();
+            }
+            return;
         }
+
+        ThreadUtils.postToBackgroundThread(new Runnable() {
+            @Override
+            public void run() {
+                LoadFaviconTask.closeHTTPClient();
+            }
+        });
     }
 }