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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/photo_picker/BitmapScalerWorkerTask.java

Issue 2845773003: Photo Picker Dialog: Add caching for the decoded images. (Closed)
Patch Set: Address feedback from Theresa 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/photo_picker/BitmapUtils.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser.photo_picker;
6
7 import android.graphics.Bitmap;
8 import android.os.AsyncTask;
9 import android.util.LruCache;
10
11 import org.chromium.base.ThreadUtils;
12
13 /**
14 * A worker task to enumerate image files on disk.
15 */
16 class BitmapScalerWorkerTask extends AsyncTask<Void, Void, Bitmap> {
Michael van Ouwerkerk 2017/05/08 13:14:48 nit: BitmapScalerTask seems cleaner.
17 private final LruCache<String, Bitmap> mCache;
18 private final Bitmap mBitmap;
19 private final String mFilePath;
20 private final int mSize;
21
22 /**
23 * A BitmapScalerWorkerTask constructor.
24 */
25 public BitmapScalerWorkerTask(
26 LruCache<String, Bitmap> cache, String filePath, Bitmap bitmap, int size) {
27 mCache = cache;
28 mBitmap = bitmap;
Michael van Ouwerkerk 2017/05/08 13:14:48 nit: you could make this the execution input param
29 mFilePath = filePath;
30 mSize = size;
31 }
32
33 /**
34 * Enumerates (in the background) the image files on disk. Called on a non-U I thread
35 * @param params Ignored, do not use.
36 * @return A sorted list of images (by last-modified first).
37 */
38 @Override
39 protected Bitmap doInBackground(Void... params) {
40 assert !ThreadUtils.runningOnUiThread();
41
42 if (isCancelled()) return null;
43
44 return BitmapUtils.scale(mBitmap, mSize, false);
45 }
46
47 /**
48 * Communicates the results back to the client. Called on the UI thread.
49 * @param result The resulting scaled bitmap
50 */
51 @Override
52 protected void onPostExecute(Bitmap result) {
53 if (isCancelled()) {
54 return;
55 }
56
57 mCache.put(mFilePath, result);
58 }
59 }
OLDNEW
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/photo_picker/BitmapUtils.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698