From e4600fca519144d8d9b82a82fdfaabcc77182f40 Mon Sep 17 00:00:00 2001 From: George Mount Date: Wed, 1 May 2013 16:56:32 -0700 Subject: Allow prefetch for cache, reducing priority for prefetched images. Bug 8446191 Required for I86cfa59f448daa4e7b9fd7ea9ada2d69357e1f63 Change-Id: I7cccfffc539988d26fc751e16726b05fb2ba21bd --- src/com/android/photos/data/MediaCache.java | 30 ++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'src/com/android/photos/data/MediaCache.java') diff --git a/src/com/android/photos/data/MediaCache.java b/src/com/android/photos/data/MediaCache.java index 9cf69d643..0952a4017 100644 --- a/src/com/android/photos/data/MediaCache.java +++ b/src/com/android/photos/data/MediaCache.java @@ -107,6 +107,8 @@ public class MediaCache { void notifyReady(); void setFile(File file) throws FileNotFoundException; + + boolean isPrefetch(); } private static class NotifyOriginalReady implements NotifyReady { @@ -119,13 +121,20 @@ public class MediaCache { @Override public void notifyReady() { - mCallback.originalReady(mFile); + if (mCallback != null) { + mCallback.originalReady(mFile); + } } @Override public void setFile(File file) { mFile = file; } + + @Override + public boolean isPrefetch() { + return mCallback == null; + } } private static class NotifyImageReady implements NotifyReady { @@ -138,7 +147,9 @@ public class MediaCache { @Override public void notifyReady() { - mCallback.imageReady(mInputStream); + if (mCallback != null) { + mCallback.imageReady(mInputStream); + } } @Override @@ -149,6 +160,11 @@ public class MediaCache { public void setBytes(byte[] bytes) { mInputStream = new ByteArrayInputStream(bytes); } + + @Override + public boolean isPrefetch() { + return mCallback == null; + } } /** A media item to be retrieved and its notifications. */ @@ -496,7 +512,15 @@ public class MediaCache { } synchronized (tasks) { ProcessingJob job = new ProcessingJob(uri, size, complete, lowResolution); - tasks.add(job); + if (complete.isPrefetch()) { + tasks.add(job); + } else { + int index = tasks.size() - 1; + while (index >= 0 && tasks.get(index).complete.isPrefetch()) { + index--; + } + tasks.add(index + 1, job); + } tasks.notifyAll(); } } -- cgit v1.2.3