[macOS Sierra] Layout Test http/wpt/cache-storage/cache-put-keys.https.any.worker...
[WebKit-https.git] / Source / WebKit / NetworkProcess / cache / CacheStorageEngineCaches.cpp
index dae2012..070fa5f 100644 (file)
@@ -26,6 +26,7 @@
 #include "config.h"
 #include "CacheStorageEngine.h"
 
+#include "Logging.h"
 #include "NetworkCacheCoders.h"
 #include "NetworkCacheIOChannel.h"
 #include <WebCore/SecurityOrigin.h>
@@ -68,6 +69,7 @@ void Caches::retrieveOriginFromDirectory(const String& folderPath, WorkQueue& qu
         channel->read(0, std::numeric_limits<size_t>::max(), nullptr, [completionHandler = WTFMove(completionHandler)](const Data& data, int error) mutable {
             ASSERT(RunLoop::isMain());
             if (error) {
+                RELEASE_LOG_ERROR(CacheStorage, "Caches::retrieveOriginFromDirectory failed reading channel with error %d", error);
                 completionHandler(std::nullopt);
                 return;
             }
@@ -138,8 +140,9 @@ void Caches::initialize(WebCore::DOMCacheEngine::CompletionCallback&& callback)
         return;
     }
 
-    auto storage = Storage::open(m_rootPath, Storage::Mode::Normal);
+    auto storage = Storage::open(m_rootPath, Storage::Mode::AvoidRandomness);
     if (!storage) {
+        RELEASE_LOG_ERROR(CacheStorage, "Caches::initialize failed opening storage");
         callback(Error::WriteDisk);
         return;
     }
@@ -150,6 +153,8 @@ void Caches::initialize(WebCore::DOMCacheEngine::CompletionCallback&& callback)
 
     storeOrigin([this] (std::optional<Error>&& error) mutable {
         if (error) {
+            RELEASE_LOG_ERROR(CacheStorage, "Caches::initialize failed storing origin with error %d", *error);
+
             auto pendingCallbacks = WTFMove(m_pendingInitializationCallbacks);
             for (auto& callback : pendingCallbacks)
                 callback(Error::WriteDisk);
@@ -162,6 +167,8 @@ void Caches::initialize(WebCore::DOMCacheEngine::CompletionCallback&& callback)
             makeDirty();
 
             if (!result.has_value()) {
+                RELEASE_LOG_ERROR(CacheStorage, "Caches::initialize failed reading caches from disk with error %d", result.error());
+
                 auto pendingCallbacks = WTFMove(m_pendingInitializationCallbacks);
                 for (auto& callback : pendingCallbacks)
                     callback(result.error());
@@ -367,11 +374,8 @@ static inline Data encodeCacheNames(const Vector<Cache>& caches)
     return Data { encoder.buffer(), encoder.bufferSize() };
 }
 
-static inline Expected<Vector<std::pair<String, String>>, Error> decodeCachesNames(const Data& data, int error)
+static inline Expected<Vector<std::pair<String, String>>, Error> decodeCachesNames(const Data& data)
 {
-    if (error)
-        return makeUnexpected(Error::ReadDisk);
-
     WTF::Persistence::Decoder decoder(data.data(), data.size());
     uint64_t count;
     if (!decoder.decode(count))
@@ -415,8 +419,15 @@ void Caches::readCachesFromDisk(WTF::Function<void(Expected<Vector<Cache>, Error
             return;
         }
 
-        auto result = decodeCachesNames(data, error);
+        if (error) {
+            RELEASE_LOG_ERROR(CacheStorage, "Caches::readCachesFromDisk failed reading caches from disk with error %d", error);
+            callback(makeUnexpected(Error::ReadDisk));
+            return;
+        }
+
+        auto result = decodeCachesNames(data);
         if (!result.has_value()) {
+            RELEASE_LOG_ERROR(CacheStorage, "Caches::decodeCachesNames failed decoding caches with error %d", result.error());
             callback(makeUnexpected(result.error()));
             return;
         }
@@ -446,6 +457,9 @@ void Caches::writeCachesToDisk(CompletionCallback&& callback)
     m_isWritingCachesToDisk = true;
     m_engine->writeFile(cachesListFilename(m_rootPath), encodeCacheNames(m_caches), [this, protectedThis = makeRef(*this), callback = WTFMove(callback)](std::optional<Error>&& error) mutable {
         m_isWritingCachesToDisk = false;
+        if (error)
+            RELEASE_LOG_ERROR(CacheStorage, "Caches::writeCachesToDisk failed writing caches to disk with error %d", *error);
+
         callback(WTFMove(error));
         while (!m_pendingWritingCachesToDiskCallbacks.isEmpty() && !m_isWritingCachesToDisk)
             m_pendingWritingCachesToDiskCallbacks.takeFirst()(std::nullopt);
@@ -509,12 +523,14 @@ void Caches::readRecord(const NetworkCache::Key& key, WTF::Function<void(Expecte
 
     m_storage->retrieve(key, 4, [protectedStorage = makeRef(*m_storage), callback = WTFMove(callback)](std::unique_ptr<Storage::Record> storage, const Storage::Timings&) mutable {
         if (!storage) {
+            RELEASE_LOG_ERROR(CacheStorage, "Caches::readRecord failed reading record from disk");
             callback(makeUnexpected(Error::ReadDisk));
             return false;
         }
 
         auto record = Cache::decode(*storage);
         if (!record) {
+            RELEASE_LOG_ERROR(CacheStorage, "Caches::readRecord failed decoding record from disk");
             callback(makeUnexpected(Error::ReadDisk));
             return false;
         }