[Qt] QNetworkReplyHandler refactoring: remove nested event loop.
authorluiz@webkit.org <luiz@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Apr 2011 23:54:03 +0000 (23:54 +0000)
committerluiz@webkit.org <luiz@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Apr 2011 23:54:03 +0000 (23:54 +0000)
https://bugs.webkit.org/show_bug.cgi?id=58375

Reviewed by Andreas Kling.

As QNAM now makes actual synchronous loads there is no need for a nested event loop
in ResourceHandleQt.

Moving the call for QNetworkReplyWrapper::synchronousLoad from
ResourceHandle::loadResourceSynchronously to QNetworkReplyHandler::start for the
redirections to work in synchronous requests.

* platform/network/qt/QNetworkReplyHandler.cpp:
(WebCore::QNetworkReplyHandler::start):
* platform/network/qt/QNetworkReplyHandler.h:
* platform/network/qt/ResourceHandleQt.cpp:
(WebCore::WebCoreSynchronousLoader::WebCoreSynchronousLoader):
(WebCore::WebCoreSynchronousLoader::didReceiveResponse):
(WebCore::WebCoreSynchronousLoader::didReceiveData):
(WebCore::WebCoreSynchronousLoader::didFinishLoading):
(WebCore::WebCoreSynchronousLoader::didFail):
(WebCore::ResourceHandle::loadResourceSynchronously):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@83788 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/network/qt/QNetworkReplyHandler.cpp
Source/WebCore/platform/network/qt/QNetworkReplyHandler.h
Source/WebCore/platform/network/qt/ResourceHandleQt.cpp

index a2df5a8..28813c9 100644 (file)
@@ -1,3 +1,28 @@
+2011-04-12  Luiz Agostini  <luiz.agostini@openbossa.org>
+
+        Reviewed by Andreas Kling.
+
+        [Qt] QNetworkReplyHandler refactoring: remove nested event loop.
+        https://bugs.webkit.org/show_bug.cgi?id=58375
+
+        As QNAM now makes actual synchronous loads there is no need for a nested event loop
+        in ResourceHandleQt.
+
+        Moving the call for QNetworkReplyWrapper::synchronousLoad from
+        ResourceHandle::loadResourceSynchronously to QNetworkReplyHandler::start for the
+        redirections to work in synchronous requests.
+
+        * platform/network/qt/QNetworkReplyHandler.cpp:
+        (WebCore::QNetworkReplyHandler::start):
+        * platform/network/qt/QNetworkReplyHandler.h:
+        * platform/network/qt/ResourceHandleQt.cpp:
+        (WebCore::WebCoreSynchronousLoader::WebCoreSynchronousLoader):
+        (WebCore::WebCoreSynchronousLoader::didReceiveResponse):
+        (WebCore::WebCoreSynchronousLoader::didReceiveData):
+        (WebCore::WebCoreSynchronousLoader::didFinishLoading):
+        (WebCore::WebCoreSynchronousLoader::didFail):
+        (WebCore::ResourceHandle::loadResourceSynchronously):
+
 2011-04-13  Roland Steiner  <rolandsteiner@chromium.org>
 
         Reviewed by David Hyatt.
index 00cfcf2..feb3629 100644 (file)
@@ -630,6 +630,7 @@ void QNetworkReplyHandler::start()
     m_replyWrapper = new QNetworkReplyWrapper(&m_queue, reply, this);
 
     if (m_loadType == SynchronousLoad && m_replyWrapper->reply()->isFinished()) {
+        m_replyWrapper->synchronousLoad();
         // If supported, a synchronous request will be finished at this point, no need to hook up the signals.
         return;
     }
@@ -638,12 +639,6 @@ void QNetworkReplyHandler::start()
         connect(m_replyWrapper->reply(), SIGNAL(uploadProgress(qint64, qint64)), this, SLOT(uploadProgress(qint64, qint64)));
 }
 
-void QNetworkReplyHandler::synchronousLoad()
-{
-    if (m_replyWrapper)
-        m_replyWrapper->synchronousLoad();
-}
-
 }
 
 #include "moc_QNetworkReplyHandler.cpp"
index eff63f4..fced2df 100644 (file)
@@ -109,8 +109,6 @@ public:
 
     QNetworkReply* release();
 
-    void synchronousLoad();
-
 public slots:
     void finish();
     void sendResponseIfNeeded();
index dced7b2..642d0a6 100644 (file)
@@ -53,62 +53,22 @@ namespace WebCore {
 
 class WebCoreSynchronousLoader : public ResourceHandleClient {
 public:
-    WebCoreSynchronousLoader();
-
-    void waitForCompletion();
-
-    virtual void didReceiveResponse(ResourceHandle*, const ResourceResponse&);
-    virtual void didReceiveData(ResourceHandle*, const char*, int, int lengthReceived);
-    virtual void didFinishLoading(ResourceHandle*, double /*finishTime*/);
-    virtual void didFail(ResourceHandle*, const ResourceError&);
-
-    ResourceResponse resourceResponse() const { return m_response; }
-    ResourceError resourceError() const { return m_error; }
-    Vector<char> data() const { return m_data; }
-
-    void setReplyFinished(bool finished) { m_replyFinished = finished; }
-
+    WebCoreSynchronousLoader(ResourceError& error, ResourceResponse& response, Vector<char>& data)
+        : m_error(error)
+        , m_response(response)
+        , m_data(data)
+    {}
+
+    virtual void didReceiveResponse(ResourceHandle*, const ResourceResponse& response) { m_response = response; }
+    virtual void didReceiveData(ResourceHandle*, const char* data, int length, int) { m_data.append(data, length); }
+    virtual void didFinishLoading(ResourceHandle*, double /*finishTime*/) {}
+    virtual void didFail(ResourceHandle*, const ResourceError& error) { m_error = error; }
 private:
-    ResourceResponse m_response;
-    ResourceError m_error;
-    Vector<char> m_data;
-    QEventLoop m_eventLoop;
-    bool m_replyFinished;
+    ResourceError& m_error;
+    ResourceResponse& m_response;
+    Vector<char>& m_data;
 };
 
-WebCoreSynchronousLoader::WebCoreSynchronousLoader()
-        : m_replyFinished(false)
-{
-}
-
-void WebCoreSynchronousLoader::didReceiveResponse(ResourceHandle*, const ResourceResponse& response)
-{
-    m_response = response;
-}
-
-void WebCoreSynchronousLoader::didReceiveData(ResourceHandle*, const char* data, int length, int)
-{
-    m_data.append(data, length);
-}
-
-void WebCoreSynchronousLoader::didFinishLoading(ResourceHandle*, double)
-{
-    if (!m_replyFinished)
-        m_eventLoop.exit();
-}
-
-void WebCoreSynchronousLoader::didFail(ResourceHandle*, const ResourceError& error)
-{
-    m_error = error;
-    if (!m_replyFinished)
-        m_eventLoop.exit();
-}
-
-void WebCoreSynchronousLoader::waitForCompletion()
-{
-    m_eventLoop.exec(QEventLoop::ExcludeUserInputEvents);
-}
-
 ResourceHandleInternal::~ResourceHandleInternal()
 {
 }
@@ -191,7 +151,7 @@ PassRefPtr<SharedBuffer> ResourceHandle::bufferedData()
 
 void ResourceHandle::loadResourceSynchronously(NetworkingContext* context, const ResourceRequest& request, StoredCredentials /*storedCredentials*/, ResourceError& error, ResourceResponse& response, Vector<char>& data)
 {
-    WebCoreSynchronousLoader syncLoader;
+    WebCoreSynchronousLoader syncLoader(error, response, data);
     RefPtr<ResourceHandle> handle = adoptRef(new ResourceHandle(request, &syncLoader, true, false));
 
     ResourceHandleInternal* d = handle->getInternal();
@@ -204,19 +164,10 @@ void ResourceHandle::loadResourceSynchronously(NetworkingContext* context, const
         d->m_firstRequest.setURL(urlWithCredentials);
     }
     d->m_context = context;
-    d->m_job = new QNetworkReplyHandler(handle.get(), QNetworkReplyHandler::SynchronousLoad);
-
-    QNetworkReply* reply = d->m_job->reply();
-    // When using synchronous calls, we are finished when reaching this point.
-    if (reply->isFinished()) {
-        syncLoader.setReplyFinished(true);
-        d->m_job->synchronousLoad();
-    } else
-        syncLoader.waitForCompletion();
-
-    error = syncLoader.resourceError();
-    data = syncLoader.data();
-    response = syncLoader.resourceResponse();
+
+    // starting in deferred mode gives d->m_job the chance of being set before sending the request.
+    d->m_job = new QNetworkReplyHandler(handle.get(), QNetworkReplyHandler::SynchronousLoad, true);
+    d->m_job->setLoadingDeferred(false);
 }
 
 void ResourceHandle::platformSetDefersLoading(bool defers)