Changeset 183755 in webkit
- Timestamp:
- May 4, 2015, 11:51:36 AM (10 years ago)
- Location:
- trunk/Source/WebKit2
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r183746 r183755 1 2015-05-04 Antti Koivisto <antti@apple.com> 2 3 Network Cache: Support time based cache clearing 4 https://bugs.webkit.org/show_bug.cgi?id=144568 5 <rdar://problem/19769820> 6 7 Reviewed by Andreas Kling. 8 9 Support clearing cache entries newer than given time only. 10 11 * NetworkProcess/cache/NetworkCache.cpp: 12 (WebKit::NetworkCache::Cache::deleteDumpFile): 13 (WebKit::NetworkCache::Storage::traverse): 14 15 Also fix thread safety of traverse handler function. 16 17 (WebKit::NetworkCache::Cache::clear): 18 19 Also add completion handler to support the API properly. 20 21 * NetworkProcess/cache/NetworkCache.h: 22 * NetworkProcess/cache/NetworkCacheStorage.cpp: 23 (WebKit::NetworkCache::Storage::clear): 24 * NetworkProcess/cache/NetworkCacheStorage.h: 25 * NetworkProcess/cocoa/NetworkProcessCocoa.mm: 26 (WebKit::clearNSURLCache): 27 28 Factor to a function. 29 30 (WebKit::NetworkProcess::clearDiskCache): 31 1 32 2015-05-04 Zan Dobersek <zdobersek@igalia.com> 2 33 -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp
r183730 r183755 41 41 #include <WebCore/SharedBuffer.h> 42 42 #include <wtf/NeverDestroyed.h> 43 #include <wtf/RunLoop.h> 43 44 #include <wtf/text/StringBuilder.h> 44 45 … … 525 526 } 526 527 527 void Cache::clear() 528 void Cache::deleteDumpFile() 529 { 530 auto queue = WorkQueue::create("com.apple.WebKit.Cache.delete"); 531 StringCapture dumpFilePathCapture(dumpFilePath()); 532 queue->dispatch([dumpFilePathCapture] { 533 WebCore::deleteFile(dumpFilePathCapture.string()); 534 }); 535 } 536 537 void Cache::clear(std::chrono::system_clock::time_point modifiedSince, std::function<void ()>&& completionHandler) 528 538 { 529 539 LOG(NetworkCache, "(NetworkProcess) clearing cache"); 530 if (m_storage) { 531 m_storage->clear(); 532 533 auto queue = WorkQueue::create("com.apple.WebKit.Cache.delete"); 534 StringCapture dumpFilePathCapture(dumpFilePath()); 535 queue->dispatch([dumpFilePathCapture] { 536 WebCore::deleteFile(dumpFilePathCapture.string()); 537 }); 538 } 540 deleteDumpFile(); 541 539 542 if (m_statistics) 540 543 m_statistics->clear(); 544 545 if (!m_storage) { 546 RunLoop::main().dispatch(completionHandler); 547 return; 548 } 549 m_storage->clear(modifiedSince, WTF::move(completionHandler)); 550 } 551 552 void Cache::clear() 553 { 554 clear(std::chrono::system_clock::time_point::min(), nullptr); 541 555 } 542 556 -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.h
r183467 r183755 102 102 103 103 void clear(); 104 void clear(std::chrono::system_clock::time_point modifiedSince, std::function<void ()>&& completionHandler); 104 105 105 106 void dumpContentsToFile(); … … 112 113 113 114 String dumpFilePath() const; 115 void deleteDumpFile(); 114 116 115 117 std::unique_ptr<Storage> m_storage; -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.cpp
r183273 r183755 658 658 } 659 659 660 void Storage::traverse(TraverseFlags flags, std::function<void (const Record*, const RecordInfo&)>&& traverseHandler) 661 { 662 ioQueue().dispatch([this, flags, traverseHandler] { 660 void Storage::traverse(TraverseFlags flags, TraverseHandler&& traverseHandler) 661 { 662 ASSERT(RunLoop::isMain()); 663 ASSERT(traverseHandler); 664 // Avoid non-thread safe std::function copies. 665 auto* traverseHandlerPtr = new TraverseHandler(WTF::move(traverseHandler)); 666 667 ioQueue().dispatch([this, flags, traverseHandlerPtr] { 668 auto& traverseHandler = *traverseHandlerPtr; 663 669 traverseCacheFiles(recordsPath(), [this, flags, &traverseHandler](const String& fileName, const String& partitionPath) { 664 670 if (fileName.length() != Key::hashStringLength()) … … 685 691 }); 686 692 }); 687 RunLoop::main().dispatch([this, traverseHandler] { 688 traverseHandler(nullptr, { }); 693 RunLoop::main().dispatch([this, traverseHandlerPtr] { 694 (*traverseHandlerPtr)(nullptr, { }); 695 delete traverseHandlerPtr; 689 696 }); 690 697 }); … … 709 716 } 710 717 711 void Storage::clear( )718 void Storage::clear(std::chrono::system_clock::time_point modifiedSinceTime, std::function<void ()>&& completionHandler) 712 719 { 713 720 ASSERT(RunLoop::isMain()); … … 720 727 m_approximateRecordsSize = 0; 721 728 722 ioQueue().dispatch([this] { 729 // Avoid non-thread safe std::function copies. 730 auto* completionHandlerPtr = completionHandler ? new std::function<void ()>(WTF::move(completionHandler)) : nullptr; 731 732 ioQueue().dispatch([this, modifiedSinceTime, completionHandlerPtr] { 723 733 auto recordsPath = this->recordsPath(); 724 traverseDirectory(recordsPath, DT_DIR, [&recordsPath ](const String& subdirName) {734 traverseDirectory(recordsPath, DT_DIR, [&recordsPath, modifiedSinceTime](const String& subdirName) { 725 735 String subdirPath = WebCore::pathByAppendingComponent(recordsPath, subdirName); 726 traverseDirectory(subdirPath, DT_REG, [&subdirPath](const String& fileName) { 727 WebCore::deleteFile(WebCore::pathByAppendingComponent(subdirPath, fileName)); 736 traverseDirectory(subdirPath, DT_REG, [&subdirPath, modifiedSinceTime](const String& fileName) { 737 auto filePath = WebCore::pathByAppendingComponent(subdirPath, fileName); 738 if (modifiedSinceTime > std::chrono::system_clock::time_point::min()) { 739 auto times = fileTimes(filePath); 740 if (times.modification < modifiedSinceTime) 741 return; 742 } 743 WebCore::deleteFile(filePath); 728 744 }); 729 745 WebCore::deleteEmptyDirectory(subdirPath); … … 732 748 // This cleans unreferences blobs. 733 749 m_blobStorage.synchronize(); 750 751 if (completionHandlerPtr) { 752 RunLoop::main().dispatch([completionHandlerPtr] { 753 (*completionHandlerPtr)(); 754 delete completionHandlerPtr; 755 }); 756 } 734 757 }); 735 758 } -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h
r183273 r183755 63 63 64 64 void remove(const Key&); 65 void clear(std::chrono::system_clock::time_point modifiedSinceTime, std::function<void ()>&& completionHandler); 65 66 66 67 struct RecordInfo { … … 75 76 }; 76 77 typedef unsigned TraverseFlags; 78 typedef std::function<void (const Record*, const RecordInfo&)> TraverseHandler; 77 79 // Null record signals end. 78 void traverse(TraverseFlags, std::function<void (const Record*, const RecordInfo&)>&&);80 void traverse(TraverseFlags, TraverseHandler&&); 79 81 80 82 void setCapacity(size_t); 81 83 size_t approximateSize() const; 82 void clear();83 84 84 85 static const unsigned version = 3; -
trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkProcessCocoa.mm
r183737 r183755 156 156 } 157 157 158 void NetworkProcess::clearDiskCache(std::chrono::system_clock::time_point modifiedSince, std::function<void ()>completionHandler)158 static void clearNSURLCache(dispatch_group_t group, std::chrono::system_clock::time_point modifiedSince, const std::function<void ()>& completionHandler) 159 159 { 160 #if ENABLE(NETWORK_CACHE) 161 NetworkCache::singleton().clear(); 162 #endif 163 164 if (!m_clearCacheDispatchGroup) 165 m_clearCacheDispatchGroup = dispatch_group_create(); 166 167 dispatch_group_async(m_clearCacheDispatchGroup, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), [modifiedSince, completionHandler] { 160 dispatch_group_async(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), [modifiedSince, completionHandler] { 168 161 NSURLCache *cache = [NSURLCache sharedURLCache]; 169 162 … … 181 174 } 182 175 176 void NetworkProcess::clearDiskCache(std::chrono::system_clock::time_point modifiedSince, std::function<void ()> completionHandler) 177 { 178 if (!m_clearCacheDispatchGroup) 179 m_clearCacheDispatchGroup = dispatch_group_create(); 180 181 #if ENABLE(NETWORK_CACHE) 182 auto group = m_clearCacheDispatchGroup; 183 dispatch_group_async(group, dispatch_get_main_queue(), [group, modifiedSince, completionHandler] { 184 NetworkCache::singleton().clear(modifiedSince, [group, modifiedSince, completionHandler] { 185 // FIXME: Probably not necessary. 186 clearNSURLCache(group, modifiedSince, completionHandler); 187 }); 188 }); 189 #else 190 clearNSURLCache(m_clearCacheDispatchGroup, modifiedSince, completionHandler); 191 #endif 192 } 193 183 194 } 184 195
Note:
See TracChangeset
for help on using the changeset viewer.