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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/photo_picker/BitmapScalerTask.java

Issue 2845773003: Photo Picker Dialog: Add caching for the decoded images. (Closed)
Patch Set: Remove dead var Created 3 years, 7 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
Index: chrome/android/java/src/org/chromium/chrome/browser/photo_picker/BitmapScalerTask.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/photo_picker/BitmapScalerTask.java b/chrome/android/java/src/org/chromium/chrome/browser/photo_picker/BitmapScalerTask.java
new file mode 100644
index 0000000000000000000000000000000000000000..2fe1519b7ed13a67aada401222b331fed38885c6
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/photo_picker/BitmapScalerTask.java
@@ -0,0 +1,56 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser.photo_picker;
+
+import android.graphics.Bitmap;
+import android.os.AsyncTask;
+import android.util.LruCache;
+
+import org.chromium.base.ThreadUtils;
+
+/**
+ * A worker task to scale bitmaps in the background.
+ */
+class BitmapScalerTask extends AsyncTask<Bitmap, Void, Bitmap> {
+ private final LruCache<String, Bitmap> mCache;
+ private final String mFilePath;
+ private final int mSize;
+
+ /**
+ * A BitmapScalerTask constructor.
+ */
+ public BitmapScalerTask(LruCache<String, Bitmap> cache, String filePath, int size) {
+ mCache = cache;
+ mFilePath = filePath;
+ mSize = size;
+ }
+
+ /**
+ * Scales the image provided. Called on a non-UI thread.
+ * @param params Ignored, do not use.
+ * @return A sorted list of images (by last-modified first).
+ */
+ @Override
+ protected Bitmap doInBackground(Bitmap... bitmaps) {
+ assert !ThreadUtils.runningOnUiThread();
+
+ if (isCancelled()) return null;
+
+ return BitmapUtils.scale(bitmaps[0], mSize, false);
+ }
+
+ /**
+ * Communicates the results back to the client. Called on the UI thread.
+ * @param result The resulting scaled bitmap.
+ */
+ @Override
+ protected void onPostExecute(Bitmap result) {
+ if (isCancelled()) {
+ return;
+ }
+
+ mCache.put(mFilePath, result);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698