diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2019-06-28 16:43:43 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2019-07-31 13:14:28 +0300 |
commit | f383f899cba71c02f2fcacd7f54b17a50f8e33d0 (patch) | |
tree | 70681e2a24d59afdfc1a17e408254ede559e1ecf | |
parent | 33a2c9aed3ee621c91853570087b500c830792e0 (diff) |
Port from QMutex::Recursive to QRecursiveMutex
Also port from QMutexLocker to std::lock_guard, as the former will not
support QRecursiveMutex going forward.
Add a guard for Qt < 5.14 to fall back to the old implementation, as
this module has to compile against the latest LTS, too.
Change-Id: Ib247135326ed199fd5fc783e906e7e3018687570
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
-rw-r--r-- | src/core/profile_io_data_qt.cpp | 37 | ||||
-rw-r--r-- | src/core/profile_io_data_qt.h | 7 | ||||
-rw-r--r-- | tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp | 17 |
3 files changed, 37 insertions, 24 deletions
diff --git a/src/core/profile_io_data_qt.cpp b/src/core/profile_io_data_qt.cpp index 9a5058a5a..38fe56f7d 100644 --- a/src/core/profile_io_data_qt.cpp +++ b/src/core/profile_io_data_qt.cpp @@ -100,6 +100,8 @@ #include "net/cert_net/cert_net_fetcher_impl.h" #endif +#include <mutex> + namespace QtWebEngineCore { static bool doNetworkSessionParamsMatch(const net::HttpNetworkSession::Params &first, @@ -164,7 +166,6 @@ ProfileIODataQt::ProfileIODataQt(ProfileQt *profile) #if QT_CONFIG(ssl) m_clientCertificateStoreData(new ClientCertificateStoreData), #endif - m_mutex(QMutex::Recursive), m_removerObserver(this), m_weakPtrFactory(this) { @@ -243,7 +244,7 @@ void ProfileIODataQt::initializeOnIOThread() m_urlRequestContext->set_enable_brotli(base::FeatureList::IsEnabled(features::kBrotliEncoding)); // this binds factory to io thread m_weakPtr = m_weakPtrFactory.GetWeakPtr(); - QMutexLocker lock(&m_mutex); + const std::lock_guard<QRecursiveMutex> lock(m_mutex); generateAllStorage(); generateJobFactory(); setGlobalCertificateVerification(); @@ -283,7 +284,7 @@ void ProfileIODataQt::cancelAllUrlRequests() void ProfileIODataQt::generateAllStorage() { Q_ASSERT(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); - QMutexLocker lock(&m_mutex); + const std::lock_guard<QRecursiveMutex> lock(m_mutex); generateStorage(); generateCookieStore(); generateUserAgent(); @@ -390,7 +391,7 @@ void ProfileIODataQt::generateCookieStore() Q_ASSERT(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); Q_ASSERT(m_urlRequestContext); - QMutexLocker lock(&m_mutex); + const std::lock_guard<QRecursiveMutex> lock(m_mutex); // FIXME: Add code to remove the old database. m_storage->set_channel_id_service( @@ -443,7 +444,7 @@ void ProfileIODataQt::generateUserAgent() Q_ASSERT(m_urlRequestContext); Q_ASSERT(m_storage); - QMutexLocker lock(&m_mutex); + const std::lock_guard<QRecursiveMutex> lock(m_mutex); m_storage->set_http_user_agent_settings(std::unique_ptr<net::HttpUserAgentSettings>( new net::StaticHttpUserAgentSettings(m_httpAcceptLanguage.toStdString(), m_httpUserAgent.toStdString()))); @@ -455,7 +456,7 @@ void ProfileIODataQt::generateHttpCache() Q_ASSERT(m_urlRequestContext); Q_ASSERT(m_storage); - QMutexLocker lock(&m_mutex); + const std::lock_guard<QRecursiveMutex> lock(m_mutex); net::HttpCache::DefaultBackend* main_backend = 0; switch (m_httpCacheType) { @@ -508,7 +509,7 @@ void ProfileIODataQt::generateJobFactory() Q_ASSERT(m_urlRequestContext); Q_ASSERT(!m_jobFactory); - QMutexLocker lock(&m_mutex); + const std::lock_guard<QRecursiveMutex> lock(m_mutex); m_updateJobFactory = false; std::unique_ptr<net::URLRequestJobFactoryImpl> jobFactory(new net::URLRequestJobFactoryImpl()); @@ -563,7 +564,7 @@ void ProfileIODataQt::regenerateJobFactory() Q_ASSERT(m_jobFactory); Q_ASSERT(m_baseJobFactory); - QMutexLocker lock(&m_mutex); + const std::lock_guard<QRecursiveMutex> lock(m_mutex); m_updateJobFactory = false; if (m_customUrlSchemes == m_installedCustomSchemes) @@ -584,7 +585,7 @@ void ProfileIODataQt::regenerateJobFactory() void ProfileIODataQt::setGlobalCertificateVerification() { Q_ASSERT(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); - QMutexLocker lock(&m_mutex); + const std::lock_guard<QRecursiveMutex> lock(m_mutex); if (m_useForGlobalCertificateVerification) { #if defined(USE_NSS_CERTS) // Set request context used by NSS for OCSP requests. @@ -623,7 +624,7 @@ void ProfileIODataQt::setFullConfiguration() void ProfileIODataQt::requestStorageGeneration() { Q_ASSERT(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); - QMutexLocker lock(&m_mutex); + const std::lock_guard<QRecursiveMutex> lock(m_mutex); if (m_initialized && !m_updateAllStorage) { m_updateAllStorage = true; createProxyConfig(); @@ -636,7 +637,7 @@ void ProfileIODataQt::requestStorageGeneration() { void ProfileIODataQt::createProxyConfig() { Q_ASSERT(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); - QMutexLocker lock(&m_mutex); + const std::lock_guard<QRecursiveMutex> lock(m_mutex); // We must create the proxy config service on the UI loop on Linux because it // must synchronously run on the glib message loop. This will be passed to // the URLRequestContextStorage on the IO thread in GetURLRequestContext(). @@ -657,7 +658,7 @@ void ProfileIODataQt::updateStorageSettings() { Q_ASSERT(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); - QMutexLocker lock(&m_mutex); + const std::lock_guard<QRecursiveMutex> lock(m_mutex); setFullConfiguration(); base::Token groupId = content::BrowserContext::GetServiceInstanceGroupFor(m_profile); @@ -672,7 +673,7 @@ void ProfileIODataQt::updateStorageSettings() void ProfileIODataQt::updateCookieStore() { Q_ASSERT(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); - QMutexLocker lock(&m_mutex); + const std::lock_guard<QRecursiveMutex> lock(m_mutex); m_persistentCookiesPolicy = m_profileAdapter->persistentCookiesPolicy(); m_cookiesPath = m_profileAdapter->cookiesPath(); if (!m_pendingStorageRequestGeneration) @@ -682,7 +683,7 @@ void ProfileIODataQt::updateCookieStore() void ProfileIODataQt::updateUserAgent() { Q_ASSERT(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); - QMutexLocker lock(&m_mutex); + const std::lock_guard<QRecursiveMutex> lock(m_mutex); m_httpAcceptLanguage = m_profileAdapter->httpAcceptLanguage(); m_httpUserAgent = m_profileAdapter->httpUserAgent(); if (!m_pendingStorageRequestGeneration) @@ -692,7 +693,7 @@ void ProfileIODataQt::updateUserAgent() void ProfileIODataQt::updateHttpCache() { Q_ASSERT(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); - QMutexLocker lock(&m_mutex); + const std::lock_guard<QRecursiveMutex> lock(m_mutex); m_httpCacheType = m_profileAdapter->httpCacheType(); m_httpCachePath = m_profileAdapter->httpCachePath(); m_httpCacheMaxSize = m_profileAdapter->httpCacheMaxSize(); @@ -716,7 +717,7 @@ void ProfileIODataQt::updateHttpCache() void ProfileIODataQt::updateJobFactory() { Q_ASSERT(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); - QMutexLocker lock(&m_mutex); + const std::lock_guard<QRecursiveMutex> lock(m_mutex); m_customUrlSchemes = m_profileAdapter->customUrlSchemes(); @@ -730,7 +731,7 @@ void ProfileIODataQt::updateJobFactory() void ProfileIODataQt::updateRequestInterceptor() { Q_ASSERT(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); - QMutexLocker lock(&m_mutex); + const std::lock_guard<QRecursiveMutex> lock(m_mutex); m_requestInterceptor = m_profileAdapter->requestInterceptor(); m_hasPageInterceptors = m_profileAdapter->hasPageRequestInterceptor(); // We in this case do not need to regenerate any Chromium classes. @@ -772,7 +773,7 @@ bool ProfileIODataQt::canGetCookies(const QUrl &firstPartyUrl, const QUrl &url) void ProfileIODataQt::updateUsedForGlobalCertificateVerification() { Q_ASSERT(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); - QMutexLocker lock(&m_mutex); + const std::lock_guard<QRecursiveMutex> lock(m_mutex); m_useForGlobalCertificateVerification = m_profileAdapter->isUsedForGlobalCertificateVerification(); if (m_useForGlobalCertificateVerification) diff --git a/src/core/profile_io_data_qt.h b/src/core/profile_io_data_qt.h index f2dc67f44..4a5b9f77d 100644 --- a/src/core/profile_io_data_qt.h +++ b/src/core/profile_io_data_qt.h @@ -177,7 +177,12 @@ private: QList<QByteArray> m_customUrlSchemes; QList<QByteArray> m_installedCustomSchemes; QWebEngineUrlRequestInterceptor* m_requestInterceptor = nullptr; - QMutex m_mutex; +#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) + QMutex m_mutex{QMutex::Recursive}; + using QRecursiveMutex = QMutex; +#else + QRecursiveMutex m_mutex; +#endif int m_httpCacheMaxSize = 0; bool m_initialized = false; bool m_updateAllStorage = false; diff --git a/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp b/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp index 8b75067ee..dd059791d 100644 --- a/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp +++ b/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp @@ -40,6 +40,8 @@ #include <QtWebEngineWidgets/qwebengineview.h> #include <QtWebEngineWidgets/qwebenginedownloaditem.h> +#include <mutex> + class tst_QWebEngineProfile : public QObject { Q_OBJECT @@ -255,18 +257,18 @@ public: bool isSequential() const override { return true; } qint64 bytesAvailable() const override { - QMutexLocker lock(&m_mutex); + const std::lock_guard<QRecursiveMutex> lock(m_mutex); return m_bytesAvailable; } bool atEnd() const override { - QMutexLocker lock(&m_mutex); + const std::lock_guard<QRecursiveMutex> lock(m_mutex); return (m_data.size() >= 1000 && m_bytesRead >= 1000); } protected: void timerEvent(QTimerEvent *) override { - QMutexLocker lock(&m_mutex); + const std::lock_guard<QRecursiveMutex> lock(m_mutex); m_bytesAvailable += 200; m_data.append(200, 'c'); emit readyRead(); @@ -278,7 +280,7 @@ protected: qint64 readData(char *data, qint64 maxlen) override { - QMutexLocker lock(&m_mutex); + const std::lock_guard<QRecursiveMutex> lock(m_mutex); qint64 len = qMin(qint64(m_bytesAvailable), maxlen); if (len) { memcpy(data, m_data.constData() + m_bytesRead, len); @@ -295,7 +297,12 @@ protected: } private: - mutable QMutex m_mutex{QMutex::Recursive}; +#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) + mutable QMutex m_mutex{QMutex::Recursive} + using QRecursiveMutex = QMutex; +#else + mutable QRecursiveMutex m_mutex; +#endif QByteArray m_data; QBasicTimer m_timer; int m_bytesRead; |