diff options
author | Szabolcs David <davidsz@inf.u-szeged.hu> | 2016-01-26 06:29:48 -0800 |
---|---|---|
committer | Szabolcs David <davidsz@inf.u-szeged.hu> | 2016-01-27 23:25:20 +0000 |
commit | d86feb3afcaacd57e3d661b969db173dea075f96 (patch) | |
tree | e4b58591849936890fc866c5ec848110efa6bd22 | |
parent | 2d3a5c7a4e78cdbd973416ea8fdaea6e2fb4ddb7 (diff) |
Extend HttpCacheType with NoCache option
Add option to disable cache with passing NULL as cache backend.
It behaves the same way as using HttpCache::set_mode(DISABLE), but
saves some memory without instantiating backend factory.
Change-Id: I1565cc773eda21a6bc73eebe14ab8046252a7755
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@theqtcompany.com>
-rw-r--r-- | src/core/browser_context_adapter.h | 3 | ||||
-rw-r--r-- | src/core/url_request_context_getter_qt.cpp | 3 | ||||
-rw-r--r-- | src/webengine/api/qquickwebengineprofile.cpp | 2 | ||||
-rw-r--r-- | src/webengine/api/qquickwebengineprofile.h | 3 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebengineprofile.cpp | 1 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebengineprofile.h | 3 | ||||
-rw-r--r-- | tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp | 33 |
7 files changed, 45 insertions, 3 deletions
diff --git a/src/core/browser_context_adapter.h b/src/core/browser_context_adapter.h index ee913b8cb..4fe8c63ae 100644 --- a/src/core/browser_context_adapter.h +++ b/src/core/browser_context_adapter.h @@ -107,7 +107,8 @@ public: // KEEP IN SYNC with API or add mapping layer enum HttpCacheType { MemoryHttpCache = 0, - DiskHttpCache + DiskHttpCache, + NoCache }; enum PersistentCookiesPolicy { diff --git a/src/core/url_request_context_getter_qt.cpp b/src/core/url_request_context_getter_qt.cpp index ed3378b21..d5d776732 100644 --- a/src/core/url_request_context_getter_qt.cpp +++ b/src/core/url_request_context_getter_qt.cpp @@ -368,6 +368,9 @@ void URLRequestContextGetterQt::generateHttpCache() BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE) ); break; + case BrowserContextAdapter::NoCache: + // It's safe to not create BackendFactory. + break; } net::HttpCache *cache = 0; diff --git a/src/webengine/api/qquickwebengineprofile.cpp b/src/webengine/api/qquickwebengineprofile.cpp index 523121b6f..7800d1bb0 100644 --- a/src/webengine/api/qquickwebengineprofile.cpp +++ b/src/webengine/api/qquickwebengineprofile.cpp @@ -448,6 +448,8 @@ void QQuickWebEngineProfile::setHttpUserAgent(const QString &userAgent) no persistentStoragePath is available. \value DiskHttpCache Uses a disk cache. This is the default value. + \value NoCache + Disables caching. */ /*! diff --git a/src/webengine/api/qquickwebengineprofile.h b/src/webengine/api/qquickwebengineprofile.h index 7905e5d29..11d6564c7 100644 --- a/src/webengine/api/qquickwebengineprofile.h +++ b/src/webengine/api/qquickwebengineprofile.h @@ -74,7 +74,8 @@ public: enum HttpCacheType { MemoryHttpCache, - DiskHttpCache + DiskHttpCache, + NoCache }; Q_ENUM(HttpCacheType) diff --git a/src/webenginewidgets/api/qwebengineprofile.cpp b/src/webenginewidgets/api/qwebengineprofile.cpp index c64a883d3..3d423946f 100644 --- a/src/webenginewidgets/api/qwebengineprofile.cpp +++ b/src/webenginewidgets/api/qwebengineprofile.cpp @@ -81,6 +81,7 @@ using QtWebEngineCore::BrowserContextAdapter; \value MemoryHttpCache Use an in-memory cache. This is the only setting possible if \c off-the-record is set or no cache path is available. \value DiskHttpCache Use a disk cache. This is the default. + \value NoCache Disable both in-memory and disk caching. */ /*! diff --git a/src/webenginewidgets/api/qwebengineprofile.h b/src/webenginewidgets/api/qwebengineprofile.h index 4b37a7d73..bd0687b2d 100644 --- a/src/webenginewidgets/api/qwebengineprofile.h +++ b/src/webenginewidgets/api/qwebengineprofile.h @@ -66,7 +66,8 @@ public: enum HttpCacheType { MemoryHttpCache, - DiskHttpCache + DiskHttpCache, + NoCache }; enum PersistentCookiesPolicy { diff --git a/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp b/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp index d24a43b41..93e93cb92 100644 --- a/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp +++ b/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp @@ -47,6 +47,7 @@ private Q_SLOTS: void defaultProfile(); void profileConstructors(); void clearDataFromCache(); + void disableCache(); }; void tst_QWebEngineProfile::defaultProfile() @@ -112,5 +113,37 @@ void tst_QWebEngineProfile::clearDataFromCache() cacheDir.removeRecursively(); } +void tst_QWebEngineProfile::disableCache() +{ + QWebEnginePage page; + QDir cacheDir("./tst_QWebEngineProfile_cacheDir"); + if (cacheDir.exists()) + cacheDir.removeRecursively(); + cacheDir.mkpath(cacheDir.path()); + + QWebEngineProfile *profile = page.profile(); + profile->setCachePath(cacheDir.path()); + QVERIFY(!cacheDir.entryList().contains("Cache")); + + profile->setHttpCacheType(QWebEngineProfile::NoCache); + QSignalSpy loadFinishedSpy(&page, SIGNAL(loadFinished(bool))); + page.load(QUrl("http://qt-project.org")); + if (!loadFinishedSpy.wait(10000) || !loadFinishedSpy.at(0).at(0).toBool()) + QSKIP("Couldn't load page from network, skipping test."); + + cacheDir.refresh(); + QVERIFY(!cacheDir.entryList().contains("Cache")); + + profile->setHttpCacheType(QWebEngineProfile::DiskHttpCache); + page.load(QUrl("http://qt-project.org")); + if (!loadFinishedSpy.wait(10000) || !loadFinishedSpy.at(1).at(0).toBool()) + QSKIP("Couldn't load page from network, skipping test."); + + cacheDir.refresh(); + QVERIFY(cacheDir.entryList().contains("Cache")); + + cacheDir.removeRecursively(); +} + QTEST_MAIN(tst_QWebEngineProfile) #include "tst_qwebengineprofile.moc" |