Changeset 182841 in webkit


Ignore:
Timestamp:
Apr 15, 2015, 4:19:19 AM (11 years ago)
Author:
Antti Koivisto
Message:

Network Cache: Add thread-safe accessors for storage paths
https://bugs.webkit.org/show_bug.cgi?id=143668

Reviewed by Darin Adler.

Less need to use StringCapture.

  • NetworkProcess/cache/NetworkCache.cpp:

(WebKit::NetworkCache::Cache::dumpFilePath):
(WebKit::NetworkCache::Cache::storagePath):

  • NetworkProcess/cache/NetworkCacheStorage.cpp:

(WebKit::NetworkCache::makeRecordsDirectoryPath):
(WebKit::NetworkCache::Storage::Storage):
(WebKit::NetworkCache::Storage::basePath):
(WebKit::NetworkCache::Storage::versionPath):
(WebKit::NetworkCache::Storage::recordsPath):
(WebKit::NetworkCache::Storage::synchronize):
(WebKit::NetworkCache::Storage::remove):
(WebKit::NetworkCache::Storage::dispatchReadOperation):
(WebKit::NetworkCache::Storage::finishReadOperation):
(WebKit::NetworkCache::Storage::dispatchWriteOperation):
(WebKit::NetworkCache::Storage::traverse):
(WebKit::NetworkCache::Storage::clear):
(WebKit::NetworkCache::Storage::shrink):
(WebKit::NetworkCache::Storage::deleteOldVersions):
(WebKit::NetworkCache::makeRecordDirectoryPath): Deleted.

  • NetworkProcess/cache/NetworkCacheStorage.h:

(WebKit::NetworkCache::Storage::baseDirectoryPath): Deleted.
(WebKit::NetworkCache::Storage::directoryPath): Deleted.

Location:
trunk/Source/WebKit2
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r182822 r182841  
     12015-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
    1332015-04-14  Tim Horton  <timothy_horton@apple.com>
    234
  • trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp

    r182803 r182841  
    427427String Cache::dumpFilePath() const
    428428{
    429     return WebCore::pathByAppendingComponent(m_storage->baseDirectoryPath(), "dump.json");
     429    return WebCore::pathByAppendingComponent(m_storage->versionPath(), "dump.json");
    430430}
    431431
     
    500500String Cache::storagePath() const
    501501{
    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  
    6666}
    6767
    68 static String makeRecordDirectoryPath(const String& baseDirectoryPath)
     68static String makeRecordsDirectoryPath(const String& baseDirectoryPath)
    6969{
    7070    return WebCore::pathByAppendingComponent(makeVersionedDirectoryPath(baseDirectoryPath), recordsDirectoryName);
     
    7777
    7878Storage::Storage(const String& baseDirectoryPath)
    79     : m_baseDirectoryPath(baseDirectoryPath)
    80     , m_directoryPath(makeRecordDirectoryPath(baseDirectoryPath))
     79    : m_basePath(baseDirectoryPath)
     80    , m_recordsPath(makeRecordsDirectoryPath(baseDirectoryPath))
    8181    , m_ioQueue(WorkQueue::create("com.apple.WebKit.Cache.Storage", WorkQueue::Type::Concurrent))
    8282    , m_backgroundIOQueue(WorkQueue::create("com.apple.WebKit.Cache.Storage.background", WorkQueue::Type::Concurrent, WorkQueue::QOS::Background))
     
    8888}
    8989
     90
     91String Storage::basePath() const
     92{
     93    return m_basePath.isolatedCopy();
     94}
     95
     96String Storage::versionPath() const
     97{
     98    return makeVersionedDirectoryPath(basePath());
     99}
     100
     101String Storage::recordsPath() const
     102{
     103    return m_recordsPath.isolatedCopy();
     104}
     105
    90106size_t Storage::approximateSize() const
    91107{
     
    103119    LOG(NetworkCacheStorage, "(NetworkProcess) synchronizing cache");
    104120
    105     StringCapture cachePathCapture(m_directoryPath);
    106     backgroundIOQueue().dispatch([this, cachePathCapture] {
    107         String cachePath = cachePathCapture.string();
    108 
     121    backgroundIOQueue().dispatch([this] {
    109122        auto filter = std::make_unique<ContentsFilter>();
    110123        size_t size = 0;
    111124        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) {
    113126            Key::HashType hash;
    114127            if (!Key::stringToHash(fileName, hash))
     
    330343    // The next synchronization will update everything.
    331344
    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));
    337349    });
    338350}
     
    351363    ASSERT(m_activeReadOperations.contains(&read));
    352364
    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);
    357369        // FIXME: Body and header retrieves can be done in parallel.
    358370        auto bodyBlob = m_blobStorage.get(bodyPath);
     
    372384    bool success = read.completionHandler(WTF::move(record));
    373385    if (success)
    374         updateFileModificationTime(recordPathForKey(read.key, m_directoryPath));
     386        updateFileModificationTime(recordPathForKey(read.key, recordsPath()));
    375387    else
    376388        remove(read.key);
     
    445457    addToContentsFilter(write.record.key);
    446458
    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);
    452464
    453465        WebCore::makeAllDirectories(partitionPath);
     
    538550void Storage::traverse(TraverseFlags flags, std::function<void (const Record*, const RecordInfo&)>&& traverseHandler)
    539551{
    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) {
    544554            auto recordPath = WebCore::pathByAppendingComponent(partitionPath, fileName);
    545555
     
    596606    m_approximateSize = 0;
    597607
    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);
    604612            traverseDirectory(subdirPath, DT_REG, [&subdirPath](const String& fileName) {
    605613                WebCore::deleteFile(WebCore::pathByAppendingComponent(subdirPath, fileName));
     
    665673    LOG(NetworkCacheStorage, "(NetworkProcess) shrinking cache approximateSize=%zu capacity=%zu", approximateSize(), m_capacity);
    666674
    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) {
    671678            auto recordPath = WebCore::pathByAppendingComponent(partitionPath, fileName);
    672679            auto bodyPath = bodyPathForRecordPath(recordPath);
     
    687694
    688695        // 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);
    691698            WebCore::deleteEmptyDirectory(partitionPath);
    692699        });
     
    705712{
    706713    // 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();
    710716        traverseDirectory(cachePath, DT_DIR, [&cachePath](const String& subdirName) {
    711717            if (subdirName.startsWith(versionDirectoryPrefix))
  • trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h

    r182803 r182841  
    8484    static const unsigned version = 3;
    8585
    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;
    8889
    8990private:
     
    121122    void addToContentsFilter(const Key&);
    122123
    123     const String m_baseDirectoryPath;
    124     const String m_directoryPath;
     124    const String m_basePath;
     125    const String m_recordsPath;
    125126
    126127    size_t m_capacity { std::numeric_limits<size_t>::max() };
Note: See TracChangeset for help on using the changeset viewer.