Make NetworkProcess get cache storage parameters at creation of the CacheStorage...
authoryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 15 Jun 2018 01:05:49 +0000 (01:05 +0000)
committeryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 15 Jun 2018 01:05:49 +0000 (01:05 +0000)
https://bugs.webkit.org/show_bug.cgi?id=186166

Reviewed by Alex Christensen.

Source/WebCore:

Covered by existing tests.

* platform/network/NetworkStorageSession.h:
(WebCore::NetworkStorageSession::cacheStorageDirectory const): Deleted.
(WebCore::NetworkStorageSession::setCacheStorageDirectory): Deleted.
(WebCore::NetworkStorageSession::cacheStoragePerOriginQuota const): Deleted.
(WebCore::NetworkStorageSession::setCacheStoragePerOriginQuota): Deleted.

Source/WebKit:

Make CacheStorage::Engine creation asynchronous.
Update Engine public methods be static methods taking a SessionID, which will be used to create the engine.

Add IPC methods to retrieve cache storage parameters from NetworkProcess to UIProcess.

Add NetworkProcessProxy ability to compute the cache storage parameters based on the SessionID.
For that purpose, make NetworkProcessProxy store a map of SessionID-to-WebsiteDataStore.

* NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::deleteWebsiteData):
(WebKit::NetworkProcess::deleteWebsiteDataForOrigins):
(WebKit::NetworkProcess::cacheStorageParameters):
(WebKit::NetworkProcess::setCacheStorageParameters):
(WebKit::NetworkProcess::cacheStorageDirectory const): Deleted.
(WebKit::NetworkProcess::cacheStoragePerOriginQuota const): Deleted.
* NetworkProcess/NetworkProcess.h:
* NetworkProcess/NetworkProcess.messages.in:
* NetworkProcess/NetworkProcessCreationParameters.cpp:
(WebKit::NetworkProcessCreationParameters::encode const):
(WebKit::NetworkProcessCreationParameters::decode):
* NetworkProcess/NetworkProcessCreationParameters.h:
* NetworkProcess/cache/CacheStorageEngine.cpp:
(WebKit::CacheStorage::Engine::from):
(WebKit::CacheStorage::Engine::fetchEntries):
(WebKit::CacheStorage::Engine::open):
(WebKit::CacheStorage::Engine::remove):
(WebKit::CacheStorage::Engine::retrieveCaches):
(WebKit::CacheStorage::Engine::retrieveRecords):
(WebKit::CacheStorage::Engine::putRecords):
(WebKit::CacheStorage::Engine::deleteMatchingRecords):
(WebKit::CacheStorage::Engine::lock):
(WebKit::CacheStorage::Engine::unlock):
(WebKit::CacheStorage::Engine::clearMemoryRepresentation):
(WebKit::CacheStorage::Engine::representation):
(WebKit::CacheStorage::Engine::clearAllCaches):
(WebKit::CacheStorage::Engine::clearCachesForOrigin):
(WebKit::CacheStorage::Engine::Engine):
(WebKit::CacheStorage::Engine::readCachesFromDisk):
(WebKit::CacheStorage::Engine::defaultEngine): Deleted.
* NetworkProcess/cache/CacheStorageEngine.h:
(WebKit::CacheStorage::Engine::shouldPersist const):
(WebKit::CacheStorage::Engine::weakPtrFactory):
(WebKit::CacheStorage::Engine::create): Deleted.
* NetworkProcess/cache/CacheStorageEngineConnection.cpp:
(WebKit::CacheStorageEngineConnection::~CacheStorageEngineConnection):
(WebKit::CacheStorageEngineConnection::open):
(WebKit::CacheStorageEngineConnection::remove):
(WebKit::CacheStorageEngineConnection::caches):
(WebKit::CacheStorageEngineConnection::retrieveRecords):
(WebKit::CacheStorageEngineConnection::deleteMatchingRecords):
(WebKit::CacheStorageEngineConnection::putRecords):
(WebKit::CacheStorageEngineConnection::reference):
(WebKit::CacheStorageEngineConnection::dereference):
(WebKit::CacheStorageEngineConnection::clearMemoryRepresentation):
(WebKit::CacheStorageEngineConnection::engineRepresentation):
* NetworkProcess/cache/CacheStorageEngineConnection.h:
* NetworkProcess/cocoa/NetworkProcessCocoa.mm:
(WebKit::NetworkProcess::platformInitializeNetworkProcessCocoa):
* NetworkProcess/mac/RemoteNetworkingContext.mm:
(WebKit::RemoteNetworkingContext::ensureWebsiteDataStoreSession):
* Shared/WebsiteDataStoreParameters.cpp:
(WebKit::WebsiteDataStoreParameters::encode const):
(WebKit::WebsiteDataStoreParameters::decode):
(WebKit::WebsiteDataStoreParameters::privateSessionParameters):
* Shared/WebsiteDataStoreParameters.h:
(): Deleted.
* UIProcess/Network/NetworkProcessProxy.cpp:
(WebKit::NetworkProcessProxy::addSession):
(WebKit::NetworkProcessProxy::removeSession):
(WebKit::NetworkProcessProxy::retrieveCacheStorageParameters):
* UIProcess/Network/NetworkProcessProxy.h:
* UIProcess/Network/NetworkProcessProxy.messages.in:
* UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::ensureNetworkProcess):
(WebKit::WebProcessPool::setAnyPageGroupMightHavePrivateBrowsingEnabled):
(WebKit::WebProcessPool::pageBeginUsingWebsiteDataStore):
(WebKit::WebProcessPool::pageEndUsingWebsiteDataStore):
* UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm:
(WebKit::WebsiteDataStore::parameters):
* UIProcess/WebsiteData/WebsiteDataStore.cpp:
(WebKit::WebsiteDataStore::~WebsiteDataStore):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@232863 268f45cc-cd09-0410-ab3c-d52691b4dbfc

22 files changed:
Source/WebCore/ChangeLog
Source/WebCore/platform/network/NetworkStorageSession.h
Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/NetworkProcess.cpp
Source/WebKit/NetworkProcess/NetworkProcess.h
Source/WebKit/NetworkProcess/NetworkProcess.messages.in
Source/WebKit/NetworkProcess/NetworkProcessCreationParameters.cpp
Source/WebKit/NetworkProcess/NetworkProcessCreationParameters.h
Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp
Source/WebKit/NetworkProcess/cache/CacheStorageEngine.h
Source/WebKit/NetworkProcess/cache/CacheStorageEngineConnection.cpp
Source/WebKit/NetworkProcess/cache/CacheStorageEngineConnection.h
Source/WebKit/NetworkProcess/cocoa/NetworkProcessCocoa.mm
Source/WebKit/NetworkProcess/mac/RemoteNetworkingContext.mm
Source/WebKit/Shared/WebsiteDataStoreParameters.cpp
Source/WebKit/Shared/WebsiteDataStoreParameters.h
Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp
Source/WebKit/UIProcess/Network/NetworkProcessProxy.h
Source/WebKit/UIProcess/Network/NetworkProcessProxy.messages.in
Source/WebKit/UIProcess/WebProcessPool.cpp
Source/WebKit/UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm
Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp

index 6b9657c..ab0a735 100644 (file)
@@ -1,3 +1,18 @@
+2018-06-14  Youenn Fablet  <youenn@apple.com>
+
+        Make NetworkProcess get cache storage parameters at creation of the CacheStorage engine
+        https://bugs.webkit.org/show_bug.cgi?id=186166
+
+        Reviewed by Alex Christensen.
+
+        Covered by existing tests.
+
+        * platform/network/NetworkStorageSession.h:
+        (WebCore::NetworkStorageSession::cacheStorageDirectory const): Deleted.
+        (WebCore::NetworkStorageSession::setCacheStorageDirectory): Deleted.
+        (WebCore::NetworkStorageSession::cacheStoragePerOriginQuota const): Deleted.
+        (WebCore::NetworkStorageSession::setCacheStoragePerOriginQuota): Deleted.
+
 2018-06-14  Matt Lewis  <jlewis3@apple.com>
 
         Unreviewed, rolling out r232823.
index 2a78644..6e99393 100644 (file)
@@ -85,11 +85,6 @@ public:
     WEBCORE_EXPORT NSHTTPCookieStorage *nsCookieStorage() const;
 #endif
 
-    const String& cacheStorageDirectory() const { return m_cacheStorageDirectory; }
-    void setCacheStorageDirectory(String&& path) { m_cacheStorageDirectory = WTFMove(path); }
-    uint64_t cacheStoragePerOriginQuota() const { return m_cacheStoragePerOriginQuota; }
-    void setCacheStoragePerOriginQuota(uint64_t quota) { m_cacheStoragePerOriginQuota = quota; }
-
 #if PLATFORM(COCOA) || USE(CFURLCONNECTION)
     WEBCORE_EXPORT static void ensureSession(PAL::SessionID, const String& identifierBase, RetainPtr<CFHTTPCookieStorageRef>&&);
     NetworkStorageSession(PAL::SessionID, RetainPtr<CFURLStorageSessionRef>&&, RetainPtr<CFHTTPCookieStorageRef>&&);
@@ -173,9 +168,6 @@ private:
 
     CredentialStorage m_credentialStorage;
 
-    String m_cacheStorageDirectory;
-    uint64_t m_cacheStoragePerOriginQuota { 0 };
-
 #if HAVE(CFNETWORK_STORAGE_PARTITIONING)
     bool shouldPartitionCookies(const String& topPrivatelyControlledDomain) const;
     bool shouldBlockThirdPartyCookies(const String& topPrivatelyControlledDomain) const;
index d79098a..a887768 100644 (file)
@@ -1,3 +1,92 @@
+2018-06-14  Youenn Fablet  <youenn@apple.com>
+
+        Make NetworkProcess get cache storage parameters at creation of the CacheStorage engine
+        https://bugs.webkit.org/show_bug.cgi?id=186166
+
+        Reviewed by Alex Christensen.
+
+        Make CacheStorage::Engine creation asynchronous.
+        Update Engine public methods be static methods taking a SessionID, which will be used to create the engine.
+
+        Add IPC methods to retrieve cache storage parameters from NetworkProcess to UIProcess.
+
+        Add NetworkProcessProxy ability to compute the cache storage parameters based on the SessionID.
+        For that purpose, make NetworkProcessProxy store a map of SessionID-to-WebsiteDataStore.
+
+        * NetworkProcess/NetworkProcess.cpp:
+        (WebKit::NetworkProcess::deleteWebsiteData):
+        (WebKit::NetworkProcess::deleteWebsiteDataForOrigins):
+        (WebKit::NetworkProcess::cacheStorageParameters):
+        (WebKit::NetworkProcess::setCacheStorageParameters):
+        (WebKit::NetworkProcess::cacheStorageDirectory const): Deleted.
+        (WebKit::NetworkProcess::cacheStoragePerOriginQuota const): Deleted.
+        * NetworkProcess/NetworkProcess.h:
+        * NetworkProcess/NetworkProcess.messages.in:
+        * NetworkProcess/NetworkProcessCreationParameters.cpp:
+        (WebKit::NetworkProcessCreationParameters::encode const):
+        (WebKit::NetworkProcessCreationParameters::decode):
+        * NetworkProcess/NetworkProcessCreationParameters.h:
+        * NetworkProcess/cache/CacheStorageEngine.cpp:
+        (WebKit::CacheStorage::Engine::from):
+        (WebKit::CacheStorage::Engine::fetchEntries):
+        (WebKit::CacheStorage::Engine::open):
+        (WebKit::CacheStorage::Engine::remove):
+        (WebKit::CacheStorage::Engine::retrieveCaches):
+        (WebKit::CacheStorage::Engine::retrieveRecords):
+        (WebKit::CacheStorage::Engine::putRecords):
+        (WebKit::CacheStorage::Engine::deleteMatchingRecords):
+        (WebKit::CacheStorage::Engine::lock):
+        (WebKit::CacheStorage::Engine::unlock):
+        (WebKit::CacheStorage::Engine::clearMemoryRepresentation):
+        (WebKit::CacheStorage::Engine::representation):
+        (WebKit::CacheStorage::Engine::clearAllCaches):
+        (WebKit::CacheStorage::Engine::clearCachesForOrigin):
+        (WebKit::CacheStorage::Engine::Engine):
+        (WebKit::CacheStorage::Engine::readCachesFromDisk):
+        (WebKit::CacheStorage::Engine::defaultEngine): Deleted.
+        * NetworkProcess/cache/CacheStorageEngine.h:
+        (WebKit::CacheStorage::Engine::shouldPersist const):
+        (WebKit::CacheStorage::Engine::weakPtrFactory):
+        (WebKit::CacheStorage::Engine::create): Deleted.
+        * NetworkProcess/cache/CacheStorageEngineConnection.cpp:
+        (WebKit::CacheStorageEngineConnection::~CacheStorageEngineConnection):
+        (WebKit::CacheStorageEngineConnection::open):
+        (WebKit::CacheStorageEngineConnection::remove):
+        (WebKit::CacheStorageEngineConnection::caches):
+        (WebKit::CacheStorageEngineConnection::retrieveRecords):
+        (WebKit::CacheStorageEngineConnection::deleteMatchingRecords):
+        (WebKit::CacheStorageEngineConnection::putRecords):
+        (WebKit::CacheStorageEngineConnection::reference):
+        (WebKit::CacheStorageEngineConnection::dereference):
+        (WebKit::CacheStorageEngineConnection::clearMemoryRepresentation):
+        (WebKit::CacheStorageEngineConnection::engineRepresentation):
+        * NetworkProcess/cache/CacheStorageEngineConnection.h:
+        * NetworkProcess/cocoa/NetworkProcessCocoa.mm:
+        (WebKit::NetworkProcess::platformInitializeNetworkProcessCocoa):
+        * NetworkProcess/mac/RemoteNetworkingContext.mm:
+        (WebKit::RemoteNetworkingContext::ensureWebsiteDataStoreSession):
+        * Shared/WebsiteDataStoreParameters.cpp:
+        (WebKit::WebsiteDataStoreParameters::encode const):
+        (WebKit::WebsiteDataStoreParameters::decode):
+        (WebKit::WebsiteDataStoreParameters::privateSessionParameters):
+        * Shared/WebsiteDataStoreParameters.h:
+        (): Deleted.
+        * UIProcess/Network/NetworkProcessProxy.cpp:
+        (WebKit::NetworkProcessProxy::addSession):
+        (WebKit::NetworkProcessProxy::removeSession):
+        (WebKit::NetworkProcessProxy::retrieveCacheStorageParameters):
+        * UIProcess/Network/NetworkProcessProxy.h:
+        * UIProcess/Network/NetworkProcessProxy.messages.in:
+        * UIProcess/WebProcessPool.cpp:
+        (WebKit::WebProcessPool::ensureNetworkProcess):
+        (WebKit::WebProcessPool::setAnyPageGroupMightHavePrivateBrowsingEnabled):
+        (WebKit::WebProcessPool::pageBeginUsingWebsiteDataStore):
+        (WebKit::WebProcessPool::pageEndUsingWebsiteDataStore):
+        * UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm:
+        (WebKit::WebsiteDataStore::parameters):
+        * UIProcess/WebsiteData/WebsiteDataStore.cpp:
+        (WebKit::WebsiteDataStore::~WebsiteDataStore):
+
 2018-06-14  Basuke Suzuki  <Basuke.Suzuki@sony.com>
 
         [Win] Add IPC error case for broken pipe
index 3fb8164..722a752 100644 (file)
@@ -132,6 +132,10 @@ NetworkProcess::NetworkProcess()
 
 NetworkProcess::~NetworkProcess()
 {
+    for (auto& callbacks : m_cacheStorageParametersCallbacks.values()) {
+        for (auto& callback : callbacks)
+            callback(String { }, 0);
+    }
 }
 
 AuthenticationManager& NetworkProcess::authenticationManager()
@@ -563,7 +567,7 @@ void NetworkProcess::deleteWebsiteData(PAL::SessionID sessionID, OptionSet<Websi
     });
 
     if (websiteDataTypes.contains(WebsiteDataType::DOMCache))
-        CacheStorage::Engine::from(sessionID).clearAllCaches(clearTasksHandler);
+        CacheStorage::Engine::clearAllCaches(sessionID, clearTasksHandler.copyRef());
 
     if (websiteDataTypes.contains(WebsiteDataType::DiskCache) && !sessionID.isEphemeral())
         clearDiskCache(modifiedSince, [clearTasksHandler = WTFMove(clearTasksHandler)] { });
@@ -607,7 +611,7 @@ void NetworkProcess::deleteWebsiteDataForOrigins(PAL::SessionID sessionID, Optio
 
     if (websiteDataTypes.contains(WebsiteDataType::DOMCache)) {
         for (auto& originData : originDatas)
-            CacheStorage::Engine::from(sessionID).clearCachesForOrigin(originData, clearTasksHandler);
+            CacheStorage::Engine::clearCachesForOrigin(sessionID, SecurityOriginData { originData }, clearTasksHandler.copyRef());
     }
 
     if (websiteDataTypes.contains(WebsiteDataType::DiskCache) && !sessionID.isEphemeral())
@@ -848,19 +852,25 @@ void NetworkProcess::prefetchDNS(const String& hostname)
     WebCore::prefetchDNS(hostname);
 }
 
-String NetworkProcess::cacheStorageDirectory(PAL::SessionID sessionID) const
+void NetworkProcess::cacheStorageParameters(PAL::SessionID sessionID, CacheStorageParametersCallback&& callback)
 {
-    if (sessionID.isEphemeral())
-        return { };
-
-    if (sessionID == PAL::SessionID::defaultSessionID())
-        return m_cacheStorageDirectory;
+    m_cacheStorageParametersCallbacks.ensure(sessionID, [&] {
+        parentProcessConnection()->send(Messages::NetworkProcessProxy::RetrieveCacheStorageParameters { sessionID }, 0);
+        return Vector<CacheStorageParametersCallback> { };
+    }).iterator->value.append(WTFMove(callback));
+}
 
-    auto* session = NetworkStorageSession::storageSession(sessionID);
-    if (!session)
-        return { };
+void NetworkProcess::setCacheStorageParameters(PAL::SessionID sessionID, uint64_t quota, String&& cacheStorageDirectory, SandboxExtension::Handle&& handle)
+{
+    auto iterator = m_cacheStorageParametersCallbacks.find(sessionID);
+    if (iterator == m_cacheStorageParametersCallbacks.end())
+        return;
 
-    return session->cacheStorageDirectory();
+    SandboxExtension::consumePermanently(handle);
+    auto callbacks = WTFMove(iterator->value);
+    m_cacheStorageParametersCallbacks.remove(iterator);
+    for (auto& callback : callbacks)
+        callback(String { cacheStorageDirectory }, quota);
 }
 
 void NetworkProcess::preconnectTo(const WebCore::URL& url, WebCore::StoredCredentialsPolicy storedCredentialsPolicy)
@@ -879,11 +889,6 @@ void NetworkProcess::preconnectTo(const WebCore::URL& url, WebCore::StoredCreden
 #endif
 }
 
-uint64_t NetworkProcess::cacheStoragePerOriginQuota() const
-{
-    return m_cacheStoragePerOriginQuota;
-}
-
 void NetworkProcess::registerURLSchemeAsSecure(const String& scheme) const
 {
     SchemeRegistry::registerURLSchemeAsSecure(scheme);
index 08e24dc..be34931 100644 (file)
@@ -143,8 +143,9 @@ public:
 #endif
 
     Seconds loadThrottleLatency() const { return m_loadThrottleLatency; }
-    String cacheStorageDirectory(PAL::SessionID) const;
-    uint64_t cacheStoragePerOriginQuota() const;
+
+    using CacheStorageParametersCallback = CompletionHandler<void(const String&, uint64_t quota)>;
+    void cacheStorageParameters(PAL::SessionID, CacheStorageParametersCallback&&);
 
     void preconnectTo(const WebCore::URL&, WebCore::StoredCredentialsPolicy);
 
@@ -206,6 +207,8 @@ private:
 
     void clearCachedCredentials();
 
+    void setCacheStorageParameters(PAL::SessionID, uint64_t quota, String&& cacheStorageDirectory, SandboxExtension::Handle&&);
+
     // FIXME: This should take a session ID so we can identify which disk cache to delete.
     void clearDiskCache(WallTime modifiedSince, Function<void ()>&& completionHandler);
 
@@ -253,8 +256,6 @@ private:
     // Connections to WebProcesses.
     Vector<RefPtr<NetworkConnectionToWebProcess>> m_webProcessConnections;
 
-    String m_cacheStorageDirectory;
-    uint64_t m_cacheStoragePerOriginQuota { 0 };
     String m_diskCacheDirectory;
     bool m_hasSetCacheModel;
     CacheModel m_cacheModel;
@@ -279,6 +280,8 @@ private:
 #endif
     HashSet<PAL::SessionID> m_sessionsControlledByAutomation;
 
+    HashMap<PAL::SessionID, Vector<CacheStorageParametersCallback>> m_cacheStorageParametersCallbacks;
+
 #if PLATFORM(COCOA)
     void platformInitializeNetworkProcessCocoa(const NetworkProcessCreationParameters&);
     void setCookieStoragePartitioningEnabled(bool);
index 563a565..8376bbc 100644 (file)
@@ -98,4 +98,6 @@ messages -> NetworkProcess LegacyReceiver {
     RegisterURLSchemeAsDisplayIsolated(String scheme)
     RegisterURLSchemeAsCORSEnabled(String scheme)
     RegisterURLSchemeAsCanDisplayOnlyIfCanRequest(String scheme)
+
+    SetCacheStorageParameters(PAL::SessionID sessionID, uint64_t quota, String cacheStorageDirectory, WebKit::SandboxExtension::Handle handle);
 }
index 8c909fd..2010b43 100644 (file)
@@ -46,9 +46,6 @@ void NetworkProcessCreationParameters::encode(IPC::Encoder& encoder) const
     encoder.encodeEnum(cacheModel);
     encoder << diskCacheSizeOverride;
     encoder << canHandleHTTPSServerTrustEvaluation;
-    encoder << cacheStorageDirectory;
-    encoder << cacheStoragePerOriginQuota;
-    encoder << cacheStorageDirectoryExtensionHandle;
     encoder << diskCacheDirectory;
     encoder << diskCacheDirectoryExtensionHandle;
     encoder << shouldEnableNetworkCacheEfficacyLogging;
@@ -130,16 +127,6 @@ bool NetworkProcessCreationParameters::decode(IPC::Decoder& decoder, NetworkProc
         return false;
     if (!decoder.decode(result.canHandleHTTPSServerTrustEvaluation))
         return false;
-    if (!decoder.decode(result.cacheStorageDirectory))
-        return false;
-    if (!decoder.decode(result.cacheStoragePerOriginQuota))
-        return false;
-    
-    std::optional<SandboxExtension::Handle> cacheStorageDirectoryExtensionHandle;
-    decoder >> cacheStorageDirectoryExtensionHandle;
-    if (!cacheStorageDirectoryExtensionHandle)
-        return false;
-    result.cacheStorageDirectoryExtensionHandle = WTFMove(*cacheStorageDirectoryExtensionHandle);
 
     if (!decoder.decode(result.diskCacheDirectory))
         return false;
index 22e1b9b..4388945 100644 (file)
@@ -56,9 +56,6 @@ struct NetworkProcessCreationParameters {
     int64_t diskCacheSizeOverride { -1 };
     bool canHandleHTTPSServerTrustEvaluation { true };
 
-    String cacheStorageDirectory;
-    uint64_t cacheStoragePerOriginQuota;
-    SandboxExtension::Handle cacheStorageDirectoryExtensionHandle;
     String diskCacheDirectory;
     SandboxExtension::Handle diskCacheDirectoryExtensionHandle;
     bool shouldEnableNetworkCacheEfficacyLogging { false };
index dc87264..e626e23 100644 (file)
@@ -80,12 +80,23 @@ Engine::~Engine()
         callback(Data { }, 1);
 }
 
-Engine& Engine::from(PAL::SessionID sessionID)
+void Engine::from(PAL::SessionID sessionID, Function<void(Engine&)>&& callback)
 {
-    auto addResult = globalEngineMap().add(sessionID, nullptr);
-    if (addResult.isNewEntry)
-        addResult.iterator->value = Engine::create(NetworkProcess::singleton().cacheStorageDirectory(sessionID));
-    return *addResult.iterator->value;
+    auto iterator = globalEngineMap().find(sessionID);
+    if (iterator != globalEngineMap().end()) {
+        callback(*iterator->value);
+        return;
+    }
+
+    if (sessionID.isEphemeral())
+        sessionID = PAL::SessionID::legacyPrivateSessionID();
+
+    NetworkProcess::singleton().cacheStorageParameters(sessionID, [sessionID, callback = WTFMove(callback)](auto&& rootPath, auto quota) {
+        auto addResult = globalEngineMap().add(sessionID, nullptr);
+        if (addResult.isNewEntry)
+            addResult.iterator->value = adoptRef(*new Engine { String { rootPath }, quota });
+        callback(*addResult.iterator->value);
+    });
 }
 
 void Engine::destroyEngine(PAL::SessionID sessionID)
@@ -94,20 +105,101 @@ void Engine::destroyEngine(PAL::SessionID sessionID)
     globalEngineMap().remove(sessionID);
 }
 
-void Engine::fetchEntries(PAL::SessionID sessionID, bool shouldComputeSize, WTF::CompletionHandler<void(Vector<WebsiteData::Entry>)>&& completionHandler)
+void Engine::fetchEntries(PAL::SessionID sessionID, bool shouldComputeSize, CompletionHandler<void(Vector<WebsiteData::Entry>)>&& completionHandler)
+{
+    from(sessionID, [shouldComputeSize, completionHandler = WTFMove(completionHandler)] (auto& engine) mutable {
+        engine.fetchEntries(shouldComputeSize, WTFMove(completionHandler));
+    });
+}
+
+void Engine::open(PAL::SessionID sessionID, WebCore::ClientOrigin&& origin, String&& cacheName, WebCore::DOMCacheEngine::CacheIdentifierCallback&& callback)
+{
+    from(sessionID, [origin = WTFMove(origin), cacheName = WTFMove(cacheName), callback = WTFMove(callback)](auto& engine) mutable {
+        engine.open(origin, cacheName, WTFMove(callback));
+    });
+}
+
+void Engine::remove(PAL::SessionID sessionID, uint64_t cacheIdentifier, WebCore::DOMCacheEngine::CacheIdentifierCallback&& callback)
+{
+    from(sessionID, [cacheIdentifier, callback = WTFMove(callback)](auto& engine) mutable {
+        engine.remove(cacheIdentifier, WTFMove(callback));
+    });
+}
+
+void Engine::retrieveCaches(PAL::SessionID sessionID, WebCore::ClientOrigin&& origin, uint64_t updateCounter, WebCore::DOMCacheEngine::CacheInfosCallback&& callback)
+{
+    from(sessionID, [origin = WTFMove(origin), updateCounter, callback = WTFMove(callback)](auto& engine) mutable {
+        engine.retrieveCaches(origin, updateCounter, WTFMove(callback));
+    });
+}
+
+
+void Engine::retrieveRecords(PAL::SessionID sessionID, uint64_t cacheIdentifier, WebCore::URL&& url, WebCore::DOMCacheEngine::RecordsCallback&& callback)
+{
+    from(sessionID, [cacheIdentifier, url = WTFMove(url), callback = WTFMove(callback)](auto& engine) mutable {
+        engine.retrieveRecords(cacheIdentifier, WTFMove(url), WTFMove(callback));
+    });
+}
+
+void Engine::putRecords(PAL::SessionID sessionID, uint64_t cacheIdentifier, Vector<WebCore::DOMCacheEngine::Record>&& records, WebCore::DOMCacheEngine::RecordIdentifiersCallback&& callback)
 {
-    from(sessionID).fetchEntries(shouldComputeSize, WTFMove(completionHandler));
+    from(sessionID, [cacheIdentifier, records = WTFMove(records), callback = WTFMove(callback)](auto& engine) mutable {
+        engine.putRecords(cacheIdentifier, WTFMove(records), WTFMove(callback));
+    });
+}
+
+void Engine::deleteMatchingRecords(PAL::SessionID sessionID, uint64_t cacheIdentifier, WebCore::ResourceRequest&& request, WebCore::CacheQueryOptions&& options, WebCore::DOMCacheEngine::RecordIdentifiersCallback&& callback)
+{
+    from(sessionID, [cacheIdentifier, request = WTFMove(request), options = WTFMove(options), callback = WTFMove(callback)](auto& engine) mutable {
+        engine.deleteMatchingRecords(cacheIdentifier, WTFMove(request), WTFMove(options), WTFMove(callback));
+    });
+}
+
+void Engine::lock(PAL::SessionID sessionID, uint64_t cacheIdentifier)
+{
+    from(sessionID, [cacheIdentifier](auto& engine) mutable {
+        engine.lock(cacheIdentifier);
+    });
+}
+
+void Engine::unlock(PAL::SessionID sessionID, uint64_t cacheIdentifier)
+{
+    from(sessionID, [cacheIdentifier](auto& engine) mutable {
+        engine.unlock(cacheIdentifier);
+    });
 }
 
-Engine& Engine::defaultEngine()
+void Engine::clearMemoryRepresentation(PAL::SessionID sessionID, WebCore::ClientOrigin&& origin, WebCore::DOMCacheEngine::CompletionCallback&& callback)
 {
-    auto sessionID = PAL::SessionID::defaultSessionID();
-    static NeverDestroyed<Ref<Engine>> defaultEngine = { Engine::create(NetworkProcess::singleton().cacheStorageDirectory(sessionID)) };
-    return defaultEngine.get();
+    from(sessionID, [origin = WTFMove(origin), callback = WTFMove(callback)](auto& engine) mutable {
+        engine.clearMemoryRepresentation(origin, WTFMove(callback));
+    });
+}
+
+void Engine::representation(PAL::SessionID sessionID, CompletionHandler<void(String&&)>&& callback)
+{
+    from(sessionID, [callback = WTFMove(callback)](auto& engine) mutable {
+        callback(engine.representation());
+    });
+}
+
+void Engine::clearAllCaches(PAL::SessionID sessionID, Ref<WTF::CallbackAggregator>&& aggregator)
+{
+    from(sessionID, [aggregator = WTFMove(aggregator)](auto& engine) mutable {
+        engine.clearAllCaches(aggregator);
+    });
+}
+
+void Engine::clearCachesForOrigin(PAL::SessionID sessionID, WebCore::SecurityOriginData&& originData, Ref<WTF::CallbackAggregator>&& aggregator)
+{
+    from(sessionID, [originData = WTFMove(originData), aggregator = WTFMove(aggregator)](auto& engine) mutable {
+        engine.clearCachesForOrigin(originData, aggregator);
+    });
 }
 
-Engine::Engine(String&& rootPath)
+Engine::Engine(String&& rootPath, uint64_t quota)
     : m_rootPath(WTFMove(rootPath))
+    , m_quota(quota)
 {
     if (!m_rootPath.isNull())
         m_ioQueue = WorkQueue::create("com.apple.WebKit.CacheStorageEngine.serialBackground", WorkQueue::Type::Serial, WorkQueue::QOS::Background);
@@ -229,7 +321,7 @@ void Engine::readCachesFromDisk(const WebCore::ClientOrigin& origin, CachesCallb
     initialize([this, origin, callback = WTFMove(callback)](std::optional<Error>&& error) mutable {
         auto& caches = m_caches.ensure(origin, [&origin, this] {
             auto path = cachesRootPath(origin);
-            return Caches::create(*this, WebCore::ClientOrigin { origin }, WTFMove(path), NetworkProcess::singleton().cacheStoragePerOriginQuota());
+            return Caches::create(*this, WebCore::ClientOrigin { origin }, WTFMove(path), m_quota);
         }).iterator->value;
 
         if (caches->isInitialized()) {
index cdfc348..d5c9419 100644 (file)
@@ -57,24 +57,28 @@ class Engine : public RefCounted<Engine>, public CanMakeWeakPtr<Engine> {
 public:
     ~Engine();
 
-    static Engine& from(PAL::SessionID);
+    static void from(PAL::SessionID, Function<void(Engine&)>&&);
     static void destroyEngine(PAL::SessionID);
     static void fetchEntries(PAL::SessionID, bool shouldComputeSize, WTF::CompletionHandler<void(Vector<WebsiteData::Entry>)>&&);
 
-    static Ref<Engine> create(String&& rootPath) { return adoptRef(*new Engine(WTFMove(rootPath))); }
+    static void open(PAL::SessionID, WebCore::ClientOrigin&&, String&& cacheName, WebCore::DOMCacheEngine::CacheIdentifierCallback&&);
+    static void remove(PAL::SessionID, uint64_t cacheIdentifier, WebCore::DOMCacheEngine::CacheIdentifierCallback&&);
+    static void retrieveCaches(PAL::SessionID, WebCore::ClientOrigin&&, uint64_t updateCounter, WebCore::DOMCacheEngine::CacheInfosCallback&&);
 
-    bool shouldPersist() const { return !!m_ioQueue;}
+    static void retrieveRecords(PAL::SessionID, uint64_t cacheIdentifier, WebCore::URL&&, WebCore::DOMCacheEngine::RecordsCallback&&);
+    static void putRecords(PAL::SessionID, uint64_t cacheIdentifier, Vector<WebCore::DOMCacheEngine::Record>&&, WebCore::DOMCacheEngine::RecordIdentifiersCallback&&);
+    static void deleteMatchingRecords(PAL::SessionID, uint64_t cacheIdentifier, WebCore::ResourceRequest&&, WebCore::CacheQueryOptions&&, WebCore::DOMCacheEngine::RecordIdentifiersCallback&&);
 
-    void open(const WebCore::ClientOrigin&, const String& cacheName, WebCore::DOMCacheEngine::CacheIdentifierCallback&&);
-    void remove(uint64_t cacheIdentifier, WebCore::DOMCacheEngine::CacheIdentifierCallback&&);
-    void retrieveCaches(const WebCore::ClientOrigin&, uint64_t updateCounter, WebCore::DOMCacheEngine::CacheInfosCallback&&);
+    static void lock(PAL::SessionID, uint64_t cacheIdentifier);
+    static void unlock(PAL::SessionID, uint64_t cacheIdentifier);
 
-    void retrieveRecords(uint64_t cacheIdentifier, WebCore::URL&&, WebCore::DOMCacheEngine::RecordsCallback&&);
-    void putRecords(uint64_t cacheIdentifier, Vector<WebCore::DOMCacheEngine::Record>&&, WebCore::DOMCacheEngine::RecordIdentifiersCallback&&);
-    void deleteMatchingRecords(uint64_t cacheIdentifier, WebCore::ResourceRequest&&, WebCore::CacheQueryOptions&&, WebCore::DOMCacheEngine::RecordIdentifiersCallback&&);
+    static void clearMemoryRepresentation(PAL::SessionID, WebCore::ClientOrigin&&, WebCore::DOMCacheEngine::CompletionCallback&&);
+    static void representation(PAL::SessionID, CompletionHandler<void(String&&)>&&);
 
-    void lock(uint64_t cacheIdentifier);
-    void unlock(uint64_t cacheIdentifier);
+    static void clearAllCaches(PAL::SessionID, Ref<WTF::CallbackAggregator>&&);
+    static void clearCachesForOrigin(PAL::SessionID, WebCore::SecurityOriginData&&, Ref<WTF::CallbackAggregator>&&);
+
+    bool shouldPersist() const { return !!m_ioQueue;}
 
     void writeFile(const String& filename, NetworkCache::Data&&, WebCore::DOMCacheEngine::CompletionCallback&&);
     void readFile(const String& filename, CompletionHandler<void(const NetworkCache::Data&, int error)>&&);
@@ -84,15 +88,25 @@ public:
     const NetworkCache::Salt& salt() const { return m_salt.value(); }
     uint64_t nextCacheIdentifier() { return ++m_nextCacheIdentifier; }
 
-    void clearMemoryRepresentation(const WebCore::ClientOrigin&, WebCore::DOMCacheEngine::CompletionCallback&&);
-    String representation();
+private:
+    Engine(String&& rootPath, uint64_t quota);
+
+    void open(const WebCore::ClientOrigin&, const String& cacheName, WebCore::DOMCacheEngine::CacheIdentifierCallback&&);
+    void remove(uint64_t cacheIdentifier, WebCore::DOMCacheEngine::CacheIdentifierCallback&&);
+    void retrieveCaches(const WebCore::ClientOrigin&, uint64_t updateCounter, WebCore::DOMCacheEngine::CacheInfosCallback&&);
 
     void clearAllCaches(WTF::CallbackAggregator&);
     void clearCachesForOrigin(const WebCore::SecurityOriginData&, WTF::CallbackAggregator&);
 
-private:
-    static Engine& defaultEngine();
-    explicit Engine(String&& rootPath);
+    void clearMemoryRepresentation(const WebCore::ClientOrigin&, WebCore::DOMCacheEngine::CompletionCallback&&);
+    String representation();
+
+    void retrieveRecords(uint64_t cacheIdentifier, WebCore::URL&&, WebCore::DOMCacheEngine::RecordsCallback&&);
+    void putRecords(uint64_t cacheIdentifier, Vector<WebCore::DOMCacheEngine::Record>&&, WebCore::DOMCacheEngine::RecordIdentifiersCallback&&);
+    void deleteMatchingRecords(uint64_t cacheIdentifier, WebCore::ResourceRequest&&, WebCore::CacheQueryOptions&&, WebCore::DOMCacheEngine::RecordIdentifiersCallback&&);
+
+    void lock(uint64_t cacheIdentifier);
+    void unlock(uint64_t cacheIdentifier);
 
     String cachesRootPath(const WebCore::ClientOrigin&);
 
@@ -113,6 +127,7 @@ private:
     HashMap<WebCore::ClientOrigin, RefPtr<Caches>> m_caches;
     uint64_t m_nextCacheIdentifier { 0 };
     String m_rootPath;
+    uint64_t m_quota { 0 };
     RefPtr<WorkQueue> m_ioQueue;
     std::optional<NetworkCache::Salt> m_salt;
     HashMap<CacheIdentifier, LockCount> m_cacheLocks;
index 535f05a..a562345 100644 (file)
@@ -58,15 +58,15 @@ CacheStorageEngineConnection::~CacheStorageEngineConnection()
         auto& sessionID = keyValue.key;
         for (auto& references : keyValue.value) {
             ASSERT(references.value);
-            Engine::from(sessionID).unlock(references.key);
+            Engine::unlock(sessionID, references.key);
         }
     }
 }
 
-void CacheStorageEngineConnection::open(PAL::SessionID sessionID, uint64_t requestIdentifier, const WebCore::ClientOrigin& origin, const String& cacheName)
+void CacheStorageEngineConnection::open(PAL::SessionID sessionID, uint64_t requestIdentifier, WebCore::ClientOrigin&& origin, String&& cacheName)
 {
     RELEASE_LOG_IF_ALLOWED("open (%" PRIu64 ")", requestIdentifier);
-    Engine::from(sessionID).open(origin, cacheName, [connection = makeRef(m_connection.connection()), sessionID, requestIdentifier](const CacheIdentifierOrError& result) {
+    Engine::open(sessionID, WTFMove(origin), WTFMove(cacheName), [connection = makeRef(m_connection.connection()), sessionID, requestIdentifier](const CacheIdentifierOrError& result) {
         RELEASE_LOG_FUNCTION_IF_ALLOWED_IN_CALLBACK("open", "cache identifier is %" PRIu64, [](const auto& value) { return value.identifier; });
         connection->send(Messages::WebCacheStorageConnection::OpenCompleted(requestIdentifier, result), sessionID.sessionID());
     });
@@ -75,16 +75,16 @@ void CacheStorageEngineConnection::open(PAL::SessionID sessionID, uint64_t reque
 void CacheStorageEngineConnection::remove(PAL::SessionID sessionID, uint64_t requestIdentifier, uint64_t cacheIdentifier)
 {
     RELEASE_LOG_IF_ALLOWED("remove (%" PRIu64 ") cache %" PRIu64, requestIdentifier, cacheIdentifier);
-    Engine::from(sessionID).remove(cacheIdentifier, [connection = makeRef(m_connection.connection()), sessionID, requestIdentifier](const CacheIdentifierOrError& result) {
+    Engine::remove(sessionID, cacheIdentifier, [connection = makeRef(m_connection.connection()), sessionID, requestIdentifier](const CacheIdentifierOrError& result) {
         RELEASE_LOG_FUNCTION_IF_ALLOWED_IN_CALLBACK("remove", "removed cache %" PRIu64, [](const auto& value) { return value.identifier; });
         connection->send(Messages::WebCacheStorageConnection::RemoveCompleted(requestIdentifier, result), sessionID.sessionID());
     });
 }
 
-void CacheStorageEngineConnection::caches(PAL::SessionID sessionID, uint64_t requestIdentifier, const WebCore::ClientOrigin& origin, uint64_t updateCounter)
+void CacheStorageEngineConnection::caches(PAL::SessionID sessionID, uint64_t requestIdentifier, WebCore::ClientOrigin&& origin, uint64_t updateCounter)
 {
     RELEASE_LOG_IF_ALLOWED("caches (%" PRIu64 ")", requestIdentifier);
-    Engine::from(sessionID).retrieveCaches(origin, updateCounter, [connection = makeRef(m_connection.connection()), sessionID, origin, requestIdentifier](CacheInfosOrError&& result) {
+    Engine::retrieveCaches(sessionID, WTFMove(origin), updateCounter, [connection = makeRef(m_connection.connection()), sessionID, origin, requestIdentifier](CacheInfosOrError&& result) {
         RELEASE_LOG_FUNCTION_IF_ALLOWED_IN_CALLBACK("caches", "caches size is %lu", [](const auto& value) { return value.infos.size(); });
         connection->send(Messages::WebCacheStorageConnection::UpdateCaches(requestIdentifier, result), sessionID.sessionID());
     });
@@ -93,7 +93,7 @@ void CacheStorageEngineConnection::caches(PAL::SessionID sessionID, uint64_t req
 void CacheStorageEngineConnection::retrieveRecords(PAL::SessionID sessionID, uint64_t requestIdentifier, uint64_t cacheIdentifier, WebCore::URL&& url)
 {
     RELEASE_LOG_IF_ALLOWED("retrieveRecords (%" PRIu64 ") in cache %" PRIu64, requestIdentifier, cacheIdentifier);
-    Engine::from(sessionID).retrieveRecords(cacheIdentifier, WTFMove(url), [connection = makeRef(m_connection.connection()), sessionID, requestIdentifier](RecordsOrError&& result) {
+    Engine::retrieveRecords(sessionID, cacheIdentifier, WTFMove(url), [connection = makeRef(m_connection.connection()), sessionID, requestIdentifier](RecordsOrError&& result) {
         RELEASE_LOG_FUNCTION_IF_ALLOWED_IN_CALLBACK("retrieveRecords", "records size is %lu", [](const auto& value) { return value.size(); });
         connection->send(Messages::WebCacheStorageConnection::UpdateRecords(requestIdentifier, result), sessionID.sessionID());
     });
@@ -102,7 +102,7 @@ void CacheStorageEngineConnection::retrieveRecords(PAL::SessionID sessionID, uin
 void CacheStorageEngineConnection::deleteMatchingRecords(PAL::SessionID sessionID, uint64_t requestIdentifier, uint64_t cacheIdentifier, WebCore::ResourceRequest&& request, WebCore::CacheQueryOptions&& options)
 {
     RELEASE_LOG_IF_ALLOWED("deleteMatchingRecords (%" PRIu64 ") in cache %" PRIu64, requestIdentifier, cacheIdentifier);
-    Engine::from(sessionID).deleteMatchingRecords(cacheIdentifier, WTFMove(request), WTFMove(options), [connection = makeRef(m_connection.connection()), sessionID, requestIdentifier](RecordIdentifiersOrError&& result) {
+    Engine::deleteMatchingRecords(sessionID, cacheIdentifier, WTFMove(request), WTFMove(options), [connection = makeRef(m_connection.connection()), sessionID, requestIdentifier](RecordIdentifiersOrError&& result) {
         RELEASE_LOG_FUNCTION_IF_ALLOWED_IN_CALLBACK("deleteMatchingRecords", "deleted %lu records",  [](const auto& value) { return value.size(); });
         connection->send(Messages::WebCacheStorageConnection::DeleteRecordsCompleted(requestIdentifier, result), sessionID.sessionID());
     });
@@ -111,7 +111,7 @@ void CacheStorageEngineConnection::deleteMatchingRecords(PAL::SessionID sessionI
 void CacheStorageEngineConnection::putRecords(PAL::SessionID sessionID, uint64_t requestIdentifier, uint64_t cacheIdentifier, Vector<Record>&& records)
 {
     RELEASE_LOG_IF_ALLOWED("putRecords (%" PRIu64 ") in cache %" PRIu64 ", %lu records", requestIdentifier, cacheIdentifier, records.size());
-    Engine::from(sessionID).putRecords(cacheIdentifier, WTFMove(records), [connection = makeRef(m_connection.connection()), sessionID, requestIdentifier](RecordIdentifiersOrError&& result) {
+    Engine::putRecords(sessionID, cacheIdentifier, WTFMove(records), [connection = makeRef(m_connection.connection()), sessionID, requestIdentifier](RecordIdentifiersOrError&& result) {
         RELEASE_LOG_FUNCTION_IF_ALLOWED_IN_CALLBACK("putRecords", "put %lu records",  [](const auto& value) { return value.size(); });
         connection->send(Messages::WebCacheStorageConnection::PutRecordsCompleted(requestIdentifier, result), sessionID.sessionID());
     });
@@ -127,7 +127,7 @@ void CacheStorageEngineConnection::reference(PAL::SessionID sessionID, uint64_t
         return 0;
     }).iterator->value;
     if (!counter++)
-        Engine::from(sessionID).lock(cacheIdentifier);
+        Engine::lock(sessionID, cacheIdentifier);
 }
 
 void CacheStorageEngineConnection::dereference(PAL::SessionID sessionID, uint64_t cacheIdentifier)
@@ -147,20 +147,22 @@ void CacheStorageEngineConnection::dereference(PAL::SessionID sessionID, uint64_
     if (--referenceResult->value)
         return;
 
-    Engine::from(sessionID).unlock(cacheIdentifier);
+    Engine::unlock(sessionID, cacheIdentifier);
     references.remove(referenceResult);
 }
 
-void CacheStorageEngineConnection::clearMemoryRepresentation(PAL::SessionID sessionID, uint64_t requestIdentifier, const WebCore::ClientOrigin& origin)
+void CacheStorageEngineConnection::clearMemoryRepresentation(PAL::SessionID sessionID, uint64_t requestIdentifier, WebCore::ClientOrigin&& origin)
 {
-    Engine::from(sessionID).clearMemoryRepresentation(origin, [connection = makeRef(m_connection.connection()), sessionID, requestIdentifier] (std::optional<Error>&& error) {
+    Engine::clearMemoryRepresentation(sessionID, WTFMove(origin), [connection = makeRef(m_connection.connection()), sessionID, requestIdentifier] (std::optional<Error>&& error) {
         connection->send(Messages::WebCacheStorageConnection::ClearMemoryRepresentationCompleted(requestIdentifier, error), sessionID.sessionID());
     });
 }
 
 void CacheStorageEngineConnection::engineRepresentation(PAL::SessionID sessionID, uint64_t requestIdentifier)
 {
-    m_connection.connection().send(Messages::WebCacheStorageConnection::EngineRepresentationCompleted(requestIdentifier, Engine::from(sessionID).representation()), sessionID.sessionID());
+    Engine::representation(sessionID, [connection = makeRef(m_connection.connection()), sessionID, requestIdentifier] (auto&& representation) {
+        connection->send(Messages::WebCacheStorageConnection::EngineRepresentationCompleted { requestIdentifier, representation }, sessionID.sessionID());
+    });
 }
 
 }
index e57c5e3..bc880f5 100644 (file)
@@ -50,9 +50,9 @@ public:
 private:
     explicit CacheStorageEngineConnection(NetworkConnectionToWebProcess&);
 
-    void open(PAL::SessionID, uint64_t openRequestIdentifier, const WebCore::ClientOrigin&, const String& cacheName);
+    void open(PAL::SessionID, uint64_t openRequestIdentifier, WebCore::ClientOrigin&&, String&& cacheName);
     void remove(PAL::SessionID, uint64_t removeRequestIdentifier, uint64_t cacheIdentifier);
-    void caches(PAL::SessionID, uint64_t retrieveCachesIdentifier, const WebCore::ClientOrigin&, uint64_t updateCounter);
+    void caches(PAL::SessionID, uint64_t retrieveCachesIdentifier, WebCore::ClientOrigin&&, uint64_t updateCounter);
 
     void retrieveRecords(PAL::SessionID, uint64_t requestIdentifier, uint64_t cacheIdentifier, WebCore::URL&&);
     void deleteMatchingRecords(PAL::SessionID, uint64_t requestIdentifier, uint64_t cacheIdentifier, WebCore::ResourceRequest&&, WebCore::CacheQueryOptions&&);
@@ -61,7 +61,7 @@ private:
     void reference(PAL::SessionID, uint64_t cacheIdentifier);
     void dereference(PAL::SessionID, uint64_t cacheIdentifier);
 
-    void clearMemoryRepresentation(PAL::SessionID, uint64_t requestIdentifier, const WebCore::ClientOrigin&);
+    void clearMemoryRepresentation(PAL::SessionID, uint64_t requestIdentifier, WebCore::ClientOrigin&&);
     void engineRepresentation(PAL::SessionID, uint64_t requestIdentifier);
 
     NetworkConnectionToWebProcess& m_connection;
index 7e48cf8..0171843 100644 (file)
@@ -110,12 +110,6 @@ void NetworkProcess::platformInitializeNetworkProcessCocoa(const NetworkProcessC
 
     ASSERT(!m_diskCacheIsDisabledForTesting);
 
-    if (!parameters.cacheStorageDirectory.isNull()) {
-        m_cacheStorageDirectory = parameters.cacheStorageDirectory;
-        m_cacheStoragePerOriginQuota = parameters.cacheStoragePerOriginQuota;
-        SandboxExtension::consumePermanently(parameters.cacheStorageDirectoryExtensionHandle);
-    }
-
 #if ENABLE(WIFI_ASSERTIONS)
     initializeWiFiAssertions(parameters);
 #endif
index e989bd8..1e02e91 100644 (file)
@@ -72,12 +72,6 @@ void RemoteNetworkingContext::ensureWebsiteDataStoreSession(WebsiteDataStorePara
     for (const auto& cookie : parameters.pendingCookies)
         session->setCookie(cookie);
 
-    if (!sessionID.isEphemeral() && !parameters.cacheStorageDirectory.isNull()) {
-        SandboxExtension::consumePermanently(parameters.cacheStorageDirectoryExtensionHandle);
-        session->setCacheStorageDirectory(WTFMove(parameters.cacheStorageDirectory));
-        session->setCacheStoragePerOriginQuota(parameters.cacheStoragePerOriginQuota);
-    }
-
     SessionTracker::setSession(sessionID, NetworkSession::create(WTFMove(parameters.networkSessionParameters)));
 }
 
index 57dad55..8ac9950 100644 (file)
@@ -41,9 +41,6 @@ void WebsiteDataStoreParameters::encode(IPC::Encoder& encoder) const
     encoder << uiProcessCookieStorageIdentifier;
     encoder << cookieStoragePathExtensionHandle;
     encoder << pendingCookies;
-    encoder << cacheStorageDirectory;
-    encoder << cacheStoragePerOriginQuota;
-    encoder << cacheStorageDirectoryExtensionHandle;
 }
 
 std::optional<WebsiteDataStoreParameters> WebsiteDataStoreParameters::decode(IPC::Decoder& decoder)
@@ -67,29 +64,13 @@ std::optional<WebsiteDataStoreParameters> WebsiteDataStoreParameters::decode(IPC
     decoder >> pendingCookies;
     if (!pendingCookies)
         return std::nullopt;
-
-    std::optional<String> cacheStorageDirectory;
-    decoder >> cacheStorageDirectory;
-    if (!cacheStorageDirectory)
-        return std::nullopt;
-
-    std::optional<uint64_t> cacheStoragePerOriginQuota;
-    decoder >> cacheStoragePerOriginQuota;
-    if (!cacheStoragePerOriginQuota)
-        return std::nullopt;
-
-    std::optional<SandboxExtension::Handle> cacheStorageDirectoryExtensionHandle;
-    decoder >> cacheStorageDirectoryExtensionHandle;
-    if (!cacheStorageDirectoryExtensionHandle)
-        return std::nullopt;
-    
-    return {{ WTFMove(*uiProcessCookieStorageIdentifier), WTFMove(*cookieStoragePathExtensionHandle), WTFMove(*pendingCookies), WTFMove(*cacheStorageDirectory), WTFMove(*cacheStoragePerOriginQuota), WTFMove(*cacheStorageDirectoryExtensionHandle), WTFMove(*networkSessionParameters)}};
+    return {{ WTFMove(*uiProcessCookieStorageIdentifier), WTFMove(*cookieStoragePathExtensionHandle), WTFMove(*pendingCookies), WTFMove(*networkSessionParameters)}};
 }
 
 WebsiteDataStoreParameters WebsiteDataStoreParameters::privateSessionParameters(PAL::SessionID sessionID)
 {
     ASSERT(sessionID.isEphemeral());
-    return { { }, { }, { }, { }, WebsiteDataStore::defaultCacheStoragePerOriginQuota, { }, { sessionID, { }, AllowsCellularAccess::Yes
+    return { { }, { }, { }, { sessionID, { }, AllowsCellularAccess::Yes
 #if PLATFORM(COCOA)
         , nullptr
 #endif
index 8d43496..abff503 100644 (file)
@@ -54,9 +54,6 @@ struct WebsiteDataStoreParameters {
     Vector<uint8_t> uiProcessCookieStorageIdentifier;
     SandboxExtension::Handle cookieStoragePathExtensionHandle;
     Vector<WebCore::Cookie> pendingCookies;
-    String cacheStorageDirectory;
-    uint64_t cacheStoragePerOriginQuota { 0 };
-    SandboxExtension::Handle cacheStorageDirectoryExtensionHandle;
     NetworkSessionCreationParameters networkSessionParameters;
 };
 
index 2514568..d745025 100644 (file)
@@ -574,6 +574,41 @@ void NetworkProcessProxy::didSyncAllCookies()
     }
 }
 
+void NetworkProcessProxy::addSession(Ref<WebsiteDataStore>&& store)
+{
+    if (canSendMessage())
+        send(Messages::NetworkProcess::AddWebsiteDataStore { store->parameters() }, 0);
+    auto sessionID = store->sessionID();
+    if (!sessionID.isEphemeral())
+        m_websiteDataStores.set(sessionID, WTFMove(store));
+}
+
+void NetworkProcessProxy::removeSession(PAL::SessionID sessionID)
+{
+    if (canSendMessage())
+        send(Messages::NetworkProcess::DestroySession { sessionID }, 0);
+    if (!sessionID.isEphemeral())
+        m_websiteDataStores.remove(sessionID);
+}
+
+void NetworkProcessProxy::retrieveCacheStorageParameters(PAL::SessionID sessionID)
+{
+    auto iterator = m_websiteDataStores.find(sessionID);
+    if (iterator == m_websiteDataStores.end()) {
+        auto quota = m_processPool.websiteDataStore() ? m_processPool.websiteDataStore()->websiteDataStore().cacheStoragePerOriginQuota() : WebsiteDataStore::defaultCacheStoragePerOriginQuota;
+        send(Messages::NetworkProcess::SetCacheStorageParameters { sessionID, quota, { }, { } }, 0);
+        return;
+    }
+
+    auto& store = *iterator->value;
+    auto& cacheStorageDirectory = store.cacheStorageDirectory();
+    SandboxExtension::Handle cacheStorageDirectoryExtensionHandle;
+    if (!cacheStorageDirectory.isEmpty())
+        SandboxExtension::createHandleForReadWriteDirectory(cacheStorageDirectory, cacheStorageDirectoryExtensionHandle);
+
+    send(Messages::NetworkProcess::SetCacheStorageParameters { sessionID, store.cacheStoragePerOriginQuota(), cacheStorageDirectory, cacheStorageDirectoryExtensionHandle }, 0);
+}
+
 #if ENABLE(CONTENT_EXTENSIONS)
 void NetworkProcessProxy::contentExtensionRules(UserContentControllerIdentifier identifier)
 {
index ef6656c..6cc521c 100644 (file)
@@ -26,6 +26,7 @@
 #ifndef NetworkProcessProxy_h
 #define NetworkProcessProxy_h
 
+#include "APIWebsiteDataStore.h"
 #include "ChildProcessProxy.h"
 #if ENABLE(LEGACY_CUSTOM_PROTOCOL_MANAGER)
 #include "LegacyCustomProtocolManagerProxy.h"
@@ -99,6 +100,9 @@ public:
     void didDestroyWebUserContentControllerProxy(WebUserContentControllerProxy&);
 #endif
 
+    void addSession(Ref<WebsiteDataStore>&&);
+    void removeSession(PAL::SessionID);
+
 private:
     NetworkProcessProxy(WebProcessPool&);
 
@@ -143,6 +147,7 @@ private:
     void storageAccessRequestResult(bool wasGranted, uint64_t contextId);
     void allStorageAccessEntriesResult(Vector<String>&& domains, uint64_t contextId);
 #endif
+    void retrieveCacheStorageParameters(PAL::SessionID);
 
 #if ENABLE(CONTENT_EXTENSIONS)
     void contentExtensionRules(UserContentControllerIdentifier);
@@ -177,6 +182,8 @@ private:
 #if ENABLE(CONTENT_EXTENSIONS)
     HashSet<WebUserContentControllerProxy*> m_webUserContentControllerProxies;
 #endif
+
+    HashMap<PAL::SessionID, RefPtr<WebsiteDataStore>> m_websiteDataStores;
 };
 
 } // namespace WebKit
index 108862a..996a4a5 100644 (file)
@@ -53,4 +53,6 @@ messages -> NetworkProcessProxy LegacyReceiver {
 #if ENABLE(CONTENT_EXTENSIONS)
     ContentExtensionRules(WebKit::UserContentControllerIdentifier identifier)
 #endif
+
+    RetrieveCacheStorageParameters(PAL::SessionID sessionID)
 }
index 4c0f00e..7c6cec0 100644 (file)
@@ -448,22 +448,19 @@ NetworkProcessProxy& WebProcessPool::ensureNetworkProcess(WebsiteDataStore* with
 {
     if (m_networkProcess) {
         if (withWebsiteDataStore) {
-            m_networkProcess->send(Messages::NetworkProcess::AddWebsiteDataStore(withWebsiteDataStore->parameters()), 0);
+            m_networkProcess->addSession(makeRef(*withWebsiteDataStore));
             withWebsiteDataStore->clearPendingCookies();
         }
         return *m_networkProcess;
     }
 
-    if (m_websiteDataStore)
-        m_websiteDataStore->websiteDataStore().resolveDirectoriesIfNecessary();
-
     m_networkProcess = NetworkProcessProxy::create(*this);
 
     NetworkProcessCreationParameters parameters;
 
     if (withWebsiteDataStore) {
         auto websiteDataStoreParameters = withWebsiteDataStore->parameters();
-        parameters.defaultSessionParameters = websiteDataStoreParameters.networkSessionParameters;
+        parameters.defaultSessionParameters = WTFMove(websiteDataStoreParameters.networkSessionParameters);
 
         // FIXME: This isn't conceptually correct, but it's needed to preserve behavior introduced in r213241.
         // We should separate the concept of the default session from the currently used persistent session.
@@ -482,11 +479,6 @@ NetworkProcessProxy& WebProcessPool::ensureNetworkProcess(WebsiteDataStore* with
     for (auto& scheme : m_urlSchemesRegisteredForCustomProtocols)
         parameters.urlSchemesRegisteredForCustomProtocols.append(scheme);
 
-    parameters.cacheStorageDirectory = m_websiteDataStore ? m_websiteDataStore->websiteDataStore().cacheStorageDirectory() : API::WebsiteDataStore::defaultCacheStorageDirectory();
-    if (!parameters.cacheStorageDirectory.isEmpty())
-        SandboxExtension::createHandleForReadWriteDirectory(parameters.cacheStorageDirectory, parameters.cacheStorageDirectoryExtensionHandle);
-    parameters.cacheStoragePerOriginQuota = m_websiteDataStore ? m_websiteDataStore->websiteDataStore().cacheStoragePerOriginQuota() : WebsiteDataStore::defaultCacheStoragePerOriginQuota;
-
     parameters.diskCacheDirectory = m_configuration->diskCacheDirectory();
     if (!parameters.diskCacheDirectory.isEmpty())
         SandboxExtension::createHandleForReadWriteDirectory(parameters.diskCacheDirectory, parameters.diskCacheDirectoryExtensionHandle);
@@ -537,12 +529,12 @@ NetworkProcessProxy& WebProcessPool::ensureNetworkProcess(WebsiteDataStore* with
     }
 
     if (m_websiteDataStore) {
-        m_networkProcess->send(Messages::NetworkProcess::AddWebsiteDataStore(m_websiteDataStore->websiteDataStore().parameters()), 0);
+        m_networkProcess->addSession(makeRef(m_websiteDataStore->websiteDataStore()));
         m_websiteDataStore->websiteDataStore().clearPendingCookies();
     }
     
     if (withWebsiteDataStore) {
-        m_networkProcess->send(Messages::NetworkProcess::AddWebsiteDataStore(withWebsiteDataStore->parameters()), 0);
+        m_networkProcess->addSession(makeRef(*withWebsiteDataStore));
         withWebsiteDataStore->clearPendingCookies();
     }
 
@@ -723,7 +715,7 @@ void WebProcessPool::setAnyPageGroupMightHavePrivateBrowsingEnabled(bool private
         sendToNetworkingProcess(Messages::NetworkProcess::AddWebsiteDataStore(WebsiteDataStoreParameters::legacyPrivateSessionParameters()));
         sendToAllProcesses(Messages::WebProcess::AddWebsiteDataStore(WebsiteDataStoreParameters::legacyPrivateSessionParameters()));
     } else {
-        sendToNetworkingProcess(Messages::NetworkProcess::DestroySession(PAL::SessionID::legacyPrivateSessionID()));
+        networkProcess()->removeSession(PAL::SessionID::legacyPrivateSessionID());
         sendToStorageProcess(Messages::StorageProcess::DestroySession(PAL::SessionID::legacyPrivateSessionID()));
         sendToAllProcesses(Messages::WebProcess::DestroySession(PAL::SessionID::legacyPrivateSessionID()));
     }
@@ -1197,11 +1189,13 @@ void WebProcessPool::pageBeginUsingWebsiteDataStore(WebPageProxy& page)
     auto sessionID = page.sessionID();
     if (sessionID.isEphemeral()) {
         ASSERT(page.websiteDataStore().parameters().networkSessionParameters.sessionID == sessionID);
-        sendToNetworkingProcess(Messages::NetworkProcess::AddWebsiteDataStore(page.websiteDataStore().parameters()));
+        if (m_networkProcess)
+            m_networkProcess->addSession(makeRef(page.websiteDataStore()));
         page.process().send(Messages::WebProcess::AddWebsiteDataStore(WebsiteDataStoreParameters::privateSessionParameters(sessionID)), 0);
         page.websiteDataStore().clearPendingCookies();
     } else if (sessionID != PAL::SessionID::defaultSessionID()) {
-        sendToNetworkingProcess(Messages::NetworkProcess::AddWebsiteDataStore(page.websiteDataStore().parameters()));
+        if (m_networkProcess)
+            m_networkProcess->addSession(makeRef(page.websiteDataStore()));
         page.process().send(Messages::WebProcess::AddWebsiteDataStore(page.websiteDataStore().parameters()), 0);
         page.websiteDataStore().clearPendingCookies();
 
@@ -1237,7 +1231,7 @@ void WebProcessPool::pageEndUsingWebsiteDataStore(WebPageProxy& page)
 
         // The last user of this non-default PAL::SessionID is gone, so clean it up in the child processes.
         if (networkProcess())
-            networkProcess()->send(Messages::NetworkProcess::DestroySession(sessionID), 0);
+            networkProcess()->removeSession(sessionID);
         page.process().send(Messages::WebProcess::DestroySession(sessionID), 0);
     }
 }
index a373f0f..c0e1605 100644 (file)
@@ -78,11 +78,6 @@ WebsiteDataStoreParameters WebsiteDataStore::parameters()
     if (!cookieFile.isEmpty())
         SandboxExtension::createHandleForReadWriteDirectory(WebCore::FileSystem::directoryName(cookieFile), parameters.cookieStoragePathExtensionHandle);
 
-    if (!m_configuration.cacheStorageDirectory.isNull()) {
-        parameters.cacheStorageDirectory = m_configuration.cacheStorageDirectory;
-        SandboxExtension::createHandleForReadWriteDirectory(parameters.cacheStorageDirectory, parameters.cacheStorageDirectoryExtensionHandle);
-    }
-
     return parameters;
 }
 
index 68192de..a984c0f 100644 (file)
@@ -118,8 +118,9 @@ WebsiteDataStore::~WebsiteDataStore()
         ASSERT(nonDefaultDataStores().get(m_sessionID) == this);
         nonDefaultDataStores().remove(m_sessionID);
         for (auto& processPool : WebProcessPool::allProcessPools()) {
-            processPool->sendToNetworkingProcess(Messages::NetworkProcess::DestroySession(m_sessionID));
             processPool->sendToStorageProcess(Messages::StorageProcess::DestroySession(m_sessionID));
+            if (auto* networkProcess = processPool->networkProcess())
+                networkProcess->removeSession(m_sessionID);
         }
     }
 }