OSDN Git Service

Merge Chromium at 9.0.597.55: Move formsSeen call to IO thread.
authorBen Murdoch <benm@google.com>
Mon, 10 Jan 2011 12:40:47 +0000 (12:40 +0000)
committerBen Murdoch <benm@google.com>
Tue, 11 Jan 2011 15:29:34 +0000 (15:29 +0000)
When we search the document for forms to be autofilled, we make a URL
request to the AutoFill server to ask it for form field data. With
Chromium r67655, this URL request needs to be made on a Chrome thread.

This is a simple fix for the merge, which blocks until the call
completes.

See http://src.chromium.org/viewvc/chrome?view=rev&revision=67655

Change-Id: Iad96314e4ecb66ee7e65c1ef846709e9c41b0e2e

WebKit/android/WebCoreSupport/autofill/WebAutoFill.cpp
WebKit/android/WebCoreSupport/autofill/WebAutoFill.h

index b8afbe9..a80636c 100644 (file)
@@ -52,6 +52,7 @@ WebAutoFill::WebAutoFill()
     : mQueryId(1)
     , mWebViewCore(0)
     , mLastSearchDomVersion(0)
+    , mParsingForms(false)
 {
     mTabContents = new TabContents();
     setEmptyProfile();
@@ -89,6 +90,8 @@ void WebAutoFill::searchDocument(WebCore::Frame* frame)
     if (!enabled())
         return;
 
+    MutexLocker lock(mFormsSeenMutex);
+
     init();
 
     cleanUpQueryMap();
@@ -104,8 +107,24 @@ void WebAutoFill::searchDocument(WebCore::Frame* frame)
 
     mFormManager->ExtractForms(frame);
     mFormManager->GetFormsInFrame(frame, FormManager::REQUIRE_AUTOCOMPLETE, &mForms);
-    mAutoFillManager->FormsSeen(mForms);
 
+    // Needs to be done on a Chrome thread as it will make a URL request to the AutoFill server.
+    // TODO: Use our own Autofill thread instead of the IO thread.
+    // TODO: For now, block here. Would like to make this properly async.
+    base::Thread* thread = WebUrlLoaderClient::ioThread();
+    mParsingForms = true;
+    thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(this, &WebAutoFill::formsSeenImpl));
+    while (mParsingForms)
+        mFormsSeenCondition.wait(mFormsSeenMutex);
+}
+
+// Called on the Chromium IO thread.
+void WebAutoFill::formsSeenImpl()
+{
+    MutexLocker lock(mFormsSeenMutex);
+    mAutoFillManager->FormsSeen(mForms);
+    mParsingForms = false;
+    mFormsSeenCondition.signal();
 }
 
 void WebAutoFill::formFieldFocused(WebCore::HTMLFormControlElement* formFieldElement)
@@ -148,6 +167,7 @@ void WebAutoFill::formFieldFocused(WebCore::HTMLFormControlElement* formFieldEle
     mQueryMap[mQueryId] = new FormDataAndField(form, formField);
 
     bool suggestions = mAutoFillManager->GetAutoFillSuggestions(*form, *formField);
+
     mQueryId++;
     if (!suggestions) {
         ASSERT(mWebViewCore);
index ee1ac17..9389281 100644 (file)
@@ -34,6 +34,7 @@
 #include <vector>
 #include <wtf/Noncopyable.h>
 #include <wtf/OwnPtr.h>
+#include <wtf/ThreadingPrimitives.h>
 
 class AutoFillManager;
 class AutoFillProfile;
@@ -112,9 +113,15 @@ private:
     WebViewCore* mWebViewCore;
 
     int mLastSearchDomVersion;
+
+    WTF::Mutex mFormsSeenMutex; // Guards mFormsSeenCondition and mParsingForms.
+    WTF::ThreadCondition mFormsSeenCondition;
+    bool volatile mParsingForms;
 };
 
 }
 
+DISABLE_RUNNABLE_METHOD_REFCOUNT(android::WebAutoFill);
+
 #endif // ENABLE(WEB_AUTOFILL)
 #endif // WebAutoFill_h