diff options
-rw-r--r-- | WebKit/Android.mk | 1 | ||||
-rw-r--r-- | WebKit/android/WebCoreSupport/ChromiumIncludes.h | 2 | ||||
-rw-r--r-- | WebKit/android/WebCoreSupport/WebCache.cpp | 100 | ||||
-rw-r--r-- | WebKit/android/WebCoreSupport/WebCache.h | 54 | ||||
-rw-r--r-- | WebKit/android/jni/WebCoreFrameBridge.cpp | 44 |
5 files changed, 187 insertions, 14 deletions
diff --git a/WebKit/Android.mk b/WebKit/Android.mk index 8de7989..8b15740 100644 --- a/WebKit/Android.mk +++ b/WebKit/Android.mk @@ -32,6 +32,7 @@ LOCAL_SRC_FILES := \ ifeq ($(HTTP_STACK),chrome) LOCAL_SRC_FILES := $(LOCAL_SRC_FILES) \ + android/WebCoreSupport/WebCache.cpp \ android/WebCoreSupport/WebUrlLoader.cpp \ android/WebCoreSupport/WebUrlLoaderClient.cpp \ android/WebCoreSupport/WebRequest.cpp \ diff --git a/WebKit/android/WebCoreSupport/ChromiumIncludes.h b/WebKit/android/WebCoreSupport/ChromiumIncludes.h index 635c4da..dce6d52 100644 --- a/WebKit/android/WebCoreSupport/ChromiumIncludes.h +++ b/WebKit/android/WebCoreSupport/ChromiumIncludes.h @@ -58,8 +58,10 @@ #include <net/base/cookie_monster.h> #include <net/base/data_url.h> #include <net/base/io_buffer.h> +#include <net/base/net_errors.h> #include <net/base/mime_util.h> #include <net/base/ssl_config_service.h> +#include <net/disk_cache/disk_cache.h> #include <net/http/http_auth_handler_factory.h> #include <net/http/http_cache.h> #include <net/http/http_network_layer.h> diff --git a/WebKit/android/WebCoreSupport/WebCache.cpp b/WebKit/android/WebCoreSupport/WebCache.cpp new file mode 100644 index 0000000..006bb74 --- /dev/null +++ b/WebKit/android/WebCoreSupport/WebCache.cpp @@ -0,0 +1,100 @@ +/* + * Copyright 2010, The Android Open Source Project + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "WebCache.h" +#include "WebRequestContext.h" +#include "WebUrlLoaderClient.h" + +namespace android { + +WebCache* WebCache::s_instance = 0; + +void WebCache::clear() +{ + base::Thread* thread = WebUrlLoaderClient::ioThread(); + if (thread) + thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(getInstance(), &WebCache::doClear)); +} + +WebCache::WebCache() + : m_doomAllEntriesCallback(this, &WebCache::doomAllEntries) + , m_doneCallback(this, &WebCache::done) + , m_isClearInProgress(false) +{ +} + +WebCache* WebCache::getInstance() +{ + if (!s_instance) { + s_instance = new WebCache(); + s_instance->AddRef(); + } + return s_instance; +} + +void WebCache::doClear() +{ + if (m_isClearInProgress) + return; + m_isClearInProgress = true; + URLRequestContext* context = WebRequestContext::GetAndroidContext(); + net::HttpTransactionFactory* factory = context->http_transaction_factory(); + int code = factory->GetCache()->GetBackend(&m_cacheBackend, &m_doomAllEntriesCallback); + // Code ERR_IO_PENDING indicates that the operation is still in progress and + // the supplied callback will be invoked when it completes. + if (code == net::ERR_IO_PENDING) + return; + else if (code != OK) { + m_isClearInProgress = false; + return; + } + doomAllEntries(0 /*unused*/); +} + +void WebCache::doomAllEntries(int) +{ + if (!m_cacheBackend) { + m_isClearInProgress = false; + return; + } + + int code = m_cacheBackend->DoomAllEntries(&m_doneCallback); + // Code ERR_IO_PENDING indicates that the operation is still in progress and + // the supplied callback will be invoked when it completes. + if (code == net::ERR_IO_PENDING) + return; + else if (code != OK) { + m_isClearInProgress = false; + return; + } + done(0 /*unused*/); +} + +void WebCache::done(int) +{ + m_isClearInProgress = false; +} + +} // namespace android diff --git a/WebKit/android/WebCoreSupport/WebCache.h b/WebKit/android/WebCoreSupport/WebCache.h new file mode 100644 index 0000000..9fd980f --- /dev/null +++ b/WebKit/android/WebCoreSupport/WebCache.h @@ -0,0 +1,54 @@ +/* + * Copyright 2010, The Android Open Source Project + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WebCache_h +#define WebCache_h + +#include "ChromiumIncludes.h" + +namespace android { + +class WebCache : public base::RefCountedThreadSafe<WebCache> { +public: + static void clear(); + +private: + WebCache(); + static WebCache* getInstance(); + + void doClear(); + void doomAllEntries(int); + void done(int); + + static WebCache* s_instance; + net::CompletionCallbackImpl<WebCache> m_doomAllEntriesCallback; + net::CompletionCallbackImpl<WebCache> m_doneCallback; + disk_cache::Backend* m_cacheBackend; + bool m_isClearInProgress; +}; + +} // namespace android + +#endif diff --git a/WebKit/android/jni/WebCoreFrameBridge.cpp b/WebKit/android/jni/WebCoreFrameBridge.cpp index d89f965..f1de0c9 100644 --- a/WebKit/android/jni/WebCoreFrameBridge.cpp +++ b/WebKit/android/jni/WebCoreFrameBridge.cpp @@ -78,6 +78,7 @@ #include "StringBuilder.h" #include "SubstituteData.h" #include "UserGestureIndicator.h" +#include "WebCache.h" #include "WebCoreJni.h" #include "WebCoreResourceLoader.h" #include "WebHistory.h" @@ -1552,19 +1553,8 @@ static jboolean CacheDisabled(JNIEnv *env, jobject obj) return WebCore::cache()->disabled(); } -static void ClearCache(JNIEnv *env, jobject obj) +static void ClearWebCoreCache() { -#ifdef ANDROID_INSTRUMENT - TimeCounterAuto counter(TimeCounter::NativeCallbackTimeCounter); -#if USE(JSC) - JSC::JSLock lock(false); - JSC::Heap::Statistics jsHeapStatistics = WebCore::JSDOMWindow::commonJSGlobalData()->heap.statistics(); - LOGD("About to gc and JavaScript heap size is %d and has %d bytes free", - jsHeapStatistics.size, jsHeapStatistics.free); -#endif // USE(JSC) - LOGD("About to clear cache and current cache has %d bytes live and %d bytes dead", - cache()->getLiveSize(), cache()->getDeadSize()); -#endif // ANDROID_INSTRUMENT if (!WebCore::cache()->disabled()) { // Disabling the cache will remove all resources from the cache. They may // still live on if they are referenced by some Web page though. @@ -1578,13 +1568,39 @@ static void ClearCache(JNIEnv *env, jobject obj) WebCore::pageCache()->setCapacity(0); WebCore::pageCache()->releaseAutoreleasedPagesNow(); WebCore::pageCache()->setCapacity(pageCapacity); +} + +static void ClearWebViewCache() +{ +#if USE(CHROME_NETWORK_STACK) + WebCache::clear(); +#else + // The Android network stack provides a WebView cache in CacheManager.java. + // Clearing this is handled entirely Java-side. +#endif +} -#if USE(JSC) +static void ClearCache(JNIEnv *env, jobject obj) +{ +#ifdef ANDROID_INSTRUMENT + TimeCounterAuto counter(TimeCounter::NativeCallbackTimeCounter); +#if USE(JSC) + JSC::JSLock lock(false); + JSC::Heap::Statistics jsHeapStatistics = WebCore::JSDOMWindow::commonJSGlobalData()->heap.statistics(); + LOGD("About to gc and JavaScript heap size is %d and has %d bytes free", + jsHeapStatistics.size, jsHeapStatistics.free); +#endif // USE(JSC) + LOGD("About to clear cache and current cache has %d bytes live and %d bytes dead", + cache()->getLiveSize(), cache()->getDeadSize()); +#endif // ANDROID_INSTRUMENT + ClearWebCoreCache(); + ClearWebViewCache(); +#if USE(JSC) // force JavaScript to GC when clear cache WebCore::gcController().garbageCollectSoon(); #elif USE(V8) WebCore::Frame* pFrame = GET_NATIVE_FRAME(env, obj); - pFrame->script()->lowMemoryNotification(); + pFrame->script()->lowMemoryNotification(); #endif // USE(JSC) } |