OSDN Git Service

Clear cached stitching preview thumbnails.
authorGeorge Mount <mount@google.com>
Thu, 11 Oct 2012 16:51:32 +0000 (09:51 -0700)
committerGeorge Mount <mount@google.com>
Thu, 11 Oct 2012 17:05:08 +0000 (10:05 -0700)
 Bug 7328408

Change-Id: Ifbc469dc9eef95025cd8e828a0df80e76d2ff064

gallerycommon/src/com/android/gallery3d/common/BlobCache.java
src/com/android/gallery3d/data/ImageCacheService.java

index 7788e61..3c131e5 100644 (file)
@@ -74,6 +74,7 @@ import java.io.RandomAccessFile;
 import java.nio.ByteOrder;
 import java.nio.MappedByteBuffer;
 import java.nio.channels.FileChannel;
+import java.util.Arrays;
 import java.util.zip.Adler32;
 
 public class BlobCache implements Closeable {
@@ -379,6 +380,16 @@ public class BlobCache implements Closeable {
         updateIndexHeader();
     }
 
+    public void clearEntry(long key) throws IOException {
+        if (!lookupInternal(key, mActiveHashStart)) {
+            return; // Nothing to clear
+        }
+        byte[] header = mBlobHeader;
+        Arrays.fill(header, (byte) 0);
+        mActiveDataFile.seek(mFileOffset);
+        mActiveDataFile.write(header);
+    }
+
     // Appends the data to the active file. It also updates the hash entry.
     // The proper hash entry (suitable for insertion or replacement) must be
     // pointed by mSlotOffset.
@@ -485,6 +496,9 @@ public class BlobCache implements Closeable {
                 return false;
             }
             long blobKey = readLong(header, BH_KEY);
+            if (blobKey == 0) {
+                return false; // This entry has been cleared.
+            }
             if (blobKey != req.key) {
                 Log.w(TAG, "blob key does not match: " + blobKey);
                 return false;
index 38e32cb..d42e952 100644 (file)
@@ -91,6 +91,18 @@ public class ImageCacheService {
         }
     }
 
+    public void clearImageData(Path path, int type) {
+        byte[] key = makeKey(path, type);
+        long cacheKey = Utils.crc64Long(key);
+        synchronized (mCache) {
+            try {
+                mCache.clearEntry(cacheKey);
+            } catch (IOException ex) {
+                // ignore.
+            }
+        }
+    }
+
     private static byte[] makeKey(Path path, int type) {
         return GalleryUtils.getBytes(path.toString() + "+" + type);
     }