Changeset 182841 in webkit
- Timestamp:
- Apr 15, 2015, 4:19:19 AM (11 years ago)
- Location:
- trunk/Source/WebKit2
- Files:
-
- 4 edited
-
ChangeLog (modified) (1 diff)
-
NetworkProcess/cache/NetworkCache.cpp (modified) (2 diffs)
-
NetworkProcess/cache/NetworkCacheStorage.cpp (modified) (13 diffs)
-
NetworkProcess/cache/NetworkCacheStorage.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r182822 r182841 1 2015-04-15 Antti Koivisto <antti@apple.com> 2 3 Network Cache: Add thread-safe accessors for storage paths 4 https://bugs.webkit.org/show_bug.cgi?id=143668 5 6 Reviewed by Darin Adler. 7 8 Less need to use StringCapture. 9 10 * NetworkProcess/cache/NetworkCache.cpp: 11 (WebKit::NetworkCache::Cache::dumpFilePath): 12 (WebKit::NetworkCache::Cache::storagePath): 13 * NetworkProcess/cache/NetworkCacheStorage.cpp: 14 (WebKit::NetworkCache::makeRecordsDirectoryPath): 15 (WebKit::NetworkCache::Storage::Storage): 16 (WebKit::NetworkCache::Storage::basePath): 17 (WebKit::NetworkCache::Storage::versionPath): 18 (WebKit::NetworkCache::Storage::recordsPath): 19 (WebKit::NetworkCache::Storage::synchronize): 20 (WebKit::NetworkCache::Storage::remove): 21 (WebKit::NetworkCache::Storage::dispatchReadOperation): 22 (WebKit::NetworkCache::Storage::finishReadOperation): 23 (WebKit::NetworkCache::Storage::dispatchWriteOperation): 24 (WebKit::NetworkCache::Storage::traverse): 25 (WebKit::NetworkCache::Storage::clear): 26 (WebKit::NetworkCache::Storage::shrink): 27 (WebKit::NetworkCache::Storage::deleteOldVersions): 28 (WebKit::NetworkCache::makeRecordDirectoryPath): Deleted. 29 * NetworkProcess/cache/NetworkCacheStorage.h: 30 (WebKit::NetworkCache::Storage::baseDirectoryPath): Deleted. 31 (WebKit::NetworkCache::Storage::directoryPath): Deleted. 32 1 33 2015-04-14 Tim Horton <timothy_horton@apple.com> 2 34 -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp
r182803 r182841 427 427 String Cache::dumpFilePath() const 428 428 { 429 return WebCore::pathByAppendingComponent(m_storage-> baseDirectoryPath(), "dump.json");429 return WebCore::pathByAppendingComponent(m_storage->versionPath(), "dump.json"); 430 430 } 431 431 … … 500 500 String Cache::storagePath() const 501 501 { 502 return m_storage ? m_storage-> directoryPath() : String();503 } 504 505 } 506 } 507 508 #endif 502 return m_storage ? m_storage->versionPath() : String(); 503 } 504 505 } 506 } 507 508 #endif -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.cpp
r182803 r182841 66 66 } 67 67 68 static String makeRecord DirectoryPath(const String& baseDirectoryPath)68 static String makeRecordsDirectoryPath(const String& baseDirectoryPath) 69 69 { 70 70 return WebCore::pathByAppendingComponent(makeVersionedDirectoryPath(baseDirectoryPath), recordsDirectoryName); … … 77 77 78 78 Storage::Storage(const String& baseDirectoryPath) 79 : m_base DirectoryPath(baseDirectoryPath)80 , m_ directoryPath(makeRecordDirectoryPath(baseDirectoryPath))79 : m_basePath(baseDirectoryPath) 80 , m_recordsPath(makeRecordsDirectoryPath(baseDirectoryPath)) 81 81 , m_ioQueue(WorkQueue::create("com.apple.WebKit.Cache.Storage", WorkQueue::Type::Concurrent)) 82 82 , m_backgroundIOQueue(WorkQueue::create("com.apple.WebKit.Cache.Storage.background", WorkQueue::Type::Concurrent, WorkQueue::QOS::Background)) … … 88 88 } 89 89 90 91 String Storage::basePath() const 92 { 93 return m_basePath.isolatedCopy(); 94 } 95 96 String Storage::versionPath() const 97 { 98 return makeVersionedDirectoryPath(basePath()); 99 } 100 101 String Storage::recordsPath() const 102 { 103 return m_recordsPath.isolatedCopy(); 104 } 105 90 106 size_t Storage::approximateSize() const 91 107 { … … 103 119 LOG(NetworkCacheStorage, "(NetworkProcess) synchronizing cache"); 104 120 105 StringCapture cachePathCapture(m_directoryPath); 106 backgroundIOQueue().dispatch([this, cachePathCapture] { 107 String cachePath = cachePathCapture.string(); 108 121 backgroundIOQueue().dispatch([this] { 109 122 auto filter = std::make_unique<ContentsFilter>(); 110 123 size_t size = 0; 111 124 unsigned count = 0; 112 traverseCacheFiles( cachePath, [&filter, &size, &count](const String& fileName, const String& partitionPath) {125 traverseCacheFiles(recordsPath(), [&filter, &size, &count](const String& fileName, const String& partitionPath) { 113 126 Key::HashType hash; 114 127 if (!Key::stringToHash(fileName, hash)) … … 330 343 // The next synchronization will update everything. 331 344 332 StringCapture recordPathCapture(recordPathForKey(key, m_directoryPath)); 333 StringCapture bodyPathCapture(bodyPathForKey(key, m_directoryPath)); 334 serialBackgroundIOQueue().dispatch([this, recordPathCapture, bodyPathCapture] { 335 WebCore::deleteFile(recordPathCapture.string()); 336 m_blobStorage.remove(bodyPathCapture.string()); 345 serialBackgroundIOQueue().dispatch([this, key] { 346 auto recordsPath = this->recordsPath(); 347 WebCore::deleteFile(recordPathForKey(key, recordsPath)); 348 m_blobStorage.remove(bodyPathForKey(key, recordsPath)); 337 349 }); 338 350 } … … 351 363 ASSERT(m_activeReadOperations.contains(&read)); 352 364 353 StringCapture cachePathCapture(m_directoryPath);354 ioQueue().dispatch([this, &read, cachePathCapture] {355 auto recordPath = recordPathForKey(read.key, cachePathCapture.string());356 auto bodyPath = bodyPathForKey(read.key, cachePathCapture.string());365 ioQueue().dispatch([this, &read] { 366 auto recordsPath = this->recordsPath(); 367 auto recordPath = recordPathForKey(read.key, recordsPath); 368 auto bodyPath = bodyPathForKey(read.key, recordsPath); 357 369 // FIXME: Body and header retrieves can be done in parallel. 358 370 auto bodyBlob = m_blobStorage.get(bodyPath); … … 372 384 bool success = read.completionHandler(WTF::move(record)); 373 385 if (success) 374 updateFileModificationTime(recordPathForKey(read.key, m_directoryPath));386 updateFileModificationTime(recordPathForKey(read.key, recordsPath())); 375 387 else 376 388 remove(read.key); … … 445 457 addToContentsFilter(write.record.key); 446 458 447 StringCapture cachePathCapture(m_directoryPath);448 backgroundIOQueue().dispatch([this, &write, cachePathCapture] {449 auto partitionPath = partitionPathForKey(write.record.key, cachePathCapture.string());450 auto recordPath = recordPathForKey(write.record.key, cachePathCapture.string());451 auto bodyPath = bodyPathForKey(write.record.key, cachePathCapture.string());459 backgroundIOQueue().dispatch([this, &write] { 460 auto recordsPath = this->recordsPath(); 461 auto partitionPath = partitionPathForKey(write.record.key, recordsPath); 462 auto recordPath = recordPathForKey(write.record.key, recordsPath); 463 auto bodyPath = bodyPathForKey(write.record.key, recordsPath); 452 464 453 465 WebCore::makeAllDirectories(partitionPath); … … 538 550 void Storage::traverse(TraverseFlags flags, std::function<void (const Record*, const RecordInfo&)>&& traverseHandler) 539 551 { 540 StringCapture cachePathCapture(m_directoryPath); 541 ioQueue().dispatch([this, flags, cachePathCapture, traverseHandler] { 542 String cachePath = cachePathCapture.string(); 543 traverseCacheFiles(cachePath, [this, flags, &traverseHandler](const String& fileName, const String& partitionPath) { 552 ioQueue().dispatch([this, flags, traverseHandler] { 553 traverseCacheFiles(recordsPath(), [this, flags, &traverseHandler](const String& fileName, const String& partitionPath) { 544 554 auto recordPath = WebCore::pathByAppendingComponent(partitionPath, fileName); 545 555 … … 596 606 m_approximateSize = 0; 597 607 598 StringCapture directoryPathCapture(m_directoryPath); 599 600 ioQueue().dispatch([this, directoryPathCapture] { 601 String directoryPath = directoryPathCapture.string(); 602 traverseDirectory(directoryPath, DT_DIR, [&directoryPath](const String& subdirName) { 603 String subdirPath = WebCore::pathByAppendingComponent(directoryPath, subdirName); 608 ioQueue().dispatch([this] { 609 auto recordsPath = this->recordsPath(); 610 traverseDirectory(recordsPath, DT_DIR, [&recordsPath](const String& subdirName) { 611 String subdirPath = WebCore::pathByAppendingComponent(recordsPath, subdirName); 604 612 traverseDirectory(subdirPath, DT_REG, [&subdirPath](const String& fileName) { 605 613 WebCore::deleteFile(WebCore::pathByAppendingComponent(subdirPath, fileName)); … … 665 673 LOG(NetworkCacheStorage, "(NetworkProcess) shrinking cache approximateSize=%zu capacity=%zu", approximateSize(), m_capacity); 666 674 667 StringCapture cachePathCapture(m_directoryPath); 668 backgroundIOQueue().dispatch([this, cachePathCapture] { 669 String cachePath = cachePathCapture.string(); 670 traverseCacheFiles(cachePath, [this](const String& fileName, const String& partitionPath) { 675 backgroundIOQueue().dispatch([this] { 676 auto recordsPath = this->recordsPath(); 677 traverseCacheFiles(recordsPath, [this](const String& fileName, const String& partitionPath) { 671 678 auto recordPath = WebCore::pathByAppendingComponent(partitionPath, fileName); 672 679 auto bodyPath = bodyPathForRecordPath(recordPath); … … 687 694 688 695 // Let system figure out if they are really empty. 689 traverseDirectory( cachePath, DT_DIR, [&cachePath](const String& subdirName) {690 auto partitionPath = WebCore::pathByAppendingComponent( cachePath, subdirName);696 traverseDirectory(recordsPath, DT_DIR, [&recordsPath](const String& subdirName) { 697 auto partitionPath = WebCore::pathByAppendingComponent(recordsPath, subdirName); 691 698 WebCore::deleteEmptyDirectory(partitionPath); 692 699 }); … … 705 712 { 706 713 // Delete V1 cache. 707 StringCapture cachePathCapture(m_baseDirectoryPath); 708 backgroundIOQueue().dispatch([cachePathCapture] { 709 String cachePath = cachePathCapture.string(); 714 backgroundIOQueue().dispatch([this] { 715 auto cachePath = basePath(); 710 716 traverseDirectory(cachePath, DT_DIR, [&cachePath](const String& subdirName) { 711 717 if (subdirName.startsWith(versionDirectoryPrefix)) -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h
r182803 r182841 84 84 static const unsigned version = 3; 85 85 86 const String& baseDirectoryPath() const { return m_baseDirectoryPath; } 87 const String& directoryPath() const { return m_directoryPath; } 86 String basePath() const; 87 String versionPath() const; 88 String recordsPath() const; 88 89 89 90 private: … … 121 122 void addToContentsFilter(const Key&); 122 123 123 const String m_base DirectoryPath;124 const String m_ directoryPath;124 const String m_basePath; 125 const String m_recordsPath; 125 126 126 127 size_t m_capacity { std::numeric_limits<size_t>::max() };
Note:
See TracChangeset
for help on using the changeset viewer.