Changeset 180949 in webkit
- Timestamp:
- Mar 3, 2015 12:13:01 PM (9 years ago)
- Location:
- trunk/Source/WebKit2
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r180947 r180949 1 2015-03-03 Antti Koivisto <antti@apple.com> 2 3 Include key to NetworkCacheStorage::Entry 4 https://bugs.webkit.org/show_bug.cgi?id=142215 5 6 Reviewed by Chris Dumez. 7 8 This simplified code. The key is saved as part of the entry so it makes logical sense too. 9 10 * NetworkProcess/cache/NetworkCache.cpp: 11 (WebKit::makeCacheKey): 12 (WebKit::encodeStorageEntry): 13 (WebKit::NetworkCache::retrieve): 14 (WebKit::NetworkCache::store): 15 (WebKit::NetworkCache::update): 16 (WebKit::NetworkCache::traverse): 17 (WebKit::entryAsJSON): 18 (WebKit::NetworkCache::dumpContentsToFile): 19 * NetworkProcess/cache/NetworkCacheKey.cpp: 20 (WebKit::NetworkCacheKey::operator=): 21 * NetworkProcess/cache/NetworkCacheKey.h: 22 (WebKit::NetworkCacheKey::isNull): 23 * NetworkProcess/cache/NetworkCacheStorage.h: 24 * NetworkProcess/cache/NetworkCacheStorageCocoa.mm: 25 (WebKit::decodeEntry): 26 (WebKit::encodeEntryHeader): 27 (WebKit::retrieveFromMemory): 28 (WebKit::NetworkCacheStorage::retrieve): 29 (WebKit::NetworkCacheStorage::store): 30 (WebKit::NetworkCacheStorage::update): 31 (WebKit::NetworkCacheStorage::traverse): 32 (WebKit::NetworkCacheStorage::dispatchPendingWriteOperations): 33 (WebKit::NetworkCacheStorage::dispatchFullWriteOperation): 34 (WebKit::NetworkCacheStorage::dispatchHeaderWriteOperation): 35 1 36 2015-03-03 Antti Koivisto <antti@apple.com> 2 37 -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp
r180905 r180949 1 1 /* 2 * Copyright (C) 2014 Apple Inc. All rights reserved.2 * Copyright (C) 2014-2015 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 85 85 } 86 86 87 static NetworkCacheKey makeCacheKey(const WebCore::ResourceRequest& request) 88 { 89 #if ENABLE(CACHE_PARTITIONING) 90 String partition = request.cachePartition(); 91 #else 92 String partition; 93 #endif 94 if (partition.isEmpty()) 95 partition = ASCIILiteral("No partition"); 96 return NetworkCacheKey(request.httpMethod(), partition, request.url().string()); 97 } 98 87 99 static NetworkCacheStorage::Entry encodeStorageEntry(const WebCore::ResourceRequest& request, const WebCore::ResourceResponse& response, PassRefPtr<WebCore::SharedBuffer> responseData) 88 100 { … … 114 126 body = NetworkCacheStorage::Data(reinterpret_cast<const uint8_t*>(responseData->data()), responseData->size()); 115 127 116 return NetworkCacheStorage::Entry { timeStamp, header, body };128 return NetworkCacheStorage::Entry { makeCacheKey(request), timeStamp, header, body }; 117 129 } 118 130 … … 232 244 } 233 245 234 static NetworkCacheKey makeCacheKey(const WebCore::ResourceRequest& request)235 {236 #if ENABLE(CACHE_PARTITIONING)237 String partition = request.cachePartition();238 #else239 String partition;240 #endif241 if (partition.isEmpty())242 partition = ASCIILiteral("No partition");243 return NetworkCacheKey(request.httpMethod(), partition, request.url().string());244 }245 246 246 void NetworkCache::retrieve(const WebCore::ResourceRequest& originalRequest, uint64_t webPageID, std::function<void (std::unique_ptr<Entry>)> completionHandler) 247 247 { … … 273 273 return false; 274 274 } 275 ASSERT(entry->key == storageKey); 276 275 277 CachedEntryReuseFailure failure = CachedEntryReuseFailure::None; 276 278 auto decodedEntry = decodeStorageEntry(*entry, originalRequest, failure); … … 330 332 LOG(NetworkCache, "(NetworkProcess) storing %s, partition %s", originalRequest.url().string().latin1().data(), originalRequest.cachePartition().latin1().data()); 331 333 332 auto key = makeCacheKey(originalRequest);333 334 StoreDecision storeDecision = canStore(originalRequest, response); 334 335 if (storeDecision != StoreDecision::Yes) { 335 336 LOG(NetworkCache, "(NetworkProcess) didn't store"); 336 if (m_statistics) 337 if (m_statistics) { 338 auto key = makeCacheKey(originalRequest); 337 339 m_statistics->recordNotCachingResponse(key, storeDecision); 340 } 338 341 return; 339 342 } … … 341 344 auto storageEntry = encodeStorageEntry(originalRequest, response, WTF::move(responseData)); 342 345 343 m_storage->store( key,storageEntry, [completionHandler](bool success, const NetworkCacheStorage::Data& bodyData) {346 m_storage->store(storageEntry, [completionHandler](bool success, const NetworkCacheStorage::Data& bodyData) { 344 347 MappedBody mappedBody; 345 348 #if ENABLE(SHAREABLE_RESOURCE) … … 363 366 WebCore::updateResponseHeadersAfterRevalidation(response, validatingResponse); 364 367 365 auto key = makeCacheKey(originalRequest);366 368 auto updateEntry = encodeStorageEntry(originalRequest, response, entry.buffer); 367 369 368 m_storage->update( key,updateEntry, entry.storageEntry, [](bool success, const NetworkCacheStorage::Data&) {370 m_storage->update(updateEntry, entry.storageEntry, [](bool success, const NetworkCacheStorage::Data&) { 369 371 LOG(NetworkCache, "(NetworkProcess) updated, success=%d", success); 370 372 }); … … 375 377 ASSERT(isEnabled()); 376 378 377 m_storage->traverse([traverseHandler](const NetworkCache Key& key, const NetworkCacheStorage::Entry* entry) {379 m_storage->traverse([traverseHandler](const NetworkCacheStorage::Entry* entry) { 378 380 if (!entry) { 379 381 traverseHandler(nullptr); … … 397 399 } 398 400 399 static bool entryAsJSON(StringBuilder& json, const NetworkCache Key& key, const NetworkCacheStorage::Entry& entry)401 static bool entryAsJSON(StringBuilder& json, const NetworkCacheStorage::Entry& entry) 400 402 { 401 403 NetworkCacheDecoder decoder(entry.header.data(), entry.header.size()); … … 405 407 json.append("{\n"); 406 408 json.append("\"hash\": "); 407 JSC::appendQuotedJSONStringToBuilder(json, key.hashAsString());409 JSC::appendQuotedJSONStringToBuilder(json, entry.key.hashAsString()); 408 410 json.append(",\n"); 409 411 json.append("\"partition\": "); 410 JSC::appendQuotedJSONStringToBuilder(json, key.partition());412 JSC::appendQuotedJSONStringToBuilder(json, entry.key.partition()); 411 413 json.append(",\n"); 412 414 json.append("\"timestamp\": "); … … 440 442 return; 441 443 WebCore::writeToFile(dumpFileHandle, "[\n", 2); 442 m_storage->traverse([dumpFileHandle](const NetworkCache Key& key, const NetworkCacheStorage::Entry* entry) {444 m_storage->traverse([dumpFileHandle](const NetworkCacheStorage::Entry* entry) { 443 445 if (!entry) { 444 446 WebCore::writeToFile(dumpFileHandle, "{}\n]\n", 5); … … 448 450 } 449 451 StringBuilder json; 450 if (!entryAsJSON(json, key,*entry))452 if (!entryAsJSON(json, *entry)) 451 453 return; 452 454 json.append(",\n"); -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheKey.cpp
r179782 r180949 58 58 , m_hash(computeHash()) 59 59 { 60 } 61 62 NetworkCacheKey& NetworkCacheKey::operator=(const NetworkCacheKey& other) 63 { 64 m_method = other.m_method.isolatedCopy(); 65 m_partition = other.m_partition.isolatedCopy(); 66 m_identifier = other.m_identifier.isolatedCopy(); 67 m_hash = other.m_hash; 68 return *this; 60 69 } 61 70 -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheKey.h
r179781 r180949 46 46 NetworkCacheKey(const String& method, const String& partition, const String& identifier); 47 47 48 NetworkCacheKey& operator=(const NetworkCacheKey&); 49 50 bool isNull() const { return m_identifier.isNull(); } 51 48 52 const String& method() const { return m_method; } 49 53 const String& partition() const { return m_partition; } … … 67 71 private: 68 72 HashType computeHash() const; 69 void operator=(const NetworkCacheKey&) = delete;70 73 71 74 String m_method; -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h
r180894 r180949 137 137 138 138 struct Entry { 139 NetworkCacheKey key; 139 140 std::chrono::milliseconds timeStamp; 140 141 Data header; … … 146 147 147 148 typedef std::function<void (bool success, const Data& mappedBody)> StoreCompletionHandler; 148 void store(const NetworkCacheKey&, constEntry&, StoreCompletionHandler&&);149 void update(const NetworkCacheKey&, constEntry& updateEntry, const Entry& existingEntry, StoreCompletionHandler&&);149 void store(const Entry&, StoreCompletionHandler&&); 150 void update(const Entry& updateEntry, const Entry& existingEntry, StoreCompletionHandler&&); 150 151 151 152 // Null entry signals end. 152 void traverse(std::function<void (const NetworkCacheKey&, constEntry*)>&&);153 void traverse(std::function<void (const Entry*)>&&); 153 154 154 155 void setMaximumSize(size_t); … … 177 178 178 179 struct WriteOperation { 179 NetworkCacheKey key;180 180 Entry entry; 181 181 Optional<Entry> existingEntry; -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorageCocoa.mm
r180947 r180949 302 302 } 303 303 304 return std::make_unique<NetworkCacheStorage::Entry>(NetworkCacheStorage::Entry { 304 return std::unique_ptr<NetworkCacheStorage::Entry>(new NetworkCacheStorage::Entry { 305 metaData.key, 305 306 metaData.timeStamp, 306 307 headerData, … … 326 327 } 327 328 328 static DispatchPtr<dispatch_data_t> encodeEntryHeader(const NetworkCache Key& key, const NetworkCacheStorage::Entry& entry)329 { 330 EntryMetaData metaData( key);329 static DispatchPtr<dispatch_data_t> encodeEntryHeader(const NetworkCacheStorage::Entry& entry) 330 { 331 EntryMetaData metaData(entry.key); 331 332 metaData.timeStamp = entry.timeStamp; 332 333 metaData.headerChecksum = hashData(entry.header.dispatchData()); … … 422 423 { 423 424 for (auto& operation : operations) { 424 if (operation-> key == key) {425 if (operation->entry.key == key) { 425 426 LOG(NetworkCacheStorage, "(NetworkProcess) found write operation in progress"); 426 427 auto entry = operation->entry; … … 438 439 ASSERT(RunLoop::isMain()); 439 440 ASSERT(priority <= maximumRetrievePriority); 441 ASSERT(!key.isNull()); 440 442 441 443 if (!m_maximumSize) { … … 454 456 return; 455 457 456 m_pendingReadOperationsByPriority[priority].append( std::make_unique<ReadOperation>(ReadOperation { key, WTF::move(completionHandler) }));458 m_pendingReadOperationsByPriority[priority].append(new ReadOperation { key, WTF::move(completionHandler) }); 457 459 dispatchPendingReadOperations(); 458 460 } 459 461 460 void NetworkCacheStorage::store(const NetworkCacheKey& key, const Entry& entry, StoreCompletionHandler&& completionHandler) 461 { 462 ASSERT(RunLoop::isMain()); 462 void NetworkCacheStorage::store(const Entry& entry, StoreCompletionHandler&& completionHandler) 463 { 464 ASSERT(RunLoop::isMain()); 465 ASSERT(!entry.key.isNull()); 463 466 464 467 if (!m_maximumSize) { … … 467 470 } 468 471 469 auto writeOperation = std::make_unique<WriteOperation>(WriteOperation { key, entry, { }, WTF::move(completionHandler) }); 470 m_pendingWriteOperations.append(WTF::move(writeOperation)); 472 m_pendingWriteOperations.append(new WriteOperation { entry, { }, WTF::move(completionHandler) }); 471 473 472 474 // Add key to the filter already here as we do lookups from the pending operations too. 473 m_contentsFilter.add( key.shortHash());475 m_contentsFilter.add(entry.key.shortHash()); 474 476 475 477 dispatchPendingWriteOperations(); 476 478 } 477 479 478 void NetworkCacheStorage::update(const NetworkCacheKey& key, const Entry& updateEntry, const Entry& existingEntry, StoreCompletionHandler&& completionHandler) 479 { 480 ASSERT(RunLoop::isMain()); 480 void NetworkCacheStorage::update(const Entry& updateEntry, const Entry& existingEntry, StoreCompletionHandler&& completionHandler) 481 { 482 ASSERT(RunLoop::isMain()); 483 ASSERT(!existingEntry.key.isNull()); 484 ASSERT(existingEntry.key == updateEntry.key); 481 485 482 486 if (!m_maximumSize) { … … 485 489 } 486 490 487 auto writeOperation = std::make_unique<WriteOperation>(WriteOperation { key, updateEntry, existingEntry, WTF::move(completionHandler) }); 488 m_pendingWriteOperations.append(WTF::move(writeOperation)); 491 m_pendingWriteOperations.append(new WriteOperation { updateEntry, existingEntry, WTF::move(completionHandler) }); 489 492 490 493 dispatchPendingWriteOperations(); 491 494 } 492 495 493 void NetworkCacheStorage::traverse(std::function<void (const NetworkCacheKey&, constEntry*)>&& traverseHandler)496 void NetworkCacheStorage::traverse(std::function<void (const Entry*)>&& traverseHandler) 494 497 { 495 498 StringCapture cachePathCapture(m_directoryPath); … … 505 508 NetworkCacheStorage::Data headerData; 506 509 if (decodeEntryHeader(fileData, metaData, headerData)) { 507 Entry entry { metaData. timeStamp, headerData, Data() };508 traverseHandler( metaData.key,&entry);510 Entry entry { metaData.key, metaData.timeStamp, headerData, Data() }; 511 traverseHandler(&entry); 509 512 } 510 513 if (done) … … 514 517 }); 515 518 dispatch_async(dispatch_get_main_queue(), [this, traverseHandler] { 516 traverseHandler( { },nullptr);519 traverseHandler(nullptr); 517 520 }); 518 521 }); … … 534 537 m_activeWriteOperations.add(WTF::move(writeOperation)); 535 538 536 if (write.existingEntry && m_contentsFilter.mayContain(write. key.shortHash())) {539 if (write.existingEntry && m_contentsFilter.mayContain(write.entry.key.shortHash())) { 537 540 dispatchHeaderWriteOperation(write); 538 541 continue; … … 547 550 ASSERT(m_activeWriteOperations.contains(&write)); 548 551 549 if (!m_contentsFilter.mayContain(write. key.shortHash()))550 m_contentsFilter.add(write. key.shortHash());552 if (!m_contentsFilter.mayContain(write.entry.key.shortHash())) 553 m_contentsFilter.add(write.entry.key.shortHash()); 551 554 552 555 StringCapture cachePathCapture(m_directoryPath); 553 556 dispatch_async(m_backgroundIOQueue.get(), [this, &write, cachePathCapture] { 554 auto encodedHeader = encodeEntryHeader(write. key, write.entry);557 auto encodedHeader = encodeEntryHeader(write.entry); 555 558 auto writeData = adoptDispatch(dispatch_data_create_concat(encodedHeader.get(), write.entry.body.dispatchData())); 556 559 … … 558 561 559 562 int fd; 560 auto channel = openFileForKey(write. key, FileOpenType::Create, cachePathCapture.string(), fd);563 auto channel = openFileForKey(write.entry.key, FileOpenType::Create, cachePathCapture.string(), fd); 561 564 dispatch_io_write(channel.get(), 0, writeData.get(), dispatch_get_main_queue(), [this, &write, fd, bodyOffset](bool done, dispatch_data_t, int error) { 562 565 ASSERT_UNUSED(done, done); 563 566 LOG(NetworkCacheStorage, "(NetworkProcess) write complete error=%d", error); 564 567 if (error) { 565 if (m_contentsFilter.mayContain(write. key.shortHash()))566 m_contentsFilter.remove(write. key.shortHash());568 if (m_contentsFilter.mayContain(write.entry.key.shortHash())) 569 m_contentsFilter.remove(write.entry.key.shortHash()); 567 570 } 568 571 size_t bodySize = write.entry.body.size(); … … 591 594 ASSERT(write.existingEntry); 592 595 ASSERT(m_activeWriteOperations.contains(&write)); 593 ASSERT(m_contentsFilter.mayContain(write. key.shortHash()));596 ASSERT(m_contentsFilter.mayContain(write.entry.key.shortHash())); 594 597 595 598 // Try to update the header of an existing entry. 596 599 StringCapture cachePathCapture(m_directoryPath); 597 600 dispatch_async(m_backgroundIOQueue.get(), [this, &write, cachePathCapture] { 598 auto headerData = encodeEntryHeader(write. key, write.entry);599 auto existingHeaderData = encodeEntryHeader(write. key, write.existingEntry.value());601 auto headerData = encodeEntryHeader(write.entry); 602 auto existingHeaderData = encodeEntryHeader(write.existingEntry.value()); 600 603 601 604 bool pageRoundedHeaderSizeChanged = dispatch_data_get_size(headerData.get()) != dispatch_data_get_size(existingHeaderData.get()); … … 609 612 610 613 int fd; 611 auto channel = openFileForKey(write. key, FileOpenType::Write, cachePathCapture.string(), fd);614 auto channel = openFileForKey(write.entry.key, FileOpenType::Write, cachePathCapture.string(), fd); 612 615 dispatch_io_write(channel.get(), 0, headerData.get(), dispatch_get_main_queue(), [this, &write](bool done, dispatch_data_t, int error) { 613 616 ASSERT_UNUSED(done, done); … … 615 618 616 619 if (error) 617 removeEntry(write. key);620 removeEntry(write.entry.key); 618 621 619 622 write.completionHandler(!error, Data());
Note: See TracChangeset
for help on using the changeset viewer.