Changeset 251968 in webkit
- Timestamp:
- Nov 2, 2019 8:44:29 PM (4 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r251965 r251968 1 2019-11-02 Chris Dumez <cdumez@apple.com> 2 3 Port DOMCache / DOMCacheStorage to the HTML5 event loop 4 https://bugs.webkit.org/show_bug.cgi?id=203772 5 6 Reviewed by Sam Weinig. 7 8 * Modules/cache/DOMCache.cpp: 9 (WebCore::DOMCache::DOMCache): 10 (WebCore::DOMCache::match): 11 (WebCore::DOMCache::matchAll): 12 (WebCore::DOMCache::addAll): 13 (WebCore::DOMCache::putWithResponseData): 14 (WebCore::DOMCache::put): 15 (WebCore::DOMCache::remove): 16 (WebCore::DOMCache::keys): 17 (WebCore::DOMCache::enqueueTask): 18 (WebCore::DOMCache::hasPendingActivity const): Deleted. 19 * Modules/cache/DOMCache.h: 20 * Modules/cache/DOMCacheStorage.cpp: 21 (WebCore::DOMCacheStorage::DOMCacheStorage): 22 (WebCore::DOMCacheStorage::doSequentialMatch): 23 (WebCore::DOMCacheStorage::match): 24 (WebCore::DOMCacheStorage::has): 25 (WebCore::DOMCacheStorage::open): 26 (WebCore::DOMCacheStorage::doOpen): 27 (WebCore::DOMCacheStorage::remove): 28 (WebCore::DOMCacheStorage::doRemove): 29 (WebCore::DOMCacheStorage::keys): 30 (WebCore::DOMCacheStorage::enqueueTask): 31 (WebCore::DOMCacheStorage::hasPendingActivity const): Deleted. 32 * Modules/cache/DOMCacheStorage.h: 33 1 34 2019-11-02 Oriol Brufau <obrufau@igalia.com> 2 35 -
trunk/Source/WebCore/Modules/cache/DOMCache.cpp
r251244 r251968 27 27 #include "DOMCache.h" 28 28 29 #include "AbstractEventLoop.h" 29 30 #include "CacheQueryOptions.h" 30 31 #include "FetchResponse.h" … … 34 35 #include "ReadableStreamChunk.h" 35 36 #include "ScriptExecutionContext.h" 36 #include "SuspendableTaskQueue.h"37 37 #include <wtf/CompletionHandler.h> 38 38 #include <wtf/URL.h> … … 46 46 , m_identifier(identifier) 47 47 , m_connection(WTFMove(connection)) 48 , m_taskQueue(SuspendableTaskQueue::create(&context))49 48 { 50 49 suspendIfNeeded(); … … 61 60 { 62 61 doMatch(WTFMove(info), WTFMove(options), [this, protectedThis = makeRef(*this), promise = WTFMove(promise)](ExceptionOr<RefPtr<FetchResponse>>&& result) mutable { 63 m_taskQueue->enqueueTask([promise = WTFMove(promise), result = WTFMove(result)]() mutable {62 enqueueTask([promise = WTFMove(promise), result = WTFMove(result)]() mutable { 64 63 if (result.hasException()) { 65 64 promise->reject(result.releaseException()); … … 125 124 if (!request) { 126 125 retrieveRecords(URL { }, [this, promise = WTFMove(promise)](Optional<Exception>&& exception) mutable { 127 m_taskQueue->enqueueTask([this, promise = WTFMove(promise), exception = WTFMove(exception)]() mutable {126 enqueueTask([this, promise = WTFMove(promise), exception = WTFMove(exception)]() mutable { 128 127 if (exception) { 129 128 promise.reject(WTFMove(exception.value())); … … 136 135 } 137 136 queryCache(request.releaseNonNull(), WTFMove(options), [this, promise = WTFMove(promise)](ExceptionOr<Vector<CacheStorageRecord>>&& result) mutable { 138 m_taskQueue->enqueueTask([this, promise = WTFMove(promise), result = WTFMove(result)]() mutable {137 enqueueTask([this, promise = WTFMove(promise), result = WTFMove(result)]() mutable { 139 138 if (result.hasException()) { 140 139 promise.reject(result.releaseException()); … … 244 243 auto taskHandler = FetchTasksHandler::create(*this, [this, protectedThis = makeRef(*this), promise = WTFMove(promise)](ExceptionOr<Vector<Record>>&& result) mutable { 245 244 if (result.hasException()) { 246 m_taskQueue->enqueueTask([promise = WTFMove(promise), exception = result.releaseException()]() mutable {245 enqueueTask([promise = WTFMove(promise), exception = result.releaseException()]() mutable { 247 246 promise.reject(WTFMove(exception)); 248 247 }); … … 250 249 } 251 250 batchPutOperation(result.releaseReturnValue(), [this, protectedThis = WTFMove(protectedThis), promise = WTFMove(promise)](ExceptionOr<void>&& result) mutable { 252 m_taskQueue->enqueueTask([promise = WTFMove(promise), result = WTFMove(result)]() mutable {251 enqueueTask([promise = WTFMove(promise), result = WTFMove(result)]() mutable { 253 252 promise.settle(WTFMove(result)); 254 253 }); … … 315 314 { 316 315 if (responseBody.hasException()) { 317 m_taskQueue->enqueueTask([promise = WTFMove(promise), exception = responseBody.releaseException()]() mutable {316 enqueueTask([promise = WTFMove(promise), exception = responseBody.releaseException()]() mutable { 318 317 promise.reject(WTFMove(exception)); 319 318 }); … … 325 324 body = buffer.releaseNonNull(); 326 325 batchPutOperation(request.get(), response.get(), WTFMove(body), [this, protectedThis = makeRef(*this), promise = WTFMove(promise)](ExceptionOr<void>&& result) mutable { 327 m_taskQueue->enqueueTask([promise = WTFMove(promise), result = WTFMove(result)]() mutable {326 enqueueTask([promise = WTFMove(promise), result = WTFMove(result)]() mutable { 328 327 promise.settle(WTFMove(result)); 329 328 }); … … 391 390 392 391 batchPutOperation(request.get(), response.get(), response->consumeBody(), [this, protectedThis = makeRef(*this), promise = WTFMove(promise)](ExceptionOr<void>&& result) mutable { 393 m_taskQueue->enqueueTask([promise = WTFMove(promise), result = WTFMove(result)]() mutable {392 enqueueTask([promise = WTFMove(promise), result = WTFMove(result)]() mutable { 394 393 promise.settle(WTFMove(result)); 395 394 }); … … 409 408 410 409 batchDeleteOperation(requestOrException.releaseReturnValue(), WTFMove(options), [this, protectedThis = makeRef(*this), promise = WTFMove(promise)](ExceptionOr<bool>&& result) mutable { 411 m_taskQueue->enqueueTask([promise = WTFMove(promise), result = WTFMove(result)]() mutable {410 enqueueTask([promise = WTFMove(promise), result = WTFMove(result)]() mutable { 412 411 promise.settle(WTFMove(result)); 413 412 }); … … 437 436 if (!request) { 438 437 retrieveRecords(URL { }, [this, promise = WTFMove(promise)](Optional<Exception>&& exception) mutable { 439 m_taskQueue->enqueueTask([this, promise = WTFMove(promise), exception = WTFMove(exception)]() mutable {438 enqueueTask([this, promise = WTFMove(promise), exception = WTFMove(exception)]() mutable { 440 439 if (exception) { 441 440 promise.reject(WTFMove(exception.value())); … … 449 448 450 449 queryCache(request.releaseNonNull(), WTFMove(options), [this, protectedThis = makeRef(*this), promise = WTFMove(promise)](auto&& result) mutable { 451 m_taskQueue->enqueueTask([promise = WTFMove(promise), result = WTFMove(result)]() mutable {450 enqueueTask([promise = WTFMove(promise), result = WTFMove(result)]() mutable { 452 451 if (result.hasException()) { 453 452 promise.reject(result.releaseException()); … … 609 608 } 610 609 611 bool DOMCache::hasPendingActivity() const 612 { 613 return m_taskQueue->hasPendingTasks() || ActiveDOMObject::hasPendingActivity(); 614 } 615 610 void DOMCache::enqueueTask(Function<void()>&& task) 611 { 612 auto* context = scriptExecutionContext(); 613 if (!context) 614 return; 615 context->eventLoop().queueTask(TaskSource::DOMManipulation, *context, [protectedThis = makeRef(*this), pendingActivity = makePendingActivity(*this), task = WTFMove(task)] { 616 task(); 617 }); 618 } 616 619 617 620 } // namespace WebCore -
trunk/Source/WebCore/Modules/cache/DOMCache.h
r251244 r251968 34 34 35 35 class ScriptExecutionContext; 36 class SuspendableTaskQueue;37 36 38 37 class DOMCache final : public RefCounted<DOMCache>, public ActiveDOMObject { … … 64 63 CacheStorageConnection& connection() { return m_connection.get(); } 65 64 66 // ActiveDOMObject67 bool hasPendingActivity() const final;68 69 65 private: 70 66 DOMCache(ScriptExecutionContext&, String&& name, uint64_t identifier, Ref<CacheStorageConnection>&&); … … 89 85 DOMCacheEngine::Record toConnectionRecord(const FetchRequest&, FetchResponse&, DOMCacheEngine::ResponseBody&&); 90 86 87 void enqueueTask(Function<void()>&&); 88 91 89 String m_name; 92 90 uint64_t m_identifier; … … 95 93 Vector<CacheStorageRecord> m_records; 96 94 bool m_isStopped { false }; 97 UniqueRef<SuspendableTaskQueue> m_taskQueue;98 95 }; 99 96 -
trunk/Source/WebCore/Modules/cache/DOMCacheStorage.cpp
r251244 r251968 32 32 #include "JSFetchResponse.h" 33 33 #include "ScriptExecutionContext.h" 34 #include "SuspendableTaskQueue.h"35 34 36 35 namespace WebCore { … … 40 39 : ActiveDOMObject(&context) 41 40 , m_connection(WTFMove(connection)) 42 , m_taskQueue(SuspendableTaskQueue::create(&context))43 41 { 44 42 suspendIfNeeded(); … … 90 88 { 91 89 startSequentialMatch(WTF::map(m_caches, copyCache), WTFMove(info), WTFMove(options), [this, pendingActivity = makePendingActivity(*this), promise = WTFMove(promise)](auto&& result) mutable { 92 m_taskQueue->enqueueTask([promise = WTFMove(promise), result = WTFMove(result)]() mutable {90 enqueueTask([promise = WTFMove(promise), result = WTFMove(result)]() mutable { 93 91 if (result.hasException()) { 94 92 promise->reject(result.releaseException()); … … 108 106 retrieveCaches([this, info = WTFMove(info), options = WTFMove(options), promise = WTFMove(promise)](Optional<Exception>&& exception) mutable { 109 107 if (exception) { 110 m_taskQueue->enqueueTask([promise = WTFMove(promise), exception = WTFMove(exception.value())]() mutable {108 enqueueTask([promise = WTFMove(promise), exception = WTFMove(exception.value())]() mutable { 111 109 promise->reject(WTFMove(exception)); 112 110 }); … … 120 118 return; 121 119 } 122 m_taskQueue->enqueueTask([promise = WTFMove(promise)]() mutable {120 enqueueTask([promise = WTFMove(promise)]() mutable { 123 121 promise->resolve(); 124 122 }); … … 133 131 { 134 132 retrieveCaches([this, name, promise = WTFMove(promise)](Optional<Exception>&& exception) mutable { 135 m_taskQueue->enqueueTask([this, name, promise = WTFMove(promise), exception = WTFMove(exception)]() mutable {133 enqueueTask([this, name, promise = WTFMove(promise), exception = WTFMove(exception)]() mutable { 136 134 if (exception) { 137 135 promise.reject(WTFMove(exception.value())); … … 190 188 retrieveCaches([this, name, promise = WTFMove(promise)](Optional<Exception>&& exception) mutable { 191 189 if (exception) { 192 m_taskQueue->enqueueTask([promise = WTFMove(promise), exception = WTFMove(exception.value())]() mutable {190 enqueueTask([promise = WTFMove(promise), exception = WTFMove(exception.value())]() mutable { 193 191 promise.reject(WTFMove(exception)); 194 192 }); … … 203 201 auto position = m_caches.findMatching([&](auto& item) { return item->name() == name; }); 204 202 if (position != notFound) { 205 m_taskQueue->enqueueTask([this, promise = WTFMove(promise), cache = m_caches[position].copyRef()]() mutable {203 enqueueTask([this, promise = WTFMove(promise), cache = m_caches[position].copyRef()]() mutable { 206 204 promise.resolve(DOMCache::create(*scriptExecutionContext(), String { cache->name() }, cache->identifier(), m_connection.copyRef())); 207 205 }); … … 211 209 m_connection->open(*origin(), name, [this, name, promise = WTFMove(promise), pendingActivity = makePendingActivity(*this)](const CacheIdentifierOrError& result) mutable { 212 210 if (!result.has_value()) { 213 m_taskQueue->enqueueTask([this, promise = WTFMove(promise), error = result.error()]() mutable {211 enqueueTask([this, promise = WTFMove(promise), error = result.error()]() mutable { 214 212 promise.reject(DOMCacheEngine::convertToExceptionAndLog(scriptExecutionContext(), error)); 215 213 }); … … 218 216 logConsolePersistencyError(scriptExecutionContext(), name); 219 217 220 m_taskQueue->enqueueTask([this, name, promise = WTFMove(promise), identifier = result.value().identifier]() mutable {218 enqueueTask([this, name, promise = WTFMove(promise), identifier = result.value().identifier]() mutable { 221 219 auto cache = DOMCache::create(*scriptExecutionContext(), String { name }, identifier, m_connection.copyRef()); 222 220 promise.resolve(cache); … … 231 229 retrieveCaches([this, name, promise = WTFMove(promise)](Optional<Exception>&& exception) mutable { 232 230 if (exception) { 233 m_taskQueue->enqueueTask([promise = WTFMove(promise), exception = WTFMove(exception.value())]() mutable {231 enqueueTask([promise = WTFMove(promise), exception = WTFMove(exception.value())]() mutable { 234 232 promise.reject(WTFMove(exception)); 235 233 }); … … 244 242 auto position = m_caches.findMatching([&](auto& item) { return item->name() == name; }); 245 243 if (position == notFound) { 246 m_taskQueue->enqueueTask([promise = WTFMove(promise)]() mutable {244 enqueueTask([promise = WTFMove(promise)]() mutable { 247 245 promise.resolve(false); 248 246 }); … … 251 249 252 250 m_connection->remove(m_caches[position]->identifier(), [this, name, promise = WTFMove(promise), pendingActivity = makePendingActivity(*this)](const CacheIdentifierOrError& result) mutable { 253 m_taskQueue->enqueueTask([this, name, promise = WTFMove(promise), result]() mutable {251 enqueueTask([this, name, promise = WTFMove(promise), result]() mutable { 254 252 if (!result.has_value()) 255 253 promise.reject(DOMCacheEngine::convertToExceptionAndLog(scriptExecutionContext(), result.error())); … … 266 264 { 267 265 retrieveCaches([this, promise = WTFMove(promise)](Optional<Exception>&& exception) mutable { 268 m_taskQueue->enqueueTask([this, promise = WTFMove(promise), exception = WTFMove(exception)]() mutable {266 enqueueTask([this, promise = WTFMove(promise), exception = WTFMove(exception)]() mutable { 269 267 if (exception) { 270 268 promise.reject(WTFMove(exception.value())); … … 289 287 } 290 288 291 bool DOMCacheStorage::hasPendingActivity() const 292 { 293 return m_taskQueue->hasPendingTasks() || ActiveDOMObject::hasPendingActivity(); 289 void DOMCacheStorage::enqueueTask(Function<void()>&& task) 290 { 291 auto* context = scriptExecutionContext(); 292 if (!context) 293 return; 294 context->eventLoop().queueTask(TaskSource::DOMManipulation, *context, [protectedThis = makeRef(*this), pendingActivity = makePendingActivity(*this), task = WTFMove(task)] { 295 task(); 296 }); 294 297 } 295 298 -
trunk/Source/WebCore/Modules/cache/DOMCacheStorage.h
r251244 r251968 33 33 namespace WebCore { 34 34 35 class SuspendableTaskQueue;36 37 35 class DOMCacheStorage : public RefCounted<DOMCacheStorage>, public ActiveDOMObject { 38 36 public: … … 47 45 void remove(const String&, DOMPromiseDeferred<IDLBoolean>&&); 48 46 void keys(KeysPromise&&); 49 50 // ActiveDOMObject51 bool hasPendingActivity() const final;52 47 53 48 private: … … 65 60 Optional<ClientOrigin> origin() const; 66 61 62 void enqueueTask(Function<void()>&&); 63 67 64 Vector<Ref<DOMCache>> m_caches; 68 65 uint64_t m_updateCounter { 0 }; 69 66 Ref<CacheStorageConnection> m_connection; 70 UniqueRef<SuspendableTaskQueue> m_taskQueue;71 67 bool m_isStopped { false }; 72 68 }; -
trunk/Source/WebCore/workers/WorkerEventLoop.cpp
r251934 r251968 99 99 if (!context || context->activeDOMObjectsAreStopped() || context->activeDOMObjectsAreSuspended()) 100 100 return; 101 for (auto& task : m_tasks) 101 auto tasks = std::exchange(m_tasks, Vector<Task>()); 102 for (auto& task : tasks) 102 103 task.task(); 103 104 }
Note: See TracChangeset
for help on using the changeset viewer.