Changeset 225481 in webkit
- Timestamp:
- Dec 4, 2017 10:13:45 AM (6 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r225480 r225481 1 2017-12-04 Youenn Fablet <youenn@apple.com> 2 3 WorkerCacheStorageConnection should handle the case of terminated workers 4 https://bugs.webkit.org/show_bug.cgi?id=180304 5 6 Reviewed by Chris Dumez. 7 8 No web page observable change of behavior. 9 10 Reworked WorkerCacheStorageConnection hopping. 11 Instead of refing/unrefing itself, it refs the worker thread and the main thread connection. 12 This worker thread is then used on the way back from the main thread. 13 14 * Modules/cache/WorkerCacheStorageConnection.cpp: 15 (WebCore::WorkerCacheStorageConnection::create): 16 (WebCore::WorkerCacheStorageConnection::WorkerCacheStorageConnection): 17 (WebCore::WorkerCacheStorageConnection::doOpen): 18 (WebCore::WorkerCacheStorageConnection::doRemove): 19 (WebCore::WorkerCacheStorageConnection::doRetrieveCaches): 20 (WebCore::WorkerCacheStorageConnection::reference): 21 (WebCore::WorkerCacheStorageConnection::dereference): 22 (WebCore::WorkerCacheStorageConnection::doRetrieveRecords): 23 (WebCore::WorkerCacheStorageConnection::doBatchDeleteOperation): 24 (WebCore::WorkerCacheStorageConnection::doBatchPutOperation): 25 * Modules/cache/WorkerCacheStorageConnection.h: 26 * workers/WorkerGlobalScope.cpp: 27 (WebCore::WorkerGlobalScope::cacheStorageConnection): 28 * workers/WorkerGlobalScope.h: 29 1 30 2017-12-04 Frederic Wang <fwang@igalia.com> 2 31 -
trunk/Source/WebCore/Modules/cache/WorkerCacheStorageConnection.cpp
r223935 r225481 92 92 { 93 93 auto connection = adoptRef(*new WorkerCacheStorageConnection(scope)); 94 callOnMainThread ([protectedConnection = connection.copyRef()]() mutable {95 ASSERT(isMainThread());96 protectedConnection->m_mainThreadConnection = protectedConnection->m_proxy.createCacheStorageConnection();97 });94 callOnMainThreadAndWait([workerThread = makeRef(scope.thread()), connection = connection.ptr()]() mutable { 95 connection->m_mainThreadConnection = workerThread->workerLoaderProxy().createCacheStorageConnection(); 96 }); 97 ASSERT(connection->m_mainThreadConnection); 98 98 return connection; 99 99 } … … 101 101 WorkerCacheStorageConnection::WorkerCacheStorageConnection(WorkerGlobalScope& scope) 102 102 : m_scope(scope) 103 , m_proxy(m_scope.thread().workerLoaderProxy())104 , m_taskMode(WorkerRunLoop::defaultMode().isolatedCopy())105 103 { 106 104 } … … 114 112 void WorkerCacheStorageConnection::doOpen(uint64_t requestIdentifier, const String& origin, const String& cacheName) 115 113 { 116 callOnMainThread([this, protectedThis = makeRef(*this), requestIdentifier, origin = origin.isolatedCopy(), cacheName = cacheName.isolatedCopy()]() mutable { 117 ASSERT(isMainThread()); 118 ASSERT(m_mainThreadConnection); 119 120 m_mainThreadConnection->open(origin, cacheName, [this, protectedThis = WTFMove(protectedThis), requestIdentifier](const CacheIdentifierOrError& result) mutable { 121 m_proxy.postTaskForModeToWorkerGlobalScope([this, protectedThis = WTFMove(protectedThis), requestIdentifier, result](ScriptExecutionContext& context) mutable { 122 ASSERT_UNUSED(context, context.isWorkerGlobalScope()); 123 openCompleted(requestIdentifier, result); 124 }, m_taskMode); 114 callOnMainThread([workerThread = makeRef(m_scope.thread()), mainThreadConnection = m_mainThreadConnection, requestIdentifier, origin = origin.isolatedCopy(), cacheName = cacheName.isolatedCopy()] () mutable { 115 mainThreadConnection->open(origin, cacheName, [workerThread = WTFMove(workerThread), requestIdentifier] (const CacheIdentifierOrError& result) mutable { 116 workerThread->runLoop().postTaskForMode([requestIdentifier, result] (auto& scope) mutable { 117 downcast<WorkerGlobalScope>(scope).cacheStorageConnection().openCompleted(requestIdentifier, result); 118 }, WorkerRunLoop::defaultMode()); 125 119 }); 126 120 }); … … 129 123 void WorkerCacheStorageConnection::doRemove(uint64_t requestIdentifier, uint64_t cacheIdentifier) 130 124 { 131 callOnMainThread([this, protectedThis = makeRef(*this), requestIdentifier, cacheIdentifier]() mutable { 132 ASSERT(isMainThread()); 133 ASSERT(m_mainThreadConnection); 134 135 m_mainThreadConnection->remove(cacheIdentifier, [this, protectedThis = WTFMove(protectedThis), requestIdentifier, cacheIdentifier](const CacheIdentifierOrError& result) mutable { 125 callOnMainThread([workerThread = makeRef(m_scope.thread()), mainThreadConnection = m_mainThreadConnection, requestIdentifier, cacheIdentifier] () mutable { 126 mainThreadConnection->remove(cacheIdentifier, [workerThread = WTFMove(workerThread), requestIdentifier, cacheIdentifier] (const CacheIdentifierOrError& result) mutable { 136 127 ASSERT_UNUSED(cacheIdentifier, !result.hasValue() || result.value().identifier == cacheIdentifier); 137 m_proxy.postTaskForModeToWorkerGlobalScope([this, protectedThis = WTFMove(protectedThis), requestIdentifier, result](ScriptExecutionContext& context) mutable { 138 ASSERT_UNUSED(context, context.isWorkerGlobalScope()); 139 removeCompleted(requestIdentifier, result); 140 }, m_taskMode); 128 workerThread->runLoop().postTaskForMode([requestIdentifier, result] (auto& scope) mutable { 129 downcast<WorkerGlobalScope>(scope).cacheStorageConnection().removeCompleted(requestIdentifier, result); 130 }, WorkerRunLoop::defaultMode()); 141 131 }); 142 132 }); … … 145 135 void WorkerCacheStorageConnection::doRetrieveCaches(uint64_t requestIdentifier, const String& origin, uint64_t updateCounter) 146 136 { 147 callOnMainThread([this, protectedThis = makeRef(*this), requestIdentifier, origin = origin.isolatedCopy(), updateCounter]() mutable { 148 ASSERT(isMainThread()); 149 ASSERT(m_mainThreadConnection); 150 151 m_mainThreadConnection->retrieveCaches(origin, updateCounter, [this, protectedThis = WTFMove(protectedThis), requestIdentifier](CacheInfosOrError&& result) mutable { 137 callOnMainThread([workerThread = makeRef(m_scope.thread()), mainThreadConnection = m_mainThreadConnection, requestIdentifier, origin = origin.isolatedCopy(), updateCounter] () mutable { 138 mainThreadConnection->retrieveCaches(origin, updateCounter, [workerThread = WTFMove(workerThread), requestIdentifier] (CacheInfosOrError&& result) mutable { 152 139 CacheInfosOrError isolatedResult; 153 140 if (!result.hasValue()) … … 156 143 isolatedResult = result.value().isolatedCopy(); 157 144 158 m_proxy.postTaskForModeToWorkerGlobalScope([this, protectedThis = WTFMove(protectedThis), requestIdentifier, result = WTFMove(isolatedResult)](ScriptExecutionContext& context) mutable { 159 ASSERT_UNUSED(context, context.isWorkerGlobalScope()); 160 updateCaches(requestIdentifier, WTFMove(result)); 161 }, m_taskMode); 145 workerThread->runLoop().postTaskForMode([requestIdentifier, result = WTFMove(isolatedResult)] (auto& scope) mutable { 146 downcast<WorkerGlobalScope>(scope).cacheStorageConnection().updateCaches(requestIdentifier, WTFMove(result)); 147 }, WorkerRunLoop::defaultMode()); 162 148 }); 163 149 }); … … 166 152 void WorkerCacheStorageConnection::reference(uint64_t cacheIdentifier) 167 153 { 168 callOnMainThread([this, protectedThis = makeRef(*this), cacheIdentifier]() { 169 ASSERT(isMainThread()); 170 ASSERT(m_mainThreadConnection); 171 172 m_mainThreadConnection->reference(cacheIdentifier); 154 callOnMainThread([mainThreadConnection = m_mainThreadConnection, cacheIdentifier]() { 155 mainThreadConnection->reference(cacheIdentifier); 173 156 }); 174 157 } … … 176 159 void WorkerCacheStorageConnection::dereference(uint64_t cacheIdentifier) 177 160 { 178 callOnMainThread([this, protectedThis = makeRef(*this), cacheIdentifier]() { 179 ASSERT(isMainThread()); 180 ASSERT(m_mainThreadConnection); 181 182 m_mainThreadConnection->dereference(cacheIdentifier); 161 callOnMainThread([mainThreadConnection = m_mainThreadConnection, cacheIdentifier]() { 162 mainThreadConnection->dereference(cacheIdentifier); 183 163 }); 184 164 } … … 211 191 void WorkerCacheStorageConnection::doRetrieveRecords(uint64_t requestIdentifier, uint64_t cacheIdentifier, const URL& url) 212 192 { 213 callOnMainThread([this, protectedThis = makeRef(*this), requestIdentifier, cacheIdentifier, url = url.isolatedCopy()]() mutable { 214 ASSERT(isMainThread()); 215 ASSERT(m_mainThreadConnection); 216 217 m_mainThreadConnection->retrieveRecords(cacheIdentifier, url, [this, protectedThis = WTFMove(protectedThis), requestIdentifier](RecordsOrError&& result) mutable { 218 m_proxy.postTaskForModeToWorkerGlobalScope([this, protectedThis = WTFMove(protectedThis), result = recordsDataOrErrorFromRecords(result), requestIdentifier](ScriptExecutionContext& context) mutable { 219 ASSERT_UNUSED(context, context.isWorkerGlobalScope()); 220 updateRecords(requestIdentifier, recordsOrErrorFromRecordsData(WTFMove(result))); 221 }, m_taskMode); 193 callOnMainThread([workerThread = makeRef(m_scope.thread()), mainThreadConnection = m_mainThreadConnection, requestIdentifier, cacheIdentifier, url = url.isolatedCopy()]() mutable { 194 mainThreadConnection->retrieveRecords(cacheIdentifier, url, [workerThread = WTFMove(workerThread), requestIdentifier](RecordsOrError&& result) mutable { 195 workerThread->runLoop().postTaskForMode([result = recordsDataOrErrorFromRecords(result), requestIdentifier] (auto& scope) mutable { 196 downcast<WorkerGlobalScope>(scope).cacheStorageConnection().updateRecords(requestIdentifier, recordsOrErrorFromRecordsData(WTFMove(result))); 197 }, WorkerRunLoop::defaultMode()); 222 198 }); 223 199 }); … … 226 202 void WorkerCacheStorageConnection::doBatchDeleteOperation(uint64_t requestIdentifier, uint64_t cacheIdentifier, const ResourceRequest& request, CacheQueryOptions&& options) 227 203 { 228 callOnMainThread([this, protectedThis = makeRef(*this), requestIdentifier, cacheIdentifier, request = request.isolatedCopy(), options = options.isolatedCopy()]() mutable { 229 ASSERT(isMainThread()); 230 ASSERT(m_mainThreadConnection); 231 232 m_mainThreadConnection->batchDeleteOperation(cacheIdentifier, request, WTFMove(options), [this, protectedThis = WTFMove(protectedThis), requestIdentifier](RecordIdentifiersOrError&& result) mutable { 233 234 m_proxy.postTaskForModeToWorkerGlobalScope([this, protectedThis = WTFMove(protectedThis), requestIdentifier, result = WTFMove(result)](ScriptExecutionContext& context) mutable { 235 ASSERT_UNUSED(context, context.isWorkerGlobalScope()); 236 deleteRecordsCompleted(requestIdentifier, WTFMove(result)); 237 }, m_taskMode); 204 callOnMainThread([workerThread = makeRef(m_scope.thread()), mainThreadConnection = m_mainThreadConnection, requestIdentifier, cacheIdentifier, request = request.isolatedCopy(), options = options.isolatedCopy()]() mutable { 205 mainThreadConnection->batchDeleteOperation(cacheIdentifier, request, WTFMove(options), [workerThread = WTFMove(workerThread), requestIdentifier](RecordIdentifiersOrError&& result) mutable { 206 workerThread->runLoop().postTaskForMode([requestIdentifier, result = WTFMove(result)] (auto& scope) mutable { 207 downcast<WorkerGlobalScope>(scope).cacheStorageConnection().deleteRecordsCompleted(requestIdentifier, WTFMove(result)); 208 }, WorkerRunLoop::defaultMode()); 238 209 }); 239 210 }); … … 242 213 void WorkerCacheStorageConnection::doBatchPutOperation(uint64_t requestIdentifier, uint64_t cacheIdentifier, Vector<Record>&& records) 243 214 { 244 callOnMainThread([this, protectedThis = makeRef(*this), requestIdentifier, cacheIdentifier, recordsData = recordsDataFromRecords(records)]() mutable { 245 ASSERT(isMainThread()); 246 ASSERT(m_mainThreadConnection); 247 248 m_mainThreadConnection->batchPutOperation(cacheIdentifier, recordsFromRecordsData(WTFMove(recordsData)), [this, protectedThis = WTFMove(protectedThis), requestIdentifier](RecordIdentifiersOrError&& result) mutable { 249 250 m_proxy.postTaskForModeToWorkerGlobalScope([this, protectedThis = WTFMove(protectedThis), requestIdentifier, result = WTFMove(result)](ScriptExecutionContext& context) mutable { 251 ASSERT_UNUSED(context, context.isWorkerGlobalScope()); 252 putRecordsCompleted(requestIdentifier, WTFMove(result)); 253 }, m_taskMode); 215 callOnMainThread([workerThread = makeRef(m_scope.thread()), mainThreadConnection = m_mainThreadConnection, requestIdentifier, cacheIdentifier, recordsData = recordsDataFromRecords(records)]() mutable { 216 mainThreadConnection->batchPutOperation(cacheIdentifier, recordsFromRecordsData(WTFMove(recordsData)), [workerThread = WTFMove(workerThread), requestIdentifier] (RecordIdentifiersOrError&& result) mutable { 217 workerThread->runLoop().postTaskForMode([requestIdentifier, result = WTFMove(result)] (auto& scope) mutable { 218 downcast<WorkerGlobalScope>(scope).cacheStorageConnection().putRecordsCompleted(requestIdentifier, WTFMove(result)); 219 }, WorkerRunLoop::defaultMode()); 254 220 }); 255 221 }); -
trunk/Source/WebCore/Modules/cache/WorkerCacheStorageConnection.h
r221710 r225481 42 42 explicit WorkerCacheStorageConnection(WorkerGlobalScope&); 43 43 44 // WebCore::CacheStorageConnection 44 // WebCore::CacheStorageConnection. 45 45 void doOpen(uint64_t requestIdentifier, const String& origin, const String& cacheName) final; 46 46 void doRemove(uint64_t requestIdentifier, uint64_t cacheIdentifier) final; … … 56 56 57 57 WorkerGlobalScope& m_scope; 58 WorkerLoaderProxy& m_proxy;59 String m_taskMode;60 58 61 59 RefPtr<CacheStorageConnection> m_mainThreadConnection; -
trunk/Source/WebCore/workers/WorkerGlobalScope.cpp
r225470 r225481 396 396 } 397 397 398 CacheStorageConnection& WorkerGlobalScope::cacheStorageConnection()398 WorkerCacheStorageConnection& WorkerGlobalScope::cacheStorageConnection() 399 399 { 400 400 if (!m_cacheStorageConnection) -
trunk/Source/WebCore/workers/WorkerGlobalScope.h
r224788 r225481 72 72 #endif 73 73 74 CacheStorageConnection& cacheStorageConnection();74 WorkerCacheStorageConnection& cacheStorageConnection(); 75 75 76 76 WorkerScriptController* script() { return m_script.get(); }
Note: See TracChangeset
for help on using the changeset viewer.