Changeset 83695 in webkit


Ignore:
Timestamp:
Apr 12, 2011 9:30:11 PM (13 years ago)
Author:
luiz@webkit.org
Message:

[Qt] QNetworkReplyHandler refactoring: remove nested event loop.
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):

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r83694 r83695  
     12011-04-12  Luiz Agostini  <luiz.agostini@openbossa.org>
     2
     3        Reviewed by Andreas Kling.
     4
     5        [Qt] QNetworkReplyHandler refactoring: remove nested event loop.
     6        https://bugs.webkit.org/show_bug.cgi?id=58375
     7
     8        As QNAM now makes actual synchronous loads there is no need for a nested event loop
     9        in ResourceHandleQt.
     10
     11        Moving the call for QNetworkReplyWrapper::synchronousLoad from
     12        ResourceHandle::loadResourceSynchronously to QNetworkReplyHandler::start for the
     13        redirections to work in synchronous requests.
     14
     15        * platform/network/qt/QNetworkReplyHandler.cpp:
     16        (WebCore::QNetworkReplyHandler::start):
     17        * platform/network/qt/QNetworkReplyHandler.h:
     18        * platform/network/qt/ResourceHandleQt.cpp:
     19        (WebCore::WebCoreSynchronousLoader::WebCoreSynchronousLoader):
     20        (WebCore::WebCoreSynchronousLoader::didReceiveResponse):
     21        (WebCore::WebCoreSynchronousLoader::didReceiveData):
     22        (WebCore::WebCoreSynchronousLoader::didFinishLoading):
     23        (WebCore::WebCoreSynchronousLoader::didFail):
     24        (WebCore::ResourceHandle::loadResourceSynchronously):
     25
    1262011-04-12  Vangelis Kokkevis  <vangelis@chromium.org>
    227
  • trunk/Source/WebCore/platform/network/qt/QNetworkReplyHandler.cpp

    r83691 r83695  
    631631
    632632    if (m_loadType == SynchronousLoad && m_replyWrapper->reply()->isFinished()) {
     633        m_replyWrapper->synchronousLoad();
    633634        // If supported, a synchronous request will be finished at this point, no need to hook up the signals.
    634635        return;
     
    639640}
    640641
    641 void QNetworkReplyHandler::synchronousLoad()
    642 {
    643     if (m_replyWrapper)
    644         m_replyWrapper->synchronousLoad();
    645 }
    646 
    647642}
    648643
  • trunk/Source/WebCore/platform/network/qt/QNetworkReplyHandler.h

    r83691 r83695  
    110110    QNetworkReply* release();
    111111
    112     void synchronousLoad();
    113 
    114112public slots:
    115113    void finish();
  • trunk/Source/WebCore/platform/network/qt/ResourceHandleQt.cpp

    r83691 r83695  
    5454class WebCoreSynchronousLoader : public ResourceHandleClient {
    5555public:
    56     WebCoreSynchronousLoader();
     56    WebCoreSynchronousLoader(ResourceError& error, ResourceResponse& response, Vector<char>& data)
     57        : m_error(error)
     58        , m_response(response)
     59        , m_data(data)
     60    {}
    5761
    58     void waitForCompletion();
    59 
    60     virtual void didReceiveResponse(ResourceHandle*, const ResourceResponse&);
    61     virtual void didReceiveData(ResourceHandle*, const char*, int, int lengthReceived);
    62     virtual void didFinishLoading(ResourceHandle*, double /*finishTime*/);
    63     virtual void didFail(ResourceHandle*, const ResourceError&);
    64 
    65     ResourceResponse resourceResponse() const { return m_response; }
    66     ResourceError resourceError() const { return m_error; }
    67     Vector<char> data() const { return m_data; }
    68 
    69     void setReplyFinished(bool finished) { m_replyFinished = finished; }
    70 
     62    virtual void didReceiveResponse(ResourceHandle*, const ResourceResponse& response) { m_response = response; }
     63    virtual void didReceiveData(ResourceHandle*, const char* data, int length, int) { m_data.append(data, length); }
     64    virtual void didFinishLoading(ResourceHandle*, double /*finishTime*/) {}
     65    virtual void didFail(ResourceHandle*, const ResourceError& error) { m_error = error; }
    7166private:
    72     ResourceResponse m_response;
    73     ResourceError m_error;
    74     Vector<char> m_data;
    75     QEventLoop m_eventLoop;
    76     bool m_replyFinished;
     67    ResourceError& m_error;
     68    ResourceResponse& m_response;
     69    Vector<char>& m_data;
    7770};
    78 
    79 WebCoreSynchronousLoader::WebCoreSynchronousLoader()
    80         : m_replyFinished(false)
    81 {
    82 }
    83 
    84 void WebCoreSynchronousLoader::didReceiveResponse(ResourceHandle*, const ResourceResponse& response)
    85 {
    86     m_response = response;
    87 }
    88 
    89 void WebCoreSynchronousLoader::didReceiveData(ResourceHandle*, const char* data, int length, int)
    90 {
    91     m_data.append(data, length);
    92 }
    93 
    94 void WebCoreSynchronousLoader::didFinishLoading(ResourceHandle*, double)
    95 {
    96     if (!m_replyFinished)
    97         m_eventLoop.exit();
    98 }
    99 
    100 void WebCoreSynchronousLoader::didFail(ResourceHandle*, const ResourceError& error)
    101 {
    102     m_error = error;
    103     if (!m_replyFinished)
    104         m_eventLoop.exit();
    105 }
    106 
    107 void WebCoreSynchronousLoader::waitForCompletion()
    108 {
    109     m_eventLoop.exec(QEventLoop::ExcludeUserInputEvents);
    110 }
    11171
    11272ResourceHandleInternal::~ResourceHandleInternal()
     
    192152void ResourceHandle::loadResourceSynchronously(NetworkingContext* context, const ResourceRequest& request, StoredCredentials /*storedCredentials*/, ResourceError& error, ResourceResponse& response, Vector<char>& data)
    193153{
    194     WebCoreSynchronousLoader syncLoader;
     154    WebCoreSynchronousLoader syncLoader(error, response, data);
    195155    RefPtr<ResourceHandle> handle = adoptRef(new ResourceHandle(request, &syncLoader, true, false));
    196156
     
    205165    }
    206166    d->m_context = context;
    207     d->m_job = new QNetworkReplyHandler(handle.get(), QNetworkReplyHandler::SynchronousLoad);
    208167
    209     QNetworkReply* reply = d->m_job->reply();
    210     // When using synchronous calls, we are finished when reaching this point.
    211     if (reply->isFinished()) {
    212         syncLoader.setReplyFinished(true);
    213         d->m_job->synchronousLoad();
    214     } else
    215         syncLoader.waitForCompletion();
    216 
    217     error = syncLoader.resourceError();
    218     data = syncLoader.data();
    219     response = syncLoader.resourceResponse();
     168    // starting in deferred mode gives d->m_job the chance of being set before sending the request.
     169    d->m_job = new QNetworkReplyHandler(handle.get(), QNetworkReplyHandler::SynchronousLoad, true);
     170    d->m_job->setLoadingDeferred(false);
    220171}
    221172
Note: See TracChangeset for help on using the changeset viewer.