Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3755)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/physicalweb/PwsClient.java

Issue 1427663004: Use BitmapHttpRequest to fetch favicon for Nearby URLs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: wip (taking changes from dfalcantara,dvh) Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/physicalweb/NearbyUrlsAdapter.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/physicalweb/PwsClient.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/PwsClient.java b/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/PwsClient.java
index ff15a2c410bbcf93dcc87ffef509f4556dfddd2b..5e661ea50c285335b6ff932ebf51dbbb93f17b31 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/PwsClient.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/PwsClient.java
@@ -4,6 +4,7 @@
package org.chromium.chrome.browser.physicalweb;
+import android.graphics.Bitmap;
import android.os.AsyncTask;
import org.chromium.base.Log;
@@ -35,6 +36,18 @@ class PwsClient {
public void onPwsResults(Collection<PwsResult> pwsResults);
}
+ /**
+ * Callback that is run after receiving the response to an icon fetch request.
+ */
+ public interface FetchIconCallback {
+ /**
+ * Handle newly returned favicon Bitmaps.
+ * @param iconUrl The favicon URL.
+ * @param iconBitmap The icon image data.
+ */
+ public void onIconReceived(String iconUrl, Bitmap iconBitmap);
+ }
+
private static JSONObject createResolveScanPayload(Collection<String> urls)
throws JSONException {
// Encode the urls.
@@ -90,12 +103,14 @@ class PwsClient {
// Create the response callback.
JsonObjectHttpRequest.RequestCallback requestCallback =
new JsonObjectHttpRequest.RequestCallback() {
+ @Override
public void onResponse(JSONObject result) {
ThreadUtils.assertOnUiThread();
Collection<PwsResult> pwsResults = parseResolveScanResponse(result);
resolveScanCallback.onPwsResults(pwsResults);
}
+ @Override
public void onError(int responseCode, Exception e) {
ThreadUtils.assertOnUiThread();
String httpErr = "";
@@ -122,4 +137,42 @@ class PwsClient {
// The callback will be called on the main thread.
AsyncTask.THREAD_POOL_EXECUTOR.execute(request);
}
+
+ /**
+ * Send an HTTP request to fetch a favicon.
+ * @param iconUrl The URL of the favicon.
+ * @param fetchIconCallback The callback to be run when the icon is received.
+ */
+ public void fetchIcon(final String iconUrl,
+ final FetchIconCallback fetchIconCallback) {
+ // Create the response callback.
+ BitmapHttpRequest.RequestCallback requestCallback =
+ new BitmapHttpRequest.RequestCallback() {
+ @Override
+ public void onResponse(Bitmap iconBitmap) {
+ fetchIconCallback.onIconReceived(iconUrl, iconBitmap);
+ }
+
+ @Override
+ public void onError(int responseCode, Exception e) {
+ ThreadUtils.assertOnUiThread();
+ String httpErr = "";
+ if (responseCode > 0) {
+ httpErr = ", HTTP " + responseCode;
+ }
+ Log.e(TAG, "Error requesting icon%s", httpErr, e);
+ }
+ };
+
+ // Create the request.
+ BitmapHttpRequest request = null;
+ try {
+ request = new BitmapHttpRequest(iconUrl, requestCallback);
+ } catch (MalformedURLException e) {
+ Log.e(TAG, "Error creating icon request", e);
+ return;
+ }
+ // The callback will be called on the main thread.
+ AsyncTask.THREAD_POOL_EXECUTOR.execute(request);
+ }
}
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/physicalweb/NearbyUrlsAdapter.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698