summaryrefslogtreecommitdiffstats
path: root/tools/qml/qmlruntime.cpp
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2010-03-18 01:16:53 (GMT)
committerMartin Jones <martin.jones@nokia.com>2010-03-18 01:16:53 (GMT)
commitad49a46304c4b74ebc7dea8f314b89bc6aef63a3 (patch)
tree023458a017cdc24599f3ceca9cbb240c3fad7f6c /tools/qml/qmlruntime.cpp
parent4b4e9be3ea5a267c8fc05d6ff5aca972d64eb705 (diff)
downloadQt-ad49a46304c4b74ebc7dea8f314b89bc6aef63a3.zip
Qt-ad49a46304c4b74ebc7dea8f314b89bc6aef63a3.tar.gz
Qt-ad49a46304c4b74ebc7dea8f314b89bc6aef63a3.tar.bz2
Don't destroy cookie jar until while someone may be using it.
Diffstat (limited to 'tools/qml/qmlruntime.cpp')
-rw-r--r--tools/qml/qmlruntime.cpp58
1 files changed, 34 insertions, 24 deletions
diff --git a/tools/qml/qmlruntime.cpp b/tools/qml/qmlruntime.cpp
index c7acf2c..6660947 100644
--- a/tools/qml/qmlruntime.cpp
+++ b/tools/qml/qmlruntime.cpp
@@ -351,30 +351,10 @@ private:
class NetworkAccessManagerFactory : public QDeclarativeNetworkAccessManagerFactory
{
public:
- NetworkAccessManagerFactory() : cookieJar(0), cacheSize(0) {}
- ~NetworkAccessManagerFactory() {
- delete cookieJar;
- }
+ NetworkAccessManagerFactory() : cacheSize(0) {}
+ ~NetworkAccessManagerFactory() {}
- QNetworkAccessManager *create(QObject *parent) {
- QMutexLocker lock(&mutex);
- QNetworkAccessManager *manager = new QNetworkAccessManager(parent);
- if (!cookieJar)
- cookieJar = new PersistentCookieJar(0);
- manager->setCookieJar(cookieJar);
- cookieJar->setParent(0);
- setupProxy(manager);
- if (cacheSize > 0) {
- QNetworkDiskCache *cache = new QNetworkDiskCache;
- cache->setCacheDirectory(QDir::tempPath()+QLatin1String("/qml-duiviewer-network-cache"));
- cache->setMaximumCacheSize(cacheSize);
- manager->setCache(cache);
- } else {
- manager->setCache(0);
- }
- qDebug() << "created new network access manager for" << parent;
- return manager;
- }
+ QNetworkAccessManager *create(QObject *parent);
void setupProxy(QNetworkAccessManager *nam)
{
@@ -419,11 +399,41 @@ public:
}
}
- PersistentCookieJar *cookieJar;
+ static PersistentCookieJar *cookieJar;
QMutex mutex;
int cacheSize;
};
+PersistentCookieJar *NetworkAccessManagerFactory::cookieJar = 0;
+
+static void cleanup_cookieJar()
+{
+ delete NetworkAccessManagerFactory::cookieJar;
+ NetworkAccessManagerFactory::cookieJar = 0;
+}
+
+QNetworkAccessManager *NetworkAccessManagerFactory::create(QObject *parent)
+{
+ QMutexLocker lock(&mutex);
+ QNetworkAccessManager *manager = new QNetworkAccessManager(parent);
+ if (!cookieJar) {
+ qAddPostRoutine(cleanup_cookieJar);
+ cookieJar = new PersistentCookieJar(0);
+ }
+ manager->setCookieJar(cookieJar);
+ cookieJar->setParent(0);
+ setupProxy(manager);
+ if (cacheSize > 0) {
+ QNetworkDiskCache *cache = new QNetworkDiskCache;
+ cache->setCacheDirectory(QDir::tempPath()+QLatin1String("/qml-duiviewer-network-cache"));
+ cache->setMaximumCacheSize(cacheSize);
+ manager->setCache(cache);
+ } else {
+ manager->setCache(0);
+ }
+ qDebug() << "created new network access manager for" << parent;
+ return manager;
+}
QString QDeclarativeViewer::getVideoFileName()
{