Changeset 251968 in webkit


Ignore:
Timestamp:
Nov 2, 2019 8:44:29 PM (4 years ago)
Author:
Chris Dumez
Message:

Port DOMCache / DOMCacheStorage to the HTML5 event loop
https://bugs.webkit.org/show_bug.cgi?id=203772

Reviewed by Sam Weinig.

  • Modules/cache/DOMCache.cpp:

(WebCore::DOMCache::DOMCache):
(WebCore::DOMCache::match):
(WebCore::DOMCache::matchAll):
(WebCore::DOMCache::addAll):
(WebCore::DOMCache::putWithResponseData):
(WebCore::DOMCache::put):
(WebCore::DOMCache::remove):
(WebCore::DOMCache::keys):
(WebCore::DOMCache::enqueueTask):
(WebCore::DOMCache::hasPendingActivity const): Deleted.

  • Modules/cache/DOMCache.h:
  • Modules/cache/DOMCacheStorage.cpp:

(WebCore::DOMCacheStorage::DOMCacheStorage):
(WebCore::DOMCacheStorage::doSequentialMatch):
(WebCore::DOMCacheStorage::match):
(WebCore::DOMCacheStorage::has):
(WebCore::DOMCacheStorage::open):
(WebCore::DOMCacheStorage::doOpen):
(WebCore::DOMCacheStorage::remove):
(WebCore::DOMCacheStorage::doRemove):
(WebCore::DOMCacheStorage::keys):
(WebCore::DOMCacheStorage::enqueueTask):
(WebCore::DOMCacheStorage::hasPendingActivity const): Deleted.

  • Modules/cache/DOMCacheStorage.h:
Location:
trunk/Source/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r251965 r251968  
     12019-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
    1342019-11-02  Oriol Brufau  <obrufau@igalia.com>
    235
  • trunk/Source/WebCore/Modules/cache/DOMCache.cpp

    r251244 r251968  
    2727#include "DOMCache.h"
    2828
     29#include "AbstractEventLoop.h"
    2930#include "CacheQueryOptions.h"
    3031#include "FetchResponse.h"
     
    3435#include "ReadableStreamChunk.h"
    3536#include "ScriptExecutionContext.h"
    36 #include "SuspendableTaskQueue.h"
    3737#include <wtf/CompletionHandler.h>
    3838#include <wtf/URL.h>
     
    4646    , m_identifier(identifier)
    4747    , m_connection(WTFMove(connection))
    48     , m_taskQueue(SuspendableTaskQueue::create(&context))
    4948{
    5049    suspendIfNeeded();
     
    6160{
    6261    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 {
    6463            if (result.hasException()) {
    6564                promise->reject(result.releaseException());
     
    125124    if (!request) {
    126125        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 {
    128127                if (exception) {
    129128                    promise.reject(WTFMove(exception.value()));
     
    136135    }
    137136    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 {
    139138            if (result.hasException()) {
    140139                promise.reject(result.releaseException());
     
    244243    auto taskHandler = FetchTasksHandler::create(*this, [this, protectedThis = makeRef(*this), promise = WTFMove(promise)](ExceptionOr<Vector<Record>>&& result) mutable {
    245244        if (result.hasException()) {
    246             m_taskQueue->enqueueTask([promise = WTFMove(promise), exception = result.releaseException()]() mutable {
     245            enqueueTask([promise = WTFMove(promise), exception = result.releaseException()]() mutable {
    247246                promise.reject(WTFMove(exception));
    248247            });
     
    250249        }
    251250        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 {
    253252                promise.settle(WTFMove(result));
    254253            });
     
    315314{
    316315    if (responseBody.hasException()) {
    317         m_taskQueue->enqueueTask([promise = WTFMove(promise), exception = responseBody.releaseException()]() mutable {
     316        enqueueTask([promise = WTFMove(promise), exception = responseBody.releaseException()]() mutable {
    318317            promise.reject(WTFMove(exception));
    319318        });
     
    325324        body = buffer.releaseNonNull();
    326325    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 {
    328327            promise.settle(WTFMove(result));
    329328        });
     
    391390
    392391    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 {
    394393            promise.settle(WTFMove(result));
    395394        });
     
    409408
    410409    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 {
    412411            promise.settle(WTFMove(result));
    413412        });
     
    437436    if (!request) {
    438437        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 {
    440439                if (exception) {
    441440                    promise.reject(WTFMove(exception.value()));
     
    449448
    450449    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 {
    452451            if (result.hasException()) {
    453452                promise.reject(result.releaseException());
     
    609608}
    610609
    611 bool DOMCache::hasPendingActivity() const
    612 {
    613     return m_taskQueue->hasPendingTasks() || ActiveDOMObject::hasPendingActivity();
    614 }
    615 
     610void 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}
    616619
    617620} // namespace WebCore
  • trunk/Source/WebCore/Modules/cache/DOMCache.h

    r251244 r251968  
    3434
    3535class ScriptExecutionContext;
    36 class SuspendableTaskQueue;
    3736
    3837class DOMCache final : public RefCounted<DOMCache>, public ActiveDOMObject {
     
    6463    CacheStorageConnection& connection() { return m_connection.get(); }
    6564
    66     // ActiveDOMObject
    67     bool hasPendingActivity() const final;
    68 
    6965private:
    7066    DOMCache(ScriptExecutionContext&, String&& name, uint64_t identifier, Ref<CacheStorageConnection>&&);
     
    8985    DOMCacheEngine::Record toConnectionRecord(const FetchRequest&, FetchResponse&, DOMCacheEngine::ResponseBody&&);
    9086
     87    void enqueueTask(Function<void()>&&);
     88
    9189    String m_name;
    9290    uint64_t m_identifier;
     
    9593    Vector<CacheStorageRecord> m_records;
    9694    bool m_isStopped { false };
    97     UniqueRef<SuspendableTaskQueue> m_taskQueue;
    9895};
    9996
  • trunk/Source/WebCore/Modules/cache/DOMCacheStorage.cpp

    r251244 r251968  
    3232#include "JSFetchResponse.h"
    3333#include "ScriptExecutionContext.h"
    34 #include "SuspendableTaskQueue.h"
    3534
    3635namespace WebCore {
     
    4039    : ActiveDOMObject(&context)
    4140    , m_connection(WTFMove(connection))
    42     , m_taskQueue(SuspendableTaskQueue::create(&context))
    4341{
    4442    suspendIfNeeded();
     
    9088{
    9189    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 {
    9391            if (result.hasException()) {
    9492                promise->reject(result.releaseException());
     
    108106    retrieveCaches([this, info = WTFMove(info), options = WTFMove(options), promise = WTFMove(promise)](Optional<Exception>&& exception) mutable {
    109107        if (exception) {
    110             m_taskQueue->enqueueTask([promise = WTFMove(promise), exception = WTFMove(exception.value())]() mutable {
     108            enqueueTask([promise = WTFMove(promise), exception = WTFMove(exception.value())]() mutable {
    111109                promise->reject(WTFMove(exception));
    112110            });
     
    120118                return;
    121119            }
    122             m_taskQueue->enqueueTask([promise = WTFMove(promise)]() mutable {
     120            enqueueTask([promise = WTFMove(promise)]() mutable {
    123121                promise->resolve();
    124122            });
     
    133131{
    134132    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 {
    136134            if (exception) {
    137135                promise.reject(WTFMove(exception.value()));
     
    190188    retrieveCaches([this, name, promise = WTFMove(promise)](Optional<Exception>&& exception) mutable {
    191189        if (exception) {
    192             m_taskQueue->enqueueTask([promise = WTFMove(promise), exception = WTFMove(exception.value())]() mutable {
     190            enqueueTask([promise = WTFMove(promise), exception = WTFMove(exception.value())]() mutable {
    193191                promise.reject(WTFMove(exception));
    194192            });
     
    203201    auto position = m_caches.findMatching([&](auto& item) { return item->name() == name; });
    204202    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 {
    206204            promise.resolve(DOMCache::create(*scriptExecutionContext(), String { cache->name() }, cache->identifier(), m_connection.copyRef()));
    207205        });
     
    211209    m_connection->open(*origin(), name, [this, name, promise = WTFMove(promise), pendingActivity = makePendingActivity(*this)](const CacheIdentifierOrError& result) mutable {
    212210        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 {
    214212                promise.reject(DOMCacheEngine::convertToExceptionAndLog(scriptExecutionContext(), error));
    215213            });
     
    218216                logConsolePersistencyError(scriptExecutionContext(), name);
    219217
    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 {
    221219                auto cache = DOMCache::create(*scriptExecutionContext(), String { name }, identifier, m_connection.copyRef());
    222220                promise.resolve(cache);
     
    231229    retrieveCaches([this, name, promise = WTFMove(promise)](Optional<Exception>&& exception) mutable {
    232230        if (exception) {
    233             m_taskQueue->enqueueTask([promise = WTFMove(promise), exception = WTFMove(exception.value())]() mutable {
     231            enqueueTask([promise = WTFMove(promise), exception = WTFMove(exception.value())]() mutable {
    234232                promise.reject(WTFMove(exception));
    235233            });
     
    244242    auto position = m_caches.findMatching([&](auto& item) { return item->name() == name; });
    245243    if (position == notFound) {
    246         m_taskQueue->enqueueTask([promise = WTFMove(promise)]() mutable {
     244        enqueueTask([promise = WTFMove(promise)]() mutable {
    247245            promise.resolve(false);
    248246        });
     
    251249
    252250    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 {
    254252            if (!result.has_value())
    255253                promise.reject(DOMCacheEngine::convertToExceptionAndLog(scriptExecutionContext(), result.error()));
     
    266264{
    267265    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 {
    269267            if (exception) {
    270268                promise.reject(WTFMove(exception.value()));
     
    289287}
    290288
    291 bool DOMCacheStorage::hasPendingActivity() const
    292 {
    293     return m_taskQueue->hasPendingTasks() || ActiveDOMObject::hasPendingActivity();
     289void 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    });
    294297}
    295298
  • trunk/Source/WebCore/Modules/cache/DOMCacheStorage.h

    r251244 r251968  
    3333namespace WebCore {
    3434
    35 class SuspendableTaskQueue;
    36 
    3735class DOMCacheStorage : public RefCounted<DOMCacheStorage>, public ActiveDOMObject {
    3836public:
     
    4745    void remove(const String&, DOMPromiseDeferred<IDLBoolean>&&);
    4846    void keys(KeysPromise&&);
    49 
    50     // ActiveDOMObject
    51     bool hasPendingActivity() const final;
    5247
    5348private:
     
    6560    Optional<ClientOrigin> origin() const;
    6661
     62    void enqueueTask(Function<void()>&&);
     63
    6764    Vector<Ref<DOMCache>> m_caches;
    6865    uint64_t m_updateCounter { 0 };
    6966    Ref<CacheStorageConnection> m_connection;
    70     UniqueRef<SuspendableTaskQueue> m_taskQueue;
    7167    bool m_isStopped { false };
    7268};
  • trunk/Source/WebCore/workers/WorkerEventLoop.cpp

    r251934 r251968  
    9999    if (!context || context->activeDOMObjectsAreStopped() || context->activeDOMObjectsAreSuspended())
    100100        return;
    101     for (auto& task : m_tasks)
     101    auto tasks = std::exchange(m_tasks, Vector<Task>());
     102    for (auto& task : tasks)
    102103        task.task();
    103104}
Note: See TracChangeset for help on using the changeset viewer.