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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/media/ui/MediaImageManager.java

Issue 2627103002: [MediaNotification] Avoid fetching image twice when artwork doesn't change (Closed)
Patch Set: fixed tests Created 3 years, 11 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 | « no previous file | chrome/android/junit/src/org/chromium/chrome/browser/media/ui/MediaImageManagerTest.java » ('j') | 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/media/ui/MediaImageManager.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/media/ui/MediaImageManager.java b/chrome/android/java/src/org/chromium/chrome/browser/media/ui/MediaImageManager.java
index e6af620aa71ea21d04c7892823e9617ce266c55a..bd45b9dde658b006261f38ce568c931b2cea27c9 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/media/ui/MediaImageManager.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/media/ui/MediaImageManager.java
@@ -77,6 +77,12 @@ public class MediaImageManager implements ImageDownloadCallback {
// The callback to be called when the pending download image request completes.
private MediaImageCallback mCallback;
+ // The last image src for download, used for avoiding fetching the same src when artwork is set
+ // multiple times but the same src is chosen.
+ //
+ // Will be reset when initiating a new download request, and set to |null| when download failed.
+ private String mLastImageSrc;
+
/**
* MediaImageManager constructor.
* @param minimumSize The minimum size of images to download.
@@ -128,11 +134,14 @@ public class MediaImageManager implements ImageDownloadCallback {
mCallback = callback;
MediaImage image = selectImage(images);
if (image == null) {
- mCallback.onImageDownloaded(null);
- clearRequests();
+ onDownloadFailed();
return;
}
+ // Avoid fetching the same image twice.
+ if (TextUtils.equals(image.getSrc(), mLastImageSrc)) return;
+ mLastImageSrc = image.getSrc();
+
// Limit |maxBitmapSize| to |MAX_BITMAP_SIZE_FOR_DOWNLOAD| to avoid passing huge bitmaps
// through JNI. |maxBitmapSize| does not prevent huge images to be downloaded. It is used to
// filter/rescale the download images. See documentation of
@@ -169,8 +178,12 @@ public class MediaImageManager implements ImageDownloadCallback {
bestScore = newScore;
}
}
- mCallback.onImageDownloaded(bestBitmap);
- clearRequests();
+ if (bestBitmap != null) {
+ mCallback.onImageDownloaded(bestBitmap);
+ clearRequests();
+ } else {
+ onDownloadFailed();
+ }
}
/**
@@ -197,6 +210,12 @@ public class MediaImageManager implements ImageDownloadCallback {
mCallback = null;
}
+ private void onDownloadFailed() {
+ mLastImageSrc = null;
+ mCallback.onImageDownloaded(null);
+ clearRequests();
+ }
+
private double getImageScore(MediaImage image) {
if (image == null) return 0;
if (image.getSizes().isEmpty()) return DEFAULT_IMAGE_SIZE_SCORE;
« no previous file with comments | « no previous file | chrome/android/junit/src/org/chromium/chrome/browser/media/ui/MediaImageManagerTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698