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

Commit 473e017c authored by Steve Block's avatar Steve Block Committed by Android Git Automerger
Browse files

am 808751fe: Avoid superfluous calls to CacheManager with the Chromium HTTP stack

* commit '808751fe':
  Avoid superfluous calls to CacheManager with the Chromium HTTP stack
parents 5b5e46bd 808751fe
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -488,8 +488,10 @@ class BrowserFrame extends Handler {
                        }
                    }
                }
                if (!JniUtil.useChromiumHttpStack()) {
                    WebViewWorker.getHandler().sendEmptyMessage(
                            WebViewWorker.MSG_TRIM_CACHE);
                }
                break;
            }

+4 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.webkit;

import android.net.http.Headers;
import android.text.TextUtils;
import android.webkit.JniUtil;

/**
 * This class is a concrete implementation of StreamLoader that uses a
@@ -36,6 +37,9 @@ class CacheLoader extends StreamLoader {
     */
    CacheLoader(LoadListener loadListener, CacheManager.CacheResult result) {
        super(loadListener);

        assert !JniUtil.useChromiumHttpStack();

        mCacheResult = result;
    }

+50 −1
Original line number Diff line number Diff line
@@ -190,6 +190,11 @@ public final class CacheManager {
     * @param context The application context.
     */
    static void init(Context context) {
        if (JniUtil.useChromiumHttpStack()) {
            // TODO: Need to init mBaseDir.
            return;
        }

        mDataBase = WebViewDatabase.getInstance(context.getApplicationContext());
        mBaseDir = new File(context.getCacheDir(), "webviewCache");
        if (createCacheDirectory() && mClearCacheOnInit) {
@@ -204,6 +209,8 @@ public final class CacheManager {
     * @return true if the cache directory didn't exist and was created.
     */
    static private boolean createCacheDirectory() {
        assert !JniUtil.useChromiumHttpStack();

        if (!mBaseDir.exists()) {
            if(!mBaseDir.mkdirs()) {
                Log.w(LOGTAG, "Unable to create webviewCache directory");
@@ -245,6 +252,8 @@ public final class CacheManager {
     * @param disabled Whether the cache should be disabled
     */
    static void setCacheDisabled(boolean disabled) {
        assert !JniUtil.useChromiumHttpStack();

        if (disabled == mDisabled) {
            return;
        }
@@ -269,6 +278,8 @@ public final class CacheManager {
    // only called from WebViewWorkerThread
    // make sure to call enableTransaction/disableTransaction in pair
    static boolean enableTransaction() {
        assert !JniUtil.useChromiumHttpStack();

        if (++mRefCount == 1) {
            mDataBase.startCacheTransaction();
            return true;
@@ -279,6 +290,8 @@ public final class CacheManager {
    // only called from WebViewWorkerThread
    // make sure to call enableTransaction/disableTransaction in pair
    static boolean disableTransaction() {
        assert !JniUtil.useChromiumHttpStack();

        if (--mRefCount == 0) {
            mDataBase.endCacheTransaction();
            return true;
@@ -289,12 +302,16 @@ public final class CacheManager {
    // only called from WebViewWorkerThread
    // make sure to call startTransaction/endTransaction in pair
    static boolean startTransaction() {
        assert !JniUtil.useChromiumHttpStack();

        return mDataBase.startCacheTransaction();
    }

    // only called from WebViewWorkerThread
    // make sure to call startTransaction/endTransaction in pair
    static boolean endTransaction() {
        assert !JniUtil.useChromiumHttpStack();

        boolean ret = mDataBase.endCacheTransaction();
        if (++mTrimCacheCount >= TRIM_CACHE_INTERVAL) {
            mTrimCacheCount = 0;
@@ -347,8 +364,12 @@ public final class CacheManager {
            return null;
        }

        String databaseKey = getDatabaseKey(url, postIdentifier);
        if (JniUtil.useChromiumHttpStack()) {
            // TODO: Implement this.
            return null;
        }

        String databaseKey = getDatabaseKey(url, postIdentifier);
        CacheResult result = mDataBase.getCache(databaseKey);
        if (result == null) {
            return null;
@@ -415,6 +436,11 @@ public final class CacheManager {
    @Deprecated
    public static CacheResult createCacheFile(String url, int statusCode,
            Headers headers, String mimeType, boolean forceCache) {
        if (JniUtil.useChromiumHttpStack()) {
            // TODO: Implement this.
            return null;
        }

        return createCacheFile(url, statusCode, headers, mimeType, 0,
                forceCache);
    }
@@ -422,6 +448,8 @@ public final class CacheManager {
    static CacheResult createCacheFile(String url, int statusCode,
            Headers headers, String mimeType, long postIdentifier,
            boolean forceCache) {
        assert !JniUtil.useChromiumHttpStack();

        if (!forceCache && mDisabled) {
            return null;
        }
@@ -493,6 +521,11 @@ public final class CacheManager {
            return;
        }

        if (JniUtil.useChromiumHttpStack()) {
            // TODO: Implement this.
            return;
        }

        if (!cacheRet.outFile.exists()) {
            // the file in the cache directory can be removed by the system
            return;
@@ -520,6 +553,8 @@ public final class CacheManager {
    }

    static boolean cleanupCacheFile(CacheResult cacheRet) {
        assert !JniUtil.useChromiumHttpStack();

        try {
            cacheRet.outStream.close();
        } catch (IOException e) {
@@ -534,6 +569,8 @@ public final class CacheManager {
     * @return Whether the removal succeeded.
     */
    static boolean removeAllCacheFiles() {
        assert !JniUtil.useChromiumHttpStack();

        // Note, this is called before init() when the database is
        // created or upgraded.
        if (mBaseDir == null) {
@@ -570,6 +607,8 @@ public final class CacheManager {
    }

    static void trimCacheIfNeeded() {
        assert !JniUtil.useChromiumHttpStack();

        if (mDataBase.getCacheTotalSize() > CACHE_THRESHOLD) {
            List<String> pathList = mDataBase.trimCache(CACHE_TRIM_AMOUNT);
            int size = pathList.size();
@@ -603,6 +642,8 @@ public final class CacheManager {
    }

    static void clearCache() {
        assert !JniUtil.useChromiumHttpStack();

        // delete database
        mDataBase.clearCache();
    }
@@ -617,12 +658,16 @@ public final class CacheManager {
    }

    private static String getDatabaseKey(String url, long postIdentifier) {
        assert !JniUtil.useChromiumHttpStack();

        if (postIdentifier == 0) return url;
        return postIdentifier + url;
    }

    @SuppressWarnings("deprecation")
    private static void setupFiles(String url, CacheResult cacheRet) {
        assert !JniUtil.useChromiumHttpStack();

        if (true) {
            // Note: SHA1 is much stronger hash. But the cost of setupFiles() is
            // 3.2% cpu time for a fresh load of nytimes.com. While a simple
@@ -689,6 +734,8 @@ public final class CacheManager {
    }

    private static void appendAsHex(int i, StringBuffer ret) {
        assert !JniUtil.useChromiumHttpStack();

        String hex = Integer.toHexString(i);
        switch (hex.length()) {
            case 1:
@@ -718,6 +765,8 @@ public final class CacheManager {

    private static CacheResult parseHeaders(int statusCode, Headers headers,
            String mimeType) {
        assert !JniUtil.useChromiumHttpStack();

        // if the contentLength is already larger than CACHE_MAX_SIZE, skip it
        if (headers.getContentLength() > CACHE_MAX_SIZE) return null;

+6 −2
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.net.http.RequestHandle;
import android.os.Build;
import android.util.Log;
import android.webkit.CacheManager.CacheResult;
import android.webkit.JniUtil;

import java.util.HashMap;
import java.util.Map;
@@ -56,6 +57,8 @@ class FrameLoader {
    
    FrameLoader(LoadListener listener, WebSettings settings,
            String method, WebResourceResponse interceptResponse) {
        assert !JniUtil.useChromiumHttpStack();

        mListener = listener;
        mHeaders = null;
        mMethod = method;
@@ -148,9 +151,10 @@ class FrameLoader {

    }

    /* package */
    static boolean handleLocalFile(String url, LoadListener loadListener,
    private static boolean handleLocalFile(String url, LoadListener loadListener,
            WebSettings settings) {
        assert !JniUtil.useChromiumHttpStack();

        // Attempt to decode the percent-encoded url before passing to the
        // local loaders.
        try {
+4 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.webkit.CacheManager.CacheResult;
import android.webkit.JniUtil;

import com.android.internal.R;

@@ -156,6 +157,8 @@ class LoadListener extends Handler implements EventHandler {
            int nativeLoader, boolean synchronous, boolean isMainPageLoader,
            boolean isMainResource, boolean userGesture, long postIdentifier,
            String username, String password) {
        assert !JniUtil.useChromiumHttpStack();

        if (DebugFlags.LOAD_LISTENER) {
            Log.v(LOGTAG, "LoadListener constructor url=" + url);
        }
@@ -991,6 +994,7 @@ class LoadListener extends Handler implements EventHandler {
     * URL.
     */
    static boolean willLoadFromCache(String url, long identifier) {
        assert !JniUtil.useChromiumHttpStack();
        boolean inCache =
                CacheManager.getCacheFile(url, identifier, null) != null;
        if (DebugFlags.LOAD_LISTENER) {
Loading