Changeset 252381 in webkit
- Timestamp:
- Nov 12, 2019 5:24:28 PM (4 years ago)
- Location:
- trunk/Source/WebKit
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r252377 r252381 1 2019-11-12 Sihui Liu <sihui_liu@apple.com> 2 3 Add size file for CacheStorage 4 https://bugs.webkit.org/show_bug.cgi?id=204027 5 <rdar://problem/57100861> 6 7 Reviewed by Youenn Fablet. 8 9 Keep the CacheStorage size in a separate file so that we can get that value without waiting for Engine to 10 initialize and read caches from disk. 11 12 No behavior change as the file is not in use now. 13 14 * NetworkProcess/cache/CacheStorageEngine.cpp: 15 (WebKit::CacheStorage::Engine::writeSizeFile): 16 (WebKit::CacheStorage::Engine::readSizeFile): 17 (WebKit::CacheStorage::Engine::clearAllCachesFromDisk): 18 (WebKit::CacheStorage::Engine::deleteDirectoryRecursivelyOnBackgroundThread): 19 * NetworkProcess/cache/CacheStorageEngine.h: 20 * NetworkProcess/cache/CacheStorageEngineCaches.cpp: 21 (WebKit::CacheStorage::Caches::cachesSizeFilename): 22 (WebKit::CacheStorage::Caches::updateSizeFile): 23 (WebKit::CacheStorage::Caches::initializeSize): 24 (WebKit::CacheStorage::Caches::writeRecord): 25 (WebKit::CacheStorage::Caches::removeRecord): 26 (WebKit::CacheStorage::Caches::resetSpaceUsed): 27 * NetworkProcess/cache/CacheStorageEngineCaches.h: 28 1 29 2019-11-12 Wenson Hsieh <wenson_hsieh@apple.com> 2 30 -
trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp
r252369 r252381 36 36 #include <wtf/CallbackAggregator.h> 37 37 #include <wtf/NeverDestroyed.h> 38 #include <wtf/Scope.h> 38 39 #include <wtf/text/StringBuilder.h> 39 40 #include <wtf/text/StringHash.h> … … 45 46 using namespace WebCore::DOMCacheEngine; 46 47 using namespace NetworkCache; 48 49 static Lock globalSizeFileLock; 47 50 48 51 String Engine::cachesRootPath(const WebCore::ClientOrigin& origin) … … 462 465 } 463 466 467 void Engine::writeSizeFile(const String& path, uint64_t size) 468 { 469 if (!shouldPersist()) 470 return; 471 472 m_ioQueue->dispatch([path = path.isolatedCopy(), size]() { 473 LockHolder locker(globalSizeFileLock); 474 auto fileHandle = FileSystem::openFile(path, FileSystem::FileOpenMode::Write); 475 auto closeFileHandler = makeScopeExit([&] { 476 FileSystem::closeFile(fileHandle); 477 }); 478 if (!FileSystem::isHandleValid(fileHandle)) 479 return; 480 481 FileSystem::truncateFile(fileHandle, 0); 482 FileSystem::writeToFile(fileHandle, String::number(size).utf8().data(), String::number(size).utf8().length()); 483 }); 484 } 485 486 Optional<uint64_t> Engine::readSizeFile(const String& path) 487 { 488 ASSERT(!RunLoop::isMain()); 489 490 LockHolder locker(globalSizeFileLock); 491 auto fileHandle = FileSystem::openFile(path, FileSystem::FileOpenMode::Read); 492 auto closeFileHandle = makeScopeExit([&] { 493 FileSystem::closeFile(fileHandle); 494 }); 495 496 if (!FileSystem::isHandleValid(fileHandle)) 497 return WTF::nullopt; 498 499 long long fileSize = 0; 500 if (!FileSystem::getFileSize(path, fileSize) || !fileSize) 501 return WTF::nullopt; 502 503 size_t bytesToRead; 504 if (!WTF::convertSafely(fileSize, bytesToRead)) 505 return WTF::nullopt; 506 507 Vector<char> buffer(bytesToRead); 508 size_t totalBytesRead = FileSystem::readFromFile(fileHandle, buffer.data(), buffer.size()); 509 if (totalBytesRead != bytesToRead) 510 return WTF::nullopt; 511 512 return String::fromUTF8(buffer.data()).toUInt64Strict(); 513 } 514 464 515 class ReadOriginsTaskCounter : public RefCounted<ReadOriginsTaskCounter> { 465 516 public: … … 566 617 567 618 m_ioQueue->dispatch([path = m_rootPath.isolatedCopy(), completionHandler = WTFMove(completionHandler)]() mutable { 619 LockHolder locker(globalSizeFileLock); 568 620 for (auto& filename : FileSystem::listDirectory(path, "*")) { 569 621 if (FileSystem::fileIsDirectory(filename, FileSystem::ShouldFollowSymbolicLinks::No)) … … 624 676 625 677 m_ioQueue->dispatch([path = path.isolatedCopy(), completionHandler = WTFMove(completionHandler)]() mutable { 678 LockHolder locker(globalSizeFileLock); 626 679 deleteDirectoryRecursively(path); 627 680 -
trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.h
r252369 r252381 85 85 void readFile(const String& filename, CompletionHandler<void(const NetworkCache::Data&, int error)>&&); 86 86 void removeFile(const String& filename); 87 void writeSizeFile(const String&, uint64_t size); 88 static Optional<uint64_t> readSizeFile(const String&); 87 89 88 90 const String& rootPath() const { return m_rootPath; } -
trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp
r252369 r252381 52 52 } 53 53 54 String Caches::cachesSizeFilename(const String& cachesRootsPath) 55 { 56 return FileSystem::pathByAppendingComponent(cachesRootsPath, "estimatedsize"_s); 57 } 58 54 59 Ref<Caches> Caches::create(Engine& engine, WebCore::ClientOrigin&& origin, String&& rootPath, WebCore::StorageQuotaManager& quotaManager) 55 60 { … … 204 209 } 205 210 211 void Caches::updateSizeFile() 212 { 213 if (m_engine) 214 m_engine->writeSizeFile(cachesSizeFilename(m_rootPath), m_size); 215 } 216 206 217 void Caches::initializeSize() 207 218 { … … 222 233 } 223 234 m_size = size; 235 updateSizeFile(); 236 224 237 m_isInitialized = true; 225 238 auto pendingCallbacks = WTFMove(m_pendingInitializationCallbacks); … … 536 549 m_size += recordInformation.size; 537 550 m_size -= previousRecordSize; 551 updateSizeFile(); 538 552 539 553 if (!shouldPersist()) { … … 592 606 ASSERT(m_size >= record.size); 593 607 m_size -= record.size; 608 updateSizeFile(); 609 594 610 removeCacheEntry(record.key); 595 611 } … … 609 625 { 610 626 m_size = 0; 627 updateSizeFile(); 628 611 629 if (m_quotaManager) { 612 630 m_quotaManager->removeUser(*this); -
trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.h
r252369 r252381 45 45 class Caches final : public RefCounted<Caches>, private WebCore::StorageQuotaUser { 46 46 public: 47 static String cachesSizeFilename(const String&); 47 48 static Ref<Caches> create(Engine&, WebCore::ClientOrigin&&, String&& rootPath, WebCore::StorageQuotaManager&); 48 49 ~Caches(); … … 106 107 bool hasActiveCache() const; 107 108 109 void updateSizeFile(); 110 108 111 bool m_isInitialized { false }; 109 112 Engine* m_engine { nullptr };
Note: See TracChangeset
for help on using the changeset viewer.