diff options
author | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2016-01-27 11:21:53 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2016-01-27 20:35:11 +0000 |
commit | fd7f2367515bd243a171ae1234b3443d6f24955d (patch) | |
tree | b543d2e324c5cc2f7ea13cbd78eaa2b425ee3c15 /src/core/url_request_custom_job.h | |
parent | eeb18149fa6d796dd5202f080b828099a9187046 (diff) |
Fix multi-thread protection in custom url handler
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 <michael.bruning@theqtcompany.com>
Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
Diffstat (limited to 'src/core/url_request_custom_job.h')
-rw-r--r-- | src/core/url_request_custom_job.h | 40 |
1 files changed, 30 insertions, 10 deletions
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<QIODevice> m_device; - QPointer<URLRequestCustomJobDelegate> 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<URLRequestCustomJob> m_weakFactory; - - friend class URLRequestCustomJobDelegate; - - DISALLOW_COPY_AND_ASSIGN(URLRequestCustomJob); + bool m_asyncInitialized; + base::WeakPtrFactory<URLRequestCustomJobShared> m_weakFactory; }; } // namespace QtWebEngineCore |