diff options
author | Benjamin C Meyer <ben@meyerhome.net> | 2009-09-01 07:51:56 (GMT) |
---|---|---|
committer | Thiago Macieira <thiago.macieira@nokia.com> | 2009-09-01 08:32:11 (GMT) |
commit | 925912ebf552417306a5bd20fd986afda6a582be (patch) | |
tree | d459905a04f1540fef8569d03417647c95a98ef4 /src/network/access/qnetworkreplyimpl.cpp | |
parent | 63e2f5d2c95ece21fd32d0690022b89c38fee865 (diff) | |
download | Qt-925912ebf552417306a5bd20fd986afda6a582be.zip Qt-925912ebf552417306a5bd20fd986afda6a582be.tar.gz Qt-925912ebf552417306a5bd20fd986afda6a582be.tar.bz2 |
QNetworkAccessManager can delete the QAbstractNetworkCache pointer at
any point. Rather then keep a separate pointer to the cache in the
reply use the pointer kept by the manager so the reply never tries
to access a cache pointer that has already been deleted.
Autotest: included
Merge-request: 1124
Reviewed-by: Thiago Macieira <thiago.macieira@nokia.com>
Diffstat (limited to 'src/network/access/qnetworkreplyimpl.cpp')
-rw-r--r-- | src/network/access/qnetworkreplyimpl.cpp | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/src/network/access/qnetworkreplyimpl.cpp b/src/network/access/qnetworkreplyimpl.cpp index c37c66d..c805d59 100644 --- a/src/network/access/qnetworkreplyimpl.cpp +++ b/src/network/access/qnetworkreplyimpl.cpp @@ -53,7 +53,7 @@ QT_BEGIN_NAMESPACE inline QNetworkReplyImplPrivate::QNetworkReplyImplPrivate() : backend(0), outgoingData(0), - copyDevice(0), networkCache(0), + copyDevice(0), cacheEnabled(false), cacheSaveDevice(0), notificationHandlingPaused(false), bytesDownloaded(0), lastBytesDownloaded(-1), bytesUploaded(-1), @@ -203,11 +203,6 @@ void QNetworkReplyImplPrivate::setup(QNetworkAccessManager::Operation op, const QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection); } -void QNetworkReplyImplPrivate::setNetworkCache(QAbstractNetworkCache *nc) -{ - networkCache = nc; -} - void QNetworkReplyImplPrivate::backendNotify(InternalNotifications notification) { Q_Q(QNetworkReplyImpl); @@ -277,17 +272,27 @@ void QNetworkReplyImplPrivate::resumeNotificationHandling() QCoreApplication::postEvent(q, new QEvent(QEvent::NetworkReplyUpdated)); } +QAbstractNetworkCache *QNetworkReplyImplPrivate::networkCache() const +{ + if (!backend) + return 0; + return backend->networkCache(); +} + void QNetworkReplyImplPrivate::createCache() { // check if we can save and if we're allowed to - if (!networkCache || !request.attribute(QNetworkRequest::CacheSaveControlAttribute, true).toBool()) + if (!networkCache() + || request.attribute(QNetworkRequest::CacheLoadControlAttribute, + QNetworkRequest::PreferNetwork).toInt() + == QNetworkRequest::AlwaysNetwork) return; cacheEnabled = true; } bool QNetworkReplyImplPrivate::isCachingEnabled() const { - return (cacheEnabled && networkCache != 0); + return (cacheEnabled && networkCache() != 0); } void QNetworkReplyImplPrivate::setCachingEnabled(bool enable) @@ -311,7 +316,7 @@ void QNetworkReplyImplPrivate::setCachingEnabled(bool enable) qDebug("QNetworkReplyImpl: setCachingEnabled(true) called after setCachingEnabled(false) -- " "backend %s probably needs to be fixed", backend->metaObject()->className()); - networkCache->remove(url); + networkCache()->remove(url); cacheSaveDevice = 0; cacheEnabled = false; } @@ -320,9 +325,9 @@ void QNetworkReplyImplPrivate::setCachingEnabled(bool enable) void QNetworkReplyImplPrivate::completeCacheSave() { if (cacheEnabled && errorCode != QNetworkReplyImpl::NoError) { - networkCache->remove(url); + networkCache()->remove(url); } else if (cacheEnabled && cacheSaveDevice) { - networkCache->insert(cacheSaveDevice); + networkCache()->insert(cacheSaveDevice); } cacheSaveDevice = 0; cacheEnabled = false; @@ -385,15 +390,15 @@ void QNetworkReplyImplPrivate::feed(const QByteArray &data) metaData.setAttributes(attributes); } - cacheSaveDevice = networkCache->prepare(metaData); + cacheSaveDevice = networkCache()->prepare(metaData); if (!cacheSaveDevice || (cacheSaveDevice && !cacheSaveDevice->isOpen())) { if (cacheSaveDevice && !cacheSaveDevice->isOpen()) qCritical("QNetworkReplyImpl: network cache returned a device that is not open -- " "class %s probably needs to be fixed", - networkCache->metaObject()->className()); + networkCache()->metaObject()->className()); - networkCache->remove(url); + networkCache()->remove(url); cacheSaveDevice = 0; cacheEnabled = false; } @@ -524,7 +529,7 @@ QNetworkReplyImpl::~QNetworkReplyImpl() { Q_D(QNetworkReplyImpl); if (d->isCachingEnabled()) - d->networkCache->remove(url()); + d->networkCache()->remove(url()); } void QNetworkReplyImpl::abort() |