Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c70cf9af authored by Grace Kloba's avatar Grace Kloba Committed by Android Git Automerger
Browse files

am 9002eb44: am 67166b6e: Merge "Cleanup the cache file when we decide not...

am 9002eb44: am 67166b6e: Merge "Cleanup the cache file when we decide not saving it. This logic was lost when we switched back using FLASH instead of RAM for the cache." into eclair-mr2

Merge commit '9002eb44'

* commit '9002eb44':
  Cleanup the cache file when we decide not saving it.
parents 3bf657a2 9002eb44
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -56,6 +56,9 @@ public final class CacheManager {
    private static long CACHE_THRESHOLD = 6 * 1024 * 1024;
    private static long CACHE_TRIM_AMOUNT = 2 * 1024 * 1024;

    // Limit the maximum cache file size to half of the normal capacity
    static long CACHE_MAX_SIZE = (CACHE_THRESHOLD - CACHE_TRIM_AMOUNT) / 2;

    private static boolean mDisabled;

    // Reference count the enable/disable transaction
@@ -448,7 +451,6 @@ public final class CacheManager {
            return;
        }

        cacheRet.contentLength = cacheRet.outFile.length();
        boolean redirect = checkCacheRedirect(cacheRet.httpStatusCode);
        if (redirect) {
            // location is in database, no need to keep the file
@@ -470,6 +472,15 @@ public final class CacheManager {
        }
    }

    static boolean cleanupCacheFile(CacheResult cacheRet) {
        try {
            cacheRet.outStream.close();
        } catch (IOException e) {
            return false;
        }
        return cacheRet.outFile.delete();
    }

    /**
     * remove all cache files
     * 
@@ -644,6 +655,9 @@ public final class CacheManager {

    private static CacheResult parseHeaders(int statusCode, Headers headers,
            String mimeType) {
        // if the contentLength is already larger than CACHE_MAX_SIZE, skip it
        if (headers.getContentLength() > CACHE_MAX_SIZE) return null;

        // TODO: if authenticated or secure, return null
        CacheResult ret = new CacheResult();
        ret.httpStatusCode = statusCode;
+24 −6
Original line number Diff line number Diff line
@@ -936,7 +936,10 @@ class LoadListener extends Handler implements EventHandler {
    void downloadFile() {
        // Setting the Cache Result to null ensures that this
        // content is not added to the cache
        if (mCacheResult != null) {
            CacheManager.cleanupCacheFile(mCacheResult);
            mCacheResult = null;
        }

        // Inform the client that they should download a file
        mBrowserFrame.getCallbackProxy().onDownloadStart(url(), 
@@ -1096,12 +1099,20 @@ class LoadListener extends Handler implements EventHandler {

            if (c.mLength != 0) {
                if (mCacheResult != null) {
                    mCacheResult.contentLength += c.mLength;
                    if (mCacheResult.contentLength > CacheManager.CACHE_MAX_SIZE) {
                        CacheManager.cleanupCacheFile(mCacheResult);
                        mCacheResult = null;
                    } else {
                        try {
                        mCacheResult.outStream.write(c.mArray, 0, c.mLength);
                            mCacheResult.outStream
                                    .write(c.mArray, 0, c.mLength);
                        } catch (IOException e) {
                            CacheManager.cleanupCacheFile(mCacheResult);
                            mCacheResult = null;
                        }
                    }
                }
                nativeAddData(c.mArray, c.mLength);
            }
            c.release();
@@ -1117,6 +1128,8 @@ class LoadListener extends Handler implements EventHandler {
        if (mCacheResult != null) {
            if (getErrorID() == OK) {
                CacheManager.saveCacheFile(mUrl, mPostIdentifier, mCacheResult);
            } else {
                CacheManager.cleanupCacheFile(mCacheResult);
            }

            // we need to reset mCacheResult to be null
@@ -1181,7 +1194,10 @@ class LoadListener extends Handler implements EventHandler {
            mRequestHandle = null;
        }

        if (mCacheResult != null) {
            CacheManager.cleanupCacheFile(mCacheResult);
            mCacheResult = null;
        }
        mCancelled = true;

        clearNativeLoader();
@@ -1246,6 +1262,8 @@ class LoadListener extends Handler implements EventHandler {
                if (getErrorID() == OK) {
                    CacheManager.saveCacheFile(mUrl, mPostIdentifier,
                            mCacheResult);
                } else {
                    CacheManager.cleanupCacheFile(mCacheResult);
                }
                mCacheResult = null;
            }