Modified: trunk/Source/WebKit/ChangeLog (221084 => 221085)
--- trunk/Source/WebKit/ChangeLog 2017-08-23 17:41:48 UTC (rev 221084)
+++ trunk/Source/WebKit/ChangeLog 2017-08-23 17:52:56 UTC (rev 221085)
@@ -1,3 +1,18 @@
+2017-08-23 Youenn Fablet <[email protected]>
+
+ CacheStorageEngine readCachesFromDisk callback should return the read Caches
+ https://bugs.webkit.org/show_bug.cgi?id=175882
+
+ 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:
+
2017-08-23 Chris Dumez <[email protected]>
Regression(r221059): NetworkDataTask::didReceiveResponse() should not use PolicyUse for HTTP/0.9
Modified: trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp (221084 => 221085)
--- trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp 2017-08-23 17:41:48 UTC (rev 221084)
+++ trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp 2017-08-23 17:52:56 UTC (rev 221085)
@@ -64,15 +64,13 @@
void CacheStorageEngine::open(const String& origin, const String& cacheName, CacheIdentifierCallback&& callback)
{
- readCachesFromDisk([this, origin, cacheName, callback = WTFMove(callback)](std::optional<Error>&& error) mutable {
- if (error) {
- callback(makeUnexpected(error.value()));
+ readCachesFromDisk(origin, [this, cacheName, callback = WTFMove(callback)](CachesOrError&& cachesOrError) mutable {
+ if (!cachesOrError.hasValue()) {
+ callback(makeUnexpected(cachesOrError.error()));
return;
}
- auto& caches = m_caches.ensure(origin, [] {
- return Vector<Cache>();
- }).iterator->value;
+ auto& caches = cachesOrError.value().get();
auto position = caches.findMatching([&](const auto& item) { return item.name == cacheName; });
if (position == notFound) {
@@ -118,12 +116,20 @@
void CacheStorageEngine::retrieveCaches(const String& origin, CacheInfosCallback&& callback)
{
- readCachesFromDisk([this, origin, callback = WTFMove(callback)](std::optional<Error>&& error) mutable {
- if (error) {
- callback(makeUnexpected(error.value()));
+ readCachesFromDisk(origin, [this, callback = WTFMove(callback)](CachesOrError&& cachesOrError) mutable {
+ if (!cachesOrError.hasValue()) {
+ callback(makeUnexpected(cachesOrError.error()));
return;
}
- callback(caches(origin));
+
+ auto& caches = cachesOrError.value().get();
+
+ Vector<WebCore::CacheStorageConnection::CacheInfo> cachesInfo;
+ cachesInfo.reserveInitialCapacity(caches.size());
+ for (auto& cache : caches)
+ cachesInfo.uncheckedAppend(WebCore::CacheStorageConnection::CacheInfo { cache.identifier, cache.name});
+
+ callback(WTFMove(cachesInfo));
});
}
@@ -230,10 +236,15 @@
callback(std::nullopt);
}
-void CacheStorageEngine::readCachesFromDisk(CompletionCallback&& callback)
+void CacheStorageEngine::readCachesFromDisk(const String& origin, CachesCallback&& callback)
{
// FIXME: Implement reading.
- callback(std::nullopt);
+
+ auto& caches = m_caches.ensure(origin, [] {
+ return Vector<Cache>();
+ }).iterator->value;
+
+ callback(std::reference_wrapper<Vector<Cache>> { caches });
}
void CacheStorageEngine::readCache(uint64_t cacheIdentifier, CacheCallback&& callback)
@@ -277,20 +288,6 @@
return result;
}
-Vector<WebCore::CacheStorageConnection::CacheInfo> CacheStorageEngine::caches(const String& origin) const
-{
- auto iterator = m_caches.find(origin);
- if (iterator == m_caches.end())
- return { };
-
- Vector<WebCore::CacheStorageConnection::CacheInfo> cachesInfo;
- cachesInfo.reserveInitialCapacity(iterator->value.size());
- for (auto& cache : iterator->value)
- cachesInfo.uncheckedAppend(WebCore::CacheStorageConnection::CacheInfo { cache.identifier, cache.name});
-
- return cachesInfo;
-}
-
Vector<uint64_t> CacheStorageEngine::queryCache(const Vector<Record>& records, const WebCore::ResourceRequest& request, const WebCore::CacheQueryOptions& options)
{
if (!options.ignoreMethod && request.httpMethod() != "GET")
Modified: trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.h (221084 => 221085)
--- trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.h 2017-08-23 17:41:48 UTC (rev 221084)
+++ trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.h 2017-08-23 17:52:56 UTC (rev 221085)
@@ -79,9 +79,6 @@
private:
static CacheStorageEngine& defaultEngine();
- void writeCachesToDisk(CompletionCallback&&);
- void readCachesFromDisk(CompletionCallback&&);
-
struct Cache {
uint64_t identifier;
String name;
@@ -89,11 +86,15 @@
uint64_t nextRecordIdentifier { 0 };
};
+ void writeCachesToDisk(CompletionCallback&&);
+
+ using CachesOrError = Expected<std::reference_wrapper<Vector<Cache>>, Error>;
+ using CachesCallback = Function<void(CachesOrError&&)>;
+ void readCachesFromDisk(const String& origin, Function<void(CachesOrError&&)>&&);
+
using CacheOrError = Expected<std::reference_wrapper<Cache>, Error>;
using CacheCallback = Function<void(CacheOrError&&)>;
- Vector<WebCore::CacheStorageConnection::CacheInfo> caches(const String& origin) const;
-
void readCache(uint64_t cacheIdentifier, CacheCallback&&);
void writeCacheRecords(uint64_t cacheIdentifier, Vector<uint64_t>&&, RecordIdentifiersCallback&&);
void removeCacheRecords(uint64_t cacheIdentifier, Vector<uint64_t>&&, RecordIdentifiersCallback&&);