summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@theqtcompany.com>2016-01-26 17:35:06 +0100
committerJoerg Bornemann <joerg.bornemann@theqtcompany.com>2016-01-26 17:54:48 +0000
commiteeb18149fa6d796dd5202f080b828099a9187046 (patch)
tree49b32875d223c9efa3ce487989a9dc7cecba25cd /src/core
parent9490ae8570c950e8120e498fbdc459f5754df0bf (diff)
Fix occasional "WeakPtrs must be checked on the same sequenced thread."
Revert 7c7ee9a9, and fix the issue by passing a raw this pointer to startAsync. Bind will take care of calling AddRef/Release for us. Otherwise the WeakPtr would get assigned to the UI thread and must be invalidated in the same. Change-Id: Iee741dde521cf085a086e397a8154fa1384d58d1 Task-number: QTBUG-49670 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@theqtcompany.com>
Diffstat (limited to 'src/core')
-rw-r--r--src/core/url_request_custom_job.cpp17
-rw-r--r--src/core/url_request_custom_job.h3
2 files changed, 9 insertions, 11 deletions
diff --git a/src/core/url_request_custom_job.cpp b/src/core/url_request_custom_job.cpp
index 907f71c2e..84c898c3a 100644
--- a/src/core/url_request_custom_job.cpp
+++ b/src/core/url_request_custom_job.cpp
@@ -60,8 +60,7 @@ URLRequestCustomJob::URLRequestCustomJob(URLRequest *request, NetworkDelegate *n
, m_schemeHandler(schemeHandler)
, m_error(0)
, m_started(false)
- , m_weakFactoryIO(this)
- , m_weakFactoryUI(this)
+ , m_weakFactory(this)
{
}
@@ -79,7 +78,8 @@ URLRequestCustomJob::~URLRequestCustomJob()
void URLRequestCustomJob::Start()
{
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
- content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, base::Bind(&URLRequestCustomJob::startAsync, m_weakFactoryIO.GetWeakPtr()));
+ content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
+ base::Bind(&URLRequestCustomJob::startAsync, this));
}
void URLRequestCustomJob::Kill()
@@ -94,8 +94,7 @@ void URLRequestCustomJob::Kill()
if (m_device && m_device->isOpen())
m_device->close();
m_device = 0;
- m_weakFactoryIO.InvalidateWeakPtrs();
- m_weakFactoryUI.InvalidateWeakPtrs();
+ m_weakFactory.InvalidateWeakPtrs();
URLRequestJob::Kill();
}
@@ -153,7 +152,7 @@ void URLRequestCustomJob::setReplyDevice(QIODevice *device)
m_device->open(QIODevice::ReadOnly);
if (m_device && m_device->isReadable())
- content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, base::Bind(&URLRequestCustomJob::notifyStarted, m_weakFactoryUI.GetWeakPtr()));
+ content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, base::Bind(&URLRequestCustomJob::notifyStarted, m_weakFactory.GetWeakPtr()));
else
fail(ERR_INVALID_URL);
}
@@ -181,7 +180,7 @@ void URLRequestCustomJob::redirect(const GURL &url)
QMutexLocker lock(&m_mutex);
m_redirect = url;
- content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, base::Bind(&URLRequestCustomJob::notifyStarted, m_weakFactoryUI.GetWeakPtr()));
+ content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, base::Bind(&URLRequestCustomJob::notifyStarted, m_weakFactory.GetWeakPtr()));
}
void URLRequestCustomJob::abort()
@@ -191,7 +190,7 @@ void URLRequestCustomJob::abort()
if (m_device && m_device->isOpen())
m_device->close();
m_device = 0;
- content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, base::Bind(&URLRequestCustomJob::notifyCanceled, m_weakFactoryUI.GetWeakPtr()));
+ content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, base::Bind(&URLRequestCustomJob::notifyCanceled, m_weakFactory.GetWeakPtr()));
}
void URLRequestCustomJob::notifyCanceled()
@@ -216,7 +215,7 @@ void URLRequestCustomJob::fail(int error)
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
QMutexLocker lock(&m_mutex);
m_error = error;
- content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, base::Bind(&URLRequestCustomJob::notifyFailure, m_weakFactoryUI.GetWeakPtr()));
+ content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, base::Bind(&URLRequestCustomJob::notifyFailure, m_weakFactory.GetWeakPtr()));
}
void URLRequestCustomJob::notifyFailure()
diff --git a/src/core/url_request_custom_job.h b/src/core/url_request_custom_job.h
index be5cae43c..a994c467a 100644
--- a/src/core/url_request_custom_job.h
+++ b/src/core/url_request_custom_job.h
@@ -87,8 +87,7 @@ private:
int m_error;
GURL m_redirect;
bool m_started;
- base::WeakPtrFactory<URLRequestCustomJob> m_weakFactoryIO;
- base::WeakPtrFactory<URLRequestCustomJob> m_weakFactoryUI;
+ base::WeakPtrFactory<URLRequestCustomJob> m_weakFactory;
friend class URLRequestCustomJobDelegate;