Changeset 209189 in webkit
- Timestamp:
- Dec 1, 2016, 11:31:06 AM (8 years ago)
- Location:
- trunk/Source/WebKit2
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r209184 r209189 1 2016-12-01 Antti Koivisto <antti@apple.com> 2 3 Revert r208931 4 https://bugs.webkit.org/show_bug.cgi?id=164924 5 6 PLT regression. 7 8 * NetworkProcess/cache/NetworkCache.cpp: 9 (WebKit::NetworkCache::makeCacheKey): 10 (WebKit::NetworkCache::Cache::makeCacheKey): Deleted. 11 * NetworkProcess/cache/NetworkCache.h: 12 * NetworkProcess/cache/NetworkCacheBlobStorage.cpp: 13 (WebKit::NetworkCache::BlobStorage::BlobStorage): 14 (WebKit::NetworkCache::BlobStorage::add): 15 (WebKit::NetworkCache::BlobStorage::get): 16 * NetworkProcess/cache/NetworkCacheBlobStorage.h: 17 * NetworkProcess/cache/NetworkCacheData.cpp: 18 (WebKit::NetworkCache::computeSHA1): 19 (WebKit::NetworkCache::makeSalt): Deleted. 20 (WebKit::NetworkCache::readOrMakeSalt): Deleted. 21 * NetworkProcess/cache/NetworkCacheData.h: 22 * NetworkProcess/cache/NetworkCacheKey.cpp: 23 (WebKit::NetworkCache::noPartitionString): 24 (WebKit::NetworkCache::Key::Key): 25 (WebKit::NetworkCache::Key::hasPartition): 26 (WebKit::NetworkCache::Key::computeHash): 27 (WebKit::NetworkCache::Key::hashAsString): 28 (WebKit::NetworkCache::Key::computePartitionHash): Deleted. 29 * NetworkProcess/cache/NetworkCacheKey.h: 30 (WebKit::NetworkCache::Key::hash): 31 (WebKit::NetworkCache::Key::partitionHash): Deleted. 32 (WebKit::NetworkCache::Key::hashAsString): Deleted. 33 (WebKit::NetworkCache::Key::partitionHashAsString): Deleted. 34 * NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.cpp: 35 (WebKit::NetworkCache::makeSubresourcesKey): 36 (WebKit::NetworkCache::constructRevalidationRequest): 37 (WebKit::NetworkCache::SpeculativeLoadManager::PendingFrameLoad::saveToDiskIfReady): 38 (WebKit::NetworkCache::SpeculativeLoadManager::retrieveSubresourcesEntry): 39 * NetworkProcess/cache/NetworkCacheStorage.cpp: 40 (WebKit::NetworkCache::Storage::open): 41 (WebKit::NetworkCache::traverseRecordsFiles): 42 (WebKit::NetworkCache::Storage::Storage): 43 (WebKit::NetworkCache::Storage::recordDirectoryPathForKey): 44 (WebKit::NetworkCache::decodeRecordHeader): 45 (WebKit::NetworkCache::Storage::readRecord): 46 (WebKit::NetworkCache::Storage::encodeRecord): 47 (WebKit::NetworkCache::Storage::traverse): 48 (WebKit::NetworkCache::makeSaltFilePath): Deleted. 49 * NetworkProcess/cache/NetworkCacheStorage.h: 50 (WebKit::NetworkCache::Storage::salt): Deleted. 51 1 52 2016-11-30 Sam Weinig <sam@webkit.org> 2 53 -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp
r208985 r209189 115 115 } 116 116 117 Key Cache::makeCacheKey(const WebCore::ResourceRequest& request)117 static Key makeCacheKey(const WebCore::ResourceRequest& request) 118 118 { 119 119 #if ENABLE(CACHE_PARTITIONING) … … 126 126 // ranges so only the same exact range request will be served from the cache. 127 127 String range = request.httpHeaderField(WebCore::HTTPHeaderName::Range); 128 return { partition, resourceType(), range, request.url().string() , m_storage->salt()};128 return { partition, resourceType(), range, request.url().string() }; 129 129 } 130 130 -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.h
r208931 r209189 130 130 ~Cache() = delete; 131 131 132 Key makeCacheKey(const WebCore::ResourceRequest&);133 134 132 String dumpFilePath() const; 135 133 void deleteDumpFile(); -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheBlobStorage.cpp
r208931 r209189 41 41 namespace NetworkCache { 42 42 43 BlobStorage::BlobStorage(const String& blobDirectoryPath , Salt salt)43 BlobStorage::BlobStorage(const String& blobDirectoryPath) 44 44 : m_blobDirectoryPath(blobDirectoryPath) 45 , m_salt(salt)46 45 { 47 46 } … … 87 86 ASSERT(!RunLoop::isMain()); 88 87 89 auto hash = computeSHA1(data , m_salt);88 auto hash = computeSHA1(data); 90 89 if (data.isEmpty()) 91 90 return { data, hash }; … … 125 124 auto data = mapFile(linkPath.data()); 126 125 127 return { data, computeSHA1(data , m_salt) };126 return { data, computeSHA1(data) }; 128 127 } 129 128 -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheBlobStorage.h
r208931 r209189 40 40 WTF_MAKE_NONCOPYABLE(BlobStorage); 41 41 public: 42 BlobStorage(const String& blobDirectoryPath , Salt);42 BlobStorage(const String& blobDirectoryPath); 43 43 44 44 struct Blob { … … 64 64 65 65 const String m_blobDirectoryPath; 66 const Salt m_salt;67 66 68 67 std::atomic<size_t> m_approximateSize { 0 }; -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheData.cpp
r208985 r209189 29 29 #if ENABLE(NETWORK_CACHE) 30 30 31 #include <WebCore/FileSystem.h>32 31 #include <fcntl.h> 33 32 #include <sys/mman.h> 34 33 #include <sys/stat.h> 35 #include <wtf/CryptographicallyRandomNumber.h>36 34 37 35 namespace WebKit { … … 106 104 } 107 105 108 SHA1::Digest computeSHA1(const Data& data , const Salt& salt)106 SHA1::Digest computeSHA1(const Data& data) 109 107 { 110 108 SHA1 sha1; 111 sha1.addBytes(salt.data(), salt.size());112 109 data.apply([&sha1](const uint8_t* data, size_t size) { 113 110 sha1.addBytes(data, size); 114 111 return true; 115 112 }); 116 117 113 SHA1::Digest digest; 118 114 sha1.computeHash(digest); … … 129 125 } 130 126 131 static Salt makeSalt()132 {133 Salt salt;134 static_assert(salt.size() == 8, "Salt size");135 *reinterpret_cast<uint32_t*>(&salt[0]) = cryptographicallyRandomNumber();136 *reinterpret_cast<uint32_t*>(&salt[4]) = cryptographicallyRandomNumber();137 return salt;138 }139 140 std::optional<Salt> readOrMakeSalt(const String& path)141 {142 auto cpath = WebCore::fileSystemRepresentation(path);143 auto fd = open(cpath.data(), O_RDONLY, 0);144 Salt salt;145 auto bytesRead = read(fd, salt.data(), salt.size());146 close(fd);147 if (bytesRead != salt.size()) {148 salt = makeSalt();149 150 unlink(cpath.data());151 fd = open(cpath.data(), O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);152 bool success = write(fd, salt.data(), salt.size()) == salt.size();153 close(fd);154 if (!success)155 return { };156 }157 return salt;158 }159 160 127 } // namespace NetworkCache 161 128 } // namespace WebKit -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheData.h
r208985 r209189 157 157 Data adoptAndMapFile(int fd, size_t offset, size_t); 158 158 Data mapFile(const char* path); 159 160 using Salt = std::array<uint8_t, 8>; 161 162 std::optional<Salt> readOrMakeSalt(const String& path); 163 SHA1::Digest computeSHA1(const Data&, const Salt&); 159 SHA1::Digest computeSHA1(const Data&); 164 160 165 161 } -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheKey.cpp
r208931 r209189 38 38 namespace NetworkCache { 39 39 40 static const String& noPartitionString() 41 { 42 static NeverDestroyed<String> noPartition(ASCIILiteral("No partition")); 43 return noPartition; 44 } 45 40 46 Key::Key(const Key& o) 41 47 : m_partition(o.m_partition.isolatedCopy()) … … 44 50 , m_range(o.m_range.isolatedCopy()) 45 51 , m_hash(o.m_hash) 46 , m_partitionHash(o.m_partitionHash)47 52 { 48 53 } 49 54 50 Key::Key(const String& partition, const String& type, const String& range, const String& identifier , const Salt& salt)51 : m_partition(partition )55 Key::Key(const String& partition, const String& type, const String& range, const String& identifier) 56 : m_partition(partition.isEmpty() ? noPartitionString() : partition) 52 57 , m_type(type) 53 58 , m_identifier(identifier) 54 59 , m_range(range) 55 , m_hash(computeHash(salt)) 56 , m_partitionHash(computePartitionHash(salt)) 60 , m_hash(computeHash()) 57 61 { 58 62 } … … 61 65 : m_identifier(WTF::HashTableDeletedValue) 62 66 { 67 } 68 69 bool Key::hasPartition() const 70 { 71 return m_partition != noPartitionString(); 63 72 } 64 73 … … 89 98 } 90 99 91 Key::HashType Key::computeHash( const Salt& salt) const100 Key::HashType Key::computeHash() const 92 101 { 93 102 // We don't really need a cryptographic hash. The key is always verified against the entry header. 94 103 // SHA1 just happens to be suitably sized, fast and available. 95 104 SHA1 sha1; 96 sha1.addBytes(salt.data(), salt.size());97 98 105 hashString(sha1, m_partition); 99 106 hashString(sha1, m_type); 100 107 hashString(sha1, m_identifier); 101 108 hashString(sha1, m_range); 102 103 109 SHA1::Digest hash; 104 110 sha1.computeHash(hash); … … 106 112 } 107 113 108 Key::HashType Key::computePartitionHash(const Salt& salt) const 109 { 110 SHA1 sha1; 111 sha1.addBytes(salt.data(), salt.size()); 112 113 hashString(sha1, m_partition); 114 115 SHA1::Digest hash; 116 sha1.computeHash(hash); 117 return hash; 118 } 119 120 String Key::hashAsString(const HashType& hash) 114 String Key::hashAsString() const 121 115 { 122 116 StringBuilder builder; 123 117 builder.reserveCapacity(hashStringLength()); 124 for (auto byte : hash) {118 for (auto byte : m_hash) { 125 119 builder.append(upperNibbleToASCIIHexDigit(byte)); 126 120 builder.append(lowerNibbleToASCIIHexDigit(byte)); -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheKey.h
r208931 r209189 29 29 #if ENABLE(NETWORK_CACHE) 30 30 31 #include "NetworkCacheData.h"32 31 #include <wtf/SHA1.h> 33 32 #include <wtf/text/WTFString.h> … … 46 45 Key(const Key&); 47 46 Key(Key&&) = default; 48 Key(const String& partition, const String& type, const String& range, const String& identifier , const Salt&);47 Key(const String& partition, const String& type, const String& range, const String& identifier); 49 48 50 49 Key& operator=(const Key&); … … 56 55 bool isNull() const { return m_identifier.isNull(); } 57 56 57 bool hasPartition() const; 58 58 const String& partition() const { return m_partition; } 59 59 const String& identifier() const { return m_identifier; } … … 61 61 const String& range() const { return m_range; } 62 62 63 const HashType& hash() const { return m_hash; } 64 const HashType& partitionHash() const { return m_partitionHash; } 63 HashType hash() const { return m_hash; } 65 64 66 65 static bool stringToHash(const String&, HashType&); 67 66 68 67 static size_t hashStringLength() { return 2 * sizeof(m_hash); } 69 String hashAsString() const { return hashAsString(m_hash); } 70 String partitionHashAsString() const { return hashAsString(m_partitionHash); } 68 String hashAsString() const; 71 69 72 70 void encode(Encoder&) const; … … 77 75 78 76 private: 79 static String hashAsString(const HashType&); 80 HashType computeHash(const Salt&) const; 81 HashType computePartitionHash(const Salt&) const; 77 HashType computeHash() const; 82 78 83 79 String m_partition; … … 86 82 String m_range; 87 83 HashType m_hash; 88 HashType m_partitionHash;89 84 }; 90 85 -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.cpp
r208985 r209189 80 80 } 81 81 82 static inline Key makeSubresourcesKey(const Key& resourceKey , const Salt& salt)83 { 84 return Key(resourceKey.partition(), subresourcesType(), resourceKey.range(), resourceKey.identifier() , salt);82 static inline Key makeSubresourcesKey(const Key& resourceKey) 83 { 84 return Key(resourceKey.partition(), subresourcesType(), resourceKey.range(), resourceKey.identifier()); 85 85 } 86 86 … … 91 91 revalidationRequest.setFirstPartyForCookies(subResourceInfo.firstPartyForCookies()); 92 92 #if ENABLE(CACHE_PARTITIONING) 93 if ( !entry.key().partition().isEmpty())93 if (entry.key().hasPartition()) 94 94 revalidationRequest.setCachePartition(entry.key().partition()); 95 95 #endif … … 227 227 m_storage.store(m_existingEntry->encodeAsStorageRecord(), [](const Data&) { }); 228 228 } else { 229 SubresourcesEntry entry(makeSubresourcesKey(m_mainResourceKey , m_storage.salt()), m_subresourceLoads);229 SubresourcesEntry entry(makeSubresourcesKey(m_mainResourceKey), m_subresourceLoads); 230 230 m_storage.store(entry.encodeAsStorageRecord(), [](const Data&) { }); 231 231 } … … 522 522 { 523 523 ASSERT(storageKey.type() == "Resource"); 524 auto subresourcesStorageKey = makeSubresourcesKey(storageKey , m_storage.salt());524 auto subresourcesStorageKey = makeSubresourcesKey(storageKey); 525 525 m_storage.retrieve(subresourcesStorageKey, static_cast<unsigned>(ResourceLoadPriority::Medium), [completionHandler = WTFMove(completionHandler)](auto record) { 526 526 if (!record) { -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.cpp
r208985 r209189 43 43 namespace NetworkCache { 44 44 45 static const char saltFileName[] = "salt";46 45 static const char versionDirectoryPrefix[] = "Version "; 47 46 static const char recordsDirectoryName[] = "Records"; … … 129 128 }; 130 129 130 std::unique_ptr<Storage> Storage::open(const String& cachePath) 131 { 132 ASSERT(RunLoop::isMain()); 133 134 if (!WebCore::makeAllDirectories(cachePath)) 135 return nullptr; 136 return std::unique_ptr<Storage>(new Storage(cachePath)); 137 } 138 131 139 static String makeVersionedDirectoryPath(const String& baseDirectoryPath) 132 140 { … … 145 153 } 146 154 147 static String makeSaltFilePath(const String& baseDirectoryPath) 148 { 149 return WebCore::pathByAppendingComponent(makeVersionedDirectoryPath(baseDirectoryPath), saltFileName); 150 } 151 152 std::unique_ptr<Storage> Storage::open(const String& cachePath) 153 { 154 ASSERT(RunLoop::isMain()); 155 156 if (!WebCore::makeAllDirectories(makeVersionedDirectoryPath(cachePath))) 157 return nullptr; 158 auto salt = readOrMakeSalt(makeSaltFilePath(cachePath)); 159 if (!salt) 160 return nullptr; 161 return std::unique_ptr<Storage>(new Storage(cachePath, *salt)); 162 } 163 164 void traverseRecordsFiles(const String& recordsPath, const String& expectedType, const RecordFileTraverseFunction& function) 165 { 166 traverseDirectory(recordsPath, [&](const String& partitionName, DirectoryEntryType entryType) { 155 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) 156 { 157 traverseDirectory(recordsPath, [&recordsPath, &function, &expectedType](const String& partitionName, DirectoryEntryType entryType) { 167 158 if (entryType != DirectoryEntryType::Directory) 168 159 return; 169 160 String partitionPath = WebCore::pathByAppendingComponent(recordsPath, partitionName); 170 traverseDirectory(partitionPath, [& ](const String& actualType, DirectoryEntryType entryType) {161 traverseDirectory(partitionPath, [&function, &partitionPath, &expectedType](const String& actualType, DirectoryEntryType entryType) { 171 162 if (entryType != DirectoryEntryType::Directory) 172 163 return; … … 208 199 } 209 200 210 Storage::Storage(const String& baseDirectoryPath , Salt salt)201 Storage::Storage(const String& baseDirectoryPath) 211 202 : m_basePath(baseDirectoryPath) 212 203 , m_recordsPath(makeRecordsDirectoryPath(baseDirectoryPath)) 213 , m_salt(salt)214 204 , m_readOperationTimeoutTimer(*this, &Storage::cancelAllReadOperations) 215 205 , m_writeOperationDispatchTimer(*this, &Storage::dispatchPendingWriteOperations) … … 217 207 , m_backgroundIOQueue(WorkQueue::create("com.apple.WebKit.Cache.Storage.background", WorkQueue::Type::Concurrent, WorkQueue::QOS::Background)) 218 208 , m_serialBackgroundIOQueue(WorkQueue::create("com.apple.WebKit.Cache.Storage.serialBackground", WorkQueue::Type::Serial, WorkQueue::QOS::Background)) 219 , m_blobStorage(makeBlobDirectoryPath(baseDirectoryPath) , m_salt)209 , m_blobStorage(makeBlobDirectoryPath(baseDirectoryPath)) 220 210 { 221 211 deleteOldVersions(); … … 337 327 String Storage::recordDirectoryPathForKey(const Key& key) const 338 328 { 329 ASSERT(!key.partition().isEmpty()); 339 330 ASSERT(!key.type().isEmpty()); 340 return WebCore::pathByAppendingComponent(WebCore::pathByAppendingComponent(recordsPath(), key.partition HashAsString()), key.type());331 return WebCore::pathByAppendingComponent(WebCore::pathByAppendingComponent(recordsPath(), key.partition()), key.type()); 341 332 } 342 333 … … 407 398 } 408 399 409 static bool decodeRecordHeader(const Data& fileData, RecordMetaData& metaData, Data& headerData , const Salt& salt)400 static bool decodeRecordHeader(const Data& fileData, RecordMetaData& metaData, Data& headerData) 410 401 { 411 402 if (!decodeRecordMetaData(metaData, fileData)) { … … 420 411 421 412 headerData = fileData.subrange(metaData.headerOffset, metaData.headerSize); 422 if (metaData.headerHash != computeSHA1(headerData , salt)) {413 if (metaData.headerHash != computeSHA1(headerData)) { 423 414 LOG(NetworkCacheStorage, "(NetworkProcess) header checksum mismatch"); 424 415 return false; … … 433 424 RecordMetaData metaData; 434 425 Data headerData; 435 if (!decodeRecordHeader(recordData, metaData, headerData , m_salt))426 if (!decodeRecordHeader(recordData, metaData, headerData)) 436 427 return; 437 428 … … 450 441 return; 451 442 bodyData = recordData.subrange(bodyOffset, metaData.bodySize); 452 if (metaData.bodyHash != computeSHA1(bodyData , m_salt))443 if (metaData.bodyHash != computeSHA1(bodyData)) 453 444 return; 454 445 } … … 512 503 RecordMetaData metaData(record.key); 513 504 metaData.epochRelativeTimeStamp = std::chrono::duration_cast<std::chrono::milliseconds>(record.timeStamp.time_since_epoch()); 514 metaData.headerHash = computeSHA1(record.header , m_salt);505 metaData.headerHash = computeSHA1(record.header); 515 506 metaData.headerSize = record.header.size(); 516 metaData.bodyHash = blob ? blob.value().hash : computeSHA1(record.body , m_salt);507 metaData.bodyHash = blob ? blob.value().hash : computeSHA1(record.body); 517 508 metaData.bodySize = record.body.size(); 518 509 metaData.isBodyInline = !blob; … … 833 824 RecordMetaData metaData; 834 825 Data headerData; 835 if (decodeRecordHeader(fileData, metaData, headerData , m_salt)) {826 if (decodeRecordHeader(fileData, metaData, headerData)) { 836 827 Record record { 837 828 metaData.key, -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h
r208985 r209189 88 88 size_t approximateSize() const; 89 89 90 static const unsigned version = 1 1;90 static const unsigned version = 10; 91 91 #if PLATFORM(MAC) 92 92 /// Allow the last stable version of the cache to co-exist with the latest development one. … … 98 98 String recordsPath() const; 99 99 100 const Salt& salt() const { return m_salt; }101 102 100 ~Storage(); 103 101 104 102 private: 105 Storage(const String& directoryPath , Salt);103 Storage(const String& directoryPath); 106 104 107 105 String recordDirectoryPathForKey(const Key&) const; … … 144 142 const String m_recordsPath; 145 143 146 const Salt m_salt;147 148 144 size_t m_capacity { std::numeric_limits<size_t>::max() }; 149 145 size_t m_approximateRecordsSize { 0 }; … … 180 176 181 177 // FIXME: Remove, used by NetworkCacheStatistics only. 182 using RecordFileTraverseFunction = std::function<void (const String& fileName, const String& hashString, const String& type, bool isBlob, const String& recordDirectoryPath)>; 183 void traverseRecordsFiles(const String& recordsPath, const String& type, const RecordFileTraverseFunction&); 178 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)>&); 184 179 185 180 }
Note:
See TracChangeset
for help on using the changeset viewer.