summaryrefslogtreecommitdiffstats
path: root/src/network/access
diff options
context:
space:
mode:
authorMarkus Goetz <Markus.Goetz@nokia.com>2010-11-08 16:23:27 (GMT)
committerMarkus Goetz <Markus.Goetz@nokia.com>2010-11-08 16:39:19 (GMT)
commita98b9daa4cd1341ee0ce6d2cf859666db9ebda59 (patch)
tree2f5b5e83529311604aaf80d570879faef92cd648 /src/network/access
parent626f13421baf258407f03e3bf21ed67138d55ea4 (diff)
downloadQt-a98b9daa4cd1341ee0ce6d2cf859666db9ebda59.zip
Qt-a98b9daa4cd1341ee0ce6d2cf859666db9ebda59.tar.gz
Qt-a98b9daa4cd1341ee0ce6d2cf859666db9ebda59.tar.bz2
QNAM: Do not need QNetworkSession in AlwaysCache load mode
Move the creation code to the top of QNAM::createRequest() to avoid setting up a QNetworkSession when it is not needed. Reviewed-by: ogoffart
Diffstat (limited to 'src/network/access')
-rw-r--r--src/network/access/qnetworkaccessbackend.cpp12
-rw-r--r--src/network/access/qnetworkaccessmanager.cpp21
2 files changed, 21 insertions, 12 deletions
diff --git a/src/network/access/qnetworkaccessbackend.cpp b/src/network/access/qnetworkaccessbackend.cpp
index 0a0987a..05eb6cb 100644
--- a/src/network/access/qnetworkaccessbackend.cpp
+++ b/src/network/access/qnetworkaccessbackend.cpp
@@ -88,18 +88,6 @@ QNetworkAccessBackendFactory::~QNetworkAccessBackendFactory()
QNetworkAccessBackend *QNetworkAccessManagerPrivate::findBackend(QNetworkAccessManager::Operation op,
const QNetworkRequest &request)
{
- QNetworkRequest::CacheLoadControl mode =
- static_cast<QNetworkRequest::CacheLoadControl>(
- request.attribute(QNetworkRequest::CacheLoadControlAttribute,
- QNetworkRequest::PreferNetwork).toInt());
- if (mode == QNetworkRequest::AlwaysCache
- && (op == QNetworkAccessManager::GetOperation
- || op == QNetworkAccessManager::HeadOperation)) {
- QNetworkAccessBackend *backend = new QNetworkAccessCacheBackend;
- backend->manager = this;
- return backend;
- }
-
if (!factoryDataShutdown) {
QMutexLocker locker(&factoryData()->mutex);
QNetworkAccessBackendFactoryData::ConstIterator it = factoryData()->constBegin(),
diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp
index e5f4d5a..effd79e 100644
--- a/src/network/access/qnetworkaccessmanager.cpp
+++ b/src/network/access/qnetworkaccessmanager.cpp
@@ -54,6 +54,7 @@
#include "qnetworkaccessfilebackend_p.h"
#include "qnetworkaccessdatabackend_p.h"
#include "qnetworkaccessdebugpipebackend_p.h"
+#include "qnetworkaccesscachebackend_p.h"
#include "qfilenetworkreply_p.h"
#include "QtCore/qbuffer.h"
@@ -970,6 +971,26 @@ QNetworkReply *QNetworkAccessManager::createRequest(QNetworkAccessManager::Opera
return new QFileNetworkReply(this, req, op);
}
+ // A request with QNetworkRequest::AlwaysCache does not need any bearer management
+ QNetworkRequest::CacheLoadControl mode =
+ static_cast<QNetworkRequest::CacheLoadControl>(
+ req.attribute(QNetworkRequest::CacheLoadControlAttribute,
+ QNetworkRequest::PreferNetwork).toInt());
+ if (mode == QNetworkRequest::AlwaysCache
+ && (op == QNetworkAccessManager::GetOperation
+ || op == QNetworkAccessManager::HeadOperation)) {
+ // FIXME Implement a QNetworkReplyCacheImpl instead, see QTBUG-15106
+ QNetworkReplyImpl *reply = new QNetworkReplyImpl(this);
+ QNetworkReplyImplPrivate *priv = reply->d_func();
+ priv->manager = this;
+ priv->backend = new QNetworkAccessCacheBackend();
+ priv->backend->manager = this->d_func();
+ priv->backend->setParent(reply);
+ priv->backend->reply = priv;
+ priv->setup(op, req, outgoingData);
+ return reply;
+ }
+
#ifndef QT_NO_BEARERMANAGEMENT
// Return a disabled network reply if network access is disabled.
// Except if the scheme is empty or file://.