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); |
+ } |
+} |