Changeset 247567 in webkit


Ignore:
Timestamp:
Jul 18, 2019 11:41:31 AM (5 years ago)
Author:
achristensen@apple.com
Message:

Move NetworkCache ownership from NetworkProcess to NetworkSession
https://bugs.webkit.org/show_bug.cgi?id=199817

Reviewed by Geoff Garen.

Source/WebKit:

I also added SPI to set the path of the NetworkCache with an API test.
If this new SPI is not used, it falls back to getting the cache location from the NetworkProcess to maintain compatibility.
We still get options, cache size, and cache model from the NetworkProcess. Those should be migrated with new SPI later.
Clearing the cache and other operations now iterate the NetworkSessions instead of assuming there is only one cache.

  • NetworkProcess/NetworkProcess.cpp:

(WebKit::NetworkProcess::fetchWebsiteData):
(WebKit::NetworkProcess::deleteWebsiteDataForOrigins):
(WebKit::NetworkProcess::deleteWebsiteDataForRegistrableDomains):
(WebKit::NetworkProcess::registrableDomainsWithWebsiteData):
(WebKit::NetworkProcess::setCacheModel):

  • NetworkProcess/NetworkProcess.h:

(WebKit::NetworkProcess::diskCacheDirectory const):
(WebKit::NetworkProcess::cacheOptions const):
(WebKit::NetworkProcess::cache): Deleted.

  • NetworkProcess/NetworkResourceLoader.cpp:

(WebKit::m_shouldCaptureExtraNetworkLoadMetrics):

  • NetworkProcess/NetworkSession.cpp:

(WebKit::NetworkSession::NetworkSession):

  • NetworkProcess/NetworkSession.h:

(WebKit::NetworkSession::cache):

  • NetworkProcess/NetworkSessionCreationParameters.cpp:

(WebKit::NetworkSessionCreationParameters::encode const):
(WebKit::NetworkSessionCreationParameters::decode):

  • NetworkProcess/NetworkSessionCreationParameters.h:
  • NetworkProcess/cache/NetworkCache.cpp:

(WebKit::NetworkCache::Cache::open):
(WebKit::NetworkCache::Cache::Cache):

  • NetworkProcess/cache/NetworkCache.h:
  • NetworkProcess/cocoa/NetworkProcessCocoa.mm:

(WebKit::NetworkProcess::platformInitializeNetworkProcessCocoa):
(WebKit::NetworkProcess::clearDiskCache):

  • NetworkProcess/cocoa/NetworkSessionCocoa.mm:

(WebKit::NetworkSessionCocoa::NetworkSessionCocoa):

  • NetworkProcess/curl/NetworkSessionCurl.cpp:

(WebKit::NetworkSessionCurl::NetworkSessionCurl):

  • NetworkProcess/soup/NetworkSessionSoup.cpp:

(WebKit::NetworkSessionSoup::NetworkSessionSoup):

  • UIProcess/API/Cocoa/WKWebsiteDataStore.mm:

(-[WKWebsiteDataStore _initWithConfiguration:]):

  • UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.h:
  • UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.mm:

(-[_WKWebsiteDataStoreConfiguration networkCacheDirectory]):
(-[_WKWebsiteDataStoreConfiguration setNetworkCacheDirectory:]):

  • UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm:

(WebKit::WebsiteDataStore::parameters):

  • UIProcess/WebsiteData/WebsiteDataStore.cpp:

(WebKit::WebsiteDataStore::resolveDirectoriesIfNecessary):

  • UIProcess/WebsiteData/WebsiteDataStore.h:

(WebKit::WebsiteDataStore::resolvedNetworkCacheDirectory const):

Tools:

  • TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm:

(TEST):

  • TestWebKitAPI/cocoa/TestWKWebView.h:
  • TestWebKitAPI/cocoa/TestWKWebView.mm:

(-[WKWebView synchronouslyLoadRequest:]):

Location:
trunk
Files:
26 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r247565 r247567  
     12019-07-18  Alex Christensen  <achristensen@webkit.org>
     2
     3        Move NetworkCache ownership from NetworkProcess to NetworkSession
     4        https://bugs.webkit.org/show_bug.cgi?id=199817
     5
     6        Reviewed by Geoff Garen.
     7
     8        I also added SPI to set the path of the NetworkCache with an API test.
     9        If this new SPI is not used, it falls back to getting the cache location from the NetworkProcess to maintain compatibility.
     10        We still get options, cache size, and cache model from the NetworkProcess.  Those should be migrated with new SPI later.
     11        Clearing the cache and other operations now iterate the NetworkSessions instead of assuming there is only one cache.
     12
     13        * NetworkProcess/NetworkProcess.cpp:
     14        (WebKit::NetworkProcess::fetchWebsiteData):
     15        (WebKit::NetworkProcess::deleteWebsiteDataForOrigins):
     16        (WebKit::NetworkProcess::deleteWebsiteDataForRegistrableDomains):
     17        (WebKit::NetworkProcess::registrableDomainsWithWebsiteData):
     18        (WebKit::NetworkProcess::setCacheModel):
     19        * NetworkProcess/NetworkProcess.h:
     20        (WebKit::NetworkProcess::diskCacheDirectory const):
     21        (WebKit::NetworkProcess::cacheOptions const):
     22        (WebKit::NetworkProcess::cache): Deleted.
     23        * NetworkProcess/NetworkResourceLoader.cpp:
     24        (WebKit::m_shouldCaptureExtraNetworkLoadMetrics):
     25        * NetworkProcess/NetworkSession.cpp:
     26        (WebKit::NetworkSession::NetworkSession):
     27        * NetworkProcess/NetworkSession.h:
     28        (WebKit::NetworkSession::cache):
     29        * NetworkProcess/NetworkSessionCreationParameters.cpp:
     30        (WebKit::NetworkSessionCreationParameters::encode const):
     31        (WebKit::NetworkSessionCreationParameters::decode):
     32        * NetworkProcess/NetworkSessionCreationParameters.h:
     33        * NetworkProcess/cache/NetworkCache.cpp:
     34        (WebKit::NetworkCache::Cache::open):
     35        (WebKit::NetworkCache::Cache::Cache):
     36        * NetworkProcess/cache/NetworkCache.h:
     37        * NetworkProcess/cocoa/NetworkProcessCocoa.mm:
     38        (WebKit::NetworkProcess::platformInitializeNetworkProcessCocoa):
     39        (WebKit::NetworkProcess::clearDiskCache):
     40        * NetworkProcess/cocoa/NetworkSessionCocoa.mm:
     41        (WebKit::NetworkSessionCocoa::NetworkSessionCocoa):
     42        * NetworkProcess/curl/NetworkSessionCurl.cpp:
     43        (WebKit::NetworkSessionCurl::NetworkSessionCurl):
     44        * NetworkProcess/soup/NetworkSessionSoup.cpp:
     45        (WebKit::NetworkSessionSoup::NetworkSessionSoup):
     46        * UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
     47        (-[WKWebsiteDataStore _initWithConfiguration:]):
     48        * UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.h:
     49        * UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.mm:
     50        (-[_WKWebsiteDataStoreConfiguration networkCacheDirectory]):
     51        (-[_WKWebsiteDataStoreConfiguration setNetworkCacheDirectory:]):
     52        * UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm:
     53        (WebKit::WebsiteDataStore::parameters):
     54        * UIProcess/WebsiteData/WebsiteDataStore.cpp:
     55        (WebKit::WebsiteDataStore::resolveDirectoriesIfNecessary):
     56        * UIProcess/WebsiteData/WebsiteDataStore.h:
     57        (WebKit::WebsiteDataStore::resolvedNetworkCacheDirectory const):
     58
    1592019-07-18  Chris Dumez  <cdumez@apple.com>
    260
  • trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp

    r247283 r247567  
    13581358    }
    13591359#endif
    1360 
    13611360    if (websiteDataTypes.contains(WebsiteDataType::DiskCache)) {
    1362         fetchDiskCacheEntries(cache(), sessionID, fetchOptions, [callbackAggregator = WTFMove(callbackAggregator)](auto entries) mutable {
    1363             callbackAggregator->m_websiteData.entries.appendVector(entries);
    1364         });
     1361        for (auto& session : networkSessions().values()) {
     1362            fetchDiskCacheEntries(session->cache(), sessionID, fetchOptions, [callbackAggregator = WTFMove(callbackAggregator)](auto entries) mutable {
     1363                callbackAggregator->m_websiteData.entries.appendVector(entries);
     1364            });
     1365        }
    13651366    }
    13661367}
     
    15171518#endif
    15181519
    1519     if (websiteDataTypes.contains(WebsiteDataType::DiskCache) && !sessionID.isEphemeral())
    1520         clearDiskCacheEntries(cache(), originDatas, [clearTasksHandler = WTFMove(clearTasksHandler)] { });
     1520    if (websiteDataTypes.contains(WebsiteDataType::DiskCache) && !sessionID.isEphemeral()) {
     1521        for (auto& session : networkSessions().values())
     1522            clearDiskCacheEntries(session->cache(), originDatas, [clearTasksHandler = WTFMove(clearTasksHandler)] { });
     1523    }
    15211524
    15221525    if (websiteDataTypes.contains(WebsiteDataType::Credentials)) {
     
    17491752    }
    17501753#endif
    1751    
     1754
    17521755    if (websiteDataTypes.contains(WebsiteDataType::DiskCache)) {
    1753         fetchDiskCacheEntries(cache(), sessionID, fetchOptions, [this, domainsToDeleteAllButCookiesFor, callbackAggregator = callbackAggregator.copyRef()](auto entries) mutable {
    1754 
    1755             Vector<SecurityOriginData> entriesToDelete;
    1756             for (auto& entry : entries) {
    1757                 if (!domainsToDeleteAllButCookiesFor.contains(RegistrableDomain::uncheckedCreateFromHost(entry.origin.host)))
    1758                     continue;
    1759                 entriesToDelete.append(entry.origin);
    1760                 callbackAggregator->m_domains.add(RegistrableDomain::uncheckedCreateFromHost(entry.origin.host));
    1761             }
    1762             clearDiskCacheEntries(cache(), entriesToDelete, [callbackAggregator = callbackAggregator.copyRef()] { });
    1763         });
     1756        for (auto& session : networkSessions().values()) {
     1757            fetchDiskCacheEntries(session->cache(), sessionID, fetchOptions, [domainsToDeleteAllButCookiesFor, callbackAggregator = callbackAggregator.copyRef(), session = session.copyRef()](auto entries) mutable {
     1758
     1759                Vector<SecurityOriginData> entriesToDelete;
     1760                for (auto& entry : entries) {
     1761                    if (!domainsToDeleteAllButCookiesFor.contains(RegistrableDomain::uncheckedCreateFromHost(entry.origin.host)))
     1762                        continue;
     1763                    entriesToDelete.append(entry.origin);
     1764                    callbackAggregator->m_domains.add(RegistrableDomain::uncheckedCreateFromHost(entry.origin.host));
     1765                }
     1766                clearDiskCacheEntries(session->cache(), entriesToDelete, [callbackAggregator = callbackAggregator.copyRef()] { });
     1767            });
     1768        }
    17641769    }
    17651770
     
    18831888   
    18841889    if (websiteDataTypes.contains(WebsiteDataType::DiskCache)) {
    1885         fetchDiskCacheEntries(cache(), sessionID, fetchOptions, [callbackAggregator = callbackAggregator.copyRef()](auto entries) mutable {
    1886             callbackAggregator->m_websiteData.entries.appendVector(entries);
    1887         });
     1890        for (auto& session : networkSessions().values()) {
     1891            fetchDiskCacheEntries(session->cache(), sessionID, fetchOptions, [callbackAggregator = callbackAggregator.copyRef()](auto entries) mutable {
     1892                callbackAggregator->m_websiteData.entries.appendVector(entries);
     1893            });
     1894        }
    18881895    }
    18891896}
     
    19771984        calculateURLCacheSizes(cacheModel, diskFreeSize, urlCacheMemoryCapacity, urlCacheDiskCapacity);
    19781985    }
    1979 
    1980     if (m_cache)
    1981         m_cache->setCapacity(urlCacheDiskCapacity);
     1986   
     1987    for (auto& session : networkSessions().values()) {
     1988        if (auto* cache = session->cache())
     1989            cache->setCapacity(urlCacheDiskCapacity);
     1990    }
    19821991}
    19831992
  • trunk/Source/WebKit/NetworkProcess/NetworkProcess.h

    r247270 r247567  
    112112#endif
    113113
     114namespace NetworkCache {
     115enum class CacheOption : uint8_t;
     116}
     117
    114118namespace CacheStorage {
    115119class Engine;
    116 }
    117 
    118 namespace NetworkCache {
    119 class Cache;
    120120}
    121121
     
    161161    AuthenticationManager& authenticationManager();
    162162    DownloadManager& downloadManager();
    163 
    164     NetworkCache::Cache* cache() { return m_cache.get(); }
    165163
    166164    void setSession(const PAL::SessionID&, Ref<NetworkSession>&&);
     
    344342    void removeKeptAliveLoad(NetworkResourceLoader&);
    345343
     344    const String& diskCacheDirectory() const { return m_diskCacheDirectory; }
     345    const OptionSet<NetworkCache::CacheOption>& cacheOptions() const { return m_cacheOptions; }
     346   
    346347private:
    347348    void platformInitializeNetworkProcess(const NetworkProcessCreationParameters&);
     
    490491    HashMap<PAL::SessionID, Ref<CacheStorage::Engine>> m_cacheEngines;
    491492
    492     RefPtr<NetworkCache::Cache> m_cache;
    493 
    494493    typedef HashMap<const char*, std::unique_ptr<NetworkProcessSupplement>, PtrHash<const char*>> NetworkProcessSupplementMap;
    495494    NetworkProcessSupplementMap m_supplements;
     
    567566
    568567    HashMap<IPC::Connection::UniqueID, PAL::SessionID> m_sessionByConnection;
     568
     569    OptionSet<NetworkCache::CacheOption> m_cacheOptions;
    569570};
    570571
  • trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp

    r247072 r247567  
    9999    , m_isAllowedToAskUserForCredentials { m_parameters.clientCredentialPolicy == ClientCredentialPolicy::MayAskClientForCredentials }
    100100    , m_bufferingTimer { *this, &NetworkResourceLoader::bufferingTimerFired }
    101     , m_cache { sessionID().isEphemeral() ? nullptr : connection.networkProcess().cache() }
    102101    , m_shouldCaptureExtraNetworkLoadMetrics(m_connection->captureExtraNetworkLoadMetricsEnabled())
    103102{
    104103    ASSERT(RunLoop::isMain());
     104
     105    if (auto* session = connection.networkProcess().networkSession(sessionID()))
     106        m_cache = session->cache();
     107
    105108    // FIXME: This is necessary because of the existence of EmptyFrameLoaderClient in WebCore.
    106109    //        Once bug 116233 is resolved, this ASSERT can just be "m_webPageID && m_webFrameID"
  • trunk/Source/WebKit/NetworkProcess/NetworkSession.cpp

    r247370 r247567  
    2828
    2929#include "AdClickAttributionManager.h"
     30#include "Logging.h"
    3031#include "NetworkProcess.h"
    3132#include "NetworkProcessProxyMessages.h"
     
    7879}
    7980
    80 NetworkSession::NetworkSession(NetworkProcess& networkProcess, PAL::SessionID sessionID, String&& localStorageDirectory, SandboxExtension::Handle& handle)
    81     : m_sessionID(sessionID)
     81NetworkSession::NetworkSession(NetworkProcess& networkProcess, const NetworkSessionCreationParameters& parameters)
     82    : m_sessionID(parameters.sessionID)
    8283    , m_networkProcess(networkProcess)
    83     , m_adClickAttribution(makeUniqueRef<AdClickAttributionManager>(sessionID))
    84     , m_storageManager(StorageManager::create(WTFMove(localStorageDirectory)))
    85 {
    86     SandboxExtension::consumePermanently(handle);
     84    , m_adClickAttribution(makeUniqueRef<AdClickAttributionManager>(parameters.sessionID))
     85    , m_storageManager(StorageManager::create(String(parameters.localStorageDirectory)))
     86{
     87    if (!m_sessionID.isEphemeral()) {
     88        String networkCacheDirectory = parameters.networkCacheDirectory;
     89        if (networkCacheDirectory.isNull())
     90            networkCacheDirectory = networkProcess.diskCacheDirectory();
     91        else
     92            SandboxExtension::consumePermanently(parameters.networkCacheDirectoryExtensionHandle);
     93
     94        m_cache = NetworkCache::Cache::open(networkProcess, networkCacheDirectory, networkProcess.cacheOptions());
     95        if (!m_cache)
     96            RELEASE_LOG_ERROR(NetworkCache, "Failed to initialize the WebKit network disk cache");
     97    }
     98
     99    SandboxExtension::consumePermanently(parameters.localStorageDirectoryExtensionHandle);
    87100    m_adClickAttribution->setPingLoadFunction([this, weakThis = makeWeakPtr(this)](NetworkResourceLoadParameters&& loadParameters, CompletionHandler<void(const WebCore::ResourceError&, const WebCore::ResourceResponse&)>&& completionHandler) {
    88101        if (!weakThis)
  • trunk/Source/WebKit/NetworkProcess/NetworkSession.h

    r247250 r247567  
    6060
    6161enum class WebsiteDataType;
    62    
     62
     63namespace NetworkCache {
     64class Cache;
     65}
     66
    6367class NetworkSession : public RefCounted<NetworkSession>, public CanMakeWeakPtr<NetworkSession> {
    6468public:
     
    101105    void removeKeptAliveLoad(NetworkResourceLoader&);
    102106
     107    NetworkCache::Cache* cache() { return m_cache.get(); }
     108
    103109    PrefetchCache& prefetchCache() { return m_prefetchCache; }
    104110    void clearPrefetchCache() { m_prefetchCache.clear(); }
     
    109115
    110116protected:
    111     NetworkSession(NetworkProcess&, PAL::SessionID, String&& localStorageDirectory, SandboxExtension::Handle&);
     117    NetworkSession(NetworkProcess&, const NetworkSessionCreationParameters&);
    112118
    113119    PAL::SessionID m_sessionID;
     
    131137    bool m_isInvalidated { false };
    132138#endif
     139    RefPtr<NetworkCache::Cache> m_cache;
    133140};
    134141
  • trunk/Source/WebKit/NetworkProcess/NetworkSessionCreationParameters.cpp

    r245979 r247567  
    5151        , { }, { }
    5252#endif
    53         , { }, { }, false, { }, { }, { }, { }, { }, { }, { }
     53        , { }, { }, false, { }, { }, { }, { }, { }, { }, { }, { }, { }
    5454    };
    5555}
     
    8686
    8787    encoder << localStorageDirectory << localStorageDirectoryExtensionHandle;
     88    encoder << networkCacheDirectory << networkCacheDirectoryExtensionHandle;
    8889
    8990    encoder << deviceManagementRestrictionsEnabled;
     
    210211    decoder >> localStorageDirectoryExtensionHandle;
    211212    if (!localStorageDirectoryExtensionHandle)
     213        return WTF::nullopt;
     214
     215    Optional<String> networkCacheDirectory;
     216    decoder >> networkCacheDirectory;
     217    if (!networkCacheDirectory)
     218        return WTF::nullopt;
     219   
     220    Optional<SandboxExtension::Handle> networkCacheDirectoryExtensionHandle;
     221    decoder >> networkCacheDirectoryExtensionHandle;
     222    if (!networkCacheDirectoryExtensionHandle)
    212223        return WTF::nullopt;
    213224
     
    254265        , WTFMove(*localStorageDirectory)
    255266        , WTFMove(*localStorageDirectoryExtensionHandle)
     267        , WTFMove(*networkCacheDirectory)
     268        , WTFMove(*networkCacheDirectoryExtensionHandle)
    256269    }};
    257270}
  • trunk/Source/WebKit/NetworkProcess/NetworkSessionCreationParameters.h

    r245979 r247567  
    9393    String localStorageDirectory;
    9494    SandboxExtension::Handle localStorageDirectoryExtensionHandle;
     95    String networkCacheDirectory;
     96    SandboxExtension::Handle networkCacheDirectoryExtensionHandle;
    9597};
    9698
  • trunk/Source/WebKit/NetworkProcess/cache/NetworkCache.cpp

    r247362 r247567  
    6060}
    6161
    62 RefPtr<Cache> Cache::open(NetworkProcess& networkProcess, const String& cachePath, OptionSet<Option> options)
    63 {
    64     auto storage = Storage::open(cachePath, options.contains(Option::TestingMode) ? Storage::Mode::AvoidRandomness : Storage::Mode::Normal);
     62RefPtr<Cache> Cache::open(NetworkProcess& networkProcess, const String& cachePath, OptionSet<CacheOption> options)
     63{
     64    auto storage = Storage::open(cachePath, options.contains(CacheOption::TestingMode) ? Storage::Mode::AvoidRandomness : Storage::Mode::Normal);
    6565
    6666    LOG(NetworkCache, "(NetworkProcess) opened cache storage, success %d", !!storage);
     
    7979#endif
    8080
    81 Cache::Cache(NetworkProcess& networkProcess, Ref<Storage>&& storage, OptionSet<Option> options)
     81Cache::Cache(NetworkProcess& networkProcess, Ref<Storage>&& storage, OptionSet<CacheOption> options)
    8282    : m_storage(WTFMove(storage))
    8383    , m_networkProcess(networkProcess)
    8484{
    8585#if ENABLE(NETWORK_CACHE_SPECULATIVE_REVALIDATION)
    86     if (options.contains(Option::SpeculativeRevalidation)) {
     86    if (options.contains(CacheOption::SpeculativeRevalidation)) {
    8787        m_lowPowerModeNotifier = std::make_unique<WebCore::LowPowerModeNotifier>([this](bool isLowPowerModeEnabled) {
    8888            ASSERT(WTF::RunLoop::isMain());
     
    9999#endif
    100100
    101     if (options.contains(Option::RegisterNotify)) {
     101    if (options.contains(CacheOption::RegisterNotify)) {
    102102#if PLATFORM(COCOA)
    103103        // Triggers with "notifyutil -p com.apple.WebKit.Cache.dump".
  • trunk/Source/WebKit/NetworkProcess/cache/NetworkCache.h

    r245796 r247567  
    8888using GlobalFrameID = std::pair<WebCore::PageIdentifier, uint64_t /*webFrameID*/>;
    8989
     90enum class CacheOption : uint8_t {
     91    // In testing mode we try to eliminate sources of randomness. Cache does not shrink and there are no read timeouts.
     92    TestingMode = 1 << 0,
     93    RegisterNotify = 1 << 1,
     94#if ENABLE(NETWORK_CACHE_SPECULATIVE_REVALIDATION)
     95    SpeculativeRevalidation = 1 << 2,
     96#endif
     97};
     98
    9099class Cache : public RefCounted<Cache> {
    91100public:
    92     enum class Option {
    93         // In testing mode we try to eliminate sources of randomness. Cache does not shrink and there are no read timeouts.
    94         TestingMode = 1 << 0,
    95         RegisterNotify = 1 << 1,
    96 #if ENABLE(NETWORK_CACHE_SPECULATIVE_REVALIDATION)
    97         SpeculativeRevalidation = 1 << 2,
    98 #endif
    99     };
    100     static RefPtr<Cache> open(NetworkProcess&, const String& cachePath, OptionSet<Option>);
     101    static RefPtr<Cache> open(NetworkProcess&, const String& cachePath, OptionSet<CacheOption>);
    101102
    102103    void setCapacity(size_t);
     
    149150
    150151private:
    151     Cache(NetworkProcess&, Ref<Storage>&&, OptionSet<Option> options);
     152    Cache(NetworkProcess&, Ref<Storage>&&, OptionSet<CacheOption>);
    152153
    153154    Key makeCacheKey(const WebCore::ResourceRequest&);
  • trunk/Source/WebKit/NetworkProcess/cocoa/NetworkProcessCocoa.mm

    r247270 r247567  
    118118
    119119    SandboxExtension::consumePermanently(parameters.diskCacheDirectoryExtensionHandle);
    120     OptionSet<NetworkCache::Cache::Option> cacheOptions { NetworkCache::Cache::Option::RegisterNotify };
     120    m_cacheOptions = { NetworkCache::CacheOption::RegisterNotify };
    121121    if (parameters.shouldUseTestingNetworkSession)
    122         cacheOptions.add(NetworkCache::Cache::Option::TestingMode);
     122        m_cacheOptions.add(NetworkCache::CacheOption::TestingMode);
    123123#if ENABLE(NETWORK_CACHE_SPECULATIVE_REVALIDATION)
    124124    if (parameters.shouldEnableNetworkCacheSpeculativeRevalidation)
    125         cacheOptions.add(NetworkCache::Cache::Option::SpeculativeRevalidation);
    126 #endif
    127 
    128     m_cache = NetworkCache::Cache::open(*this, m_diskCacheDirectory, cacheOptions);
    129     if (!m_cache)
    130         RELEASE_LOG_ERROR(NetworkCache, "Failed to initialize the WebKit network disk cache");
     125        m_cacheOptions.add(NetworkCache::CacheOption::SpeculativeRevalidation);
     126#endif
    131127
    132128    // Disable NSURLCache.
     
    201197        m_clearCacheDispatchGroup = dispatch_group_create();
    202198
    203     auto* cache = this->cache();
    204     if (!cache) {
    205         completionHandler();
    206         return;
    207     }
    208 
    209199    auto group = m_clearCacheDispatchGroup;
    210     dispatch_group_async(group, dispatch_get_main_queue(), makeBlockPtr([cache, modifiedSince, completionHandler = WTFMove(completionHandler)] () mutable {
    211         cache->clear(modifiedSince, WTFMove(completionHandler));
     200    dispatch_group_async(group, dispatch_get_main_queue(), makeBlockPtr([this, protectedThis = makeRef(*this), modifiedSince, completionHandler = WTFMove(completionHandler)] () mutable {
     201        auto aggregator = CallbackAggregator::create(WTFMove(completionHandler));
     202        for (auto& session : networkSessions().values()) {
     203            if (auto* cache = session->cache())
     204                cache->clear(modifiedSince, [aggregator = aggregator.copyRef()] () { });
     205        }
    212206    }).get());
    213207}
  • trunk/Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.mm

    r247250 r247567  
    925925
    926926NetworkSessionCocoa::NetworkSessionCocoa(NetworkProcess& networkProcess, NetworkSessionCreationParameters&& parameters)
    927     : NetworkSession(networkProcess, parameters.sessionID, WTFMove(parameters.localStorageDirectory), parameters.localStorageDirectoryExtensionHandle)
     927    : NetworkSession(networkProcess, parameters)
    928928    , m_boundInterfaceIdentifier(parameters.boundInterfaceIdentifier)
    929929    , m_sourceApplicationBundleIdentifier(parameters.sourceApplicationBundleIdentifier)
  • trunk/Source/WebKit/NetworkProcess/curl/NetworkSessionCurl.cpp

    r247250 r247567  
    3939
    4040NetworkSessionCurl::NetworkSessionCurl(NetworkProcess& networkProcess, NetworkSessionCreationParameters&& parameters)
    41     : NetworkSession(networkProcess, parameters.sessionID, WTFMove(parameters.localStorageDirectory), parameters.localStorageDirectoryExtensionHandle)
     41    : NetworkSession(networkProcess, parameters)
    4242{
    4343    if (!parameters.cookiePersistentStorageFile.isEmpty())
  • trunk/Source/WebKit/NetworkProcess/ios/NetworkProcessIOS.mm

    r246892 r247567  
    7979    if (resourceCachesToClear == InMemoryResourceCachesOnly)
    8080        return;
    81     if (m_cache)
    82         m_cache->clear();
     81    for (auto& session : networkSessions().values()) {
     82        if (auto* cache = session->cache())
     83            cache->clear();
     84    }
    8385}
    8486
  • trunk/Source/WebKit/NetworkProcess/soup/NetworkProcessSoup.cpp

    r246671 r247567  
    3030#include "NetworkCache.h"
    3131#include "NetworkProcessCreationParameters.h"
     32#include "NetworkSession.h"
    3233#include "ResourceCachesToClear.h"
    3334#include "WebCookieManager.h"
     
    3940#include <WebCore/SoupNetworkSession.h>
    4041#include <libsoup/soup.h>
     42#include <wtf/CallbackAggregator.h>
    4143#include <wtf/FileSystem.h>
    4244#include <wtf/RAMSize.h>
     
    116118    SoupNetworkSession::clearOldSoupCache(FileSystem::directoryName(m_diskCacheDirectory));
    117119
    118     OptionSet<NetworkCache::Cache::Option> cacheOptions { NetworkCache::Cache::Option::RegisterNotify };
     120    OptionSet<NetworkCache::CacheOption> cacheOptions { NetworkCache::CacheOption::RegisterNotify };
    119121#if ENABLE(NETWORK_CACHE_SPECULATIVE_REVALIDATION)
    120122    if (parameters.shouldEnableNetworkCacheSpeculativeRevalidation)
    121         cacheOptions.add(NetworkCache::Cache::Option::SpeculativeRevalidation);
     123        cacheOptions.add(NetworkCache::CacheOption::SpeculativeRevalidation);
    122124#endif
    123 
    124     m_cache = NetworkCache::Cache::open(*this, m_diskCacheDirectory, cacheOptions);
    125125
    126126    supplement<WebCookieManager>()->setHTTPCookieAcceptPolicy(parameters.cookieAcceptPolicy, OptionalCallbackID());
     
    157157void NetworkProcess::clearDiskCache(WallTime modifiedSince, CompletionHandler<void()>&& completionHandler)
    158158{
    159     if (!m_cache) {
    160         completionHandler();
    161         return;
     159    auto aggregator = CallbackAggregator::create(WTFMove(completionHandler));
     160    for (auto& session : networkSessions().values()) {
     161        if (auto* cache = session->cache())
     162            cache->clear(modifiedSince, [aggregator = aggregator.copyRef()] () { });
    162163    }
    163     m_cache->clear(modifiedSince, WTFMove(completionHandler));
    164164}
    165165
  • trunk/Source/WebKit/NetworkProcess/soup/NetworkSessionSoup.cpp

    r247250 r247567  
    4141
    4242NetworkSessionSoup::NetworkSessionSoup(NetworkProcess& networkProcess, NetworkSessionCreationParameters&& parameters)
    43     : NetworkSession(networkProcess, parameters.sessionID, WTFMove(parameters.localStorageDirectory), parameters.localStorageDirectoryExtensionHandle)
     43    : NetworkSession(networkProcess, parameters)
    4444{
    4545    networkStorageSession()->setCookieObserverHandler([this] {
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm

    r246500 r247567  
    249249        if (configuration._serviceWorkerRegistrationDirectory)
    250250            config->setServiceWorkerRegistrationDirectory(configuration._serviceWorkerRegistrationDirectory.path);
     251        if (configuration.networkCacheDirectory)
     252            config->setNetworkCacheDirectory(configuration.networkCacheDirectory.path);
    251253    } else {
    252254        RELEASE_ASSERT(!configuration._webStorageDirectory);
     
    257259        RELEASE_ASSERT(!configuration._cacheStorageDirectory);
    258260        RELEASE_ASSERT(!configuration._serviceWorkerRegistrationDirectory);
     261        RELEASE_ASSERT(!configuration.networkCacheDirectory);
    259262    }
    260263
  • trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.h

    r245979 r247567  
    5454@property (nonatomic, copy, setter=_setCacheStorageDirectory:) NSURL *_cacheStorageDirectory WK_API_AVAILABLE(macos(10.13.4), ios(11.3));
    5555@property (nonatomic, copy, setter=_setServiceWorkerRegistrationDirectory:) NSURL *_serviceWorkerRegistrationDirectory WK_API_AVAILABLE(macos(10.13.4), ios(11.3));
     56@property (nonatomic, nullable, copy) NSURL *networkCacheDirectory WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
    5657
    5758// Testing only.
  • trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsiteDataStoreConfiguration.mm

    r247476 r247567  
    9090}
    9191
     92- (NSURL *)networkCacheDirectory
     93{
     94    return [NSURL fileURLWithPath:_configuration->networkCacheDirectory() isDirectory:YES];
     95}
     96
     97- (void)setNetworkCacheDirectory:(NSURL *)url
     98{
     99    if (!_configuration->isPersistent())
     100        [NSException raise:NSInvalidArgumentException format:@"Cannot set networkCacheDirectory on a non-persistent _WKWebsiteDataStoreConfiguration."];
     101    checkURLArgument(url);
     102    _configuration->setNetworkCacheDirectory(url.path);
     103}
     104
    92105- (NSURL *)_webSQLDatabaseDirectory
    93106{
  • trunk/Source/WebKit/UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm

    r245979 r247567  
    113113        SandboxExtension::createHandleForReadWriteDirectory(localStorageDirectory, localStorageDirectoryExtensionHandle);
    114114
     115    auto networkCacheDirectory = resolvedNetworkCacheDirectory();
     116    SandboxExtension::Handle networkCacheDirectoryExtensionHandle;
     117    if (!networkCacheDirectory.isEmpty())
     118        SandboxExtension::createHandleForReadWriteDirectory(networkCacheDirectory, networkCacheDirectoryExtensionHandle);
     119
    115120    bool shouldIncludeLocalhostInResourceLoadStatistics = isSafari;
    116121    WebsiteDataStoreParameters parameters;
     
    136141        WTFMove(resourceLoadStatisticsManualPrevalentResource),
    137142        WTFMove(localStorageDirectory),
    138         WTFMove(localStorageDirectoryExtensionHandle)
     143        WTFMove(localStorageDirectoryExtensionHandle),
     144        WTFMove(networkCacheDirectory),
     145        WTFMove(networkCacheDirectoryExtensionHandle),
    139146    };
    140147    networkingHasBegun();
  • trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp

    r247270 r247567  
    207207    if (!m_configuration->deviceIdHashSaltsStorageDirectory().isEmpty())
    208208        m_resolvedConfiguration->setDeviceIdHashSaltsStorageDirectory(resolveAndCreateReadWriteDirectoryForSandboxExtension(m_configuration->deviceIdHashSaltsStorageDirectory()));
     209    if (!m_configuration->networkCacheDirectory().isEmpty())
     210        m_resolvedConfiguration->setNetworkCacheDirectory(resolveAndCreateReadWriteDirectoryForSandboxExtension(m_configuration->networkCacheDirectory()));
    209211    if (!m_configuration->resourceLoadStatisticsDirectory().isEmpty())
    210212        m_resolvedConfiguration->setResourceLoadStatisticsDirectory(resolveAndCreateReadWriteDirectoryForSandboxExtension(m_configuration->resourceLoadStatisticsDirectory()));
  • trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h

    r247146 r247567  
    185185    const String& resolvedApplicationCacheDirectory() const { return m_resolvedConfiguration->applicationCacheDirectory(); }
    186186    const String& resolvedLocalStorageDirectory() const { return m_resolvedConfiguration->localStorageDirectory(); }
     187    const String& resolvedNetworkCacheDirectory() const { return m_resolvedConfiguration->networkCacheDirectory(); }
    187188    const String& resolvedMediaCacheDirectory() const { return m_resolvedConfiguration->mediaCacheDirectory(); }
    188189    const String& resolvedMediaKeysDirectory() const { return m_resolvedConfiguration->mediaKeysStorageDirectory(); }
  • trunk/Tools/ChangeLog

    r247566 r247567  
     12019-07-18  Alex Christensen  <achristensen@webkit.org>
     2
     3        Move NetworkCache ownership from NetworkProcess to NetworkSession
     4        https://bugs.webkit.org/show_bug.cgi?id=199817
     5
     6        Reviewed by Geoff Garen.
     7
     8        * TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm:
     9        (TEST):
     10        * TestWebKitAPI/cocoa/TestWKWebView.h:
     11        * TestWebKitAPI/cocoa/TestWKWebView.mm:
     12        (-[WKWebView synchronouslyLoadRequest:]):
     13
    1142019-07-18  Youenn Fablet  <youenn@apple.com>
    215
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm

    r245979 r247567  
    2727
    2828#import "PlatformUtilities.h"
     29#import "TCPServer.h"
    2930#import "Test.h"
    3031#import "TestNavigationDelegate.h"
     
    522523    EXPECT_TRUE([[websiteDataStoreConfiguration sourceApplicationBundleIdentifier] isEqualToString:@"testidentifier"]);
    523524}
     525
     526TEST(WebKit, NetworkCacheDirectory)
     527{
     528    using namespace TestWebKitAPI;
     529    TCPServer server([] (int socket) {
     530        TCPServer::read(socket);
     531        const char* response =
     532        "HTTP/1.1 200 OK\r\n"
     533        "Cache-Control: max-age=1000000\r\n"
     534        "Content-Length: 6\r\n\r\n"
     535        "Hello!";
     536        TCPServer::write(socket, response, strlen(response));
     537    });
     538   
     539    NSURL *tempDir = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"CustomPathsTest"] isDirectory:YES];
     540   
     541    auto websiteDataStoreConfiguration = adoptNS([[_WKWebsiteDataStoreConfiguration alloc] init]);
     542    [websiteDataStoreConfiguration setNetworkCacheDirectory:tempDir];
     543
     544    auto webViewConfiguration = adoptNS([[WKWebViewConfiguration alloc] init]);
     545    [webViewConfiguration setWebsiteDataStore:[[[WKWebsiteDataStore alloc] _initWithConfiguration:websiteDataStoreConfiguration.get()] autorelease]];
     546
     547    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:webViewConfiguration.get()]);
     548    [webView synchronouslyLoadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://127.0.0.1:%d/", server.port()]]]];
     549    NSString *path = tempDir.path;
     550    NSFileManager *fileManager = [NSFileManager defaultManager];
     551    while (![fileManager fileExistsAtPath:path])
     552        Util::spinRunLoop();
     553    NSError *error = nil;
     554    [fileManager removeItemAtPath:path error:&error];
     555    EXPECT_FALSE(error);
     556}
  • trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.h

    r246924 r247567  
    5353- (void)synchronouslyLoadHTMLString:(NSString *)html;
    5454- (void)synchronouslyLoadHTMLString:(NSString *)html baseURL:(NSURL *)url;
     55- (void)synchronouslyLoadRequest:(NSURLRequest *)request;
    5556- (void)synchronouslyLoadTestPageNamed:(NSString *)pageName;
    5657- (BOOL)_synchronouslyExecuteEditCommand:(NSString *)command argument:(NSString *)argument;
  • trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.mm

    r246198 r247567  
    7272}
    7373
     74- (void)synchronouslyLoadRequest:(NSURLRequest *)request
     75{
     76    [self loadRequest:request];
     77    [self _test_waitForDidFinishNavigation];
     78}
     79
    7480- (void)synchronouslyLoadHTMLString:(NSString *)html baseURL:(NSURL *)url
    7581{
Note: See TracChangeset for help on using the changeset viewer.