diff options
author | Leon Scroggins <scroggo@google.com> | 2010-04-23 13:12:43 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2010-04-23 13:12:43 -0700 |
commit | c04c7eb145d89c9b0060160bf28a8eccf55ee502 (patch) | |
tree | 79dff7d9ee7546f1f2e0edc407d0a1cff3c9fbed | |
parent | bd931f25e786c112552f1bf119d8accdc9fac6ff (diff) | |
parent | c8393d9cfa47e3f5f279b17c412fd363e7ea94bd (diff) | |
download | packages_apps_Browser-c04c7eb145d89c9b0060160bf28a8eccf55ee502.zip packages_apps_Browser-c04c7eb145d89c9b0060160bf28a8eccf55ee502.tar.gz packages_apps_Browser-c04c7eb145d89c9b0060160bf28a8eccf55ee502.tar.bz2 |
am c8393d9c: Move queryBookmarksForUrl to background thread.
-rw-r--r-- | src/com/android/browser/AddBookmarkPage.java | 5 | ||||
-rw-r--r-- | src/com/android/browser/DownloadTouchIcon.java | 64 | ||||
-rw-r--r-- | src/com/android/browser/Tab.java | 31 |
3 files changed, 44 insertions, 56 deletions
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<String, Void, Void> { 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<String, Void, Void> { @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); } } |