Diff
Modified: trunk/Source/WebKit/ChangeLog (221704 => 221705)
--- trunk/Source/WebKit/ChangeLog 2017-09-06 21:25:19 UTC (rev 221704)
+++ trunk/Source/WebKit/ChangeLog 2017-09-06 21:37:00 UTC (rev 221705)
@@ -1,3 +1,27 @@
+2017-09-06 Youenn Fablet <[email protected]>
+
+ Introduce asynchronous opening of CacheStorageEngine cache
+ https://bugs.webkit.org/show_bug.cgi?id=176425
+
+ Reviewed by Alex Christensen.
+
+ Introducing Cache::open to allow reading from the filesystem to fill the Cache.
+ This is called by Caches when engine requests to open an existing Cache.
+
+ * NetworkProcess/cache/CacheStorageEngineCache.cpp:
+ (WebKit::CacheStorage::Cache::Cache):
+ (WebKit::CacheStorage::Cache::open):
+ (WebKit::CacheStorage::Cache::finishOpening):
+ (WebKit::CacheStorage::Cache::readRecordsList):
+ * NetworkProcess/cache/CacheStorageEngineCache.h:
+ * NetworkProcess/cache/CacheStorageEngineCaches.cpp:
+ (WebKit::CacheStorage::Caches::find):
+ (WebKit::CacheStorage::Caches::open):
+ (WebKit::CacheStorage::Caches::remove):
+ (WebKit::CacheStorage::Caches::readCachesFromDisk):
+ (WebKit::CacheStorage::Caches::find const): Deleted.
+ * NetworkProcess/cache/CacheStorageEngineCaches.h:
+
2017-09-06 Alex Christensen <[email protected]>
Unreviewed, rolling out r221694.
Modified: trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCache.cpp (221704 => 221705)
--- trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCache.cpp 2017-09-06 21:25:19 UTC (rev 221704)
+++ trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCache.cpp 2017-09-06 21:37:00 UTC (rev 221705)
@@ -65,12 +65,53 @@
return results;
}
-Cache::Cache(uint64_t identifier, String&& name)
- : m_identifier(identifier)
+Cache::Cache(Caches& caches, uint64_t identifier, State state, String&& name)
+ : m_caches(caches)
+ , m_state(state)
+ , m_identifier(identifier)
, m_name(WTFMove(name))
{
}
+void Cache::open(CompletionCallback&& callback)
+{
+ if (m_state == State::Open) {
+ callback(std::nullopt);
+ return;
+ }
+ if (m_state == State::Opening) {
+ m_pendingOpeningCallbacks.append(WTFMove(callback));
+ return;
+ }
+ m_state = State::Opening;
+ readRecordsList([caches = makeRef(m_caches), identifier = m_identifier, callback = WTFMove(callback)](std::optional<Error>&& error) mutable {
+ auto* cache = caches->find(identifier);
+ if (!cache) {
+ callback(Error::Internal);
+ return;
+ }
+ cache->finishOpening(WTFMove(callback), WTFMove(error));
+ });
+}
+
+void Cache::finishOpening(CompletionCallback&& callback, std::optional<Error>&& error)
+{
+ if (error) {
+ m_state = State::Uninitialized;
+ callback(error.value());
+ auto callbacks = WTFMove(m_pendingOpeningCallbacks);
+ for (auto& callback : callbacks)
+ callback(error.value());
+ return;
+ }
+ m_state = State::Open;
+
+ callback(std::nullopt);
+ auto callbacks = WTFMove(m_pendingOpeningCallbacks);
+ for (auto& callback : callbacks)
+ callback(std::nullopt);
+}
+
Vector<Record> Cache::retrieveRecords(const URL& url) const
{
if (url.isNull()) {
@@ -209,6 +250,12 @@
});
}
+void Cache::readRecordsList(CompletionCallback&& callback)
+{
+ // FIXME: Implement this.
+ callback(std::nullopt);
+}
+
void Cache::writeRecordsList(CompletionCallback&& callback)
{
// FIXME: Implement this.
Modified: trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCache.h (221704 => 221705)
--- trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCache.h 2017-09-06 21:25:19 UTC (rev 221704)
+++ trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCache.h 2017-09-06 21:37:00 UTC (rev 221705)
@@ -33,10 +33,15 @@
namespace CacheStorage {
+class Caches;
+
class Cache {
public:
- Cache(uint64_t identifier, String&& name);
+ enum class State { Uninitialized, Opening, Open };
+ Cache(Caches&, uint64_t identifier, State, String&& name);
+ void open(WebCore::DOMCacheEngine::CompletionCallback&&);
+
uint64_t identifier() const { return m_identifier; }
const String& name() const { return m_name; }
@@ -51,14 +56,20 @@
const Vector<WebCore::DOMCacheEngine::Record>* recordsFromURL(const WebCore::URL&) const;
WebCore::DOMCacheEngine::Record& addNewURLRecord(WebCore::DOMCacheEngine::Record&&);
+ void finishOpening(WebCore::DOMCacheEngine::CompletionCallback&&, std::optional<WebCore::DOMCacheEngine::Error>&&);
+
+ void readRecordsList(WebCore::DOMCacheEngine::CompletionCallback&&);
void writeRecordsList(WebCore::DOMCacheEngine::CompletionCallback&&);
void writeRecordToDisk(WebCore::DOMCacheEngine::Record&);
void removeRecordFromDisk(WebCore::DOMCacheEngine::Record&);
+ Caches& m_caches;
+ State m_state;
uint64_t m_identifier { 0 };
String m_name;
HashMap<String, Vector<WebCore::DOMCacheEngine::Record>> m_records;
uint64_t m_nextRecordIdentifier { 0 };
+ Vector<WebCore::DOMCacheEngine::CompletionCallback> m_pendingOpeningCallbacks;
};
} // namespace CacheStorage
Modified: trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp (221704 => 221705)
--- trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp 2017-09-06 21:25:19 UTC (rev 221704)
+++ trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp 2017-09-06 21:37:00 UTC (rev 221705)
@@ -101,7 +101,7 @@
m_rootPath = { };
}
-const Cache* Caches::find(const String& name) const
+Cache* Caches::find(const String& name)
{
auto position = m_caches.findMatching([&](const auto& item) { return item.name() == name; });
return (position != notFound) ? &m_caches[position] : nullptr;
@@ -120,9 +120,14 @@
void Caches::open(const String& name, CacheIdentifierCallback&& callback)
{
ASSERT(m_engine);
-
if (auto* cache = find(name)) {
- callback(CacheIdentifierOperationResult { cache->identifier(), false });
+ cache->open([cacheIdentifier = cache->identifier(), callback = WTFMove(callback)](std::optional<Error>&& error) mutable {
+ if (error) {
+ callback(makeUnexpected(error.value()));
+ return;
+ }
+ callback(CacheIdentifierOperationResult { cacheIdentifier, false });
+ });
return;
}
@@ -129,7 +134,8 @@
makeDirty();
uint64_t cacheIdentifier = m_engine->nextCacheIdentifier();
- m_caches.append(Cache { cacheIdentifier, String { name } });
+ m_caches.append(Cache { *this, cacheIdentifier, Cache::State::Open, String { name } });
+
writeCachesToDisk([callback = WTFMove(callback), cacheIdentifier](std::optional<Error>&& error) mutable {
callback(CacheIdentifierOperationResult { cacheIdentifier, !!error });
});
@@ -149,9 +155,8 @@
makeDirty();
- auto cache = WTFMove(m_caches[position]);
+ m_removedCaches.append(WTFMove(m_caches[position]));
m_caches.remove(position);
- m_removedCaches.append(WTFMove(cache));
writeCachesToDisk([callback = WTFMove(callback), identifier](std::optional<Error>&& error) mutable {
callback(CacheIdentifierOperationResult { identifier, !!error });
@@ -223,7 +228,7 @@
Vector<Cache> caches;
caches.reserveInitialCapacity(result.value().size());
for (auto& name : result.value())
- caches.uncheckedAppend(Cache { m_engine->nextCacheIdentifier(), WTFMove(name) });
+ caches.uncheckedAppend(Cache { *this, m_engine->nextCacheIdentifier(), Cache::State::Uninitialized, WTFMove(name) });
callback(WTFMove(caches));
});
Modified: trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.h (221704 => 221705)
--- trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.h 2017-09-06 21:25:19 UTC (rev 221704)
+++ trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.h 2017-09-06 21:37:00 UTC (rev 221705)
@@ -48,7 +48,6 @@
bool isInitialized() const { return m_isInitialized; }
WebCore::DOMCacheEngine::CacheInfos cacheInfos(uint64_t updateCounter) const;
- const Cache* find(const String& name) const;
Cache* find(uint64_t identifier);
private:
@@ -57,6 +56,9 @@
void readCachesFromDisk(WTF::Function<void(Expected<Vector<Cache>, WebCore::DOMCacheEngine::Error>&&)>&&);
void writeCachesToDisk(WebCore::DOMCacheEngine::CompletionCallback&&);
+
+ Cache* find(const String& name);
+
bool shouldPersist() const { return !m_rootPath.isNull(); }
void makeDirty() { ++m_updateCounter; }