summaryrefslogtreecommitdiffstats
path: root/src/core/url_request_custom_job_proxy.h
diff options
context:
space:
mode:
authorMichal Klocek <michal.klocek@qt.io>2017-09-04 16:00:47 +0200
committerMichal Klocek <michal.klocek@qt.io>2017-09-11 09:59:06 +0000
commit73286f99b4ecc3f11485e36b1a090849e5efd4ef (patch)
treeb8777d08de2df84bd82701cd4cc710f925d7a41c /src/core/url_request_custom_job_proxy.h
parent7a7f5276cc7bbb5138054886b1eadd5d334988a0 (diff)
Simplify URLRequestCustomJob handling
Improve implementation of URLRequestCustomJob: * remove qmutex, pass values using PostTask * do not use base::WeakPtr which is not thread safe and must always be dereferenced on the same thread * add proxy object to handle interactions between threads * do not use QPointer to track IODevice since it does not solve anything for us * QIODevice in reply method is used only by IO thread * do not make shared object to commit suicide, instead use refcounted object * improve documentation about thread safety issue of QIODevice object in reply method Change-Id: Ic29bf262de8082dfd46cb9217a68f3c982d16b9e Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io> Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src/core/url_request_custom_job_proxy.h')
-rw-r--r--src/core/url_request_custom_job_proxy.h53
1 files changed, 21 insertions, 32 deletions
diff --git a/src/core/url_request_custom_job_proxy.h b/src/core/url_request_custom_job_proxy.h
index b8c7b5c67..df7171f5e 100644
--- a/src/core/url_request_custom_job_proxy.h
+++ b/src/core/url_request_custom_job_proxy.h
@@ -40,11 +40,9 @@
#ifndef URL_REQUEST_CUSTOM_JOB_PROXY_H_
#define URL_REQUEST_CUSTOM_JOB_PROXY_H_
-#include "url/gurl.h"
#include "base/memory/weak_ptr.h"
-#include <QtCore/QMutex>
-#include <QtCore/QPointer>
-
+#include "url/gurl.h"
+#include <QtCore/QWeakPointer>
QT_FORWARD_DECLARE_CLASS(QIODevice)
@@ -52,44 +50,35 @@ namespace QtWebEngineCore {
class URLRequestCustomJob;
class URLRequestCustomJobDelegate;
+class BrowserContextAdapter;
// Used to comunicate between URLRequestCustomJob living on the IO thread
// and URLRequestCustomJobDelegate living on the UI thread.
-class URLRequestCustomJobProxy {
+class URLRequestCustomJobProxy
+ : public base::RefCountedThreadSafe<URLRequestCustomJobProxy> {
+
public:
- URLRequestCustomJobProxy(URLRequestCustomJob *job);
+ URLRequestCustomJobProxy(URLRequestCustomJob *job,
+ const std::string &scheme,
+ QWeakPointer<const BrowserContextAdapter> adapter);
~URLRequestCustomJobProxy();
- void setReplyMimeType(const std::string &);
- void setReplyCharset(const std::string &);
- void setReplyDevice(QIODevice *);
-
- void redirect(const GURL &url);
- void fail(int);
+ //void setReplyCharset(const std::string &);
+ void reply(std::string mimeType, QIODevice *device);
+ void redirect(GURL url);
void abort();
+ void fail(int error);
+ void release();
+ void initialize(GURL url, std::string method);
- void killJob();
- void unsetJobDelegate();
-
- void startAsync();
- void notifyStarted();
- void notifyFailure();
- void notifyCanceled();
-
- GURL requestUrl();
- std::string requestMethod();
-
- QMutex m_mutex;
- QPointer<QIODevice> m_device;
+ //IO thread owned
URLRequestCustomJob *m_job;
- URLRequestCustomJobDelegate *m_delegate;
- std::string m_mimeType;
- std::string m_charset;
- int m_error;
- GURL m_redirect;
bool m_started;
- bool m_asyncInitialized;
- base::WeakPtrFactory<URLRequestCustomJobProxy> m_weakFactory;
+
+ //UI thread owned
+ std::string m_scheme;
+ URLRequestCustomJobDelegate *m_delegate;
+ QWeakPointer<const BrowserContextAdapter> m_adapter;
};
} // namespace QtWebEngineCore