Changeset 247125 in webkit


Ignore:
Timestamp:
Jul 3, 2019 6:10:27 PM (5 years ago)
Author:
youenn@apple.com
Message:

Make CacheStorage::Engine directory listing operations in a background thread
https://bugs.webkit.org/show_bug.cgi?id=199470

Reviewed by Chris Dumez.

Use the io work queue to get the list of directories.
Then go back to main thread and trigger clear/fetch operation as currently done.

  • NetworkProcess/cache/CacheStorageEngine.cpp:

(WebKit::CacheStorage::ReadOriginsTaskCounter::create):
(WebKit::CacheStorage::ReadOriginsTaskCounter::ReadOriginsTaskCounter):
(WebKit::CacheStorage::Engine::getDirectories):
(WebKit::CacheStorage::Engine::fetchEntries):
(WebKit::CacheStorage::Engine::fetchDirectoryEntries):
(WebKit::CacheStorage::Engine::clearCachesForOriginFromDisk):
(WebKit::CacheStorage::Engine::clearCachesForOriginFromDirectories):

  • NetworkProcess/cache/CacheStorageEngine.h:
Location:
trunk/Source/WebKit
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r247123 r247125  
     12019-07-03  Youenn Fablet  <youenn@apple.com>
     2
     3        Make CacheStorage::Engine directory listing operations in a background thread
     4        https://bugs.webkit.org/show_bug.cgi?id=199470
     5
     6        Reviewed by Chris Dumez.
     7
     8        Use the io work queue to get the list of directories.
     9        Then go back to main thread and trigger clear/fetch operation as currently done.
     10
     11        * NetworkProcess/cache/CacheStorageEngine.cpp:
     12        (WebKit::CacheStorage::ReadOriginsTaskCounter::create):
     13        (WebKit::CacheStorage::ReadOriginsTaskCounter::ReadOriginsTaskCounter):
     14        (WebKit::CacheStorage::Engine::getDirectories):
     15        (WebKit::CacheStorage::Engine::fetchEntries):
     16        (WebKit::CacheStorage::Engine::fetchDirectoryEntries):
     17        (WebKit::CacheStorage::Engine::clearCachesForOriginFromDisk):
     18        (WebKit::CacheStorage::Engine::clearCachesForOriginFromDirectories):
     19        * NetworkProcess/cache/CacheStorageEngine.h:
     20
    1212019-07-03  Sihui Liu  <sihui_liu@apple.com>
    222
  • trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp

    r247111 r247125  
    460460class ReadOriginsTaskCounter : public RefCounted<ReadOriginsTaskCounter> {
    461461public:
    462     static Ref<ReadOriginsTaskCounter> create(WTF::CompletionHandler<void(Vector<WebsiteData::Entry>)>&& callback)
     462    static Ref<ReadOriginsTaskCounter> create(CompletionHandler<void(Vector<WebsiteData::Entry>)>&& callback)
    463463    {
    464464        return adoptRef(*new ReadOriginsTaskCounter(WTFMove(callback)));
     
    476476
    477477private:
    478     explicit ReadOriginsTaskCounter(WTF::CompletionHandler<void(Vector<WebsiteData::Entry>)>&& callback)
     478    explicit ReadOriginsTaskCounter(CompletionHandler<void(Vector<WebsiteData::Entry>)>&& callback)
    479479        : m_callback(WTFMove(callback))
    480480    {
    481481    }
    482482
    483     WTF::CompletionHandler<void(Vector<WebsiteData::Entry>)> m_callback;
     483    CompletionHandler<void(Vector<WebsiteData::Entry>)> m_callback;
    484484    Vector<WebsiteData::Entry> m_entries;
    485485};
    486486
    487 void Engine::fetchEntries(bool shouldComputeSize, WTF::CompletionHandler<void(Vector<WebsiteData::Entry>)>&& completionHandler)
     487void Engine::getDirectories(CompletionHandler<void(const Vector<String>&)>&& completionHandler)
     488{
     489    m_ioQueue->dispatch([path = m_rootPath.isolatedCopy(), completionHandler = WTFMove(completionHandler)]() mutable {
     490        Vector<String> folderPaths;
     491        for (auto& filename : FileSystem::listDirectory(path, "*")) {
     492            if (FileSystem::fileIsDirectory(filename, FileSystem::ShouldFollowSymbolicLinks::No))
     493                folderPaths.append(filename.isolatedCopy());
     494        }
     495
     496        RunLoop::main().dispatch([folderPaths = WTFMove(folderPaths), completionHandler = WTFMove(completionHandler)]() mutable {
     497            completionHandler(folderPaths);
     498        });
     499    });
     500}
     501
     502void Engine::fetchEntries(bool shouldComputeSize, CompletionHandler<void(Vector<WebsiteData::Entry>)>&& completionHandler)
    488503{
    489504    if (!shouldPersist()) {
     
    495510    }
    496511
     512    getDirectories([this, weakThis = makeWeakPtr(this), path = m_rootPath.isolatedCopy(), shouldComputeSize, completionHandler = WTFMove(completionHandler)](const auto& folderPaths) mutable {
     513        if (!weakThis)
     514            return completionHandler({ });
     515        fetchDirectoryEntries(shouldComputeSize, folderPaths, WTFMove(completionHandler));
     516    });
     517}
     518
     519void Engine::fetchDirectoryEntries(bool shouldComputeSize, const Vector<String>& folderPaths, CompletionHandler<void(Vector<WebsiteData::Entry>)>&& completionHandler)
     520{
    497521    auto taskCounter = ReadOriginsTaskCounter::create(WTFMove(completionHandler));
    498     for (auto& folderPath : FileSystem::listDirectory(m_rootPath, "*")) {
    499         if (!FileSystem::fileIsDirectory(folderPath, FileSystem::ShouldFollowSymbolicLinks::No))
    500             continue;
     522    for (auto& folderPath : folderPaths) {
    501523        Caches::retrieveOriginFromDirectory(folderPath, *m_ioQueue, [protectedThis = makeRef(*this), shouldComputeSize, taskCounter = taskCounter.copyRef()] (auto&& origin) mutable {
    502524            ASSERT(RunLoop::isMain());
     
    570592{
    571593    ASSERT(RunLoop::isMain());
    572 
     594    getDirectories([this, weakThis = makeWeakPtr(this), origin, completionHandler = WTFMove(completionHandler)](const auto& folderPaths) mutable {
     595        if (!weakThis)
     596            return completionHandler();
     597        clearCachesForOriginFromDirectories(folderPaths, origin, WTFMove(completionHandler));
     598    });
     599}
     600
     601void Engine::clearCachesForOriginFromDirectories(const Vector<String>& folderPaths, const WebCore::SecurityOriginData& origin, CompletionHandler<void()>&& completionHandler)
     602{
    573603    auto callbackAggregator = CallbackAggregator::create(WTFMove(completionHandler));
    574 
    575     for (auto& folderPath : FileSystem::listDirectory(m_rootPath, "*")) {
    576         if (!FileSystem::fileIsDirectory(folderPath, FileSystem::ShouldFollowSymbolicLinks::No))
    577             continue;
     604    for (auto& folderPath : folderPaths) {
    578605        Caches::retrieveOriginFromDirectory(folderPath, *m_ioQueue, [this, protectedThis = makeRef(*this), origin, callbackAggregator = callbackAggregator.copyRef(), folderPath] (Optional<WebCore::ClientOrigin>&& folderOrigin) mutable {
    579606            if (!folderOrigin)
  • trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.h

    r243339 r247125  
    120120    void fetchEntries(bool /* shouldComputeSize */, CompletionHandler<void(Vector<WebsiteData::Entry>)>&&);
    121121
     122    void getDirectories(CompletionHandler<void(const Vector<String>&)>&&);
     123    void fetchDirectoryEntries(bool shouldComputeSize, const Vector<String>& folderPaths, CompletionHandler<void(Vector<WebsiteData::Entry>)>&&);
     124    void clearCachesForOriginFromDirectories(const Vector<String>&, const WebCore::SecurityOriginData&, CompletionHandler<void()>&&);
     125
    122126    void initialize(WebCore::DOMCacheEngine::CompletionCallback&&);
    123127
Note: See TracChangeset for help on using the changeset viewer.