From eeb18149fa6d796dd5202f080b828099a9187046 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Tue, 26 Jan 2016 17:35:06 +0100 Subject: 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 --- src/core/url_request_custom_job.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/core/url_request_custom_job.h') 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 m_weakFactoryIO; - base::WeakPtrFactory m_weakFactoryUI; + base::WeakPtrFactory m_weakFactory; friend class URLRequestCustomJobDelegate; -- cgit v1.2.3 From fd7f2367515bd243a171ae1234b3443d6f24955d Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Wed, 27 Jan 2016 11:21:53 +0100 Subject: Fix multi-thread protection in custom url handler MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The classes were not properly protected against race conditions. To solve this there is now a class shared between the two thread that is not deleted until the classes on both threads have been deleted. Change-Id: I499bd98805ae7a195aca42f30610eb6c2b0fd0f7 Reviewed-by: Michael BrĂ¼ning Reviewed-by: Joerg Bornemann --- src/core/url_request_custom_job.h | 40 +++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) (limited to 'src/core/url_request_custom_job.h') diff --git a/src/core/url_request_custom_job.h b/src/core/url_request_custom_job.h index a994c467a..eedb41814 100644 --- a/src/core/url_request_custom_job.h +++ b/src/core/url_request_custom_job.h @@ -50,6 +50,7 @@ QT_FORWARD_DECLARE_CLASS(QWebEngineUrlSchemeHandler) namespace QtWebEngineCore { class URLRequestCustomJobDelegate; +class URLRequestCustomJobShared; // A request job that handles reading custom URL schemes class URLRequestCustomJob : public net::URLRequestJob { @@ -62,6 +63,25 @@ public: virtual bool GetCharset(std::string *charset) Q_DECL_OVERRIDE; virtual bool IsRedirectResponse(GURL* location, int* http_status_code) Q_DECL_OVERRIDE; +protected: + virtual ~URLRequestCustomJob(); + +private: + QWebEngineUrlSchemeHandler *m_schemeHandler; + URLRequestCustomJobShared *m_shared; + + friend class URLRequestCustomJobShared; + + DISALLOW_COPY_AND_ASSIGN(URLRequestCustomJob); +}; + +// A shared state between URLRequestCustomJob living on the IO thread +// and URLRequestCustomJobDelegate living on the UI thread. +class URLRequestCustomJobShared { +public: + URLRequestCustomJobShared(URLRequestCustomJob *job); + ~URLRequestCustomJobShared(); + void setReplyMimeType(const std::string &); void setReplyCharset(const std::string &); void setReplyDevice(QIODevice *); @@ -70,28 +90,28 @@ public: void fail(int); void abort(); -protected: - virtual ~URLRequestCustomJob(); + void killJob(); + void unsetJobDelegate(); + void startAsync(); void notifyStarted(); void notifyFailure(); void notifyCanceled(); -private: + GURL requestUrl(); + std::string requestMethod(); + QMutex m_mutex; QPointer m_device; - QPointer m_delegate; - QWebEngineUrlSchemeHandler *m_schemeHandler; + URLRequestCustomJob *m_job; + URLRequestCustomJobDelegate *m_delegate; std::string m_mimeType; std::string m_charset; int m_error; GURL m_redirect; bool m_started; - base::WeakPtrFactory m_weakFactory; - - friend class URLRequestCustomJobDelegate; - - DISALLOW_COPY_AND_ASSIGN(URLRequestCustomJob); + bool m_asyncInitialized; + base::WeakPtrFactory m_weakFactory; }; } // namespace QtWebEngineCore -- cgit v1.2.3