OSDN Git Service

Update Chromium HTTP stack to get database and cache paths from CookieSyncManager
authorSteve Block <steveblock@google.com>
Wed, 27 Oct 2010 10:29:59 +0000 (11:29 +0100)
committerSteve Block <steveblock@google.com>
Wed, 27 Oct 2010 13:07:30 +0000 (14:07 +0100)
Currently these paths are obtained from the BrowserFrame via JNI.
However, the paths are not synced to the BrowserFrame until the
WebCore thread has started up. This means that if the
WebRequestContext is created on the IO thread, the paths may not be
available.

This change moves the paths from BrowserFrame to CookieSyncManager to
avoid the need to wait for the WebCore thread.

Note that the new methods may be called on either the UI or WebCore
threads, so are synchronised.

Requires a change to frameworks/base ...
https://android-git.corp.google.com/g/76580

Change-Id: I61f88772d13901d66892118c79db3cac412e6bd1

WebKit/android/WebCoreSupport/WebRequestContext.cpp
WebKit/android/jni/CookieManager.cpp

index 5484979..2ff3ae8 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "ChromiumIncludes.h"
 #include "JNIUtility.h"
+#include "WebCoreJni.h"
 #include "WebUrlLoaderClient.h"
 #include "jni.h"
 
@@ -46,6 +47,9 @@ std::string acceptLanguage("");
 
 Lock userAgentLock;
 Lock acceptLanguageLock;
+
+WTF::Mutex databaseDirectoryMutex;
+WTF::Mutex cacheDirectoryMutex;
 }
 
 using namespace WTF;
@@ -105,39 +109,33 @@ const std::string& WebRequestContext::GetAcceptLanguage() const
 
 static const std::string& getDatabaseDirectory()
 {
+    // This method may be called on any thread, as the Java method is
+    // synchronized.
+    MutexLocker lock(databaseDirectoryMutex);
     static std::string databaseDirectory;
     if (databaseDirectory.empty()) {
         JNIEnv* env = JSC::Bindings::getJNIEnv();
-        jclass bridgeClass = env->FindClass("android/webkit/BrowserFrame");
+        jclass bridgeClass = env->FindClass("android/webkit/CookieSyncManager");
         jmethodID method = env->GetStaticMethodID(bridgeClass, "getDatabaseDirectory", "()Ljava/lang/String;");
-
-        jstring str = (jstring)env->CallStaticObjectMethod(bridgeClass, method);
-        jboolean isCopy;
-        const char* nativeString = env->GetStringUTFChars(str, &isCopy);
-        databaseDirectory = std::string(nativeString);
-        if (isCopy == JNI_TRUE)
-            env->ReleaseStringUTFChars(str, nativeString);
+        databaseDirectory = jstringToStdString(env, static_cast<jstring>(env->CallStaticObjectMethod(bridgeClass, method)));
+        env->DeleteLocalRef(bridgeClass);
     }
-
     return databaseDirectory;
 }
 
 static const std::string& getCacheDirectory()
 {
+    // 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/BrowserFrame");
+        jclass bridgeClass = env->FindClass("android/webkit/CookieSyncManager");
         jmethodID method = env->GetStaticMethodID(bridgeClass, "getCacheDirectory", "()Ljava/lang/String;");
-
-        jstring str = (jstring)env->CallStaticObjectMethod(bridgeClass, method);
-        jboolean isCopy;
-        const char* nativeString = env->GetStringUTFChars(str, &isCopy);
-        cacheDirectory = std::string(nativeString);
-        if (isCopy == JNI_TRUE)
-            env->ReleaseStringUTFChars(str, nativeString);
+        cacheDirectory = jstringToStdString(env, static_cast<jstring>(env->CallStaticObjectMethod(bridgeClass, method)));
+        env->DeleteLocalRef(bridgeClass);
     }
-
     return cacheDirectory;
 }
 
index 34e2cb6..7139286 100644 (file)
@@ -52,10 +52,6 @@ static void removeAllCookie(JNIEnv*, jobject) {
     // getter just returns a pointer which is only set when the context is first
     // constructed. The CookieMonster is threadsafe, so the call below is safe
     // overall.
-    //
-    // TODO: It's possible that this call is made before the WebKit thread has
-    // started up and the settings have been synced to the BrowserFrame. This
-    // will cause creation of the context to fail.
     WebRequestContext::get(false)->cookie_store()->GetCookieMonster()->DeleteAllCreatedAfter(Time(), true);
     // This will lazily create a new private browsing context. However, if the
     // context doesn't already exist, there's no need to create it, as cookies