From 05379b65a49fd212a4ea8e299d844aa6a659ee9e Mon Sep 17 00:00:00 2001 From: Kristian Monsen Date: Wed, 19 Oct 2011 11:44:34 +0100 Subject: WebKit part of fix for bug 5307956 If the cache directory is an empty string, create an in-memory cache instead. Also cleared up the storage directory logic. It should only be called once for each app now, so removed the caching and merged the two functions. Change-Id: Id9f179b5722425d1808f7d784d1071dee7aec6bc --- Source/WebKit/android/WebCoreSupport/WebCache.cpp | 39 +++++++++++------------ 1 file changed, 18 insertions(+), 21 deletions(-) (limited to 'Source/WebKit') diff --git a/Source/WebKit/android/WebCoreSupport/WebCache.cpp b/Source/WebKit/android/WebCoreSupport/WebCache.cpp index 3c49430..9b505ee 100644 --- a/Source/WebKit/android/WebCoreSupport/WebCache.cpp +++ b/Source/WebKit/android/WebCoreSupport/WebCache.cpp @@ -42,28 +42,20 @@ namespace android { static WTF::Mutex instanceMutex; -static const string& rootDirectory() -{ - // This method may be called on any thread, as the Java method is - // synchronized. - static WTF::Mutex mutex; - MutexLocker lock(mutex); - static 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(env->CallStaticObjectMethod(bridgeClass, method))); - env->DeleteLocalRef(bridgeClass); - } - return cacheDirectory; -} - static string storageDirectory() { - // Private cache is currently in memory only static const char* const kDirectory = "/webviewCacheChromium"; - string storageDirectory = rootDirectory(); + + JNIEnv* env = JSC::Bindings::getJNIEnv(); + jclass bridgeClass = env->FindClass("android/webkit/JniUtil"); + jmethodID method = env->GetStaticMethodID(bridgeClass, "getCacheDirectory", "()Ljava/lang/String;"); + string storageDirectory = jstringToStdString(env, static_cast(env->CallStaticObjectMethod(bridgeClass, method))); + env->DeleteLocalRef(bridgeClass); + + // Return empty string if storageDirectory is an empty string + if (storageDirectory.empty()) + return storageDirectory; + storageDirectory.append(kDirectory); return storageDirectory; } @@ -111,8 +103,13 @@ WebCache::WebCache(bool isPrivateBrowsing) if (isPrivateBrowsing) backendFactory = net::HttpCache::DefaultBackend::InMemory(kMaximumCacheSizeBytes / 2); else { - FilePath directoryPath(storageDirectory().c_str()); - backendFactory = new net::HttpCache::DefaultBackend(net::DISK_CACHE, directoryPath, kMaximumCacheSizeBytes, cacheMessageLoopProxy); + string storage(storageDirectory()); + if (storage.empty()) // Can't get a storage directory from the OS + backendFactory = net::HttpCache::DefaultBackend::InMemory(kMaximumCacheSizeBytes / 2); + else { + FilePath directoryPath(storage.c_str()); + backendFactory = new net::HttpCache::DefaultBackend(net::DISK_CACHE, directoryPath, kMaximumCacheSizeBytes, cacheMessageLoopProxy); + } } m_cache = new net::HttpCache(m_hostResolver.get(), -- cgit v1.1