diff options
author | Kristian Monsen <kristianm@google.com> | 2011-10-21 04:48:32 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-10-21 04:48:32 -0700 |
commit | ed040c45380a4cdedc8c4024c355eb72db755eae (patch) | |
tree | a3baabe436172f10e8753b59d7df76e7b6587f12 /Source/WebKit/android/WebCoreSupport | |
parent | 3d2c72b84e33ed0463749f0b75561dd586e45a59 (diff) | |
parent | 05379b65a49fd212a4ea8e299d844aa6a659ee9e (diff) | |
download | external_webkit-ed040c45380a4cdedc8c4024c355eb72db755eae.zip external_webkit-ed040c45380a4cdedc8c4024c355eb72db755eae.tar.gz external_webkit-ed040c45380a4cdedc8c4024c355eb72db755eae.tar.bz2 |
Merge "WebKit part of fix for bug 5307956"
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(), |