summaryrefslogtreecommitdiffstats
path: root/WebKit/android
diff options
context:
space:
mode:
Diffstat (limited to 'WebKit/android')
-rw-r--r--WebKit/android/WebCoreSupport/WebCache.cpp95
-rw-r--r--WebKit/android/WebCoreSupport/WebCache.h22
-rw-r--r--WebKit/android/WebCoreSupport/WebRequestContext.cpp47
-rw-r--r--WebKit/android/jni/WebCoreFrameBridge.cpp2
4 files changed, 99 insertions, 67 deletions
diff --git a/WebKit/android/WebCoreSupport/WebCache.cpp b/WebKit/android/WebCoreSupport/WebCache.cpp
index b0ae915..9bc148c 100644
--- a/WebKit/android/WebCoreSupport/WebCache.cpp
+++ b/WebKit/android/WebCoreSupport/WebCache.cpp
@@ -23,37 +23,95 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include "config.h"
#include "WebCache.h"
+
+#include "JNIUtility.h"
+#include "WebCoreJni.h"
#include "WebRequestContext.h"
#include "WebUrlLoaderClient.h"
+using namespace WTF;
using namespace net;
namespace android {
-WebCache* WebCache::s_instance = 0;
+static const std::string& rootDirectory()
+{
+ // This method may be called on any thread, as the Java method is
+ // synchronized.
+ static WTF::Mutex mutex;
+ MutexLocker lock(mutex);
+ static std::string cacheDirectory;
+ if (cacheDirectory.empty()) {
+ JNIEnv* env = JSC::Bindings::getJNIEnv();
+ jclass bridgeClass = env->FindClass("android/webkit/JniUtil");
+ jmethodID method = env->GetStaticMethodID(bridgeClass, "getCacheDirectory", "()Ljava/lang/String;");
+ cacheDirectory = jstringToStdString(env, static_cast<jstring>(env->CallStaticObjectMethod(bridgeClass, method)));
+ env->DeleteLocalRef(bridgeClass);
+ }
+ return cacheDirectory;
+}
-void WebCache::clear()
+WebCache* WebCache::get(bool isPrivateBrowsing)
{
- base::Thread* thread = WebUrlLoaderClient::ioThread();
- if (thread)
- thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(getInstance(), &WebCache::doClear));
+ static const char* const kDirectory = "/webviewCacheChromium";
+ static const char* const kDirectoryPrivate = "/webviewCacheChromiumPrivate";
+
+ static WebCache* regularCache = 0;
+ static WebCache* privateCache = 0;
+
+ if (isPrivateBrowsing) {
+ if (!privateCache) {
+ std::string storageDirectory = rootDirectory();
+ storageDirectory.append(kDirectoryPrivate);
+ privateCache = new WebCache(storageDirectory);
+ }
+ return privateCache;
+ }
+
+ if (!regularCache) {
+ std::string storageDirectory = rootDirectory();
+ storageDirectory.append(kDirectory);
+ regularCache = new WebCache(storageDirectory);
+ }
+ return regularCache;
}
-WebCache::WebCache()
- : m_doomAllEntriesCallback(this, &WebCache::doomAllEntries)
- , m_doneCallback(this, &WebCache::done)
+WebCache::WebCache(const std::string& storageDirectory)
+ : m_storageDirectory(storageDirectory)
+ , m_doomAllEntriesCallback(this, &WebCache::doomAllEntries)
+ , m_doneCallback(this, &WebCache::onClearDone)
, m_isClearInProgress(false)
{
+ base::Thread* ioThread = WebUrlLoaderClient::ioThread();
+ scoped_refptr<base::MessageLoopProxy> cacheMessageLoopProxy = ioThread->message_loop_proxy();
+
+ static const int kMaximumCacheSizeBytes = 20 * 1024 * 1024;
+ FilePath directoryPath(m_storageDirectory.c_str());
+ net::HttpCache::DefaultBackend* backendFactory = new net::HttpCache::DefaultBackend(net::DISK_CACHE, directoryPath, kMaximumCacheSizeBytes, cacheMessageLoopProxy);
+
+ m_hostResolver = net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism, 0, 0);
+ m_cache = new net::HttpCache(m_hostResolver.get(),
+ 0, // dnsrr_resolver
+ net::ProxyService::CreateDirect(),
+ net::SSLConfigService::CreateSystemSSLConfigService(),
+ net::HttpAuthHandlerFactory::CreateDefault(m_hostResolver.get()),
+ 0, // network_delegate
+ 0, // net_log
+ backendFactory);
}
-WebCache* WebCache::getInstance()
+void WebCache::clear()
{
- if (!s_instance) {
- s_instance = new WebCache();
- s_instance->AddRef();
- }
- return s_instance;
+ base::Thread* thread = WebUrlLoaderClient::ioThread();
+ if (thread)
+ thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(this, &WebCache::doClear));
+}
+
+void WebCache::cleanupFiles()
+{
+ WebRequestContext::removeFileOrDirectory(m_storageDirectory.c_str());
}
void WebCache::doClear()
@@ -61,9 +119,8 @@ void WebCache::doClear()
if (m_isClearInProgress)
return;
m_isClearInProgress = true;
- URLRequestContext* context = WebRequestContext::get(false /* isPrivateBrowsing */);
- HttpTransactionFactory* factory = context->http_transaction_factory();
- int code = factory->GetCache()->GetBackend(&m_cacheBackend, &m_doomAllEntriesCallback);
+
+ int code = m_cache->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 == ERR_IO_PENDING)
@@ -91,10 +148,10 @@ void WebCache::doomAllEntries(int)
m_isClearInProgress = false;
return;
}
- done(0 /*unused*/);
+ onClearDone(0 /*unused*/);
}
-void WebCache::done(int)
+void WebCache::onClearDone(int)
{
m_isClearInProgress = false;
}
diff --git a/WebKit/android/WebCoreSupport/WebCache.h b/WebKit/android/WebCoreSupport/WebCache.h
index 9fd980f..7ff0e2e 100644
--- a/WebKit/android/WebCoreSupport/WebCache.h
+++ b/WebKit/android/WebCoreSupport/WebCache.h
@@ -28,21 +28,33 @@
#include "ChromiumIncludes.h"
+#include <OwnPtr.h>
+#include <wtf/ThreadingPrimitives.h>
+
namespace android {
class WebCache : public base::RefCountedThreadSafe<WebCache> {
public:
- static void clear();
+ static WebCache* get(bool isPrivateBrowsing);
+
+ void clear();
+ void cleanupFiles();
+ net::HostResolver* hostResolver() { return m_hostResolver.get(); }
+ net::HttpCache* cache() { return m_cache.get(); }
private:
- WebCache();
- static WebCache* getInstance();
+ WebCache(const std::string& storageDirectory);
+ // For clear()
void doClear();
void doomAllEntries(int);
- void done(int);
+ void onClearDone(int);
+
+ std::string m_storageDirectory;
+ OwnPtr<net::HostResolver> m_hostResolver;
+ OwnPtr<net::HttpCache> m_cache;
- static WebCache* s_instance;
+ // For clear()
net::CompletionCallbackImpl<WebCache> m_doomAllEntriesCallback;
net::CompletionCallbackImpl<WebCache> m_doneCallback;
disk_cache::Backend* m_cacheBackend;
diff --git a/WebKit/android/WebCoreSupport/WebRequestContext.cpp b/WebKit/android/WebCoreSupport/WebRequestContext.cpp
index 61303d9..223cd8d 100644
--- a/WebKit/android/WebCoreSupport/WebRequestContext.cpp
+++ b/WebKit/android/WebCoreSupport/WebRequestContext.cpp
@@ -28,16 +28,10 @@
#include "ChromiumIncludes.h"
#include "ChromiumLogging.h"
-#include "JNIUtility.h"
+#include "WebCache.h"
#include "WebCookieJar.h"
-#include "WebCoreJni.h"
-#include "WebUrlLoaderClient.h"
-#include "jni.h"
#include <dirent.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
#include <wtf/text/CString.h>
namespace {
@@ -48,17 +42,12 @@ std::string acceptLanguage("");
Lock userAgentLock;
Lock acceptLanguageLock;
-
-WTF::Mutex cacheDirectoryMutex;
}
using namespace WTF;
namespace android {
-static const char* const kCacheDirectory = "/webviewCacheChromium";
-static const char* const kCacheDirectoryPrivate = "/webviewCacheChromiumPrivate";
-
static scoped_refptr<WebRequestContext> privateBrowsingContext(0);
static WTF::Mutex privateBrowsingContextMutex;
@@ -105,36 +94,13 @@ const std::string& WebRequestContext::GetAcceptLanguage() const
return acceptLanguage;
}
-static const std::string& cacheRootDirectory()
-{
- // This method may be called on any thread, as the Java method is
- // synchronized.
- MutexLocker lock(cacheDirectoryMutex);
- static std::string cacheDirectory;
- if (cacheDirectory.empty()) {
- JNIEnv* env = JSC::Bindings::getJNIEnv();
- jclass bridgeClass = env->FindClass("android/webkit/JniUtil");
- jmethodID method = env->GetStaticMethodID(bridgeClass, "getCacheDirectory", "()Ljava/lang/String;");
- cacheDirectory = jstringToStdString(env, static_cast<jstring>(env->CallStaticObjectMethod(bridgeClass, method)));
- env->DeleteLocalRef(bridgeClass);
- }
- return cacheDirectory;
-}
-
WebRequestContext* WebRequestContext::getImpl(bool isPrivateBrowsing)
{
- static std::string path = cacheRootDirectory();
- path.append(isPrivateBrowsing ? kCacheDirectoryPrivate : kCacheDirectory);
- FilePath cachePath(path.c_str());
-
WebRequestContext* context = new WebRequestContext();
- context->host_resolver_ = net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism, 0, 0);
- base::Thread* ioThread = WebUrlLoaderClient::ioThread();
- scoped_refptr<base::MessageLoopProxy> cacheMessageLoopProxy = ioThread->message_loop_proxy();
- // Todo: check if the context takes ownership of the cache
- net::HttpCache::DefaultBackend* defaultBackend = new net::HttpCache::DefaultBackend(net::DISK_CACHE, cachePath, 20 * 1024 * 1024, cacheMessageLoopProxy);
- context->http_transaction_factory_ = new net::HttpCache(context->host_resolver(), context->dnsrr_resolver(), net::ProxyService::CreateDirect(), net::SSLConfigService::CreateSystemSSLConfigService(), net::HttpAuthHandlerFactory::CreateDefault(context->host_resolver_), 0, 0, defaultBackend);
+ WebCache* cache = WebCache::get(isPrivateBrowsing);
+ context->host_resolver_ = cache->hostResolver();
+ context->http_transaction_factory_ = cache->cache();
WebCookieJar* cookieJar = WebCookieJar::get(isPrivateBrowsing);
context->cookie_store_ = cookieJar->cookieStore();
@@ -206,10 +172,7 @@ bool WebRequestContext::cleanupPrivateBrowsingFiles()
privateBrowsingContext = 0;
WebCookieJar::get(true)->cleanupFiles();
-
- std::string cachePath = cacheRootDirectory();
- cachePath.append(kCacheDirectoryPrivate);
- removeFileOrDirectory(cachePath.c_str());
+ WebCache::get(true)->cleanupFiles();
return true;
}
return false;
diff --git a/WebKit/android/jni/WebCoreFrameBridge.cpp b/WebKit/android/jni/WebCoreFrameBridge.cpp
index 4212aa2..b9b4b75 100644
--- a/WebKit/android/jni/WebCoreFrameBridge.cpp
+++ b/WebKit/android/jni/WebCoreFrameBridge.cpp
@@ -1666,7 +1666,7 @@ static void ClearWebCoreCache()
static void ClearWebViewCache()
{
#if USE(CHROME_NETWORK_STACK)
- WebCache::clear();
+ WebCache::get(false /*privateBrowsing*/)->clear();
#else
// The Android network stack provides a WebView cache in CacheManager.java.
// Clearing this is handled entirely Java-side.