diff options
author | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2016-05-12 14:35:34 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2016-05-13 12:00:22 +0000 |
commit | d1d64e6e66f53ccd4eb0a548e9ce726190ebae91 (patch) | |
tree | 19c25199910927ccb6535bf1be60b67e4d0ce02d /src/core/url_request_custom_job.cpp | |
parent | 0f721b93f908828952b17f2f71a66c938f680fb1 (diff) |
Better handle failure on read in custom url handlers
Chromium 49 expects url request failures to be reported as a response
to either start or on read. So we should report failures during read
and make sure we can handle QIODevice calling fail on the job.
Change-Id: Id8f619d3cb6f187c99da580c6923130a95ca91ee
Reviewed-by: Michael BrĂ¼ning <michael.bruning@theqtcompany.com>
Diffstat (limited to 'src/core/url_request_custom_job.cpp')
-rw-r--r-- | src/core/url_request_custom_job.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/core/url_request_custom_job.cpp b/src/core/url_request_custom_job.cpp index 921be0b41..887222285 100644 --- a/src/core/url_request_custom_job.cpp +++ b/src/core/url_request_custom_job.cpp @@ -143,8 +143,12 @@ int URLRequestCustomJob::ReadRawData(IOBuffer *buf, int bufSize) qint64 rv = m_shared->m_device ? m_shared->m_device->read(buf->data(), bufSize) : -1; if (rv >= 0) return static_cast<int>(rv); - else + else { + // QIODevice::read might have called fail on us. + if (m_shared->m_error) + return m_shared->m_error; return ERR_FAILED; + } } @@ -281,9 +285,11 @@ void URLRequestCustomJobShared::notifyStarted() void URLRequestCustomJobShared::fail(int error) { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); QMutexLocker lock(&m_mutex); m_error = error; + if (content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)) + return; + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); if (!m_job) return; content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, base::Bind(&URLRequestCustomJobShared::notifyFailure, m_weakFactory.GetWeakPtr())); @@ -297,11 +303,9 @@ void URLRequestCustomJobShared::notifyFailure() return; if (m_device) m_device->close(); - const URLRequestStatus status(URLRequestStatus::FAILED, m_error); - if (m_started) - m_job->SetStatus(status); - else - m_job->NotifyStartError(status); + if (!m_started) + m_job->NotifyStartError(URLRequestStatus::FromError(m_error)); + // else we fail on the next read, or the read that might already be in progress } GURL URLRequestCustomJobShared::requestUrl() |