Changeset 221085 in webkit


Ignore:
Timestamp:
Aug 23, 2017 10:52:56 AM (7 years ago)
Author:
commit-queue@webkit.org
Message:

CacheStorageEngine readCachesFromDisk callback should return the read Caches
https://bugs.webkit.org/show_bug.cgi?id=175882

Patch by Youenn Fablet <youenn@apple.com> on 2017-08-23
Reviewed by Alex Christensen.

Callback of readCachesFromDisk takes now a Caches or error parameter.

  • NetworkProcess/cache/CacheStorageEngine.cpp:

(WebKit::CacheStorageEngine::open):
(WebKit::CacheStorageEngine::retrieveCaches):
(WebKit::CacheStorageEngine::readCachesFromDisk):

  • NetworkProcess/cache/CacheStorageEngine.h:
Location:
trunk/Source/WebKit
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r221081 r221085  
     12017-08-23  Youenn Fablet  <youenn@apple.com>
     2
     3        CacheStorageEngine readCachesFromDisk callback should return the read Caches
     4        https://bugs.webkit.org/show_bug.cgi?id=175882
     5
     6        Reviewed by Alex Christensen.
     7
     8        Callback of readCachesFromDisk takes now a Caches or error parameter.
     9
     10        * NetworkProcess/cache/CacheStorageEngine.cpp:
     11        (WebKit::CacheStorageEngine::open):
     12        (WebKit::CacheStorageEngine::retrieveCaches):
     13        (WebKit::CacheStorageEngine::readCachesFromDisk):
     14        * NetworkProcess/cache/CacheStorageEngine.h:
     15
    1162017-08-23  Chris Dumez  <cdumez@apple.com>
    217
  • trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp

    r221024 r221085  
    6565void CacheStorageEngine::open(const String& origin, const String& cacheName, CacheIdentifierCallback&& callback)
    6666{
    67     readCachesFromDisk([this, origin, cacheName, callback = WTFMove(callback)](std::optional<Error>&& error) mutable {
    68         if (error) {
    69             callback(makeUnexpected(error.value()));
    70             return;
    71         }
    72 
    73         auto& caches = m_caches.ensure(origin, [] {
    74             return Vector<Cache>();
    75         }).iterator->value;
     67    readCachesFromDisk(origin, [this, cacheName, callback = WTFMove(callback)](CachesOrError&& cachesOrError) mutable {
     68        if (!cachesOrError.hasValue()) {
     69            callback(makeUnexpected(cachesOrError.error()));
     70            return;
     71        }
     72
     73        auto& caches = cachesOrError.value().get();
    7674
    7775        auto position = caches.findMatching([&](const auto& item) { return item.name == cacheName; });
     
    119117void CacheStorageEngine::retrieveCaches(const String& origin, CacheInfosCallback&& callback)
    120118{
    121     readCachesFromDisk([this, origin, callback = WTFMove(callback)](std::optional<Error>&& error) mutable {
    122         if (error) {
    123             callback(makeUnexpected(error.value()));
    124             return;
    125         }
    126         callback(caches(origin));
     119    readCachesFromDisk(origin, [this, callback = WTFMove(callback)](CachesOrError&& cachesOrError) mutable {
     120        if (!cachesOrError.hasValue()) {
     121            callback(makeUnexpected(cachesOrError.error()));
     122            return;
     123        }
     124
     125        auto& caches = cachesOrError.value().get();
     126
     127        Vector<WebCore::CacheStorageConnection::CacheInfo> cachesInfo;
     128        cachesInfo.reserveInitialCapacity(caches.size());
     129        for (auto& cache : caches)
     130            cachesInfo.uncheckedAppend(WebCore::CacheStorageConnection::CacheInfo { cache.identifier, cache.name});
     131
     132        callback(WTFMove(cachesInfo));
    127133    });
    128134}
     
    231237}
    232238
    233 void CacheStorageEngine::readCachesFromDisk(CompletionCallback&& callback)
     239void CacheStorageEngine::readCachesFromDisk(const String& origin, CachesCallback&& callback)
    234240{
    235241    // FIXME: Implement reading.
    236     callback(std::nullopt);
     242
     243    auto& caches = m_caches.ensure(origin, [] {
     244        return Vector<Cache>();
     245    }).iterator->value;
     246
     247    callback(std::reference_wrapper<Vector<Cache>> { caches });
    237248}
    238249
     
    278289}
    279290
    280 Vector<WebCore::CacheStorageConnection::CacheInfo> CacheStorageEngine::caches(const String& origin) const
    281 {
    282     auto iterator = m_caches.find(origin);
    283     if (iterator == m_caches.end())
    284         return { };
    285 
    286     Vector<WebCore::CacheStorageConnection::CacheInfo> cachesInfo;
    287     cachesInfo.reserveInitialCapacity(iterator->value.size());
    288     for (auto& cache : iterator->value)
    289         cachesInfo.uncheckedAppend(WebCore::CacheStorageConnection::CacheInfo { cache.identifier, cache.name});
    290 
    291     return cachesInfo;
    292 }
    293 
    294291Vector<uint64_t> CacheStorageEngine::queryCache(const Vector<Record>& records, const WebCore::ResourceRequest& request, const WebCore::CacheQueryOptions& options)
    295292{
  • trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.h

    r220917 r221085  
    8080    static CacheStorageEngine& defaultEngine();
    8181
    82     void writeCachesToDisk(CompletionCallback&&);
    83     void readCachesFromDisk(CompletionCallback&&);
    84 
    8582    struct Cache {
    8683        uint64_t identifier;
     
    9087    };
    9188
     89    void writeCachesToDisk(CompletionCallback&&);
     90
     91    using CachesOrError = Expected<std::reference_wrapper<Vector<Cache>>, Error>;
     92    using CachesCallback = Function<void(CachesOrError&&)>;
     93    void readCachesFromDisk(const String& origin, Function<void(CachesOrError&&)>&&);
     94
    9295    using CacheOrError = Expected<std::reference_wrapper<Cache>, Error>;
    9396    using CacheCallback = Function<void(CacheOrError&&)>;
    94 
    95     Vector<WebCore::CacheStorageConnection::CacheInfo> caches(const String& origin) const;
    9697
    9798    void readCache(uint64_t cacheIdentifier, CacheCallback&&);
Note: See TracChangeset for help on using the changeset viewer.