diff options
author | Grace Kloba <klobag@google.com> | 2010-02-15 02:15:37 -0800 |
---|---|---|
committer | Grace Kloba <klobag@google.com> | 2010-03-01 10:36:15 -0800 |
commit | 2036dbab1726c34953360a7a56d6b9ef1f2aa7dd (patch) | |
tree | 73037324cfbc6eb5baa32e46b05d9d37af44063f /core/java/android/webkit/WebViewDatabase.java | |
parent | b4e193991f9efc74978c004bcd9463cc5e85250c (diff) | |
download | frameworks_base-2036dbab1726c34953360a7a56d6b9ef1f2aa7dd.zip frameworks_base-2036dbab1726c34953360a7a56d6b9ef1f2aa7dd.tar.gz frameworks_base-2036dbab1726c34953360a7a56d6b9ef1f2aa7dd.tar.bz2 |
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
Diffstat (limited to 'core/java/android/webkit/WebViewDatabase.java')
-rw-r--r-- | core/java/android/webkit/WebViewDatabase.java | 40 |
1 files changed, 38 insertions, 2 deletions
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<String> trimCache(long amount) { + List<String> trimCache(long amount) { ArrayList<String> pathList = new ArrayList<String>(100); Cursor cursor = mCacheDatabase.rawQuery( "SELECT contentlength, filepath FROM cache ORDER BY expires ASC", @@ -727,6 +749,20 @@ public class WebViewDatabase { return pathList; } + List<String> getAllCacheFileNames() { + ArrayList<String> pathList = null; + Cursor cursor = mCacheDatabase.rawQuery("SELECT filepath FROM cache", + null); + if (cursor != null && cursor.moveToFirst()) { + pathList = new ArrayList<String>(cursor.getCount()); + do { + pathList.add(cursor.getString(0)); + } while (cursor.moveToNext()); + } + cursor.close(); + return pathList; + } + // // password functions // |