<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[287191] trunk/Source/WebKit</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/287191">287191</a></dd>
<dt>Author</dt> <dd>cdumez@apple.com</dd>
<dt>Date</dt> <dd>2021-12-17 09:25:43 -0800 (Fri, 17 Dec 2021)</dd>
</dl>

<h3>Log Message</h3>
<pre>Move storage managers from the NetworkProcess to the NetworkSession class
https://bugs.webkit.org/show_bug.cgi?id=234409

Reviewed by Alex Christensen.

Move storage managers from the NetworkProcess to the NetworkSession class since they are
per session.

* NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::lowMemoryHandler):
(WebKit::NetworkProcess::createNetworkConnectionToWebProcess):
(WebKit::NetworkProcess::addWebsiteDataStore):
(WebKit::NetworkProcess::destroySession):
(WebKit::NetworkProcess::hasLocalStorage):
(WebKit::NetworkProcess::fetchWebsiteData):
(WebKit::NetworkProcess::deleteWebsiteData):
(WebKit::NetworkProcess::deleteWebsiteDataForOrigins):
(WebKit::NetworkProcess::deleteAndRestrictWebsiteDataForRegistrableDomains):
(WebKit::NetworkProcess::registrableDomainsWithWebsiteData):
(WebKit::NetworkProcess::prepareToSuspend):
(WebKit::NetworkProcess::resume):
(WebKit::NetworkProcess::syncLocalStorage):
(WebKit::NetworkProcess::clearStorage):
(WebKit::NetworkProcess::renameOriginInWebsiteData):
(WebKit::NetworkProcess::connectionToWebProcessClosed):
(WebKit::NetworkProcess::addStorageManagerForSession): Deleted.
(WebKit::NetworkProcess::removeStorageManagerForSession): Deleted.
* NetworkProcess/NetworkProcess.h:
* NetworkProcess/NetworkSession.cpp:
(WebKit::NetworkSession::invalidateAndCancel):
(WebKit::NetworkSession::lowMemoryHandler):
(WebKit::NetworkSession::addStorageManagerSession):
* NetworkProcess/NetworkSession.h:
(WebKit::NetworkSession::storageManager):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKitChangeLog">trunk/Source/WebKit/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitNetworkProcessNetworkProcesscpp">trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp</a></li>
<li><a href="#trunkSourceWebKitNetworkProcessNetworkProcessh">trunk/Source/WebKit/NetworkProcess/NetworkProcess.h</a></li>
<li><a href="#trunkSourceWebKitNetworkProcessNetworkSessioncpp">trunk/Source/WebKit/NetworkProcess/NetworkSession.cpp</a></li>
<li><a href="#trunkSourceWebKitNetworkProcessNetworkSessionh">trunk/Source/WebKit/NetworkProcess/NetworkSession.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/ChangeLog (287190 => 287191)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/ChangeLog    2021-12-17 17:13:11 UTC (rev 287190)
+++ trunk/Source/WebKit/ChangeLog       2021-12-17 17:25:43 UTC (rev 287191)
</span><span class="lines">@@ -1,5 +1,42 @@
</span><span class="cx"> 2021-12-17  Chris Dumez  <cdumez@apple.com>
</span><span class="cx"> 
</span><ins>+        Move storage managers from the NetworkProcess to the NetworkSession class
+        https://bugs.webkit.org/show_bug.cgi?id=234409
+
+        Reviewed by Alex Christensen.
+
+        Move storage managers from the NetworkProcess to the NetworkSession class since they are
+        per session.
+
+        * NetworkProcess/NetworkProcess.cpp:
+        (WebKit::NetworkProcess::lowMemoryHandler):
+        (WebKit::NetworkProcess::createNetworkConnectionToWebProcess):
+        (WebKit::NetworkProcess::addWebsiteDataStore):
+        (WebKit::NetworkProcess::destroySession):
+        (WebKit::NetworkProcess::hasLocalStorage):
+        (WebKit::NetworkProcess::fetchWebsiteData):
+        (WebKit::NetworkProcess::deleteWebsiteData):
+        (WebKit::NetworkProcess::deleteWebsiteDataForOrigins):
+        (WebKit::NetworkProcess::deleteAndRestrictWebsiteDataForRegistrableDomains):
+        (WebKit::NetworkProcess::registrableDomainsWithWebsiteData):
+        (WebKit::NetworkProcess::prepareToSuspend):
+        (WebKit::NetworkProcess::resume):
+        (WebKit::NetworkProcess::syncLocalStorage):
+        (WebKit::NetworkProcess::clearStorage):
+        (WebKit::NetworkProcess::renameOriginInWebsiteData):
+        (WebKit::NetworkProcess::connectionToWebProcessClosed):
+        (WebKit::NetworkProcess::addStorageManagerForSession): Deleted.
+        (WebKit::NetworkProcess::removeStorageManagerForSession): Deleted.
+        * NetworkProcess/NetworkProcess.h:
+        * NetworkProcess/NetworkSession.cpp:
+        (WebKit::NetworkSession::invalidateAndCancel):
+        (WebKit::NetworkSession::lowMemoryHandler):
+        (WebKit::NetworkSession::addStorageManagerSession):
+        * NetworkProcess/NetworkSession.h:
+        (WebKit::NetworkSession::storageManager):
+
+2021-12-17  Chris Dumez  <cdumez@apple.com>
+
</ins><span class="cx">         Unreviewed, reverting r286850.
</span><span class="cx"> 
</span><span class="cx">         Put r282794 back in. It turns out it was an overall
</span></span></pre></div>
<a id="trunkSourceWebKitNetworkProcessNetworkProcesscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp (287190 => 287191)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp    2021-12-17 17:13:11 UTC (rev 287190)
+++ trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp       2021-12-17 17:25:43 UTC (rev 287191)
</span><span class="lines">@@ -304,9 +304,6 @@
</span><span class="cx">     forEachNetworkSession([critical](auto& session) {
</span><span class="cx">         session.lowMemoryHandler(critical);
</span><span class="cx">     });
</span><del>-
-    for (auto& manager : m_storageManagers.values())
-        manager->handleLowMemoryWarning();
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void NetworkProcess::initializeNetworkProcess(NetworkProcessCreationParameters&& parameters)
</span><span class="lines">@@ -389,10 +386,11 @@
</span><span class="cx"> 
</span><span class="cx">     connection.setOnLineState(NetworkStateNotifier::singleton().onLine());
</span><span class="cx"> 
</span><del>-    if (auto* session = networkSession(sessionID))
</del><ins>+    if (auto* session = networkSession(sessionID)) {
</ins><span class="cx">         session->ensureWebIDBServer().addConnection(connection.connection(), identifier);
</span><del>-    if (auto manager = m_storageManagers.get(sessionID))
-        manager->startReceivingMessageFromConnection(connection.connection());
</del><ins>+        if (auto* manager = session->storageManager())
+            manager->startReceivingMessageFromConnection(connection.connection());
+    }
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void NetworkProcess::clearCachedCredentials(PAL::SessionID sessionID)
</span><span class="lines">@@ -410,10 +408,10 @@
</span><span class="cx"> 
</span><span class="cx">     RemoteNetworkingContext::ensureWebsiteDataStoreSession(*this, parameters);
</span><span class="cx"> 
</span><del>-    addStorageManagerForSession(sessionID, parameters.generalStorageDirectory, parameters.generalStorageDirectoryHandle, parameters.localStorageDirectory, parameters.localStorageDirectoryExtensionHandle);
</del><span class="cx">     addSessionStorageQuotaManager(sessionID, parameters.perOriginStorageQuota, parameters.perThirdPartyOriginStorageQuota, parameters.cacheStorageDirectory, parameters.cacheStorageDirectoryExtensionHandle);
</span><span class="cx"> 
</span><span class="cx">     if (auto* session = networkSession(sessionID)) {
</span><ins>+        session->addStorageManagerSession(parameters.generalStorageDirectory, parameters.generalStorageDirectoryHandle, parameters.localStorageDirectory, parameters.localStorageDirectoryExtensionHandle);
</ins><span class="cx">         session->addIndexedDatabaseSession(parameters.indexedDatabaseDirectory, parameters.indexedDatabaseDirectoryExtensionHandle);
</span><span class="cx"> #if ENABLE(SERVICE_WORKER)
</span><span class="cx">         session->addServiceWorkerSession(parameters.serviceWorkerProcessTerminationDelayEnabled, WTFMove(parameters.serviceWorkerRegistrationDirectory), parameters.serviceWorkerRegistrationDirectoryExtensionHandle);
</span><span class="lines">@@ -440,21 +438,6 @@
</span><span class="cx">     m_sessionStorageQuotaManagers.remove(sessionID);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void NetworkProcess::addStorageManagerForSession(PAL::SessionID sessionID, const String& generalStoragePath, SandboxExtension::Handle& generalStoragePathHandle, const String& localStoragePath, SandboxExtension::Handle& localStoragePathHandle)
-{
-    m_storageManagers.ensure(sessionID, [&] {
-        SandboxExtension::consumePermanently(generalStoragePathHandle);
-        SandboxExtension::consumePermanently(localStoragePathHandle);
-        return NetworkStorageManager::create(sessionID, generalStoragePath, localStoragePath);
-    });
-}
-
-void NetworkProcess::removeStorageManagerForSession(PAL::SessionID sessionID)
-{
-    if (auto manager = m_storageManagers.take(sessionID))
-        manager->close();
-}
-
</del><span class="cx"> void NetworkProcess::forEachNetworkSession(const Function<void(NetworkSession&)>& functor)
</span><span class="cx"> {
</span><span class="cx">     for (auto& session : m_networkSessions.values())
</span><span class="lines">@@ -556,8 +539,6 @@
</span><span class="cx">     m_networkStorageSessions.remove(sessionID);
</span><span class="cx">     m_sessionsControlledByAutomation.remove(sessionID);
</span><span class="cx">     CacheStorage::Engine::destroyEngine(*this, sessionID);
</span><del>-
-    removeStorageManagerForSession(sessionID);
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(INTELLIGENT_TRACKING_PREVENTION)
</span><span class="lines">@@ -1044,12 +1025,12 @@
</span><span class="cx"> 
</span><span class="cx"> void NetworkProcess::hasLocalStorage(PAL::SessionID sessionID, const RegistrableDomain& domain, CompletionHandler<void(bool)>&& completionHandler)
</span><span class="cx"> {
</span><del>-    auto iterator = m_storageManagers.find(sessionID);
-    if (iterator == m_storageManagers.end())
</del><ins>+    auto* session = networkSession(sessionID);
+    if (!session || !session->storageManager())
</ins><span class="cx">         return completionHandler(false);
</span><span class="cx"> 
</span><span class="cx">     auto types = OptionSet<WebsiteDataType> { WebsiteDataType::LocalStorage };
</span><del>-    iterator->value->fetchData(types, [domain, completionHandler = WTFMove(completionHandler)](auto entries) mutable {
</del><ins>+    session->storageManager()->fetchData(types, [domain, completionHandler = WTFMove(completionHandler)](auto entries) mutable {
</ins><span class="cx">         completionHandler(WTF::anyOf(entries, [&domain](auto& entry) {
</span><span class="cx">             return domain.matches(entry.origin);
</span><span class="cx">         }));
</span><span class="lines">@@ -1518,12 +1499,10 @@
</span><span class="cx">     }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-    if (NetworkStorageManager::canHandleTypes(websiteDataTypes)) {
-        if (auto iterator = m_storageManagers.find(sessionID); iterator != m_storageManagers.end()) {
-            iterator->value->fetchData(websiteDataTypes, [callbackAggregator](auto entries) mutable {
-                callbackAggregator->m_websiteData.entries.appendVector(WTFMove(entries));
-            });
-        }
</del><ins>+    if (NetworkStorageManager::canHandleTypes(websiteDataTypes) && session && session->storageManager()) {
+        session->storageManager()->fetchData(websiteDataTypes, [callbackAggregator](auto entries) mutable {
+            callbackAggregator->m_websiteData.entries.appendVector(WTFMove(entries));
+        });
</ins><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -1586,10 +1565,8 @@
</span><span class="cx">         session->clearAlternativeServices(modifiedSince);
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-    if (NetworkStorageManager::canHandleTypes(websiteDataTypes)) {
-        if (auto iterator = m_storageManagers.find(sessionID); iterator != m_storageManagers.end())
-            iterator->value->deleteDataModifiedSince(websiteDataTypes, modifiedSince, [clearTasksHandler] { });
-    }
</del><ins>+    if (NetworkStorageManager::canHandleTypes(websiteDataTypes) && session && session->storageManager())
+        session->storageManager()->deleteDataModifiedSince(websiteDataTypes, modifiedSince, [clearTasksHandler] { });
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static void clearDiskCacheEntries(NetworkCache::Cache* cache, const Vector<SecurityOriginData>& origins, CompletionHandler<void()>&& completionHandler)
</span><span class="lines">@@ -1684,10 +1661,8 @@
</span><span class="cx">     }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-    if (NetworkStorageManager::canHandleTypes(websiteDataTypes)) {
-        if (auto iterator = m_storageManagers.find(sessionID); iterator != m_storageManagers.end())
-            iterator->value->deleteData(websiteDataTypes, originDatas, [clearTasksHandler] { });
-    }
</del><ins>+    if (NetworkStorageManager::canHandleTypes(websiteDataTypes) && session && session->storageManager())
+        session->storageManager()->deleteData(websiteDataTypes, originDatas, [clearTasksHandler] { });
</ins><span class="cx"> 
</span><span class="cx">     if (session) {
</span><span class="cx">         HashSet<WebCore::RegistrableDomain> domainsToDeleteNetworkDataFor;
</span><span class="lines">@@ -1887,13 +1862,11 @@
</span><span class="cx">         });
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    if (NetworkStorageManager::canHandleTypes(websiteDataTypes)) {
-        if (auto iterator = m_storageManagers.find(sessionID); iterator != m_storageManagers.end()) {
-            iterator->value->deleteDataForRegistrableDomains(websiteDataTypes, domainsToDeleteAllNonCookieWebsiteDataFor, [callbackAggregator](auto&& deletedDomains) mutable {
-                for (auto domain : deletedDomains)
-                    callbackAggregator->m_domains.add(WTFMove(domain));
-            });
-        }
</del><ins>+    if (NetworkStorageManager::canHandleTypes(websiteDataTypes) && session && session->storageManager()) {
+        session->storageManager()->deleteDataForRegistrableDomains(websiteDataTypes, domainsToDeleteAllNonCookieWebsiteDataFor, [callbackAggregator](auto&& deletedDomains) mutable {
+            for (auto domain : deletedDomains)
+                callbackAggregator->m_domains.add(WTFMove(domain));
+        });
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     auto dataTypesForUIProcess = WebsiteData::filter(websiteDataTypes, WebsiteDataProcessType::UI);
</span><span class="lines">@@ -2013,8 +1986,8 @@
</span><span class="cx">         });
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    if (auto iterator = m_storageManagers.find(sessionID); iterator != m_storageManagers.end()) {
-        iterator->value->fetchData(websiteDataTypes, [callbackAggregator](auto entries) mutable {
</del><ins>+    if (session && session->storageManager()) {
+        session->storageManager()->fetchData(websiteDataTypes, [callbackAggregator](auto entries) mutable {
</ins><span class="cx">             callbackAggregator->m_websiteData.entries.appendVector(WTFMove(entries));
</span><span class="cx">         });
</span><span class="cx">     }
</span><span class="lines">@@ -2220,13 +2193,12 @@
</span><span class="cx">         if (auto* swServer = session.swServer())
</span><span class="cx">             swServer->startSuspension([callbackAggregator] { });
</span><span class="cx"> #endif
</span><ins>+        if (auto* storageManager = session.storageManager())
+            storageManager->suspend([callbackAggregator] { });
</ins><span class="cx">     });
</span><span class="cx"> 
</span><span class="cx">     for (auto& connection : m_webProcessConnections.values())
</span><span class="cx">         connection->cleanupForSuspension([callbackAggregator] { });
</span><del>-
-    for (auto& manager : m_storageManagers.values())
-        manager->suspend([callbackAggregator] { });
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void NetworkProcess::applicationDidEnterBackground()
</span><span class="lines">@@ -2255,22 +2227,22 @@
</span><span class="cx"> #endif
</span><span class="cx">     PCM::Store::processDidResume();
</span><span class="cx"> 
</span><ins>+    forEachNetworkSession([](auto& session) {
</ins><span class="cx"> #if ENABLE(SERVICE_WORKER)
</span><del>-    forEachNetworkSession([] (auto& session) {
-        if (auto swServer = session.swServer())
</del><ins>+        if (auto* swServer = session.swServer())
</ins><span class="cx">             swServer->endSuspension();
</span><del>-    });
</del><span class="cx"> #endif
</span><span class="cx"> #if PLATFORM(IOS_FAMILY)
</span><del>-    forEachNetworkSession([](auto& session) {
</del><span class="cx">         if (auto* server = session.webIDBServer())
</span><span class="cx">             server->resume();
</span><ins>+#endif
+        if (auto* manager = session.storageManager())
+            manager->resume();
</ins><span class="cx">     });
</span><ins>+
+#if PLATFORM(IOS_FAMILY)
</ins><span class="cx">     m_shouldSuspendIDBServers = false;
</span><span class="cx"> #endif
</span><del>-
-    for (auto& manager : m_storageManagers.values())
-        manager->resume();
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void NetworkProcess::prefetchDNS(const String& hostname)
</span><span class="lines">@@ -2330,8 +2302,10 @@
</span><span class="cx"> void NetworkProcess::syncLocalStorage(CompletionHandler<void()>&& completionHandler)
</span><span class="cx"> {
</span><span class="cx">     auto aggregator = CallbackAggregator::create(WTFMove(completionHandler));
</span><del>-    for (auto& manager : m_storageManagers.values())
-        manager->syncLocalStorage([aggregator] { });
</del><ins>+    forEachNetworkSession([&](auto& session) {
+        if (auto* manager = session.storageManager())
+            manager->syncLocalStorage([aggregator] { });
+    });
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void NetworkProcess::resetQuota(PAL::SessionID sessionID, CompletionHandler<void()>&& completionHandler)
</span><span class="lines">@@ -2346,7 +2320,8 @@
</span><span class="cx"> 
</span><span class="cx"> void NetworkProcess::clearStorage(PAL::SessionID sessionID, CompletionHandler<void()>&& completionHandler)
</span><span class="cx"> {
</span><del>-    if (auto manager = m_storageManagers.get(sessionID))
</del><ins>+    auto* session = networkSession(sessionID);
+    if (auto* manager = session ? session->storageManager() : nullptr)
</ins><span class="cx">         manager->clearStorageForTesting(WTFMove(completionHandler));
</span><span class="cx">     else
</span><span class="cx">         completionHandler();
</span><span class="lines">@@ -2361,13 +2336,12 @@
</span><span class="cx">     if (oldOrigin.isEmpty() || newOrigin.isEmpty())
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    if (auto iterator = m_storageManagers.find(sessionID); iterator != m_storageManagers.end())
-        iterator->value->moveData(oldOrigin, newOrigin, [aggregator] { });
</del><ins>+    auto* session = networkSession(sessionID);
+    if (auto* manager = session ? session->storageManager() : nullptr)
+        manager->moveData(oldOrigin, newOrigin, [aggregator] { });
</ins><span class="cx"> 
</span><del>-    if (dataTypes.contains(WebsiteDataType::IndexedDBDatabases)) {
-        if (auto* session = networkSession(sessionID); session && session->hasIDBDatabasePath())
-            session->ensureWebIDBServer().renameOrigin(oldOrigin, newOrigin, [aggregator] { });
-    }
</del><ins>+    if (dataTypes.contains(WebsiteDataType::IndexedDBDatabases) && session && session->hasIDBDatabasePath())
+        session->ensureWebIDBServer().renameOrigin(oldOrigin, newOrigin, [aggregator] { });
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(SERVICE_WORKER)
</span><span class="lines">@@ -2592,10 +2566,9 @@
</span><span class="cx">     if (auto* session = networkSession(sessionID)) {
</span><span class="cx">         if (auto* server = session->webIDBServer())
</span><span class="cx">             server->removeConnection(connection);
</span><ins>+        if (auto* manager = session->storageManager())
+            manager->stopReceivingMessageFromConnection(connection);
</ins><span class="cx">     }
</span><del>-
-    if (auto manager = m_storageManagers.get(sessionID))
-        manager->stopReceivingMessageFromConnection(connection);
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> NetworkConnectionToWebProcess* NetworkProcess::webProcessConnection(ProcessIdentifier identifier) const
</span></span></pre></div>
<a id="trunkSourceWebKitNetworkProcessNetworkProcessh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/NetworkProcess/NetworkProcess.h (287190 => 287191)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/NetworkProcess/NetworkProcess.h      2021-12-17 17:13:11 UTC (rev 287190)
+++ trunk/Source/WebKit/NetworkProcess/NetworkProcess.h 2021-12-17 17:25:43 UTC (rev 287191)
</span><span class="lines">@@ -102,7 +102,6 @@
</span><span class="cx"> class NetworkProcessSupplement;
</span><span class="cx"> class NetworkProximityManager;
</span><span class="cx"> class NetworkResourceLoader;
</span><del>-class NetworkStorageManager;
</del><span class="cx"> class ProcessAssertion;
</span><span class="cx"> class WebPageNetworkParameters;
</span><span class="cx"> enum class CallDownloadDidStart : bool;
</span><span class="lines">@@ -520,9 +519,6 @@
</span><span class="cx">     void addSessionStorageQuotaManager(PAL::SessionID, uint64_t defaultQuota, uint64_t defaultThirdPartyQuota, const String& cacheRootPath, SandboxExtension::Handle&);
</span><span class="cx">     void removeSessionStorageQuotaManager(PAL::SessionID);
</span><span class="cx"> 
</span><del>-    void addStorageManagerForSession(PAL::SessionID, const String& path, SandboxExtension::Handle&, const String& localStoragePath, SandboxExtension::Handle&);
-    void removeStorageManagerForSession(PAL::SessionID);
-
</del><span class="cx">     // Connections to WebProcesses.
</span><span class="cx">     HashMap<WebCore::ProcessIdentifier, Ref<NetworkConnectionToWebProcess>> m_webProcessConnections;
</span><span class="cx"> 
</span><span class="lines">@@ -582,8 +578,6 @@
</span><span class="cx"> 
</span><span class="cx">     bool m_privateClickMeasurementEnabled { true };
</span><span class="cx">     bool m_ftpEnabled { false };
</span><del>-
-    HashMap<PAL::SessionID, Ref<NetworkStorageManager>> m_storageManagers; // FIXME: Should move to NetworkSession.
</del><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebKit
</span></span></pre></div>
<a id="trunkSourceWebKitNetworkProcessNetworkSessioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/NetworkProcess/NetworkSession.cpp (287190 => 287191)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/NetworkProcess/NetworkSession.cpp    2021-12-17 17:13:11 UTC (rev 287190)
+++ trunk/Source/WebKit/NetworkProcess/NetworkSession.cpp       2021-12-17 17:25:43 UTC (rev 287191)
</span><span class="lines">@@ -34,6 +34,7 @@
</span><span class="cx"> #include "NetworkResourceLoadParameters.h"
</span><span class="cx"> #include "NetworkResourceLoader.h"
</span><span class="cx"> #include "NetworkSessionCreationParameters.h"
</span><ins>+#include "NetworkStorageManager.h"
</ins><span class="cx"> #include "NotificationManagerMessageHandlerMessages.h"
</span><span class="cx"> #include "PingLoad.h"
</span><span class="cx"> #include "PrivateClickMeasurementClientImpl.h"
</span><span class="lines">@@ -201,6 +202,8 @@
</span><span class="cx"> #endif
</span><span class="cx">     if (auto server = std::exchange(m_webIDBServer, nullptr))
</span><span class="cx">         server->close();
</span><ins>+    if (auto manager = std::exchange(m_storageManager, nullptr))
+        manager->close();
</ins><span class="cx"> #if ASSERT_ENABLED
</span><span class="cx">     m_isInvalidated = true;
</span><span class="cx"> #endif
</span><span class="lines">@@ -560,6 +563,8 @@
</span><span class="cx">     if (m_swServer)
</span><span class="cx">         m_swServer->handleLowMemoryWarning();
</span><span class="cx"> #endif
</span><ins>+    if (m_storageManager)
+        m_storageManager->handleLowMemoryWarning();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(SERVICE_WORKER)
</span><span class="lines">@@ -684,4 +689,14 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void NetworkSession::addStorageManagerSession(const String& generalStoragePath, SandboxExtension::Handle& generalStoragePathHandle, const String& localStoragePath, SandboxExtension::Handle& localStoragePathHandle)
+{
+    if (m_storageManager)
+        return;
+
+    SandboxExtension::consumePermanently(generalStoragePathHandle);
+    SandboxExtension::consumePermanently(localStoragePathHandle);
+    m_storageManager = NetworkStorageManager::create(sessionID(), generalStoragePath, localStoragePath);
+}
+
</ins><span class="cx"> } // namespace WebKit
</span></span></pre></div>
<a id="trunkSourceWebKitNetworkProcessNetworkSessionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/NetworkProcess/NetworkSession.h (287190 => 287191)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/NetworkProcess/NetworkSession.h      2021-12-17 17:13:11 UTC (rev 287190)
+++ trunk/Source/WebKit/NetworkProcess/NetworkSession.h 2021-12-17 17:25:43 UTC (rev 287191)
</span><span class="lines">@@ -67,12 +67,13 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebKit {
</span><span class="cx"> 
</span><ins>+class NetworkBroadcastChannelRegistry;
</ins><span class="cx"> class NetworkDataTask;
</span><span class="cx"> class NetworkLoadScheduler;
</span><span class="cx"> class NetworkProcess;
</span><span class="cx"> class NetworkResourceLoader;
</span><del>-class NetworkBroadcastChannelRegistry;
</del><span class="cx"> class NetworkSocketChannel;
</span><ins>+class NetworkStorageManager;
</ins><span class="cx"> class ServiceWorkerFetchTask;
</span><span class="cx"> class WebIDBServer;
</span><span class="cx"> class WebPageNetworkParameters;
</span><span class="lines">@@ -210,6 +211,9 @@
</span><span class="cx">     void addIndexedDatabaseSession(const String& indexedDatabaseDirectory, SandboxExtension::Handle&);
</span><span class="cx">     bool hasIDBDatabasePath() const { return !m_idbDatabasePath.isEmpty(); }
</span><span class="cx"> 
</span><ins>+    NetworkStorageManager* storageManager() { return m_storageManager.get(); }
+    void addStorageManagerSession(const String& generalStoragePath, SandboxExtension::Handle& generalStoragePathHandle, const String& localStoragePath, SandboxExtension::Handle& localStoragePathHandle);
+
</ins><span class="cx">     NetworkLoadScheduler& networkLoadScheduler();
</span><span class="cx">     PCM::ManagerInterface& privateClickMeasurement() { return m_privateClickMeasurement.get(); }
</span><span class="cx">     void setPrivateClickMeasurementDebugMode(bool);
</span><span class="lines">@@ -305,6 +309,8 @@
</span><span class="cx">     String m_idbDatabasePath;
</span><span class="cx">     RefPtr<WebIDBServer> m_webIDBServer;
</span><span class="cx"> 
</span><ins>+    RefPtr<NetworkStorageManager> m_storageManager;
+
</ins><span class="cx"> #if PLATFORM(COCOA)
</span><span class="cx">     AppPrivacyReportTestingData m_appPrivacyReportTestingData;
</span><span class="cx"> #endif
</span></span></pre>
</div>
</div>

</body>
</html>