Title: [209189] trunk/Source/WebKit2
Revision
209189
Author
an...@apple.com
Date
2016-12-01 11:31:06 -0800 (Thu, 01 Dec 2016)

Log Message

Revert r208931
https://bugs.webkit.org/show_bug.cgi?id=164924

PLT regression.

* NetworkProcess/cache/NetworkCache.cpp:
(WebKit::NetworkCache::makeCacheKey):
(WebKit::NetworkCache::Cache::makeCacheKey): Deleted.
* NetworkProcess/cache/NetworkCache.h:
* NetworkProcess/cache/NetworkCacheBlobStorage.cpp:
(WebKit::NetworkCache::BlobStorage::BlobStorage):
(WebKit::NetworkCache::BlobStorage::add):
(WebKit::NetworkCache::BlobStorage::get):
* NetworkProcess/cache/NetworkCacheBlobStorage.h:
* NetworkProcess/cache/NetworkCacheData.cpp:
(WebKit::NetworkCache::computeSHA1):
(WebKit::NetworkCache::makeSalt): Deleted.
(WebKit::NetworkCache::readOrMakeSalt): Deleted.
* NetworkProcess/cache/NetworkCacheData.h:
* NetworkProcess/cache/NetworkCacheKey.cpp:
(WebKit::NetworkCache::noPartitionString):
(WebKit::NetworkCache::Key::Key):
(WebKit::NetworkCache::Key::hasPartition):
(WebKit::NetworkCache::Key::computeHash):
(WebKit::NetworkCache::Key::hashAsString):
(WebKit::NetworkCache::Key::computePartitionHash): Deleted.
* NetworkProcess/cache/NetworkCacheKey.h:
(WebKit::NetworkCache::Key::hash):
(WebKit::NetworkCache::Key::partitionHash): Deleted.
(WebKit::NetworkCache::Key::hashAsString): Deleted.
(WebKit::NetworkCache::Key::partitionHashAsString): Deleted.
* NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.cpp:
(WebKit::NetworkCache::makeSubresourcesKey):
(WebKit::NetworkCache::constructRevalidationRequest):
(WebKit::NetworkCache::SpeculativeLoadManager::PendingFrameLoad::saveToDiskIfReady):
(WebKit::NetworkCache::SpeculativeLoadManager::retrieveSubresourcesEntry):
* NetworkProcess/cache/NetworkCacheStorage.cpp:
(WebKit::NetworkCache::Storage::open):
(WebKit::NetworkCache::traverseRecordsFiles):
(WebKit::NetworkCache::Storage::Storage):
(WebKit::NetworkCache::Storage::recordDirectoryPathForKey):
(WebKit::NetworkCache::decodeRecordHeader):
(WebKit::NetworkCache::Storage::readRecord):
(WebKit::NetworkCache::Storage::encodeRecord):
(WebKit::NetworkCache::Storage::traverse):
(WebKit::NetworkCache::makeSaltFilePath): Deleted.
* NetworkProcess/cache/NetworkCacheStorage.h:
(WebKit::NetworkCache::Storage::salt): Deleted.

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (209188 => 209189)


--- trunk/Source/WebKit2/ChangeLog	2016-12-01 19:27:25 UTC (rev 209188)
+++ trunk/Source/WebKit2/ChangeLog	2016-12-01 19:31:06 UTC (rev 209189)
@@ -1,3 +1,54 @@
+2016-12-01  Antti Koivisto  <an...@apple.com>
+
+        Revert r208931
+        https://bugs.webkit.org/show_bug.cgi?id=164924
+
+        PLT regression.
+
+        * NetworkProcess/cache/NetworkCache.cpp:
+        (WebKit::NetworkCache::makeCacheKey):
+        (WebKit::NetworkCache::Cache::makeCacheKey): Deleted.
+        * NetworkProcess/cache/NetworkCache.h:
+        * NetworkProcess/cache/NetworkCacheBlobStorage.cpp:
+        (WebKit::NetworkCache::BlobStorage::BlobStorage):
+        (WebKit::NetworkCache::BlobStorage::add):
+        (WebKit::NetworkCache::BlobStorage::get):
+        * NetworkProcess/cache/NetworkCacheBlobStorage.h:
+        * NetworkProcess/cache/NetworkCacheData.cpp:
+        (WebKit::NetworkCache::computeSHA1):
+        (WebKit::NetworkCache::makeSalt): Deleted.
+        (WebKit::NetworkCache::readOrMakeSalt): Deleted.
+        * NetworkProcess/cache/NetworkCacheData.h:
+        * NetworkProcess/cache/NetworkCacheKey.cpp:
+        (WebKit::NetworkCache::noPartitionString):
+        (WebKit::NetworkCache::Key::Key):
+        (WebKit::NetworkCache::Key::hasPartition):
+        (WebKit::NetworkCache::Key::computeHash):
+        (WebKit::NetworkCache::Key::hashAsString):
+        (WebKit::NetworkCache::Key::computePartitionHash): Deleted.
+        * NetworkProcess/cache/NetworkCacheKey.h:
+        (WebKit::NetworkCache::Key::hash):
+        (WebKit::NetworkCache::Key::partitionHash): Deleted.
+        (WebKit::NetworkCache::Key::hashAsString): Deleted.
+        (WebKit::NetworkCache::Key::partitionHashAsString): Deleted.
+        * NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.cpp:
+        (WebKit::NetworkCache::makeSubresourcesKey):
+        (WebKit::NetworkCache::constructRevalidationRequest):
+        (WebKit::NetworkCache::SpeculativeLoadManager::PendingFrameLoad::saveToDiskIfReady):
+        (WebKit::NetworkCache::SpeculativeLoadManager::retrieveSubresourcesEntry):
+        * NetworkProcess/cache/NetworkCacheStorage.cpp:
+        (WebKit::NetworkCache::Storage::open):
+        (WebKit::NetworkCache::traverseRecordsFiles):
+        (WebKit::NetworkCache::Storage::Storage):
+        (WebKit::NetworkCache::Storage::recordDirectoryPathForKey):
+        (WebKit::NetworkCache::decodeRecordHeader):
+        (WebKit::NetworkCache::Storage::readRecord):
+        (WebKit::NetworkCache::Storage::encodeRecord):
+        (WebKit::NetworkCache::Storage::traverse):
+        (WebKit::NetworkCache::makeSaltFilePath): Deleted.
+        * NetworkProcess/cache/NetworkCacheStorage.h:
+        (WebKit::NetworkCache::Storage::salt): Deleted.
+
 2016-11-30  Sam Weinig  <s...@webkit.org>
 
         [WebIDL] Remove custom bindings for File and Blob constructors

Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp (209188 => 209189)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp	2016-12-01 19:27:25 UTC (rev 209188)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp	2016-12-01 19:31:06 UTC (rev 209189)
@@ -114,7 +114,7 @@
     m_storage->setCapacity(maximumSize);
 }
 
-Key Cache::makeCacheKey(const WebCore::ResourceRequest& request)
+static Key makeCacheKey(const WebCore::ResourceRequest& request)
 {
 #if ENABLE(CACHE_PARTITIONING)
     String partition = request.cachePartition();
@@ -125,7 +125,7 @@
     // FIXME: This implements minimal Range header disk cache support. We don't parse
     // ranges so only the same exact range request will be served from the cache.
     String range = request.httpHeaderField(WebCore::HTTPHeaderName::Range);
-    return { partition, resourceType(), range, request.url().string(), m_storage->salt() };
+    return { partition, resourceType(), range, request.url().string() };
 }
 
 static bool cachePolicyAllowsExpired(WebCore::ResourceRequestCachePolicy policy)

Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.h (209188 => 209189)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.h	2016-12-01 19:27:25 UTC (rev 209188)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.h	2016-12-01 19:31:06 UTC (rev 209189)
@@ -129,8 +129,6 @@
     Cache() = default;
     ~Cache() = delete;
 
-    Key makeCacheKey(const WebCore::ResourceRequest&);
-
     String dumpFilePath() const;
     void deleteDumpFile();
 

Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheBlobStorage.cpp (209188 => 209189)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheBlobStorage.cpp	2016-12-01 19:27:25 UTC (rev 209188)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheBlobStorage.cpp	2016-12-01 19:31:06 UTC (rev 209189)
@@ -40,9 +40,8 @@
 namespace WebKit {
 namespace NetworkCache {
 
-BlobStorage::BlobStorage(const String& blobDirectoryPath, Salt salt)
+BlobStorage::BlobStorage(const String& blobDirectoryPath)
     : m_blobDirectoryPath(blobDirectoryPath)
-    , m_salt(salt)
 {
 }
 
@@ -86,7 +85,7 @@
 {
     ASSERT(!RunLoop::isMain());
 
-    auto hash = computeSHA1(data, m_salt);
+    auto hash = computeSHA1(data);
     if (data.isEmpty())
         return { data, hash };
 
@@ -124,7 +123,7 @@
     auto linkPath = WebCore::fileSystemRepresentation(path);
     auto data = ""
 
-    return { data, computeSHA1(data, m_salt) };
+    return { data, computeSHA1(data) };
 }
 
 void BlobStorage::remove(const String& path)

Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheBlobStorage.h (209188 => 209189)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheBlobStorage.h	2016-12-01 19:27:25 UTC (rev 209188)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheBlobStorage.h	2016-12-01 19:31:06 UTC (rev 209189)
@@ -39,7 +39,7 @@
 class BlobStorage {
     WTF_MAKE_NONCOPYABLE(BlobStorage);
 public:
-    BlobStorage(const String& blobDirectoryPath, Salt);
+    BlobStorage(const String& blobDirectoryPath);
 
     struct Blob {
         Data data;
@@ -63,7 +63,6 @@
     String blobPathForHash(const SHA1::Digest&) const;
 
     const String m_blobDirectoryPath;
-    const Salt m_salt;
 
     std::atomic<size_t> m_approximateSize { 0 };
 };

Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheData.cpp (209188 => 209189)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheData.cpp	2016-12-01 19:27:25 UTC (rev 209188)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheData.cpp	2016-12-01 19:31:06 UTC (rev 209189)
@@ -28,11 +28,9 @@
 
 #if ENABLE(NETWORK_CACHE)
 
-#include <WebCore/FileSystem.h>
 #include <fcntl.h>
 #include <sys/mman.h>
 #include <sys/stat.h>
-#include <wtf/CryptographicallyRandomNumber.h>
 
 namespace WebKit {
 namespace NetworkCache {
@@ -105,15 +103,13 @@
     return Data::adoptMap(map, size, fd);
 }
 
-SHA1::Digest computeSHA1(const Data& data, const Salt& salt)
+SHA1::Digest computeSHA1(const Data& data)
 {
     SHA1 sha1;
-    sha1.addBytes(salt.data(), salt.size());
     data.apply([&sha1](const uint8_t* data, size_t size) {
         sha1.addBytes(data, size);
         return true;
     });
-
     SHA1::Digest digest;
     sha1.computeHash(digest);
     return digest;
@@ -128,35 +124,6 @@
     return !memcmp(a.data(), b.data(), a.size());
 }
 
-static Salt makeSalt()
-{
-    Salt salt;
-    static_assert(salt.size() == 8, "Salt size");
-    *reinterpret_cast<uint32_t*>(&salt[0]) = cryptographicallyRandomNumber();
-    *reinterpret_cast<uint32_t*>(&salt[4]) = cryptographicallyRandomNumber();
-    return salt;
-}
-
-std::optional<Salt> readOrMakeSalt(const String& path)
-{
-    auto cpath = WebCore::fileSystemRepresentation(path);
-    auto fd = open(cpath.data(), O_RDONLY, 0);
-    Salt salt;
-    auto bytesRead = read(fd, salt.data(), salt.size());
-    close(fd);
-    if (bytesRead != salt.size()) {
-        salt = makeSalt();
-
-        unlink(cpath.data());
-        fd = open(cpath.data(), O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
-        bool success = write(fd, salt.data(), salt.size()) == salt.size();
-        close(fd);
-        if (!success)
-            return { };
-    }
-    return salt;
-}
-
 } // namespace NetworkCache
 } // namespace WebKit
 

Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheData.h (209188 => 209189)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheData.h	2016-12-01 19:27:25 UTC (rev 209188)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheData.h	2016-12-01 19:31:06 UTC (rev 209189)
@@ -156,12 +156,8 @@
 bool bytesEqual(const Data&, const Data&);
 Data adoptAndMapFile(int fd, size_t offset, size_t);
 Data mapFile(const char* path);
+SHA1::Digest computeSHA1(const Data&);
 
-using Salt = std::array<uint8_t, 8>;
-
-std::optional<Salt> readOrMakeSalt(const String& path);
-SHA1::Digest computeSHA1(const Data&, const Salt&);
-
 }
 }
 

Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheKey.cpp (209188 => 209189)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheKey.cpp	2016-12-01 19:27:25 UTC (rev 209188)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheKey.cpp	2016-12-01 19:31:06 UTC (rev 209189)
@@ -37,6 +37,12 @@
 namespace WebKit {
 namespace NetworkCache {
 
+static const String& noPartitionString()
+{
+    static NeverDestroyed<String> noPartition(ASCIILiteral("No partition"));
+    return noPartition;
+}
+
 Key::Key(const Key& o)
     : m_partition(o.m_partition.isolatedCopy())
     , m_type(o.m_type.isolatedCopy())
@@ -43,17 +49,15 @@
     , m_identifier(o.m_identifier.isolatedCopy())
     , m_range(o.m_range.isolatedCopy())
     , m_hash(o.m_hash)
-    , m_partitionHash(o.m_partitionHash)
 {
 }
 
-Key::Key(const String& partition, const String& type, const String& range, const String& identifier, const Salt& salt)
-    : m_partition(partition)
+Key::Key(const String& partition, const String& type, const String& range, const String& identifier)
+    : m_partition(partition.isEmpty() ? noPartitionString() : partition)
     , m_type(type)
     , m_identifier(identifier)
     , m_range(range)
-    , m_hash(computeHash(salt))
-    , m_partitionHash(computePartitionHash(salt))
+    , m_hash(computeHash())
 {
 }
 
@@ -62,6 +66,11 @@
 {
 }
 
+bool Key::hasPartition() const
+{
+    return m_partition != noPartitionString();
+}
+
 Key& Key::operator=(const Key& other)
 {
     m_partition = other.m_partition.isolatedCopy();
@@ -88,40 +97,25 @@
     sha1.addBytes(reinterpret_cast<const uint8_t*>(cString.data()), cString.length() + 1);
 }
 
-Key::HashType Key::computeHash(const Salt& salt) const
+Key::HashType Key::computeHash() const
 {
     // We don't really need a cryptographic hash. The key is always verified against the entry header.
     // SHA1 just happens to be suitably sized, fast and available.
     SHA1 sha1;
-    sha1.addBytes(salt.data(), salt.size());
-
     hashString(sha1, m_partition);
     hashString(sha1, m_type);
     hashString(sha1, m_identifier);
     hashString(sha1, m_range);
-
     SHA1::Digest hash;
     sha1.computeHash(hash);
     return hash;
 }
 
-Key::HashType Key::computePartitionHash(const Salt& salt) const
+String Key::hashAsString() const
 {
-    SHA1 sha1;
-    sha1.addBytes(salt.data(), salt.size());
-
-    hashString(sha1, m_partition);
-
-    SHA1::Digest hash;
-    sha1.computeHash(hash);
-    return hash;
-}
-
-String Key::hashAsString(const HashType& hash)
-{
     StringBuilder builder;
     builder.reserveCapacity(hashStringLength());
-    for (auto byte : hash) {
+    for (auto byte : m_hash) {
         builder.append(upperNibbleToASCIIHexDigit(byte));
         builder.append(lowerNibbleToASCIIHexDigit(byte));
     }

Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheKey.h (209188 => 209189)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheKey.h	2016-12-01 19:27:25 UTC (rev 209188)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheKey.h	2016-12-01 19:31:06 UTC (rev 209189)
@@ -28,7 +28,6 @@
 
 #if ENABLE(NETWORK_CACHE)
 
-#include "NetworkCacheData.h"
 #include <wtf/SHA1.h>
 #include <wtf/text/WTFString.h>
 
@@ -45,7 +44,7 @@
     Key() { }
     Key(const Key&);
     Key(Key&&) = default;
-    Key(const String& partition, const String& type, const String& range, const String& identifier, const Salt&);
+    Key(const String& partition, const String& type, const String& range, const String& identifier);
 
     Key& operator=(const Key&);
     Key& operator=(Key&&) = default;
@@ -55,19 +54,18 @@
 
     bool isNull() const { return m_identifier.isNull(); }
 
+    bool hasPartition() const;
     const String& partition() const { return m_partition; }
     const String& identifier() const { return m_identifier; }
     const String& type() const { return m_type; }
     const String& range() const { return m_range; }
 
-    const HashType& hash() const { return m_hash; }
-    const HashType& partitionHash() const { return m_partitionHash; }
+    HashType hash() const { return m_hash; }
 
     static bool stringToHash(const String&, HashType&);
 
     static size_t hashStringLength() { return 2 * sizeof(m_hash); }
-    String hashAsString() const { return hashAsString(m_hash); }
-    String partitionHashAsString() const { return hashAsString(m_partitionHash); }
+    String hashAsString() const;
 
     void encode(Encoder&) const;
     static bool decode(Decoder&, Key&);
@@ -76,9 +74,7 @@
     bool operator!=(const Key& other) const { return !(*this == other); }
 
 private:
-    static String hashAsString(const HashType&);
-    HashType computeHash(const Salt&) const;
-    HashType computePartitionHash(const Salt&) const;
+    HashType computeHash() const;
 
     String m_partition;
     String m_type;
@@ -85,7 +81,6 @@
     String m_identifier;
     String m_range;
     HashType m_hash;
-    HashType m_partitionHash;
 };
 
 }

Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.cpp (209188 => 209189)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.cpp	2016-12-01 19:27:25 UTC (rev 209188)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.cpp	2016-12-01 19:31:06 UTC (rev 209189)
@@ -79,9 +79,9 @@
     return resource;
 }
 
-static inline Key makeSubresourcesKey(const Key& resourceKey, const Salt& salt)
+static inline Key makeSubresourcesKey(const Key& resourceKey)
 {
-    return Key(resourceKey.partition(), subresourcesType(), resourceKey.range(), resourceKey.identifier(), salt);
+    return Key(resourceKey.partition(), subresourcesType(), resourceKey.range(), resourceKey.identifier());
 }
 
 static inline ResourceRequest constructRevalidationRequest(const Entry& entry, const SubresourceInfo& subResourceInfo)
@@ -90,7 +90,7 @@
     revalidationRequest.setHTTPHeaderFields(subResourceInfo.requestHeaders());
     revalidationRequest.setFirstPartyForCookies(subResourceInfo.firstPartyForCookies());
 #if ENABLE(CACHE_PARTITIONING)
-    if (!entry.key().partition().isEmpty())
+    if (entry.key().hasPartition())
         revalidationRequest.setCachePartition(entry.key().partition());
 #endif
     ASSERT_WITH_MESSAGE(entry.key().range().isEmpty(), "range is not supported");
@@ -226,7 +226,7 @@
             m_existingEntry->updateSubresourceLoads(m_subresourceLoads);
             m_storage.store(m_existingEntry->encodeAsStorageRecord(), [](const Data&) { });
         } else {
-            SubresourcesEntry entry(makeSubresourcesKey(m_mainResourceKey, m_storage.salt()), m_subresourceLoads);
+            SubresourcesEntry entry(makeSubresourcesKey(m_mainResourceKey), m_subresourceLoads);
             m_storage.store(entry.encodeAsStorageRecord(), [](const Data&) { });
         }
     }
@@ -521,7 +521,7 @@
 void SpeculativeLoadManager::retrieveSubresourcesEntry(const Key& storageKey, std::function<void (std::unique_ptr<SubresourcesEntry>)>&& completionHandler)
 {
     ASSERT(storageKey.type() == "Resource");
-    auto subresourcesStorageKey = makeSubresourcesKey(storageKey, m_storage.salt());
+    auto subresourcesStorageKey = makeSubresourcesKey(storageKey);
     m_storage.retrieve(subresourcesStorageKey, static_cast<unsigned>(ResourceLoadPriority::Medium), [completionHandler = WTFMove(completionHandler)](auto record) {
         if (!record) {
             completionHandler(nullptr);

Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.cpp (209188 => 209189)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.cpp	2016-12-01 19:27:25 UTC (rev 209188)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.cpp	2016-12-01 19:31:06 UTC (rev 209189)
@@ -42,7 +42,6 @@
 namespace WebKit {
 namespace NetworkCache {
 
-static const char saltFileName[] = "salt";
 static const char versionDirectoryPrefix[] = "Version ";
 static const char recordsDirectoryName[] = "Records";
 static const char blobsDirectoryName[] = "Blobs";
@@ -128,6 +127,15 @@
     unsigned activeCount { 0 };
 };
 
+std::unique_ptr<Storage> Storage::open(const String& cachePath)
+{
+    ASSERT(RunLoop::isMain());
+
+    if (!WebCore::makeAllDirectories(cachePath))
+        return nullptr;
+    return std::unique_ptr<Storage>(new Storage(cachePath));
+}
+
 static String makeVersionedDirectoryPath(const String& baseDirectoryPath)
 {
     String versionSubdirectory = versionDirectoryPrefix + String::number(Storage::version);
@@ -144,30 +152,13 @@
     return WebCore::pathByAppendingComponent(makeVersionedDirectoryPath(baseDirectoryPath), blobsDirectoryName);
 }
 
-static String makeSaltFilePath(const String& baseDirectoryPath)
+void traverseRecordsFiles(const String& recordsPath, const String& expectedType, const std::function<void (const String& fileName, const String& hashString, const String& type, bool isBlob, const String& recordDirectoryPath)>& function)
 {
-    return WebCore::pathByAppendingComponent(makeVersionedDirectoryPath(baseDirectoryPath), saltFileName);
-}
-
-std::unique_ptr<Storage> Storage::open(const String& cachePath)
-{
-    ASSERT(RunLoop::isMain());
-
-    if (!WebCore::makeAllDirectories(makeVersionedDirectoryPath(cachePath)))
-        return nullptr;
-    auto salt = readOrMakeSalt(makeSaltFilePath(cachePath));
-    if (!salt)
-        return nullptr;
-    return std::unique_ptr<Storage>(new Storage(cachePath, *salt));
-}
-
-void traverseRecordsFiles(const String& recordsPath, const String& expectedType, const RecordFileTraverseFunction& function)
-{
-    traverseDirectory(recordsPath, [&](const String& partitionName, DirectoryEntryType entryType) {
+    traverseDirectory(recordsPath, [&recordsPath, &function, &expectedType](const String& partitionName, DirectoryEntryType entryType) {
         if (entryType != DirectoryEntryType::Directory)
             return;
         String partitionPath = WebCore::pathByAppendingComponent(recordsPath, partitionName);
-        traverseDirectory(partitionPath, [&](const String& actualType, DirectoryEntryType entryType) {
+        traverseDirectory(partitionPath, [&function, &partitionPath, &expectedType](const String& actualType, DirectoryEntryType entryType) {
             if (entryType != DirectoryEntryType::Directory)
                 return;
             if (!expectedType.isEmpty() && expectedType != actualType)
@@ -207,16 +198,15 @@
     });
 }
 
-Storage::Storage(const String& baseDirectoryPath, Salt salt)
+Storage::Storage(const String& baseDirectoryPath)
     : m_basePath(baseDirectoryPath)
     , m_recordsPath(makeRecordsDirectoryPath(baseDirectoryPath))
-    , m_salt(salt)
     , m_readOperationTimeoutTimer(*this, &Storage::cancelAllReadOperations)
     , m_writeOperationDispatchTimer(*this, &Storage::dispatchPendingWriteOperations)
     , m_ioQueue(WorkQueue::create("com.apple.WebKit.Cache.Storage", WorkQueue::Type::Concurrent))
     , m_backgroundIOQueue(WorkQueue::create("com.apple.WebKit.Cache.Storage.background", WorkQueue::Type::Concurrent, WorkQueue::QOS::Background))
     , m_serialBackgroundIOQueue(WorkQueue::create("com.apple.WebKit.Cache.Storage.serialBackground", WorkQueue::Type::Serial, WorkQueue::QOS::Background))
-    , m_blobStorage(makeBlobDirectoryPath(baseDirectoryPath), m_salt)
+    , m_blobStorage(makeBlobDirectoryPath(baseDirectoryPath))
 {
     deleteOldVersions();
     synchronize();
@@ -336,8 +326,9 @@
 
 String Storage::recordDirectoryPathForKey(const Key& key) const
 {
+    ASSERT(!key.partition().isEmpty());
     ASSERT(!key.type().isEmpty());
-    return WebCore::pathByAppendingComponent(WebCore::pathByAppendingComponent(recordsPath(), key.partitionHashAsString()), key.type());
+    return WebCore::pathByAppendingComponent(WebCore::pathByAppendingComponent(recordsPath(), key.partition()), key.type());
 }
 
 String Storage::recordPathForKey(const Key& key) const
@@ -406,7 +397,7 @@
     return success;
 }
 
-static bool decodeRecordHeader(const Data& fileData, RecordMetaData& metaData, Data& headerData, const Salt& salt)
+static bool decodeRecordHeader(const Data& fileData, RecordMetaData& metaData, Data& headerData)
 {
     if (!decodeRecordMetaData(metaData, fileData)) {
         LOG(NetworkCacheStorage, "(NetworkProcess) meta data decode failure");
@@ -419,7 +410,7 @@
     }
 
     headerData = fileData.subrange(metaData.headerOffset, metaData.headerSize);
-    if (metaData.headerHash != computeSHA1(headerData, salt)) {
+    if (metaData.headerHash != computeSHA1(headerData)) {
         LOG(NetworkCacheStorage, "(NetworkProcess) header checksum mismatch");
         return false;
     }
@@ -432,7 +423,7 @@
 
     RecordMetaData metaData;
     Data headerData;
-    if (!decodeRecordHeader(recordData, metaData, headerData, m_salt))
+    if (!decodeRecordHeader(recordData, metaData, headerData))
         return;
 
     if (metaData.key != readOperation.key)
@@ -449,7 +440,7 @@
         if (bodyOffset + metaData.bodySize != recordData.size())
             return;
         bodyData = recordData.subrange(bodyOffset, metaData.bodySize);
-        if (metaData.bodyHash != computeSHA1(bodyData, m_salt))
+        if (metaData.bodyHash != computeSHA1(bodyData))
             return;
     }
 
@@ -511,9 +502,9 @@
 
     RecordMetaData metaData(record.key);
     metaData.epochRelativeTimeStamp = std::chrono::duration_cast<std::chrono::milliseconds>(record.timeStamp.time_since_epoch());
-    metaData.headerHash = computeSHA1(record.header, m_salt);
+    metaData.headerHash = computeSHA1(record.header);
     metaData.headerSize = record.header.size();
-    metaData.bodyHash = blob ? blob.value().hash : computeSHA1(record.body, m_salt);
+    metaData.bodyHash = blob ? blob.value().hash : computeSHA1(record.body);
     metaData.bodySize = record.body.size();
     metaData.isBodyInline = !blob;
 
@@ -832,7 +823,7 @@
             channel->read(0, std::numeric_limits<size_t>::max(), nullptr, [this, &traverseOperation, worth, bodyShareCount](Data& fileData, int) {
                 RecordMetaData metaData;
                 Data headerData;
-                if (decodeRecordHeader(fileData, metaData, headerData, m_salt)) {
+                if (decodeRecordHeader(fileData, metaData, headerData)) {
                     Record record {
                         metaData.key,
                         std::chrono::system_clock::time_point(metaData.epochRelativeTimeStamp),

Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h (209188 => 209189)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h	2016-12-01 19:27:25 UTC (rev 209188)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h	2016-12-01 19:31:06 UTC (rev 209189)
@@ -87,7 +87,7 @@
     size_t capacity() const { return m_capacity; }
     size_t approximateSize() const;
 
-    static const unsigned version = 11;
+    static const unsigned version = 10;
 #if PLATFORM(MAC)
     /// Allow the last stable version of the cache to co-exist with the latest development one.
     static const unsigned lastStableVersion = 9;
@@ -97,12 +97,10 @@
     String versionPath() const;
     String recordsPath() const;
 
-    const Salt& salt() const { return m_salt; }
-
     ~Storage();
 
 private:
-    Storage(const String& directoryPath, Salt);
+    Storage(const String& directoryPath);
 
     String recordDirectoryPathForKey(const Key&) const;
     String recordPathForKey(const Key&) const;
@@ -143,8 +141,6 @@
     const String m_basePath;
     const String m_recordsPath;
 
-    const Salt m_salt;
-
     size_t m_capacity { std::numeric_limits<size_t>::max() };
     size_t m_approximateRecordsSize { 0 };
 
@@ -179,8 +175,7 @@
 };
 
 // FIXME: Remove, used by NetworkCacheStatistics only.
-using RecordFileTraverseFunction = std::function<void (const String& fileName, const String& hashString, const String& type, bool isBlob, const String& recordDirectoryPath)>;
-void traverseRecordsFiles(const String& recordsPath, const String& type, const RecordFileTraverseFunction&);
+void traverseRecordsFiles(const String& recordsPath, const String& type, const std::function<void (const String& fileName, const String& hashString, const String& type, bool isBodyBlob, const String& recordDirectoryPath)>&);
 
 }
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to