History

more work on proper threading of ScriptEngine

Brad Hefta-Gaub committed 11 years ago

Commit a3c02881 parent 18fbf896 files · +151 −116Browse files

Showing the changes to libraries/script-engine/src/ScriptCache.cpp (1 of 6 files). Show all

Unified · Split

libraries/script-engine/src/ScriptCache.cpp+15−2
@@ -15,6 +15,7 @@ · 14 unmodified lines
15#include <QNetworkConfiguration>15#include <QNetworkConfiguration>
16#include <QNetworkReply>16#include <QNetworkReply>
17#include <QObject>17#include <QObject>
18#include <QThread>
18 19
19#include <assert.h>20#include <assert.h>
20#include <SharedUtil.h>21#include <SharedUtil.h>
@@ -42,7 +43,7 @@ QString ScriptCache::getScript(const QUrl& unnormalizedURL, ScriptUser* scriptUs · 21 unmodified lines
42 if (alreadyWaiting) {43 if (alreadyWaiting) {
43 qCDebug(scriptengine) << "Already downloading script at:" << url.toString();44 qCDebug(scriptengine) << "Already downloading script at:" << url.toString();
44 } else {45 } else {
45 auto request = ResourceManager::createResourceRequest(this, url);46 auto request = ResourceManager::createResourceRequest(nullptr, url);
46 request->setCacheEnabled(!reload);47 request->setCacheEnabled(!reload);
47 connect(request, &ResourceRequest::finished, this, &ScriptCache::scriptDownloaded);48 connect(request, &ResourceRequest::finished, this, &ScriptCache::scriptDownloaded);
48 request->send();49 request->send();
@@ -82,6 +83,9 @@ void ScriptCache::scriptDownloaded() { · 33 unmodified lines
82}83}
83 84
84void ScriptCache::getScriptContents(const QString& scriptOrURL, contentAvailableCallback contentAvailable, bool forceDownload) {85void ScriptCache::getScriptContents(const QString& scriptOrURL, contentAvailableCallback contentAvailable, bool forceDownload) {
86 #ifdef THREAD_DEBUGGING
87 qCDebug(scriptengine) << "ScriptCache::getScriptContents() on thread [" << QThread::currentThread() << "] expected thread [" << thread() << "]";
88 #endif
85 QUrl unnormalizedURL(scriptOrURL);89 QUrl unnormalizedURL(scriptOrURL);
86 QUrl url = ResourceManager::normalizeURL(unnormalizedURL);90 QUrl url = ResourceManager::normalizeURL(unnormalizedURL);
87 91
@@ -93,6 +97,9 @@ void ScriptCache::getScriptContents(const QString& scriptOrURL, contentAvailable · 5 unmodified lines
93 97
94 if (_scriptCache.contains(url) && !forceDownload) {98 if (_scriptCache.contains(url) && !forceDownload) {
95 qCDebug(scriptengine) << "Found script in cache:" << url.toString();99 qCDebug(scriptengine) << "Found script in cache:" << url.toString();
100 #if 1 // def THREAD_DEBUGGING
101 qCDebug(scriptengine) << "ScriptCache::getScriptContents() about to call contentAvailable() on thread [" << QThread::currentThread() << "] expected thread [" << thread() << "]";
102 #endif
96 contentAvailable(url.toString(), _scriptCache[url], true, true);103 contentAvailable(url.toString(), _scriptCache[url], true, true);
97 } else {104 } else {
98 bool alreadyWaiting = _contentCallbacks.contains(url);105 bool alreadyWaiting = _contentCallbacks.contains(url);
@@ -101,7 +108,10 @@ void ScriptCache::getScriptContents(const QString& scriptOrURL, contentAvailable · 2 unmodified lines
101 if (alreadyWaiting) {108 if (alreadyWaiting) {
102 qCDebug(scriptengine) << "Already downloading script at:" << url.toString();109 qCDebug(scriptengine) << "Already downloading script at:" << url.toString();
103 } else {110 } else {
104 auto request = ResourceManager::createResourceRequest(this, url);111 #ifdef THREAD_DEBUGGING
112 qCDebug(scriptengine) << "about to call: ResourceManager::createResourceRequest(this, url); on thread [" << QThread::currentThread() << "] expected thread [" << thread() << "]";
113 #endif
114 auto request = ResourceManager::createResourceRequest(nullptr, url);
105 request->setCacheEnabled(!forceDownload);115 request->setCacheEnabled(!forceDownload);
106 connect(request, &ResourceRequest::finished, this, &ScriptCache::scriptContentAvailable);116 connect(request, &ResourceRequest::finished, this, &ScriptCache::scriptContentAvailable);
107 request->send();117 request->send();
@@ -110,6 +120,9 @@ void ScriptCache::getScriptContents(const QString& scriptOrURL, contentAvailable · 2 unmodified lines
110}120}
111 121
112void ScriptCache::scriptContentAvailable() {122void ScriptCache::scriptContentAvailable() {
123 #ifdef THREAD_DEBUGGING
124 qCDebug(scriptengine) << "ScriptCache::scriptContentAvailable() on thread [" << QThread::currentThread() << "] expected thread [" << thread() << "]";
125 #endif
113 ResourceRequest* req = qobject_cast<ResourceRequest*>(sender());126 ResourceRequest* req = qobject_cast<ResourceRequest*>(sender());
114 QUrl url = req->getUrl();127 QUrl url = req->getUrl();
115 QList<contentAvailableCallback> allCallbacks = _contentCallbacks.values(url);128 QList<contentAvailableCallback> allCallbacks = _contentCallbacks.values(url);