From c8393d9cfa47e3f5f279b17c412fd363e7ea94bd Mon Sep 17 00:00:00 2001 From: Leon Scroggins Date: Fri, 23 Apr 2010 14:58:16 -0400 Subject: Move queryBookmarksForUrl to background thread. Bug 2611964 Change-Id: I8f69ec42fbf880d031cfc2372cffd9719db4e280 --- src/com/android/browser/AddBookmarkPage.java | 5 +- src/com/android/browser/DownloadTouchIcon.java | 64 +++++++++++++------------- src/com/android/browser/Tab.java | 31 ++++--------- 3 files changed, 44 insertions(+), 56 deletions(-) (limited to 'src/com/android') diff --git a/src/com/android/browser/AddBookmarkPage.java b/src/com/android/browser/AddBookmarkPage.java index 6a6fb3b..1104d5e 100644 --- a/src/com/android/browser/AddBookmarkPage.java +++ b/src/com/android/browser/AddBookmarkPage.java @@ -135,10 +135,7 @@ public class AddBookmarkPage extends Activity { final ContentResolver cr = getContentResolver(); Bookmarks.addBookmark(null, cr, url, title, thumbnail, true); if (touchIconUrl != null) { - final Cursor c - = BrowserBookmarksAdapter.queryBookmarksForUrl(cr, - null, url, true); - new DownloadTouchIcon(cr, c, url).execute(mTouchIconUrl); + new DownloadTouchIcon(cr, url).execute(mTouchIconUrl); } mMessage.arg1 = 1; } catch (IllegalStateException e) { diff --git a/src/com/android/browser/DownloadTouchIcon.java b/src/com/android/browser/DownloadTouchIcon.java index c8701ba..b5369ae 100644 --- a/src/com/android/browser/DownloadTouchIcon.java +++ b/src/com/android/browser/DownloadTouchIcon.java @@ -39,26 +39,24 @@ import java.io.InputStream; class DownloadTouchIcon extends AsyncTask { private final ContentResolver mContentResolver; - private final Cursor mCursor; + private Cursor mCursor; private final String mOriginalUrl; private final String mUrl; private final String mUserAgent; /* package */ Tab mTab; - public DownloadTouchIcon(Tab tab, ContentResolver cr, Cursor c, WebView view) { + public DownloadTouchIcon(Tab tab, ContentResolver cr, WebView view) { mTab = tab; mContentResolver = cr; - mCursor = c; // Store these in case they change. mOriginalUrl = view.getOriginalUrl(); mUrl = view.getUrl(); mUserAgent = view.getSettings().getUserAgentString(); } - public DownloadTouchIcon(ContentResolver cr, Cursor c, String url) { + public DownloadTouchIcon(ContentResolver cr, String url) { mTab = null; mContentResolver = cr; - mCursor = c; mOriginalUrl = null; mUrl = url; mUserAgent = null; @@ -66,35 +64,39 @@ class DownloadTouchIcon extends AsyncTask { @Override public Void doInBackground(String... values) { - String url = values[0]; - - AndroidHttpClient client = AndroidHttpClient.newInstance( - mUserAgent); - HttpGet request = new HttpGet(url); - - // Follow redirects - HttpClientParams.setRedirecting(client.getParams(), true); - - try { - HttpResponse response = client.execute(request); - - if (response.getStatusLine().getStatusCode() == 200) { - HttpEntity entity = response.getEntity(); - if (entity != null) { - InputStream content = entity.getContent(); - if (content != null) { - Bitmap icon = BitmapFactory.decodeStream( - content, null, null); - storeIcon(icon); + mCursor = BrowserBookmarksAdapter.queryBookmarksForUrl(mContentResolver, + mOriginalUrl, mUrl, true); + if (mCursor != null && mCursor.getCount() > 0) { + String url = values[0]; + + AndroidHttpClient client = AndroidHttpClient.newInstance( + mUserAgent); + HttpGet request = new HttpGet(url); + + // Follow redirects + HttpClientParams.setRedirecting(client.getParams(), true); + + try { + HttpResponse response = client.execute(request); + + if (response.getStatusLine().getStatusCode() == 200) { + HttpEntity entity = response.getEntity(); + if (entity != null) { + InputStream content = entity.getContent(); + if (content != null) { + Bitmap icon = BitmapFactory.decodeStream( + content, null, null); + storeIcon(icon); + } } } + } catch (IllegalArgumentException ex) { + request.abort(); + } catch (IOException ex) { + request.abort(); + } finally { + client.close(); } - } catch (IllegalArgumentException ex) { - request.abort(); - } catch (IOException ex) { - request.abort(); - } finally { - client.close(); } if (mCursor != null) { mCursor.close(); diff --git a/src/com/android/browser/Tab.java b/src/com/android/browser/Tab.java index 01424e2..2dac050 100644 --- a/src/com/android/browser/Tab.java +++ b/src/com/android/browser/Tab.java @@ -1012,27 +1012,16 @@ class Tab { public void onReceivedTouchIconUrl(WebView view, String url, boolean precomposed) { final ContentResolver cr = mActivity.getContentResolver(); - final Cursor c = BrowserBookmarksAdapter.queryBookmarksForUrl(cr, - view.getOriginalUrl(), view.getUrl(), true); - if (c != null) { - if (c.getCount() > 0) { - // Let precomposed icons take precedence over non-composed - // icons. - if (precomposed && mTouchIconLoader != null) { - mTouchIconLoader.cancel(false); - mTouchIconLoader = null; - } - // Have only one async task at a time. - if (mTouchIconLoader == null) { - mTouchIconLoader = new DownloadTouchIcon(Tab.this, cr, - c, view); - mTouchIconLoader.execute(url); - } else { - c.close(); - } - } else { - c.close(); - } + // Let precomposed icons take precedence over non-composed + // icons. + if (precomposed && mTouchIconLoader != null) { + mTouchIconLoader.cancel(false); + mTouchIconLoader = null; + } + // Have only one async task at a time. + if (mTouchIconLoader == null) { + mTouchIconLoader = new DownloadTouchIcon(Tab.this, cr, view); + mTouchIconLoader.execute(url); } } -- cgit v1.1