diff options
author | Patrick Scott <phanna@android.com> | 2010-04-09 12:42:03 -0400 |
---|---|---|
committer | Patrick Scott <phanna@android.com> | 2010-04-12 14:26:13 -0400 |
commit | 36acfbc2b8df6e62f2d583933eca3a49265279a6 (patch) | |
tree | a738ff2f76c549c050394efe9b2b3e2462758d1a /core/java/android/webkit/WebIconDatabase.java | |
parent | 1d7a8b448e9371685894b6b02d29bcd3ae959545 (diff) | |
download | frameworks_base-36acfbc2b8df6e62f2d583933eca3a49265279a6.zip frameworks_base-36acfbc2b8df6e62f2d583933eca3a49265279a6.tar.gz frameworks_base-36acfbc2b8df6e62f2d583933eca3a49265279a6.tar.bz2 |
Add a bulk request method for bookmark icons.
Rather than dispatch a message for every url in the db, send a message to the
WebCoreThread to handle the query and iteration. Update the documentation for
requestAllIcons.
Bug: 2581894
Change-Id: I8af4f87570465dff3839db4ac492883e8805b007
Diffstat (limited to 'core/java/android/webkit/WebIconDatabase.java')
-rw-r--r-- | core/java/android/webkit/WebIconDatabase.java | 81 |
1 files changed, 74 insertions, 7 deletions
diff --git a/core/java/android/webkit/WebIconDatabase.java b/core/java/android/webkit/WebIconDatabase.java index 6cc6bb4..bb9ec48 100644 --- a/core/java/android/webkit/WebIconDatabase.java +++ b/core/java/android/webkit/WebIconDatabase.java @@ -16,10 +16,15 @@ package android.webkit; +import android.content.ContentResolver; +import android.database.Cursor; +import android.graphics.Bitmap; import android.os.Handler; import android.os.Message; -import android.graphics.Bitmap; +import android.provider.Browser; +import android.util.Log; +import java.util.HashMap; import java.util.Vector; /** @@ -30,6 +35,7 @@ import java.util.Vector; * single object. */ public final class WebIconDatabase { + private static final String LOGTAG = "WebIconDatabase"; // Global instance of a WebIconDatabase private static WebIconDatabase sIconDatabase; // EventHandler for handling messages before and after the WebCore thread is @@ -45,6 +51,7 @@ public final class WebIconDatabase { static final int REQUEST_ICON = 3; static final int RETAIN_ICON = 4; static final int RELEASE_ICON = 5; + static final int BULK_REQUEST_ICON = 6; // Message for dispatching icon request results private static final int ICON_RESULT = 10; // Actual handler that runs in WebCore thread @@ -100,12 +107,11 @@ public final class WebIconDatabase { case REQUEST_ICON: IconListener l = (IconListener) msg.obj; String url = msg.getData().getString("url"); - Bitmap icon = nativeIconForPageUrl(url); - if (icon != null) { - EventHandler.this.sendMessage( - Message.obtain(null, ICON_RESULT, - new IconResult(url, icon, l))); - } + requestIconAndSendResult(url, l); + break; + + case BULK_REQUEST_ICON: + bulkRequestIcons(msg); break; case RETAIN_ICON: @@ -126,6 +132,10 @@ public final class WebIconDatabase { } } + private synchronized boolean hasHandler() { + return mHandler != null; + } + private synchronized void postMessage(Message msg) { if (mMessages != null) { mMessages.add(msg); @@ -133,6 +143,39 @@ public final class WebIconDatabase { mHandler.sendMessage(msg); } } + + private void bulkRequestIcons(Message msg) { + HashMap map = (HashMap) msg.obj; + IconListener listener = (IconListener) map.get("listener"); + ContentResolver cr = (ContentResolver) map.get("contentResolver"); + String where = (String) map.get("where"); + + Cursor c = null; + try { + c = cr.query( + Browser.BOOKMARKS_URI, + new String[] { Browser.BookmarkColumns.URL }, + where, null, null); + if (c.moveToFirst()) { + do { + String url = c.getString(0); + requestIconAndSendResult(url, listener); + } while (c.moveToNext()); + } + } catch (IllegalStateException e) { + Log.e(LOGTAG, "BulkRequestIcons", e); + } finally { + if (c != null) c.close(); + } + } + + private void requestIconAndSendResult(String url, IconListener listener) { + Bitmap icon = nativeIconForPageUrl(url); + if (icon != null) { + sendMessage(obtainMessage(ICON_RESULT, + new IconResult(url, icon, listener))); + } + } } /** @@ -192,6 +235,30 @@ public final class WebIconDatabase { mEventHandler.postMessage(msg); } + /** {@hide} + */ + public void bulkRequestIconForPageUrl(ContentResolver cr, String where, + IconListener listener) { + if (listener == null) { + return; + } + + // Special case situation: we don't want to add this message to the + // queue if there is no handler because we may never have a real + // handler to service the messages and the cursor will never get + // closed. + if (mEventHandler.hasHandler()) { + // Don't use Bundle as it is parcelable. + HashMap<String, Object> map = new HashMap<String, Object>(); + map.put("contentResolver", cr); + map.put("where", where); + map.put("listener", listener); + Message msg = + Message.obtain(null, EventHandler.BULK_REQUEST_ICON, map); + mEventHandler.postMessage(msg); + } + } + /** * Retain the icon for the given page url. * @param url The page's url. |