⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 243818 in webkit


Ignore:
Timestamp:
Apr 3, 2019, 12:38:51 PM (7 years ago)
Author:
youenn@apple.com
Message:

Use makePendingActivity in DOMCache
https://bugs.webkit.org/show_bug.cgi?id=196515

Reviewed by Geoffrey Garen.

No change of behavior, just modernizing the code.

  • Modules/cache/DOMCache.cpp:

(WebCore::DOMCache::retrieveRecords):
(WebCore::DOMCache::batchDeleteOperation):
(WebCore::DOMCache::batchPutOperation):

  • Modules/cache/DOMCacheStorage.cpp:

(WebCore::DOMCacheStorage::match):

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r243817 r243818  
     12019-04-03  Youenn Fablet  <youenn@apple.com>
     2
     3        Use makePendingActivity in DOMCache
     4        https://bugs.webkit.org/show_bug.cgi?id=196515
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        No change of behavior, just modernizing the code.
     9
     10        * Modules/cache/DOMCache.cpp:
     11        (WebCore::DOMCache::retrieveRecords):
     12        (WebCore::DOMCache::batchDeleteOperation):
     13        (WebCore::DOMCache::batchPutOperation):
     14        * Modules/cache/DOMCacheStorage.cpp:
     15        (WebCore::DOMCacheStorage::match):
     16
    1172019-04-03  Chris Dumez  <cdumez@apple.com>
    218
  • trunk/Source/WebCore/Modules/cache/DOMCache.cpp

    r240237 r243818  
    432432void DOMCache::retrieveRecords(const URL& url, WTF::Function<void(Optional<Exception>&&)>&& callback)
    433433{
    434     setPendingActivity(*this);
    435 
    436434    URL retrieveURL = url;
    437435    retrieveURL.removeQueryAndFragmentIdentifier();
    438436
    439     m_connection->retrieveRecords(m_identifier, retrieveURL, [this, callback = WTFMove(callback)](RecordsOrError&& result) {
    440         if (!m_isStopped) {
    441             if (!result.has_value()) {
    442                 callback(DOMCacheEngine::convertToExceptionAndLog(scriptExecutionContext(), result.error()));
    443                 return;
    444             }
    445 
    446             if (result.has_value())
    447                 updateRecords(WTFMove(result.value()));
    448             callback(WTF::nullopt);
    449         }
    450         unsetPendingActivity(*this);
     437    m_connection->retrieveRecords(m_identifier, retrieveURL, [this, pendingActivity = makePendingActivity(*this), callback = WTFMove(callback)](RecordsOrError&& result) {
     438        if (m_isStopped)
     439            return;
     440
     441        if (!result.has_value()) {
     442            callback(DOMCacheEngine::convertToExceptionAndLog(scriptExecutionContext(), result.error()));
     443            return;
     444        }
     445
     446        updateRecords(WTFMove(result.value()));
     447        callback(WTF::nullopt);
    451448    });
    452449}
     
    485482void DOMCache::batchDeleteOperation(const FetchRequest& request, CacheQueryOptions&& options, WTF::Function<void(ExceptionOr<bool>&&)>&& callback)
    486483{
    487     setPendingActivity(*this);
    488     m_connection->batchDeleteOperation(m_identifier, request.internalRequest(), WTFMove(options), [this, callback = WTFMove(callback)](RecordIdentifiersOrError&& result) {
    489         if (!m_isStopped) {
    490             if (!result.has_value())
    491                 callback(DOMCacheEngine::convertToExceptionAndLog(scriptExecutionContext(), result.error()));
    492             else
    493                 callback(!result.value().isEmpty());
    494         }
    495         unsetPendingActivity(*this);
     484    m_connection->batchDeleteOperation(m_identifier, request.internalRequest(), WTFMove(options), [this, pendingActivity = makePendingActivity(*this), callback = WTFMove(callback)](RecordIdentifiersOrError&& result) {
     485        if (m_isStopped)
     486            return;
     487
     488        if (!result.has_value()) {
     489            callback(DOMCacheEngine::convertToExceptionAndLog(scriptExecutionContext(), result.error()));
     490            return;
     491        }
     492        callback(!result.value().isEmpty());
    496493    });
    497494}
     
    528525void DOMCache::batchPutOperation(Vector<Record>&& records, WTF::Function<void(ExceptionOr<void>&&)>&& callback)
    529526{
    530     setPendingActivity(*this);
    531     m_connection->batchPutOperation(m_identifier, WTFMove(records), [this, callback = WTFMove(callback)](RecordIdentifiersOrError&& result) {
    532         if (!m_isStopped) {
    533             if (!result.has_value())
    534                 callback(DOMCacheEngine::convertToExceptionAndLog(scriptExecutionContext(), result.error()));
    535             else
    536                 callback({ });
    537         }
    538         unsetPendingActivity(*this);
     527    m_connection->batchPutOperation(m_identifier, WTFMove(records), [this, pendingActivity = makePendingActivity(*this), callback = WTFMove(callback)](RecordIdentifiersOrError&& result) {
     528        if (m_isStopped)
     529            return;
     530        if (!result.has_value()) {
     531            callback(DOMCacheEngine::convertToExceptionAndLog(scriptExecutionContext(), result.error()));
     532            return;
     533        }
     534        callback({ });
    539535    });
    540536}
  • trunk/Source/WebCore/Modules/cache/DOMCacheStorage.cpp

    r240237 r243818  
    8484}
    8585
     86void DOMCacheStorage::doSequentialMatch(DOMCache::RequestInfo&& info, CacheQueryOptions&& options, Ref<DeferredPromise>&& promise)
     87{
     88    startSequentialMatch(WTF::map(m_caches, copyCache), WTFMove(info), WTFMove(options), [this, pendingActivity = makePendingActivity(*this), promise = WTFMove(promise)](ExceptionOr<FetchResponse*>&& result) mutable {
     89        if (m_isStopped)
     90            return;
     91        if (result.hasException()) {
     92            promise->reject(result.releaseException());
     93            return;
     94        }
     95        if (!result.returnValue()) {
     96            promise->resolve();
     97            return;
     98        }
     99        promise->resolve<IDLInterface<FetchResponse>>(*result.returnValue());
     100    });
     101}
     102
    86103void DOMCacheStorage::match(DOMCache::RequestInfo&& info, CacheQueryOptions&& options, Ref<DeferredPromise>&& promise)
    87104{
     
    102119        }
    103120
    104         setPendingActivity(*this);
    105         startSequentialMatch(WTF::map(m_caches, copyCache), WTFMove(info), WTFMove(options), [this, promise = WTFMove(promise)](ExceptionOr<FetchResponse*>&& result) mutable {
    106             if (!m_isStopped) {
    107                 if (result.hasException()) {
    108                     promise->reject(result.releaseException());
    109                     return;
    110                 }
    111                 if (!result.returnValue())
    112                     promise->resolve();
    113                 else
    114                     promise->resolve<IDLInterface<FetchResponse>>(*result.returnValue());
    115             }
    116             unsetPendingActivity(*this);
    117         });
     121        this->doSequentialMatch(WTFMove(info), WTFMove(options), WTFMove(promise));
    118122    });
    119123}
  • trunk/Source/WebCore/Modules/cache/DOMCacheStorage.h

    r239427 r243818  
    5555    void doOpen(const String& name, DOMPromiseDeferred<IDLInterface<DOMCache>>&&);
    5656    void doRemove(const String&, DOMPromiseDeferred<IDLBoolean>&&);
     57    void doSequentialMatch(DOMCache::RequestInfo&&, CacheQueryOptions&&, Ref<DeferredPromise>&&);
    5758    void retrieveCaches(WTF::Function<void(Optional<Exception>&&)>&&);
    5859    Ref<DOMCache> findCacheOrCreate(DOMCacheEngine::CacheInfo&&);
Note: See TracChangeset for help on using the changeset viewer.