Network Cache: Add thread-safe accessors for storage paths
[WebKit-https.git] / Source / WebKit2 / NetworkProcess / cache / NetworkCache.cpp
index b23177e..52af645 100644 (file)
@@ -92,7 +92,7 @@ static Key makeCacheKey(const WebCore::ResourceRequest& request)
 #endif
     if (partition.isEmpty())
         partition = ASCIILiteral("No partition");
-    return { partition, request.url().string() };
+    return { request.httpMethod(), partition, request.url().string()  };
 }
 
 static String headerValueForVary(const WebCore::ResourceRequest& request, const String& headerName)
@@ -370,18 +370,18 @@ void Cache::store(const WebCore::ResourceRequest& originalRequest, const WebCore
 
     auto record = cacheEntry.encodeAsStorageRecord();
 
-    m_storage->store(record, [completionHandler](bool success, const Data& bodyData) {
+    m_storage->store(record, [completionHandler](const Data& bodyData) {
         MappedBody mappedBody;
 #if ENABLE(SHAREABLE_RESOURCE)
         if (bodyData.isMap()) {
-            RefPtr<SharedMemory> sharedMemory = SharedMemory::createFromVMBuffer(const_cast<uint8_t*>(bodyData.data()), bodyData.size());
+            RefPtr<SharedMemory> sharedMemory = SharedMemory::create(const_cast<uint8_t*>(bodyData.data()), bodyData.size(), SharedMemory::Protection::ReadOnly);
             mappedBody.shareableResource = sharedMemory ? ShareableResource::create(WTF::move(sharedMemory), 0, bodyData.size()) : nullptr;
             if (mappedBody.shareableResource)
                 mappedBody.shareableResource->createHandle(mappedBody.shareableResourceHandle);
         }
 #endif
         completionHandler(mappedBody);
-        LOG(NetworkCache, "(NetworkProcess) store success=%d", success);
+        LOG(NetworkCache, "(NetworkProcess) stored");
     });
 }
 
@@ -396,9 +396,7 @@ void Cache::update(const WebCore::ResourceRequest& originalRequest, const Entry&
 
     auto updateRecord = updateEntry.encodeAsStorageRecord();
 
-    m_storage->update(updateRecord, existingEntry.sourceStorageRecord(), [](bool success, const Data&) {
-        LOG(NetworkCache, "(NetworkProcess) updated, success=%d", success);
-    });
+    m_storage->store(updateRecord, { });
 }
 
 void Cache::remove(const Key& key)
@@ -428,7 +426,7 @@ void Cache::traverse(std::function<void (const Entry*)>&& traverseHandler)
 
 String Cache::dumpFilePath() const
 {
-    return WebCore::pathByAppendingComponent(m_storage->baseDirectoryPath(), "dump.json");
+    return WebCore::pathByAppendingComponent(m_storage->versionPath(), "dump.json");
 }
 
 void Cache::dumpContentsToFile()
@@ -447,7 +445,8 @@ void Cache::dumpContentsToFile()
         size_t bodySize { 0 };
     };
     Totals totals;
-    m_storage->traverse(Storage::TraverseFlag::ComputeWorth, [fd, totals](const Storage::Record* record, const Storage::RecordInfo& info) mutable {
+    auto flags = Storage::TraverseFlag::ComputeWorth | Storage::TraverseFlag::ShareCount;
+    m_storage->traverse(flags, [fd, totals](const Storage::Record* record, const Storage::RecordInfo& info) mutable {
         if (!record) {
             StringBuilder epilogue;
             epilogue.appendLiteral("{}\n],\n");
@@ -500,7 +499,7 @@ void Cache::clear()
 
 String Cache::storagePath() const
 {
-    return m_storage ? m_storage->directoryPath() : String();
+    return m_storage ? m_storage->versionPath() : String();
 }
 
 }