diff options
author | Kristian Monsen <kristianm@google.com> | 2011-10-19 11:44:34 +0100 |
---|---|---|
committer | Kristian Monsen <kristianm@google.com> | 2011-10-19 13:39:21 +0100 |
commit | 05379b65a49fd212a4ea8e299d844aa6a659ee9e (patch) | |
tree | b4658b88c8759fbc0893c65cea7343eca48a9a60 /Source/WebKit/android/WebCoreSupport | |
parent | eb353fad1b7ce9f4b64833a21de8c222986f6dcf (diff) | |
download | external_webkit-05379b65a49fd212a4ea8e299d844aa6a659ee9e.zip external_webkit-05379b65a49fd212a4ea8e299d844aa6a659ee9e.tar.gz external_webkit-05379b65a49fd212a4ea8e299d844aa6a659ee9e.tar.bz2 |
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
Diffstat (limited to 'Source/WebKit/android/WebCoreSupport')
-rw-r--r-- | Source/WebKit/android/WebCoreSupport/WebCache.cpp | 39 |
1 files changed, 18 insertions, 21 deletions
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<jstring>(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<jstring>(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(), |