From 2036dbab1726c34953360a7a56d6b9ef1f2aa7dd Mon Sep 17 00:00:00 2001 From: Grace Kloba Date: Mon, 15 Feb 2010 02:15:37 -0800 Subject: Add a new WebCoreWorker thread to handle the tasks which should not block either UI or WebKit. It handles local file access, cache access and trim cache. Move createCache, saveCache and most of getCache out of WebCore thread so that slow IO and database will not affect loading performance. getCache can be still called from WebCore thread in the uncommon cases like redirect and POST validation. Move cache ticker from WebCore thread to WebViewWorkerThread. Move setCookie from WebCore thread to WebViewWorkerThread. Remove the unreferenced files in the cache directory while trim cache. Confirmed with our SQL expert, Vasu, there is no need to wrap clearCache with end/startTransaction any more. http://b/issue?id=2414792 http://b/issue?id=2475242 --- core/java/android/webkit/WebViewDatabase.java | 40 +++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) (limited to 'core/java/android/webkit/WebViewDatabase.java') diff --git a/core/java/android/webkit/WebViewDatabase.java b/core/java/android/webkit/WebViewDatabase.java index 110e4f8..a870931 100644 --- a/core/java/android/webkit/WebViewDatabase.java +++ b/core/java/android/webkit/WebViewDatabase.java @@ -19,6 +19,7 @@ package android.webkit; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; +import java.util.List; import java.util.Set; import java.util.Map.Entry; @@ -234,6 +235,13 @@ public class WebViewDatabase { } if (mCacheDatabase != null) { + // use read_uncommitted to speed up READ + mCacheDatabase.execSQL("PRAGMA read_uncommitted = true;"); + // as only READ can be called in the non-WebViewWorkerThread, + // and read_uncommitted is used, we can turn off database lock + // to use transaction. + mCacheDatabase.setLockingEnabled(false); + // use InsertHelper for faster insertion mCacheInserter = new DatabaseUtils.InsertHelper(mCacheDatabase, "cache"); @@ -548,19 +556,33 @@ public class WebViewDatabase { } // - // cache functions, can only be called from WebCoreThread + // cache functions // + // only called from WebViewWorkerThread boolean startCacheTransaction() { if (++mCacheTransactionRefcount == 1) { + if (!Thread.currentThread().equals( + WebViewWorker.getHandler().getLooper().getThread())) { + Log.w(LOGTAG, "startCacheTransaction should be called from " + + "WebViewWorkerThread instead of from " + + Thread.currentThread().getName()); + } mCacheDatabase.beginTransaction(); return true; } return false; } + // only called from WebViewWorkerThread boolean endCacheTransaction() { if (--mCacheTransactionRefcount == 0) { + if (!Thread.currentThread().equals( + WebViewWorker.getHandler().getLooper().getThread())) { + Log.w(LOGTAG, "endCacheTransaction should be called from " + + "WebViewWorkerThread instead of from " + + Thread.currentThread().getName()); + } try { mCacheDatabase.setTransactionSuccessful(); } finally { @@ -684,7 +706,7 @@ public class WebViewDatabase { return size; } - ArrayList trimCache(long amount) { + List trimCache(long amount) { ArrayList pathList = new ArrayList(100); Cursor cursor = mCacheDatabase.rawQuery( "SELECT contentlength, filepath FROM cache ORDER BY expires ASC", @@ -727,6 +749,20 @@ public class WebViewDatabase { return pathList; } + List getAllCacheFileNames() { + ArrayList pathList = null; + Cursor cursor = mCacheDatabase.rawQuery("SELECT filepath FROM cache", + null); + if (cursor != null && cursor.moveToFirst()) { + pathList = new ArrayList(cursor.getCount()); + do { + pathList.add(cursor.getString(0)); + } while (cursor.moveToNext()); + } + cursor.close(); + return pathList; + } + // // password functions // -- cgit v1.1