<!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>[259689] branches/safari-609-branch/Source</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/259689">259689</a></dd>
<dt>Author</dt> <dd>alancoon@apple.com</dd>
<dt>Date</dt> <dd>2020-04-07 17:32:26 -0700 (Tue, 07 Apr 2020)</dd>
</dl>

<h3>Log Message</h3>
<pre>Cherry-pick <a href="http://trac.webkit.org/projects/webkit/changeset/259316">r259316</a>. rdar://problem/61269751

    IndexedDB: destroy WebIDBServer when session is removed in network process
    https://bugs.webkit.org/show_bug.cgi?id=209606
    <rdar://problem/59310081>

    Reviewed by Geoffrey Garen.

    Source/WebCore:

    Rename immediateCloseForUserDelete to immediateClose as we now use it in destructor of IDBServer to make sure
    everything in database finishes correctly.

    * Modules/indexeddb/server/IDBServer.cpp:
    (WebCore::IDBServer::IDBServer::~IDBServer):
    (WebCore::IDBServer::IDBServer::closeAndDeleteDatabasesModifiedSince):
    (WebCore::IDBServer::IDBServer::closeAndDeleteDatabasesForOrigins):
    * Modules/indexeddb/server/UniqueIDBDatabase.cpp:
    (WebCore::IDBServer::UniqueIDBDatabase::immediateClose):
    (WebCore::IDBServer::UniqueIDBDatabase::immediateCloseForUserDelete): Deleted.
    * Modules/indexeddb/server/UniqueIDBDatabase.h:

    Source/WebKit:

    Tested manually to verify WebIDBServer is removed and its thread ends when session is removed.

    * NetworkProcess/IndexedDB/WebIDBServer.cpp:
    (WebKit::WebIDBServer::~WebIDBServer):
    (WebKit::WebIDBServer::addConnection):
    (WebKit::WebIDBServer::removeConnection):
    (WebKit::WebIDBServer::close):
    * NetworkProcess/IndexedDB/WebIDBServer.h:
    * NetworkProcess/NetworkProcess.cpp:
    (WebKit::NetworkProcess::destroySession):
    (WebKit::NetworkProcess::connectionToWebProcessClosed):

    Source/WTF:

    Add function to kill CrossThreadTaskHandler and make thread finish. Also add a callback to be called before
    thread finishes.

    * wtf/CrossThreadTaskHandler.cpp:
    (WTF::CrossThreadTaskHandler::CrossThreadTaskHandler):
    (WTF::CrossThreadTaskHandler::setCompletionCallback):
    (WTF::CrossThreadTaskHandler::kill):
    * wtf/CrossThreadTaskHandler.h:

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@259316 268f45cc-cd09-0410-ab3c-d52691b4dbfc</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari609branchSourceWTFChangeLog">branches/safari-609-branch/Source/WTF/ChangeLog</a></li>
<li><a href="#branchessafari609branchSourceWTFwtfCrossThreadTaskHandlercpp">branches/safari-609-branch/Source/WTF/wtf/CrossThreadTaskHandler.cpp</a></li>
<li><a href="#branchessafari609branchSourceWTFwtfCrossThreadTaskHandlerh">branches/safari-609-branch/Source/WTF/wtf/CrossThreadTaskHandler.h</a></li>
<li><a href="#branchessafari609branchSourceWebCoreChangeLog">branches/safari-609-branch/Source/WebCore/ChangeLog</a></li>
<li><a href="#branchessafari609branchSourceWebCoreModulesindexeddbserverIDBServercpp">branches/safari-609-branch/Source/WebCore/Modules/indexeddb/server/IDBServer.cpp</a></li>
<li><a href="#branchessafari609branchSourceWebCoreModulesindexeddbserverUniqueIDBDatabasecpp">branches/safari-609-branch/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp</a></li>
<li><a href="#branchessafari609branchSourceWebCoreModulesindexeddbserverUniqueIDBDatabaseh">branches/safari-609-branch/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.h</a></li>
<li><a href="#branchessafari609branchSourceWebKitChangeLog">branches/safari-609-branch/Source/WebKit/ChangeLog</a></li>
<li><a href="#branchessafari609branchSourceWebKitNetworkProcessIndexedDBWebIDBServercpp">branches/safari-609-branch/Source/WebKit/NetworkProcess/IndexedDB/WebIDBServer.cpp</a></li>
<li><a href="#branchessafari609branchSourceWebKitNetworkProcessIndexedDBWebIDBServerh">branches/safari-609-branch/Source/WebKit/NetworkProcess/IndexedDB/WebIDBServer.h</a></li>
<li><a href="#branchessafari609branchSourceWebKitNetworkProcessNetworkProcesscpp">branches/safari-609-branch/Source/WebKit/NetworkProcess/NetworkProcess.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari609branchSourceWTFChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-609-branch/Source/WTF/ChangeLog (259688 => 259689)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-609-branch/Source/WTF/ChangeLog  2020-04-08 00:32:13 UTC (rev 259688)
+++ branches/safari-609-branch/Source/WTF/ChangeLog     2020-04-08 00:32:26 UTC (rev 259689)
</span><span class="lines">@@ -1,3 +1,71 @@
</span><ins>+2020-04-07  Russell Epstein  <repstein@apple.com>
+
+        Cherry-pick r259316. rdar://problem/61269751
+
+    IndexedDB: destroy WebIDBServer when session is removed in network process
+    https://bugs.webkit.org/show_bug.cgi?id=209606
+    <rdar://problem/59310081>
+    
+    Reviewed by Geoffrey Garen.
+    
+    Source/WebCore:
+    
+    Rename immediateCloseForUserDelete to immediateClose as we now use it in destructor of IDBServer to make sure
+    everything in database finishes correctly.
+    
+    * Modules/indexeddb/server/IDBServer.cpp:
+    (WebCore::IDBServer::IDBServer::~IDBServer):
+    (WebCore::IDBServer::IDBServer::closeAndDeleteDatabasesModifiedSince):
+    (WebCore::IDBServer::IDBServer::closeAndDeleteDatabasesForOrigins):
+    * Modules/indexeddb/server/UniqueIDBDatabase.cpp:
+    (WebCore::IDBServer::UniqueIDBDatabase::immediateClose):
+    (WebCore::IDBServer::UniqueIDBDatabase::immediateCloseForUserDelete): Deleted.
+    * Modules/indexeddb/server/UniqueIDBDatabase.h:
+    
+    Source/WebKit:
+    
+    Tested manually to verify WebIDBServer is removed and its thread ends when session is removed.
+    
+    * NetworkProcess/IndexedDB/WebIDBServer.cpp:
+    (WebKit::WebIDBServer::~WebIDBServer):
+    (WebKit::WebIDBServer::addConnection):
+    (WebKit::WebIDBServer::removeConnection):
+    (WebKit::WebIDBServer::close):
+    * NetworkProcess/IndexedDB/WebIDBServer.h:
+    * NetworkProcess/NetworkProcess.cpp:
+    (WebKit::NetworkProcess::destroySession):
+    (WebKit::NetworkProcess::connectionToWebProcessClosed):
+    
+    Source/WTF:
+    
+    Add function to kill CrossThreadTaskHandler and make thread finish. Also add a callback to be called before
+    thread finishes.
+    
+    * wtf/CrossThreadTaskHandler.cpp:
+    (WTF::CrossThreadTaskHandler::CrossThreadTaskHandler):
+    (WTF::CrossThreadTaskHandler::setCompletionCallback):
+    (WTF::CrossThreadTaskHandler::kill):
+    * wtf/CrossThreadTaskHandler.h:
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@259316 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2020-03-31  Sihui Liu  <sihui_liu@apple.com>
+
+            IndexedDB: destroy WebIDBServer when session is removed in network process
+            https://bugs.webkit.org/show_bug.cgi?id=209606
+            <rdar://problem/59310081>
+
+            Reviewed by Geoffrey Garen.
+
+            Add function to kill CrossThreadTaskHandler and make thread finish. Also add a callback to be called before
+            thread finishes.
+
+            * wtf/CrossThreadTaskHandler.cpp:
+            (WTF::CrossThreadTaskHandler::CrossThreadTaskHandler):
+            (WTF::CrossThreadTaskHandler::setCompletionCallback):
+            (WTF::CrossThreadTaskHandler::kill):
+            * wtf/CrossThreadTaskHandler.h:
+
</ins><span class="cx"> 2020-02-20  Russell Epstein  <repstein@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Cherry-pick r256806. rdar://problem/59576023
</span></span></pre></div>
<a id="branchessafari609branchSourceWTFwtfCrossThreadTaskHandlercpp"></a>
<div class="modfile"><h4>Modified: branches/safari-609-branch/Source/WTF/wtf/CrossThreadTaskHandler.cpp (259688 => 259689)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-609-branch/Source/WTF/wtf/CrossThreadTaskHandler.cpp     2020-04-08 00:32:13 UTC (rev 259688)
+++ branches/safari-609-branch/Source/WTF/wtf/CrossThreadTaskHandler.cpp        2020-04-08 00:32:26 UTC (rev 259689)
</span><span class="lines">@@ -37,6 +37,9 @@
</span><span class="cx">     Locker<Lock> locker(m_taskThreadCreationLock);
</span><span class="cx">     Thread::create(threadName, [this] {
</span><span class="cx">         taskRunLoop();
</span><ins>+
+        if (m_completionCallback)
+            m_completionCallback();
</ins><span class="cx">     })->detach();
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -132,4 +135,15 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void CrossThreadTaskHandler::setCompletionCallback(Function<void ()>&& completionCallback)
+{
+    m_completionCallback = WTFMove(completionCallback);
+}
+
+void CrossThreadTaskHandler::kill()
+{
+    m_taskQueue.kill();
+    m_taskReplyQueue.kill();
+}
+
</ins><span class="cx"> } // namespace WTF
</span></span></pre></div>
<a id="branchessafari609branchSourceWTFwtfCrossThreadTaskHandlerh"></a>
<div class="modfile"><h4>Modified: branches/safari-609-branch/Source/WTF/wtf/CrossThreadTaskHandler.h (259688 => 259689)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-609-branch/Source/WTF/wtf/CrossThreadTaskHandler.h       2020-04-08 00:32:13 UTC (rev 259688)
+++ branches/safari-609-branch/Source/WTF/wtf/CrossThreadTaskHandler.h  2020-04-08 00:32:26 UTC (rev 259689)
</span><span class="lines">@@ -48,6 +48,9 @@
</span><span class="cx">     WTF_EXPORT_PRIVATE void suspendAndWait();
</span><span class="cx">     WTF_EXPORT_PRIVATE void resume();
</span><span class="cx"> 
</span><ins>+    WTF_EXPORT_PRIVATE void kill();
+    WTF_EXPORT_PRIVATE void setCompletionCallback(Function<void ()>&&);
+
</ins><span class="cx"> private:
</span><span class="cx">     void handleTaskRepliesOnMainThread();
</span><span class="cx">     void taskRunLoop();
</span><span class="lines">@@ -68,6 +71,8 @@
</span><span class="cx"> 
</span><span class="cx">     CrossThreadQueue<CrossThreadTask> m_taskQueue;
</span><span class="cx">     CrossThreadQueue<CrossThreadTask> m_taskReplyQueue;
</span><ins>+
+    Function<void ()> m_completionCallback;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WTF
</span></span></pre></div>
<a id="branchessafari609branchSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-609-branch/Source/WebCore/ChangeLog (259688 => 259689)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-609-branch/Source/WebCore/ChangeLog      2020-04-08 00:32:13 UTC (rev 259688)
+++ branches/safari-609-branch/Source/WebCore/ChangeLog 2020-04-08 00:32:26 UTC (rev 259689)
</span><span class="lines">@@ -1,3 +1,74 @@
</span><ins>+2020-04-07  Russell Epstein  <repstein@apple.com>
+
+        Cherry-pick r259316. rdar://problem/61269751
+
+    IndexedDB: destroy WebIDBServer when session is removed in network process
+    https://bugs.webkit.org/show_bug.cgi?id=209606
+    <rdar://problem/59310081>
+    
+    Reviewed by Geoffrey Garen.
+    
+    Source/WebCore:
+    
+    Rename immediateCloseForUserDelete to immediateClose as we now use it in destructor of IDBServer to make sure
+    everything in database finishes correctly.
+    
+    * Modules/indexeddb/server/IDBServer.cpp:
+    (WebCore::IDBServer::IDBServer::~IDBServer):
+    (WebCore::IDBServer::IDBServer::closeAndDeleteDatabasesModifiedSince):
+    (WebCore::IDBServer::IDBServer::closeAndDeleteDatabasesForOrigins):
+    * Modules/indexeddb/server/UniqueIDBDatabase.cpp:
+    (WebCore::IDBServer::UniqueIDBDatabase::immediateClose):
+    (WebCore::IDBServer::UniqueIDBDatabase::immediateCloseForUserDelete): Deleted.
+    * Modules/indexeddb/server/UniqueIDBDatabase.h:
+    
+    Source/WebKit:
+    
+    Tested manually to verify WebIDBServer is removed and its thread ends when session is removed.
+    
+    * NetworkProcess/IndexedDB/WebIDBServer.cpp:
+    (WebKit::WebIDBServer::~WebIDBServer):
+    (WebKit::WebIDBServer::addConnection):
+    (WebKit::WebIDBServer::removeConnection):
+    (WebKit::WebIDBServer::close):
+    * NetworkProcess/IndexedDB/WebIDBServer.h:
+    * NetworkProcess/NetworkProcess.cpp:
+    (WebKit::NetworkProcess::destroySession):
+    (WebKit::NetworkProcess::connectionToWebProcessClosed):
+    
+    Source/WTF:
+    
+    Add function to kill CrossThreadTaskHandler and make thread finish. Also add a callback to be called before
+    thread finishes.
+    
+    * wtf/CrossThreadTaskHandler.cpp:
+    (WTF::CrossThreadTaskHandler::CrossThreadTaskHandler):
+    (WTF::CrossThreadTaskHandler::setCompletionCallback):
+    (WTF::CrossThreadTaskHandler::kill):
+    * wtf/CrossThreadTaskHandler.h:
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@259316 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2020-03-31  Sihui Liu  <sihui_liu@apple.com>
+
+            IndexedDB: destroy WebIDBServer when session is removed in network process
+            https://bugs.webkit.org/show_bug.cgi?id=209606
+            <rdar://problem/59310081>
+
+            Reviewed by Geoffrey Garen.
+
+            Rename immediateCloseForUserDelete to immediateClose as we now use it in destructor of IDBServer to make sure
+            everything in database finishes correctly.
+
+            * Modules/indexeddb/server/IDBServer.cpp:
+            (WebCore::IDBServer::IDBServer::~IDBServer):
+            (WebCore::IDBServer::IDBServer::closeAndDeleteDatabasesModifiedSince):
+            (WebCore::IDBServer::IDBServer::closeAndDeleteDatabasesForOrigins):
+            * Modules/indexeddb/server/UniqueIDBDatabase.cpp:
+            (WebCore::IDBServer::UniqueIDBDatabase::immediateClose):
+            (WebCore::IDBServer::UniqueIDBDatabase::immediateCloseForUserDelete): Deleted.
+            * Modules/indexeddb/server/UniqueIDBDatabase.h:
+
</ins><span class="cx"> 2020-04-06  Alan Coon  <alancoon@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Cherry-pick r259538. rdar://problem/61352452
</span></span></pre></div>
<a id="branchessafari609branchSourceWebCoreModulesindexeddbserverIDBServercpp"></a>
<div class="modfile"><h4>Modified: branches/safari-609-branch/Source/WebCore/Modules/indexeddb/server/IDBServer.cpp (259688 => 259689)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-609-branch/Source/WebCore/Modules/indexeddb/server/IDBServer.cpp 2020-04-08 00:32:13 UTC (rev 259688)
+++ branches/safari-609-branch/Source/WebCore/Modules/indexeddb/server/IDBServer.cpp    2020-04-08 00:32:26 UTC (rev 259689)
</span><span class="lines">@@ -60,6 +60,9 @@
</span><span class="cx"> IDBServer::~IDBServer()
</span><span class="cx"> {
</span><span class="cx">     ASSERT(!isMainThread());
</span><ins>+
+    for (auto& database : m_uniqueIDBDatabaseMap.values())
+        database->immediateClose();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void IDBServer::registerConnection(IDBConnectionToClient& connection)
</span><span class="lines">@@ -534,7 +537,7 @@
</span><span class="cx"> 
</span><span class="cx">     HashSet<UniqueIDBDatabase*> openDatabases;
</span><span class="cx">     for (auto& database : m_uniqueIDBDatabaseMap.values())
</span><del>-        database->immediateCloseForUserDelete();
</del><ins>+        database->immediateClose();
</ins><span class="cx"> 
</span><span class="cx">     m_uniqueIDBDatabaseMap.clear();
</span><span class="cx"> 
</span><span class="lines">@@ -561,7 +564,7 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     for (auto& database : openDatabases) {
</span><del>-        database->immediateCloseForUserDelete();
</del><ins>+        database->immediateClose();
</ins><span class="cx">         m_uniqueIDBDatabaseMap.remove(database->identifier());
</span><span class="cx">     }
</span><span class="cx"> 
</span></span></pre></div>
<a id="branchessafari609branchSourceWebCoreModulesindexeddbserverUniqueIDBDatabasecpp"></a>
<div class="modfile"><h4>Modified: branches/safari-609-branch/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp (259688 => 259689)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-609-branch/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp 2020-04-08 00:32:13 UTC (rev 259688)
+++ branches/safari-609-branch/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp    2020-04-08 00:32:26 UTC (rev 259689)
</span><span class="lines">@@ -1147,9 +1147,9 @@
</span><span class="cx">         request.connection().didDeleteDatabase(result);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void UniqueIDBDatabase::immediateCloseForUserDelete()
</del><ins>+void UniqueIDBDatabase::immediateClose()
</ins><span class="cx"> {
</span><del>-    LOG(IndexedDB, "UniqueIDBDatabase::immediateCloseForUserDelete");
</del><ins>+    LOG(IndexedDB, "UniqueIDBDatabase::immediateClose");
</ins><span class="cx"> 
</span><span class="cx">     // Error out all transactions.
</span><span class="cx">     // Pending transactions must be cleared before in-progress transactions,
</span></span></pre></div>
<a id="branchessafari609branchSourceWebCoreModulesindexeddbserverUniqueIDBDatabaseh"></a>
<div class="modfile"><h4>Modified: branches/safari-609-branch/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.h (259688 => 259689)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-609-branch/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.h   2020-04-08 00:32:13 UTC (rev 259688)
+++ branches/safari-609-branch/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.h      2020-04-08 00:32:26 UTC (rev 259689)
</span><span class="lines">@@ -107,7 +107,7 @@
</span><span class="cx">     void enqueueTransaction(Ref<UniqueIDBDatabaseTransaction>&&);
</span><span class="cx"> 
</span><span class="cx">     void handleDelete(IDBConnectionToClient&, const IDBRequestData&);
</span><del>-    void immediateCloseForUserDelete();
</del><ins>+    void immediateClose();
</ins><span class="cx"> 
</span><span class="cx">     void abortActiveTransactions();
</span><span class="cx"> 
</span></span></pre></div>
<a id="branchessafari609branchSourceWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-609-branch/Source/WebKit/ChangeLog (259688 => 259689)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-609-branch/Source/WebKit/ChangeLog       2020-04-08 00:32:13 UTC (rev 259688)
+++ branches/safari-609-branch/Source/WebKit/ChangeLog  2020-04-08 00:32:26 UTC (rev 259689)
</span><span class="lines">@@ -1,5 +1,76 @@
</span><span class="cx"> 2020-04-07  Russell Epstein  <repstein@apple.com>
</span><span class="cx"> 
</span><ins>+        Cherry-pick r259316. rdar://problem/61269751
+
+    IndexedDB: destroy WebIDBServer when session is removed in network process
+    https://bugs.webkit.org/show_bug.cgi?id=209606
+    <rdar://problem/59310081>
+    
+    Reviewed by Geoffrey Garen.
+    
+    Source/WebCore:
+    
+    Rename immediateCloseForUserDelete to immediateClose as we now use it in destructor of IDBServer to make sure
+    everything in database finishes correctly.
+    
+    * Modules/indexeddb/server/IDBServer.cpp:
+    (WebCore::IDBServer::IDBServer::~IDBServer):
+    (WebCore::IDBServer::IDBServer::closeAndDeleteDatabasesModifiedSince):
+    (WebCore::IDBServer::IDBServer::closeAndDeleteDatabasesForOrigins):
+    * Modules/indexeddb/server/UniqueIDBDatabase.cpp:
+    (WebCore::IDBServer::UniqueIDBDatabase::immediateClose):
+    (WebCore::IDBServer::UniqueIDBDatabase::immediateCloseForUserDelete): Deleted.
+    * Modules/indexeddb/server/UniqueIDBDatabase.h:
+    
+    Source/WebKit:
+    
+    Tested manually to verify WebIDBServer is removed and its thread ends when session is removed.
+    
+    * NetworkProcess/IndexedDB/WebIDBServer.cpp:
+    (WebKit::WebIDBServer::~WebIDBServer):
+    (WebKit::WebIDBServer::addConnection):
+    (WebKit::WebIDBServer::removeConnection):
+    (WebKit::WebIDBServer::close):
+    * NetworkProcess/IndexedDB/WebIDBServer.h:
+    * NetworkProcess/NetworkProcess.cpp:
+    (WebKit::NetworkProcess::destroySession):
+    (WebKit::NetworkProcess::connectionToWebProcessClosed):
+    
+    Source/WTF:
+    
+    Add function to kill CrossThreadTaskHandler and make thread finish. Also add a callback to be called before
+    thread finishes.
+    
+    * wtf/CrossThreadTaskHandler.cpp:
+    (WTF::CrossThreadTaskHandler::CrossThreadTaskHandler):
+    (WTF::CrossThreadTaskHandler::setCompletionCallback):
+    (WTF::CrossThreadTaskHandler::kill):
+    * wtf/CrossThreadTaskHandler.h:
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@259316 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2020-03-31  Sihui Liu  <sihui_liu@apple.com>
+
+            IndexedDB: destroy WebIDBServer when session is removed in network process
+            https://bugs.webkit.org/show_bug.cgi?id=209606
+            <rdar://problem/59310081>
+
+            Reviewed by Geoffrey Garen.
+
+            Tested manually to verify WebIDBServer is removed and its thread ends when session is removed.
+
+            * NetworkProcess/IndexedDB/WebIDBServer.cpp:
+            (WebKit::WebIDBServer::~WebIDBServer):
+            (WebKit::WebIDBServer::addConnection):
+            (WebKit::WebIDBServer::removeConnection):
+            (WebKit::WebIDBServer::close):
+            * NetworkProcess/IndexedDB/WebIDBServer.h:
+            * NetworkProcess/NetworkProcess.cpp:
+            (WebKit::NetworkProcess::destroySession):
+            (WebKit::NetworkProcess::connectionToWebProcessClosed):
+
+2020-04-07  Russell Epstein  <repstein@apple.com>
+
</ins><span class="cx">         Cherry-pick r257222. rdar://problem/61414891
</span><span class="cx"> 
</span><span class="cx">     Protect WebProcessPool from null weak pointers in m_serviceWorkerProcesses map
</span></span></pre></div>
<a id="branchessafari609branchSourceWebKitNetworkProcessIndexedDBWebIDBServercpp"></a>
<div class="modfile"><h4>Modified: branches/safari-609-branch/Source/WebKit/NetworkProcess/IndexedDB/WebIDBServer.cpp (259688 => 259689)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-609-branch/Source/WebKit/NetworkProcess/IndexedDB/WebIDBServer.cpp       2020-04-08 00:32:13 UTC (rev 259688)
+++ branches/safari-609-branch/Source/WebKit/NetworkProcess/IndexedDB/WebIDBServer.cpp  2020-04-08 00:32:26 UTC (rev 259689)
</span><span class="lines">@@ -53,7 +53,12 @@
</span><span class="cx">     });
</span><span class="cx">     semaphore.wait();
</span><span class="cx"> }
</span><del>-    
</del><ins>+
+WebIDBServer::~WebIDBServer()
+{
+    ASSERT(RunLoop::isMain());
+}
+
</ins><span class="cx"> void WebIDBServer::closeAndDeleteDatabasesModifiedSince(WallTime modificationTime, CompletionHandler<void()>&& callback)
</span><span class="cx"> {
</span><span class="cx">     ASSERT(RunLoop::isMain());
</span><span class="lines">@@ -335,6 +340,7 @@
</span><span class="cx">         LockHolder locker(m_server->lock());
</span><span class="cx">         m_server->registerConnection(iter->value->connectionToClient());
</span><span class="cx">     });
</span><ins>+    m_connections.add(&connection);
</ins><span class="cx">     connection.addThreadMessageReceiver(Messages::WebIDBServer::messageReceiverName(), this);
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -342,6 +348,7 @@
</span><span class="cx"> {
</span><span class="cx">     ASSERT(RunLoop::isMain());
</span><span class="cx"> 
</span><ins>+    m_connections.remove(&connection);
</ins><span class="cx">     connection.removeThreadMessageReceiver(Messages::WebIDBServer::messageReceiverName());
</span><span class="cx">     postTask([this, protectedThis = makeRef(*this), connectionID = connection.uniqueID()] {
</span><span class="cx">         auto connection = m_connectionMap.take(connectionID);
</span><span class="lines">@@ -365,5 +372,26 @@
</span><span class="cx">     CrossThreadTaskHandler::postTask(CrossThreadTask(WTFMove(task)));
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WebIDBServer::close()
+{
+    ASSERT(RunLoop::isMain());
+
+    // Remove the references held by IPC::Connection.
+    for (auto* connection : m_connections)
+        connection->removeThreadMessageReceiver(Messages::WebIDBServer::messageReceiverName());
+
+    CrossThreadTaskHandler::setCompletionCallback([protectedThis = makeRef(*this)]() mutable {
+        ASSERT(!RunLoop::isMain());
+        callOnMainRunLoop([protectedThis = WTFMove(protectedThis)]() mutable { });
+    });
+
+    postTask([this]() mutable {
+        m_connectionMap.clear();
+        m_server = nullptr;
+
+        CrossThreadTaskHandler::kill();
+    });
+}
+
</ins><span class="cx"> } // namespace WebKit
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="branchessafari609branchSourceWebKitNetworkProcessIndexedDBWebIDBServerh"></a>
<div class="modfile"><h4>Modified: branches/safari-609-branch/Source/WebKit/NetworkProcess/IndexedDB/WebIDBServer.h (259688 => 259689)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-609-branch/Source/WebKit/NetworkProcess/IndexedDB/WebIDBServer.h 2020-04-08 00:32:13 UTC (rev 259688)
+++ branches/safari-609-branch/Source/WebKit/NetworkProcess/IndexedDB/WebIDBServer.h    2020-04-08 00:32:26 UTC (rev 259689)
</span><span class="lines">@@ -87,9 +87,11 @@
</span><span class="cx"> 
</span><span class="cx">     void didReceiveMessage(IPC::Connection&, IPC::Decoder&);
</span><span class="cx">     void dispatchToThread(WTF::Function<void()>&&);
</span><ins>+    void close();
</ins><span class="cx"> 
</span><span class="cx"> private:
</span><span class="cx">     WebIDBServer(PAL::SessionID, const String& directory, WebCore::IDBServer::IDBServer::StorageQuotaManagerSpaceRequester&&);
</span><ins>+    ~WebIDBServer();
</ins><span class="cx"> 
</span><span class="cx">     void postTask(WTF::Function<void()>&&);
</span><span class="cx"> 
</span><span class="lines">@@ -97,6 +99,7 @@
</span><span class="cx">     bool m_isSuspended { false };
</span><span class="cx"> 
</span><span class="cx">     HashMap<IPC::Connection::UniqueID, std::unique_ptr<WebIDBConnectionToClient>> m_connectionMap;
</span><ins>+    HashSet<IPC::Connection*> m_connections;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebKit
</span></span></pre></div>
<a id="branchessafari609branchSourceWebKitNetworkProcessNetworkProcesscpp"></a>
<div class="modfile"><h4>Modified: branches/safari-609-branch/Source/WebKit/NetworkProcess/NetworkProcess.cpp (259688 => 259689)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-609-branch/Source/WebKit/NetworkProcess/NetworkProcess.cpp       2020-04-08 00:32:13 UTC (rev 259688)
+++ branches/safari-609-branch/Source/WebKit/NetworkProcess/NetworkProcess.cpp  2020-04-08 00:32:26 UTC (rev 259689)
</span><span class="lines">@@ -578,6 +578,8 @@
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     m_storageManagerSet->remove(sessionID);
</span><ins>+    if (auto webIDBServer = m_webIDBServers.take(sessionID))
+        webIDBServer->close();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(RESOURCE_LOAD_STATISTICS)
</span><span class="lines">@@ -2544,7 +2546,8 @@
</span><span class="cx"> void NetworkProcess::connectionToWebProcessClosed(IPC::Connection& connection, PAL::SessionID sessionID)
</span><span class="cx"> {
</span><span class="cx">     m_storageManagerSet->removeConnection(connection);
</span><del>-    webIDBServer(sessionID).removeConnection(connection);
</del><ins>+    if (auto* webIDBServer = m_webIDBServers.get(sessionID))
+        webIDBServer->removeConnection(connection);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> NetworkConnectionToWebProcess* NetworkProcess::webProcessConnection(ProcessIdentifier identifier) const
</span></span></pre>
</div>
</div>

</body>
</html>