<!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>[287156] trunk/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/287156">287156</a></dd>
<dt>Author</dt> <dd>sihui_liu@apple.com</dd>
<dt>Date</dt> <dd>2021-12-16 14:00:44 -0800 (Thu, 16 Dec 2021)</dd>
</dl>

<h3>Log Message</h3>
<pre>REGRESSION (<a href="http://trac.webkit.org/projects/webkit/changeset/286601">r286601</a>): storage/filesystemaccess/sync-access-handle-read-write-worker.html and file-system-access/sandboxed_FileSystemSyncAccessHandle-truncate.https.tentative.worker.html are consistently failing
https://bugs.webkit.org/show_bug.cgi?id=234271
<rdar://problem/86434111>

Reviewed by Youenn Fablet.

Source/WebCore:

When context stops, FileSystemHandle sets its state to closed. A closed FileSystemHandle will return early on
operations including closing sync access handle (asking backend to close handle and releasing lock). If backend
thinks existing access handle is not closed, it will prevent new access handle from being created, and this
leads to the test failure.

The problem is that backend isn't notified about the close of a handle: we only set the close state in
FileSystemHandle. To fix the issue, let's make sure FileSystemStorageConnection::closeHandle is called when
context stops and when FileSystemHandle is detroyed.

* Headers.cmake:
* Modules/filesystemaccess/FileSystemDirectoryHandle.cpp:
(WebCore::FileSystemDirectoryHandle::getFileHandle):
(WebCore::FileSystemDirectoryHandle::getDirectoryHandle):
(WebCore::FileSystemDirectoryHandle::getHandle):
* Modules/filesystemaccess/FileSystemFileHandle.cpp:
(WebCore::FileSystemFileHandle::createSyncAccessHandle):
(WebCore::FileSystemFileHandle::closeSyncAccessHandle):
(WebCore::FileSystemFileHandle::close): Deleted.
* Modules/filesystemaccess/FileSystemFileHandle.h:
* Modules/filesystemaccess/FileSystemHandle.cpp:
(WebCore::FileSystemHandle::~FileSystemHandle):
(WebCore::FileSystemHandle::close):
(WebCore::FileSystemHandle::stop):
* Modules/filesystemaccess/FileSystemHandle.h:
* Modules/filesystemaccess/FileSystemHandleCloseScope.h: Added.
(WebCore::FileSystemHandleCloseScope::create):
(WebCore::FileSystemHandleCloseScope::~FileSystemHandleCloseScope):
(WebCore::FileSystemHandleCloseScope::release):
(WebCore::FileSystemHandleCloseScope::FileSystemHandleCloseScope):
* Modules/filesystemaccess/FileSystemStorageConnection.h:
* Modules/filesystemaccess/FileSystemSyncAccessHandle.cpp:
(WebCore::FileSystemSyncAccessHandle::closeBackend):
* Modules/filesystemaccess/WorkerFileSystemStorageConnection.cpp:
(WebCore::WorkerFileSystemStorageConnection::getFileHandle):
(WebCore::WorkerFileSystemStorageConnection::getDirectoryHandle):
(WebCore::WorkerFileSystemStorageConnection::didGetHandle):
(WebCore::WorkerFileSystemStorageConnection::closeSyncAccessHandle):
(WebCore::WorkerFileSystemStorageConnection::getHandle):
(WebCore::WorkerFileSystemStorageConnection::close): Deleted.
* Modules/filesystemaccess/WorkerFileSystemStorageConnection.h:
* WebCore.xcodeproj/project.pbxproj:

Source/WebKit:

* NetworkProcess/storage/FileSystemStorageHandle.cpp:
(WebKit::FileSystemStorageHandle::close):
(WebKit::FileSystemStorageHandle::closeSyncAccessHandle):
* NetworkProcess/storage/FileSystemStorageHandle.h:
* NetworkProcess/storage/FileSystemStorageManager.cpp:
(WebKit::FileSystemStorageManager::closeHandle):
* NetworkProcess/storage/NetworkStorageManager.cpp:
(WebKit::NetworkStorageManager::closeSyncAccessHandle):
(WebKit::NetworkStorageManager::closeAccessHandle): Deleted.
* NetworkProcess/storage/NetworkStorageManager.h:
* NetworkProcess/storage/NetworkStorageManager.messages.in:
* WebProcess/WebCoreSupport/WebFileSystemStorageConnection.cpp:
(WebKit::WebFileSystemStorageConnection::getFileHandle):
(WebKit::WebFileSystemStorageConnection::getDirectoryHandle):
(WebKit::WebFileSystemStorageConnection::closeSyncAccessHandle):
(WebKit::WebFileSystemStorageConnection::getHandle):
(WebKit::WebFileSystemStorageConnection::close): Deleted.
* WebProcess/WebCoreSupport/WebFileSystemStorageConnection.h:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreHeaderscmake">trunk/Source/WebCore/Headers.cmake</a></li>
<li><a href="#trunkSourceWebCoreModulesfilesystemaccessFileSystemDirectoryHandlecpp">trunk/Source/WebCore/Modules/filesystemaccess/FileSystemDirectoryHandle.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesfilesystemaccessFileSystemFileHandlecpp">trunk/Source/WebCore/Modules/filesystemaccess/FileSystemFileHandle.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesfilesystemaccessFileSystemFileHandleh">trunk/Source/WebCore/Modules/filesystemaccess/FileSystemFileHandle.h</a></li>
<li><a href="#trunkSourceWebCoreModulesfilesystemaccessFileSystemHandlecpp">trunk/Source/WebCore/Modules/filesystemaccess/FileSystemHandle.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesfilesystemaccessFileSystemHandleh">trunk/Source/WebCore/Modules/filesystemaccess/FileSystemHandle.h</a></li>
<li><a href="#trunkSourceWebCoreModulesfilesystemaccessFileSystemStorageConnectionh">trunk/Source/WebCore/Modules/filesystemaccess/FileSystemStorageConnection.h</a></li>
<li><a href="#trunkSourceWebCoreModulesfilesystemaccessFileSystemSyncAccessHandlecpp">trunk/Source/WebCore/Modules/filesystemaccess/FileSystemSyncAccessHandle.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesfilesystemaccessWorkerFileSystemStorageConnectioncpp">trunk/Source/WebCore/Modules/filesystemaccess/WorkerFileSystemStorageConnection.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesfilesystemaccessWorkerFileSystemStorageConnectionh">trunk/Source/WebCore/Modules/filesystemaccess/WorkerFileSystemStorageConnection.h</a></li>
<li><a href="#trunkSourceWebCoreWebCorexcodeprojprojectpbxproj">trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceWebKitChangeLog">trunk/Source/WebKit/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitNetworkProcessstorageFileSystemStorageHandlecpp">trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.cpp</a></li>
<li><a href="#trunkSourceWebKitNetworkProcessstorageFileSystemStorageHandleh">trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.h</a></li>
<li><a href="#trunkSourceWebKitNetworkProcessstorageFileSystemStorageManagercpp">trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageManager.cpp</a></li>
<li><a href="#trunkSourceWebKitNetworkProcessstorageNetworkStorageManagercpp">trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.cpp</a></li>
<li><a href="#trunkSourceWebKitNetworkProcessstorageNetworkStorageManagerh">trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.h</a></li>
<li><a href="#trunkSourceWebKitNetworkProcessstorageNetworkStorageManagermessagesin">trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.messages.in</a></li>
<li><a href="#trunkSourceWebKitWebProcessWebCoreSupportWebFileSystemStorageConnectioncpp">trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFileSystemStorageConnection.cpp</a></li>
<li><a href="#trunkSourceWebKitWebProcessWebCoreSupportWebFileSystemStorageConnectionh">trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFileSystemStorageConnection.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreModulesfilesystemaccessFileSystemHandleCloseScopeh">trunk/Source/WebCore/Modules/filesystemaccess/FileSystemHandleCloseScope.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (287155 => 287156)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog   2021-12-16 21:20:10 UTC (rev 287155)
+++ trunk/Source/WebCore/ChangeLog      2021-12-16 22:00:44 UTC (rev 287156)
</span><span class="lines">@@ -1,3 +1,53 @@
</span><ins>+2021-12-16  Sihui Liu  <sihui_liu@apple.com>
+
+        REGRESSION (r286601): storage/filesystemaccess/sync-access-handle-read-write-worker.html and file-system-access/sandboxed_FileSystemSyncAccessHandle-truncate.https.tentative.worker.html are consistently failing
+        https://bugs.webkit.org/show_bug.cgi?id=234271
+        <rdar://problem/86434111>
+
+        Reviewed by Youenn Fablet.
+
+        When context stops, FileSystemHandle sets its state to closed. A closed FileSystemHandle will return early on
+        operations including closing sync access handle (asking backend to close handle and releasing lock). If backend 
+        thinks existing access handle is not closed, it will prevent new access handle from being created, and this 
+        leads to the test failure.
+
+        The problem is that backend isn't notified about the close of a handle: we only set the close state in 
+        FileSystemHandle. To fix the issue, let's make sure FileSystemStorageConnection::closeHandle is called when 
+        context stops and when FileSystemHandle is detroyed.
+
+        * Headers.cmake:
+        * Modules/filesystemaccess/FileSystemDirectoryHandle.cpp:
+        (WebCore::FileSystemDirectoryHandle::getFileHandle):
+        (WebCore::FileSystemDirectoryHandle::getDirectoryHandle):
+        (WebCore::FileSystemDirectoryHandle::getHandle):
+        * Modules/filesystemaccess/FileSystemFileHandle.cpp:
+        (WebCore::FileSystemFileHandle::createSyncAccessHandle):
+        (WebCore::FileSystemFileHandle::closeSyncAccessHandle):
+        (WebCore::FileSystemFileHandle::close): Deleted.
+        * Modules/filesystemaccess/FileSystemFileHandle.h:
+        * Modules/filesystemaccess/FileSystemHandle.cpp:
+        (WebCore::FileSystemHandle::~FileSystemHandle):
+        (WebCore::FileSystemHandle::close):
+        (WebCore::FileSystemHandle::stop):
+        * Modules/filesystemaccess/FileSystemHandle.h:
+        * Modules/filesystemaccess/FileSystemHandleCloseScope.h: Added.
+        (WebCore::FileSystemHandleCloseScope::create):
+        (WebCore::FileSystemHandleCloseScope::~FileSystemHandleCloseScope):
+        (WebCore::FileSystemHandleCloseScope::release):
+        (WebCore::FileSystemHandleCloseScope::FileSystemHandleCloseScope):
+        * Modules/filesystemaccess/FileSystemStorageConnection.h:
+        * Modules/filesystemaccess/FileSystemSyncAccessHandle.cpp:
+        (WebCore::FileSystemSyncAccessHandle::closeBackend):
+        * Modules/filesystemaccess/WorkerFileSystemStorageConnection.cpp:
+        (WebCore::WorkerFileSystemStorageConnection::getFileHandle):
+        (WebCore::WorkerFileSystemStorageConnection::getDirectoryHandle):
+        (WebCore::WorkerFileSystemStorageConnection::didGetHandle):
+        (WebCore::WorkerFileSystemStorageConnection::closeSyncAccessHandle):
+        (WebCore::WorkerFileSystemStorageConnection::getHandle):
+        (WebCore::WorkerFileSystemStorageConnection::close): Deleted.
+        * Modules/filesystemaccess/WorkerFileSystemStorageConnection.h:
+        * WebCore.xcodeproj/project.pbxproj:
+
</ins><span class="cx"> 2021-12-16  Adrian Perez de Castro  <aperez@igalia.com>
</span><span class="cx"> 
</span><span class="cx">         Non-unified build fixes, late-ish December 2021 edition
</span></span></pre></div>
<a id="trunkSourceWebCoreHeaderscmake"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Headers.cmake (287155 => 287156)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Headers.cmake       2021-12-16 21:20:10 UTC (rev 287155)
+++ trunk/Source/WebCore/Headers.cmake  2021-12-16 22:00:44 UTC (rev 287156)
</span><span class="lines">@@ -172,6 +172,7 @@
</span><span class="cx">     Modules/filesystemaccess/FileSystemDirectoryHandle.h
</span><span class="cx">     Modules/filesystemaccess/FileSystemFileHandle.h
</span><span class="cx">     Modules/filesystemaccess/FileSystemHandle.h
</span><ins>+    Modules/filesystemaccess/FileSystemHandleCloseScope.h
</ins><span class="cx">     Modules/filesystemaccess/FileSystemHandleIdentifier.h
</span><span class="cx">     Modules/filesystemaccess/FileSystemStorageConnection.h
</span><span class="cx">     Modules/filesystemaccess/FileSystemSyncAccessHandle.h
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesfilesystemaccessFileSystemDirectoryHandlecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/filesystemaccess/FileSystemDirectoryHandle.cpp (287155 => 287156)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/filesystemaccess/FileSystemDirectoryHandle.cpp      2021-12-16 21:20:10 UTC (rev 287155)
+++ trunk/Source/WebCore/Modules/filesystemaccess/FileSystemDirectoryHandle.cpp 2021-12-16 22:00:44 UTC (rev 287156)
</span><span class="lines">@@ -26,6 +26,7 @@
</span><span class="cx"> #include "config.h"
</span><span class="cx"> #include "FileSystemDirectoryHandle.h"
</span><span class="cx"> 
</span><ins>+#include "FileSystemHandleCloseScope.h"
</ins><span class="cx"> #include "FileSystemStorageConnection.h"
</span><span class="cx"> #include "JSDOMPromiseDeferred.h"
</span><span class="cx"> #include "JSFileSystemDirectoryHandle.h"
</span><span class="lines">@@ -56,14 +57,13 @@
</span><span class="cx">         if (result.hasException())
</span><span class="cx">             return promise.reject(result.releaseException());
</span><span class="cx"> 
</span><del>-        auto identifier = result.returnValue();
</del><span class="cx">         auto* context = weakThis ? weakThis->scriptExecutionContext() : nullptr;
</span><del>-        if (!context) {
-            connection->closeHandle(identifier);
</del><ins>+        if (!context)
</ins><span class="cx">             return promise.reject(Exception { InvalidStateError, "Context has stopped"_s });
</span><del>-        }
</del><span class="cx"> 
</span><del>-        promise.resolve(FileSystemFileHandle::create(*context, String { name }, result.returnValue(), WTFMove(connection)));
</del><ins>+        auto [identifier, isDirectory] = result.returnValue()->release();
+        ASSERT(!isDirectory);
+        promise.resolve(FileSystemFileHandle::create(*context, String { name }, identifier, WTFMove(connection)));
</ins><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -77,13 +77,12 @@
</span><span class="cx">         if (result.hasException())
</span><span class="cx">             return promise.reject(result.releaseException());
</span><span class="cx"> 
</span><del>-        auto identifier = result.returnValue();
</del><span class="cx">         auto* context = weakThis ? weakThis->scriptExecutionContext() : nullptr;
</span><del>-        if (!context) {
-            connection->closeHandle(identifier);
</del><ins>+        if (!context)
</ins><span class="cx">             return promise.reject(Exception { InvalidStateError, "Context has stopped"_s });
</span><del>-        }
</del><span class="cx"> 
</span><ins>+        auto [identifier, isDirectory] = result.returnValue()->release();
+        ASSERT(isDirectory);
</ins><span class="cx">         promise.resolve(FileSystemDirectoryHandle::create(*context, String { name }, identifier, WTFMove(connection)));
</span><span class="cx">     });
</span><span class="cx"> }
</span><span class="lines">@@ -126,12 +125,10 @@
</span><span class="cx">         if (result.hasException())
</span><span class="cx">             return completionHandler(result.releaseException());
</span><span class="cx"> 
</span><del>-        auto [identifier, isDirectory] = result.releaseReturnValue();
</del><ins>+        auto [identifier, isDirectory] = result.returnValue()->release();
</ins><span class="cx">         auto* context = weakThis ? weakThis->scriptExecutionContext() : nullptr;
</span><del>-        if (!context) {
-            connection->closeHandle(identifier);
</del><ins>+        if (!context)
</ins><span class="cx">             return completionHandler(Exception { InvalidStateError, "Context has stopped"_s });
</span><del>-        }
</del><span class="cx"> 
</span><span class="cx">         if (isDirectory) {
</span><span class="cx">             Ref<FileSystemHandle> handle = FileSystemDirectoryHandle::create(*context, String { name }, identifier, WTFMove(connection));
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesfilesystemaccessFileSystemFileHandlecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/filesystemaccess/FileSystemFileHandle.cpp (287155 => 287156)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/filesystemaccess/FileSystemFileHandle.cpp   2021-12-16 21:20:10 UTC (rev 287155)
+++ trunk/Source/WebCore/Modules/filesystemaccess/FileSystemFileHandle.cpp      2021-12-16 22:00:44 UTC (rev 287156)
</span><span class="lines">@@ -27,6 +27,7 @@
</span><span class="cx"> #include "FileSystemFileHandle.h"
</span><span class="cx"> 
</span><span class="cx"> #include "File.h"
</span><ins>+#include "FileSystemHandleCloseScope.h"
</ins><span class="cx"> #include "FileSystemStorageConnection.h"
</span><span class="cx"> #include "FileSystemSyncAccessHandle.h"
</span><span class="cx"> #include "JSDOMPromiseDeferred.h"
</span><span class="lines">@@ -82,7 +83,7 @@
</span><span class="cx">         auto* context = protectedThis->scriptExecutionContext();
</span><span class="cx">         if (!context) {
</span><span class="cx">             FileSystem::closeFile(file);
</span><del>-            protectedThis->close(identifier, { });
</del><ins>+            protectedThis->closeSyncAccessHandle(identifier, { });
</ins><span class="cx">             return promise.reject(Exception { InvalidStateError, "Context has stopped"_s });
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="lines">@@ -90,12 +91,12 @@
</span><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void FileSystemFileHandle::close(FileSystemSyncAccessHandleIdentifier accessHandleIdentifier, CompletionHandler<void(ExceptionOr<void>&&)>&& completionHandler)
</del><ins>+void FileSystemFileHandle::closeSyncAccessHandle(FileSystemSyncAccessHandleIdentifier accessHandleIdentifier, CompletionHandler<void(ExceptionOr<void>&&)>&& completionHandler)
</ins><span class="cx"> {
</span><span class="cx">     if (isClosed())
</span><span class="cx">         return completionHandler(Exception { InvalidStateError, "Handle is closed"_s });
</span><span class="cx"> 
</span><del>-    connection().close(identifier(), accessHandleIdentifier, WTFMove(completionHandler));
</del><ins>+    connection().closeSyncAccessHandle(identifier(), accessHandleIdentifier, WTFMove(completionHandler));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void FileSystemFileHandle::registerSyncAccessHandle(FileSystemSyncAccessHandleIdentifier identifier, FileSystemSyncAccessHandle& handle)
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesfilesystemaccessFileSystemFileHandleh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/filesystemaccess/FileSystemFileHandle.h (287155 => 287156)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/filesystemaccess/FileSystemFileHandle.h     2021-12-16 21:20:10 UTC (rev 287155)
+++ trunk/Source/WebCore/Modules/filesystemaccess/FileSystemFileHandle.h        2021-12-16 22:00:44 UTC (rev 287156)
</span><span class="lines">@@ -41,7 +41,7 @@
</span><span class="cx">     void getFile(DOMPromiseDeferred<IDLInterface<File>>&&);
</span><span class="cx"> 
</span><span class="cx">     void createSyncAccessHandle(DOMPromiseDeferred<IDLInterface<FileSystemSyncAccessHandle>>&&);
</span><del>-    void close(FileSystemSyncAccessHandleIdentifier, CompletionHandler<void(ExceptionOr<void>&&)>&&);
</del><ins>+    void closeSyncAccessHandle(FileSystemSyncAccessHandleIdentifier, CompletionHandler<void(ExceptionOr<void>&&)>&&);
</ins><span class="cx">     void registerSyncAccessHandle(FileSystemSyncAccessHandleIdentifier, FileSystemSyncAccessHandle&);
</span><span class="cx">     void unregisterSyncAccessHandle(FileSystemSyncAccessHandleIdentifier);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesfilesystemaccessFileSystemHandlecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/filesystemaccess/FileSystemHandle.cpp (287155 => 287156)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/filesystemaccess/FileSystemHandle.cpp       2021-12-16 21:20:10 UTC (rev 287155)
+++ trunk/Source/WebCore/Modules/filesystemaccess/FileSystemHandle.cpp  2021-12-16 22:00:44 UTC (rev 287156)
</span><span class="lines">@@ -44,8 +44,20 @@
</span><span class="cx">     suspendIfNeeded();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-FileSystemHandle::~FileSystemHandle() = default;
</del><ins>+FileSystemHandle::~FileSystemHandle()
+{
+    close();
+}
</ins><span class="cx"> 
</span><ins>+void FileSystemHandle::close()
+{
+    if (m_isClosed)
+        return;
+    
+    m_isClosed = true;
+    m_connection->closeHandle(m_identifier);
+}
+
</ins><span class="cx"> void FileSystemHandle::isSameEntry(FileSystemHandle& handle, DOMPromiseDeferred<IDLBoolean>&& promise) const
</span><span class="cx"> {
</span><span class="cx">     if (isClosed())
</span><span class="lines">@@ -82,7 +94,7 @@
</span><span class="cx"> 
</span><span class="cx"> void FileSystemHandle::stop()
</span><span class="cx"> {
</span><del>-    m_isClosed = true;
</del><ins>+    close();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesfilesystemaccessFileSystemHandleh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/filesystemaccess/FileSystemHandle.h (287155 => 287156)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/filesystemaccess/FileSystemHandle.h 2021-12-16 21:20:10 UTC (rev 287155)
+++ trunk/Source/WebCore/Modules/filesystemaccess/FileSystemHandle.h    2021-12-16 22:00:44 UTC (rev 287156)
</span><span class="lines">@@ -36,7 +36,7 @@
</span><span class="cx"> 
</span><span class="cx"> class FileSystemStorageConnection;
</span><span class="cx"> 
</span><del>-class FileSystemHandle : public ActiveDOMObject, public CanMakeWeakPtr<FileSystemHandle>, public RefCounted<FileSystemHandle> {
</del><ins>+class FileSystemHandle : public ActiveDOMObject, public CanMakeWeakPtr<FileSystemHandle>, public ThreadSafeRefCounted<FileSystemHandle> {
</ins><span class="cx">     WTF_MAKE_ISO_ALLOCATED(FileSystemHandle);
</span><span class="cx"> public:
</span><span class="cx">     virtual ~FileSystemHandle();
</span><span class="lines">@@ -49,6 +49,7 @@
</span><span class="cx">     const String& name() const { return m_name; }
</span><span class="cx">     FileSystemHandleIdentifier identifier() const { return m_identifier; }
</span><span class="cx">     bool isClosed() const { return m_isClosed; }
</span><ins>+    void close();
</ins><span class="cx"> 
</span><span class="cx">     void isSameEntry(FileSystemHandle&, DOMPromiseDeferred<IDLBoolean>&&) const;
</span><span class="cx">     void move(FileSystemHandle&, const String& newName, DOMPromiseDeferred<void>&&);
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesfilesystemaccessFileSystemHandleCloseScopehfromrev287154trunkSourceWebCoreModulesfilesystemaccessFileSystemHandleh"></a>
<div class="copfile"><h4>Copied: trunk/Source/WebCore/Modules/filesystemaccess/FileSystemHandleCloseScope.h (from rev 287154, trunk/Source/WebCore/Modules/filesystemaccess/FileSystemHandle.h) (0 => 287156)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/filesystemaccess/FileSystemHandleCloseScope.h                               (rev 0)
+++ trunk/Source/WebCore/Modules/filesystemaccess/FileSystemHandleCloseScope.h  2021-12-16 22:00:44 UTC (rev 287156)
</span><span class="lines">@@ -0,0 +1,70 @@
</span><ins>+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "FileSystemStorageConnection.h"
+#include <wtf/RunLoop.h>
+
+namespace WebCore {
+
+class FileSystemHandleCloseScope : public ThreadSafeRefCounted<FileSystemHandleCloseScope, WTF::DestructionThread::MainRunLoop> {
+public:
+    static Ref<FileSystemHandleCloseScope> create(FileSystemHandleIdentifier identifier, bool isDirectory, FileSystemStorageConnection& connection)
+    {
+        return adoptRef(*new FileSystemHandleCloseScope(identifier, isDirectory, connection));
+    }
+
+    ~FileSystemHandleCloseScope()
+    {
+        ASSERT(RunLoop::isMain());
+
+        if (m_identifier.isValid())
+            m_connection->closeHandle(m_identifier);
+    }
+
+    std::pair<FileSystemHandleIdentifier, bool> release()
+    {
+        Locker locker { m_lock };
+        ASSERT_WITH_MESSAGE(m_identifier.isValid(), "FileSystemHandleCloseScope should not be released more than once");
+        return { std::exchange(m_identifier, { }), m_isDirectory };
+    }
+
+private:
+    FileSystemHandleCloseScope(FileSystemHandleIdentifier identifer, bool isDirectory, FileSystemStorageConnection& connection)
+        : m_identifier(identifer)
+        , m_isDirectory(isDirectory)
+        , m_connection(Ref { connection })
+    {
+        ASSERT(RunLoop::isMain());
+    }
+
+    Lock m_lock;
+    FileSystemHandleIdentifier m_identifier WTF_GUARDED_BY_LOCK(m_lock);
+    bool m_isDirectory;
+    Ref<FileSystemStorageConnection> m_connection;
+};
+
+} // namespace WebCore
</ins></span></pre></div>
<a id="trunkSourceWebCoreModulesfilesystemaccessFileSystemStorageConnectionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/filesystemaccess/FileSystemStorageConnection.h (287155 => 287156)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/filesystemaccess/FileSystemStorageConnection.h      2021-12-16 21:20:10 UTC (rev 287155)
+++ trunk/Source/WebCore/Modules/filesystemaccess/FileSystemStorageConnection.h 2021-12-16 22:00:44 UTC (rev 287156)
</span><span class="lines">@@ -37,6 +37,7 @@
</span><span class="cx"> 
</span><span class="cx"> class FileSystemDirectoryHandle;
</span><span class="cx"> class FileSystemFileHandle;
</span><ins>+class FileSystemHandleCloseScope;
</ins><span class="cx"> class FileSystemSyncAccessHandle;
</span><span class="cx"> template<typename> class ExceptionOr;
</span><span class="cx"> 
</span><span class="lines">@@ -45,7 +46,7 @@
</span><span class="cx">     virtual ~FileSystemStorageConnection() { }
</span><span class="cx"> 
</span><span class="cx">     using SameEntryCallback = CompletionHandler<void(ExceptionOr<bool>&&)>;
</span><del>-    using GetHandleCallback = CompletionHandler<void(ExceptionOr<FileSystemHandleIdentifier>&&)>;
</del><ins>+    using GetHandleCallback = CompletionHandler<void(ExceptionOr<Ref<FileSystemHandleCloseScope>>&&)>;
</ins><span class="cx">     using ResolveCallback = CompletionHandler<void(ExceptionOr<Vector<String>>&&)>;
</span><span class="cx">     using GetAccessHandleCallback = CompletionHandler<void(ExceptionOr<std::pair<FileSystemSyncAccessHandleIdentifier, FileSystem::PlatformFileHandle>>&&)>;
</span><span class="cx">     using VoidCallback = CompletionHandler<void(ExceptionOr<void>&&)>;
</span><span class="lines">@@ -63,12 +64,12 @@
</span><span class="cx">     virtual void resolve(FileSystemHandleIdentifier, FileSystemHandleIdentifier, ResolveCallback&&) = 0;
</span><span class="cx">     virtual void getFile(FileSystemHandleIdentifier, StringCallback&&) = 0;
</span><span class="cx">     virtual void createSyncAccessHandle(FileSystemHandleIdentifier, GetAccessHandleCallback&&) = 0;
</span><del>-    virtual void close(FileSystemHandleIdentifier, FileSystemSyncAccessHandleIdentifier, VoidCallback&&) = 0;
</del><ins>+    virtual void closeSyncAccessHandle(FileSystemHandleIdentifier, FileSystemSyncAccessHandleIdentifier, VoidCallback&&) = 0;
</ins><span class="cx">     virtual void registerSyncAccessHandle(FileSystemSyncAccessHandleIdentifier, ScriptExecutionContextIdentifier) = 0;
</span><span class="cx">     virtual void unregisterSyncAccessHandle(FileSystemSyncAccessHandleIdentifier) = 0;
</span><span class="cx">     virtual void invalidateAccessHandle(WebCore::FileSystemSyncAccessHandleIdentifier) = 0;
</span><span class="cx">     virtual void getHandleNames(FileSystemHandleIdentifier, GetHandleNamesCallback&&) = 0;
</span><del>-    virtual void getHandle(FileSystemHandleIdentifier, const String& name, GetHandleWithTypeCallback&&) = 0;
</del><ins>+    virtual void getHandle(FileSystemHandleIdentifier, const String& name, GetHandleCallback&&) = 0;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesfilesystemaccessFileSystemSyncAccessHandlecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/filesystemaccess/FileSystemSyncAccessHandle.cpp (287155 => 287156)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/filesystemaccess/FileSystemSyncAccessHandle.cpp     2021-12-16 21:20:10 UTC (rev 287155)
+++ trunk/Source/WebCore/Modules/filesystemaccess/FileSystemSyncAccessHandle.cpp        2021-12-16 22:00:44 UTC (rev 287156)
</span><span class="lines">@@ -181,13 +181,13 @@
</span><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     if (mode == CloseMode::Async) {
</span><del>-        m_source->close(m_identifier, [this, protectedThis = Ref { *this }](auto result) mutable {
</del><ins>+        m_source->closeSyncAccessHandle(m_identifier, [this, protectedThis = Ref { *this }](auto result) mutable {
</ins><span class="cx">             didCloseBackend(WTFMove(result));
</span><span class="cx">         });
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    m_source->close(m_identifier, [](auto) { });
</del><ins>+    m_source->closeSyncAccessHandle(m_identifier, [](auto) { });
</ins><span class="cx">     didCloseBackend({ });
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesfilesystemaccessWorkerFileSystemStorageConnectioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/filesystemaccess/WorkerFileSystemStorageConnection.cpp (287155 => 287156)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/filesystemaccess/WorkerFileSystemStorageConnection.cpp      2021-12-16 21:20:10 UTC (rev 287155)
+++ trunk/Source/WebCore/Modules/filesystemaccess/WorkerFileSystemStorageConnection.cpp 2021-12-16 22:00:44 UTC (rev 287156)
</span><span class="lines">@@ -26,6 +26,7 @@
</span><span class="cx"> #include "config.h"
</span><span class="cx"> #include "WorkerFileSystemStorageConnection.h"
</span><span class="cx"> 
</span><ins>+#include "FileSystemHandleCloseScope.h"
</ins><span class="cx"> #include "FileSystemSyncAccessHandle.h"
</span><span class="cx"> #include "WorkerGlobalScope.h"
</span><span class="cx"> #include "WorkerLoaderProxy.h"
</span><span class="lines">@@ -128,7 +129,8 @@
</span><span class="cx"> 
</span><span class="cx">     callOnMainThread([callbackIdentifier, workerThread = Ref { m_scope->thread() }, mainThreadConnection = m_mainThreadConnection, identifier, name = name.isolatedCopy(), createIfNecessary]() mutable {
</span><span class="cx">         auto mainThreadCallback = [callbackIdentifier, workerThread = WTFMove(workerThread)](auto result) mutable {
</span><del>-            workerThread->runLoop().postTaskForMode([callbackIdentifier, result = crossThreadCopy(result)] (auto& scope) mutable {
</del><ins>+            auto crossThreadResult = result.hasException() ? ExceptionOr<Ref<FileSystemHandleCloseScope>> { crossThreadCopy(result.exception()) } : ExceptionOr<Ref<FileSystemHandleCloseScope>> { result.releaseReturnValue() };
+            workerThread->runLoop().postTaskForMode([callbackIdentifier, result = WTFMove(crossThreadResult)] (auto& scope) mutable {
</ins><span class="cx">                 if (auto connection = downcast<WorkerGlobalScope>(scope).fileSystemStorageConnection())
</span><span class="cx">                     connection->didGetHandle(callbackIdentifier, WTFMove(result));
</span><span class="cx">             }, WorkerRunLoop::defaultMode());
</span><span class="lines">@@ -148,7 +150,8 @@
</span><span class="cx"> 
</span><span class="cx">     callOnMainThread([callbackIdentifier, workerThread = Ref { m_scope->thread() }, mainThreadConnection = m_mainThreadConnection, identifier, name = name.isolatedCopy(), createIfNecessary]() mutable {
</span><span class="cx">         auto mainThreadCallback = [callbackIdentifier, workerThread = WTFMove(workerThread)](auto result) mutable {
</span><del>-            workerThread->runLoop().postTaskForMode([callbackIdentifier, result = crossThreadCopy(result)] (auto& scope) mutable {
</del><ins>+            auto crossThreadResult = result.hasException() ? ExceptionOr<Ref<FileSystemHandleCloseScope>> { crossThreadCopy(result.exception()) } : ExceptionOr<Ref<FileSystemHandleCloseScope>> { result.releaseReturnValue() };
+            workerThread->runLoop().postTaskForMode([callbackIdentifier, result = WTFMove(crossThreadResult)] (auto& scope) mutable {
</ins><span class="cx">                 if (auto connection = downcast<WorkerGlobalScope>(scope).fileSystemStorageConnection())
</span><span class="cx">                     connection->didGetHandle(callbackIdentifier, WTFMove(result));
</span><span class="cx">             }, WorkerRunLoop::defaultMode());
</span><span class="lines">@@ -158,7 +161,7 @@
</span><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void WorkerFileSystemStorageConnection::didGetHandle(CallbackIdentifier callbackIdentifier, ExceptionOr<FileSystemHandleIdentifier>&& result)
</del><ins>+void WorkerFileSystemStorageConnection::didGetHandle(CallbackIdentifier callbackIdentifier, ExceptionOr<Ref<FileSystemHandleCloseScope>>&& result)
</ins><span class="cx"> {
</span><span class="cx">     if (auto callback = m_getHandleCallbacks.take(callbackIdentifier))
</span><span class="cx">         callback(WTFMove(result));
</span><span class="lines">@@ -271,7 +274,7 @@
</span><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void WorkerFileSystemStorageConnection::close(FileSystemHandleIdentifier identifier, FileSystemSyncAccessHandleIdentifier accessHandleIdentifier, FileSystemStorageConnection::VoidCallback&& callback)
</del><ins>+void WorkerFileSystemStorageConnection::closeSyncAccessHandle(FileSystemHandleIdentifier identifier, FileSystemSyncAccessHandleIdentifier accessHandleIdentifier, FileSystemStorageConnection::VoidCallback&& callback)
</ins><span class="cx"> {
</span><span class="cx">     if (!m_scope)
</span><span class="cx">         return callback(Exception { InvalidStateError });
</span><span class="lines">@@ -287,7 +290,7 @@
</span><span class="cx">             }, WorkerRunLoop::defaultMode());
</span><span class="cx">         };
</span><span class="cx"> 
</span><del>-        mainThreadConnection->close(identifier, accessHandleIdentifier, WTFMove(mainThreadCallback));
</del><ins>+        mainThreadConnection->closeSyncAccessHandle(identifier, accessHandleIdentifier, WTFMove(mainThreadCallback));
</ins><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -342,19 +345,20 @@
</span><span class="cx">         callback(WTFMove(result));
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void WorkerFileSystemStorageConnection::getHandle(FileSystemHandleIdentifier identifier, const String& name, GetHandleWithTypeCallback&& callback)
</del><ins>+void WorkerFileSystemStorageConnection::getHandle(FileSystemHandleIdentifier identifier, const String& name, GetHandleCallback&& callback)
</ins><span class="cx"> {
</span><span class="cx">     if (!m_scope)
</span><span class="cx">         return callback(Exception { InvalidStateError });
</span><span class="cx"> 
</span><span class="cx">     auto callbackIdentifier = CallbackIdentifier::generateThreadSafe();
</span><del>-    m_getHandleWithTypeCallbacks.add(callbackIdentifier, WTFMove(callback));
</del><ins>+    m_getHandleCallbacks.add(callbackIdentifier, WTFMove(callback));
</ins><span class="cx"> 
</span><span class="cx">     callOnMainThread([callbackIdentifier, workerThread = Ref { m_scope->thread() }, mainThreadConnection = m_mainThreadConnection, identifier, name = name.isolatedCopy()]() mutable {
</span><span class="cx">         auto mainThreadCallback = [callbackIdentifier, workerThread = WTFMove(workerThread)](auto result) mutable {
</span><del>-            workerThread->runLoop().postTaskForMode([callbackIdentifier, result = crossThreadCopy(result)] (auto& scope) mutable {
</del><ins>+            auto crossThreadResult = result.hasException() ? ExceptionOr<Ref<FileSystemHandleCloseScope>> { crossThreadCopy(result.exception()) } : ExceptionOr<Ref<FileSystemHandleCloseScope>> { result.releaseReturnValue() };
+            workerThread->runLoop().postTaskForMode([callbackIdentifier, result = WTFMove(crossThreadResult)] (auto& scope) mutable {
</ins><span class="cx">                 if (auto connection = downcast<WorkerGlobalScope>(scope).fileSystemStorageConnection())
</span><del>-                    connection->didGetHandleWithType(callbackIdentifier, WTFMove(result));
</del><ins>+                    connection->didGetHandle(callbackIdentifier, WTFMove(result));
</ins><span class="cx">             }, WorkerRunLoop::defaultMode());
</span><span class="cx">         };
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesfilesystemaccessWorkerFileSystemStorageConnectionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/filesystemaccess/WorkerFileSystemStorageConnection.h (287155 => 287156)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/filesystemaccess/WorkerFileSystemStorageConnection.h        2021-12-16 21:20:10 UTC (rev 287155)
+++ trunk/Source/WebCore/Modules/filesystemaccess/WorkerFileSystemStorageConnection.h   2021-12-16 22:00:44 UTC (rev 287156)
</span><span class="lines">@@ -47,7 +47,7 @@
</span><span class="cx">     void registerSyncAccessHandle(FileSystemSyncAccessHandleIdentifier, FileSystemSyncAccessHandle&);
</span><span class="cx">     using CallbackIdentifier = WorkerFileSystemStorageConnectionCallbackIdentifier;
</span><span class="cx">     void didIsSameEntry(CallbackIdentifier, ExceptionOr<bool>&&);
</span><del>-    void didGetHandle(CallbackIdentifier, ExceptionOr<FileSystemHandleIdentifier>&&);
</del><ins>+    void didGetHandle(CallbackIdentifier, ExceptionOr<Ref<FileSystemHandleCloseScope>>&&);
</ins><span class="cx">     void didResolve(CallbackIdentifier, ExceptionOr<Vector<String>>&&);
</span><span class="cx">     void completeStringCallback(CallbackIdentifier, ExceptionOr<String>&&);
</span><span class="cx">     void didCreateSyncAccessHandle(CallbackIdentifier, ExceptionOr<std::pair<FileSystemSyncAccessHandleIdentifier, FileSystem::PlatformFileHandle>>&&);
</span><span class="lines">@@ -68,10 +68,10 @@
</span><span class="cx">     void removeEntry(FileSystemHandleIdentifier, const String& name, bool deleteRecursively, FileSystemStorageConnection::VoidCallback&&) final;
</span><span class="cx">     void resolve(FileSystemHandleIdentifier, FileSystemHandleIdentifier, FileSystemStorageConnection::ResolveCallback&&) final;
</span><span class="cx">     void getHandleNames(FileSystemHandleIdentifier, GetHandleNamesCallback&&) final;
</span><del>-    void getHandle(FileSystemHandleIdentifier, const String& name, GetHandleWithTypeCallback&&) final;
</del><ins>+    void getHandle(FileSystemHandleIdentifier, const String& name, GetHandleCallback&&) final;
</ins><span class="cx">     void getFile(FileSystemHandleIdentifier, StringCallback&&) final;
</span><span class="cx">     void createSyncAccessHandle(FileSystemHandleIdentifier, FileSystemStorageConnection::GetAccessHandleCallback&&) final;
</span><del>-    void close(FileSystemHandleIdentifier, FileSystemSyncAccessHandleIdentifier, FileSystemStorageConnection::VoidCallback&&) final;
</del><ins>+    void closeSyncAccessHandle(FileSystemHandleIdentifier, FileSystemSyncAccessHandleIdentifier, FileSystemStorageConnection::VoidCallback&&) final;
</ins><span class="cx">     void registerSyncAccessHandle(FileSystemSyncAccessHandleIdentifier, ScriptExecutionContextIdentifier) final { };
</span><span class="cx">     void unregisterSyncAccessHandle(FileSystemSyncAccessHandleIdentifier) final;
</span><span class="cx">     void invalidateAccessHandle(FileSystemSyncAccessHandleIdentifier) final;
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (287155 => 287156)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj   2021-12-16 21:20:10 UTC (rev 287155)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj      2021-12-16 22:00:44 UTC (rev 287156)
</span><span class="lines">@@ -2901,6 +2901,7 @@
</span><span class="cx">          93443E8626E995BD0058538F /* FileSystemDirectoryHandle.h in Headers */ = {isa = PBXBuildFile; fileRef = 932C9BD426DD625A0053B3DB /* FileSystemDirectoryHandle.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">          93443E8726E995C00058538F /* FileSystemFileHandle.h in Headers */ = {isa = PBXBuildFile; fileRef = 932C9BD626DD625C0053B3DB /* FileSystemFileHandle.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">          93443E8826E995C40058538F /* FileSystemHandle.h in Headers */ = {isa = PBXBuildFile; fileRef = 932C9BDA26DD62610053B3DB /* FileSystemHandle.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><ins>+               93445084276A6357001F712B /* FileSystemHandleCloseScope.h in Headers */ = {isa = PBXBuildFile; fileRef = 93445082276A6356001F712B /* FileSystemHandleCloseScope.h */; settings = {ATTRIBUTES = (Private, ); }; };
</ins><span class="cx">           934907E4125BBBC8007F23A0 /* GraphicsContextCG.h in Headers */ = {isa = PBXBuildFile; fileRef = 934907E3125BBBC8007F23A0 /* GraphicsContextCG.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">          934950CD253943610099F171 /* SpeechRecognition.h in Headers */ = {isa = PBXBuildFile; fileRef = 934950B1253943480099F171 /* SpeechRecognition.h */; };
</span><span class="cx">          934950CE253943650099F171 /* SpeechRecognitionAlternative.h in Headers */ = {isa = PBXBuildFile; fileRef = 934950BC2539434E0099F171 /* SpeechRecognitionAlternative.h */; };
</span><span class="lines">@@ -12585,6 +12586,7 @@
</span><span class="cx">          93442C9F0D2B336000338FF9 /* HTMLTableRowsCollection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HTMLTableRowsCollection.cpp; sourceTree = "<group>"; };
</span><span class="cx">          93443E7B26E8A6BC0058538F /* StorageManager+FileSystemAccess.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = "StorageManager+FileSystemAccess.idl"; sourceTree = "<group>"; };
</span><span class="cx">          93443E7D26E8A6BC0058538F /* StorageManagerFileSystemAccess.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = StorageManagerFileSystemAccess.h; sourceTree = "<group>"; };
</span><ins>+               93445082276A6356001F712B /* FileSystemHandleCloseScope.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FileSystemHandleCloseScope.h; sourceTree = "<group>"; };
</ins><span class="cx">           934907E3125BBBC8007F23A0 /* GraphicsContextCG.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GraphicsContextCG.h; sourceTree = "<group>"; };
</span><span class="cx">          934950AD253943460099F171 /* SpeechRecognition.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = SpeechRecognition.idl; sourceTree = "<group>"; };
</span><span class="cx">          934950AF253943470099F171 /* SpeechRecognitionErrorCode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SpeechRecognitionErrorCode.h; sourceTree = "<group>"; };
</span><span class="lines">@@ -25012,6 +25014,7 @@
</span><span class="cx">                          932C9BD026DD62550053B3DB /* FileSystemHandle.cpp */,
</span><span class="cx">                          932C9BDA26DD62610053B3DB /* FileSystemHandle.h */,
</span><span class="cx">                          932C9BD926DD62600053B3DB /* FileSystemHandle.idl */,
</span><ins>+                               93445082276A6356001F712B /* FileSystemHandleCloseScope.h */,
</ins><span class="cx">                           935424272703BC88005CA72C /* FileSystemHandleIdentifier.h */,
</span><span class="cx">                          935424292703BCAD005CA72C /* FileSystemStorageConnection.h */,
</span><span class="cx">                          93E269A0270A5D5C002C4FF0 /* FileSystemSyncAccessHandle.cpp */,
</span><span class="lines">@@ -34296,6 +34299,7 @@
</span><span class="cx">                          83FB33751F508A5B00986E54 /* FileSystemFileEntry.h in Headers */,
</span><span class="cx">                          93443E8726E995C00058538F /* FileSystemFileHandle.h in Headers */,
</span><span class="cx">                          93443E8826E995C40058538F /* FileSystemHandle.h in Headers */,
</span><ins>+                               93445084276A6357001F712B /* FileSystemHandleCloseScope.h in Headers */,
</ins><span class="cx">                           9354242F2703CA51005CA72C /* FileSystemHandleIdentifier.h in Headers */,
</span><span class="cx">                          935424302703CB86005CA72C /* FileSystemStorageConnection.h in Headers */,
</span><span class="cx">                          93E269A2270A5D5D002C4FF0 /* FileSystemSyncAccessHandle.h in Headers */,
</span></span></pre></div>
<a id="trunkSourceWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/ChangeLog (287155 => 287156)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/ChangeLog    2021-12-16 21:20:10 UTC (rev 287155)
+++ trunk/Source/WebKit/ChangeLog       2021-12-16 22:00:44 UTC (rev 287156)
</span><span class="lines">@@ -1,3 +1,30 @@
</span><ins>+2021-12-16  Sihui Liu  <sihui_liu@apple.com>
+
+        REGRESSION (r286601): storage/filesystemaccess/sync-access-handle-read-write-worker.html and file-system-access/sandboxed_FileSystemSyncAccessHandle-truncate.https.tentative.worker.html are consistently failing
+        https://bugs.webkit.org/show_bug.cgi?id=234271
+        <rdar://problem/86434111>
+
+        Reviewed by Youenn Fablet.
+
+        * NetworkProcess/storage/FileSystemStorageHandle.cpp:
+        (WebKit::FileSystemStorageHandle::close):
+        (WebKit::FileSystemStorageHandle::closeSyncAccessHandle):
+        * NetworkProcess/storage/FileSystemStorageHandle.h:
+        * NetworkProcess/storage/FileSystemStorageManager.cpp:
+        (WebKit::FileSystemStorageManager::closeHandle):
+        * NetworkProcess/storage/NetworkStorageManager.cpp:
+        (WebKit::NetworkStorageManager::closeSyncAccessHandle):
+        (WebKit::NetworkStorageManager::closeAccessHandle): Deleted.
+        * NetworkProcess/storage/NetworkStorageManager.h:
+        * NetworkProcess/storage/NetworkStorageManager.messages.in:
+        * WebProcess/WebCoreSupport/WebFileSystemStorageConnection.cpp:
+        (WebKit::WebFileSystemStorageConnection::getFileHandle):
+        (WebKit::WebFileSystemStorageConnection::getDirectoryHandle):
+        (WebKit::WebFileSystemStorageConnection::closeSyncAccessHandle):
+        (WebKit::WebFileSystemStorageConnection::getHandle):
+        (WebKit::WebFileSystemStorageConnection::close): Deleted.
+        * WebProcess/WebCoreSupport/WebFileSystemStorageConnection.h:
+
</ins><span class="cx"> 2021-12-16  Adrian Perez de Castro  <aperez@igalia.com>
</span><span class="cx"> 
</span><span class="cx">         Non-unified build fixes, late-ish December 2021 edition
</span></span></pre></div>
<a id="trunkSourceWebKitNetworkProcessstorageFileSystemStorageHandlecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.cpp (287155 => 287156)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.cpp   2021-12-16 21:20:10 UTC (rev 287155)
+++ trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.cpp      2021-12-16 22:00:44 UTC (rev 287156)
</span><span class="lines">@@ -68,6 +68,8 @@
</span><span class="cx">     if (!m_manager)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><ins>+    if (m_activeSyncAccessHandle)
+        closeSyncAccessHandle(*m_activeSyncAccessHandle);
</ins><span class="cx">     m_manager->closeHandle(*this);
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -181,7 +183,7 @@
</span><span class="cx">     return std::pair { *m_activeSyncAccessHandle, WTFMove(*ipcHandle) };
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-std::optional<FileSystemStorageError> FileSystemStorageHandle::close(WebCore::FileSystemSyncAccessHandleIdentifier accessHandleIdentifier)
</del><ins>+std::optional<FileSystemStorageError> FileSystemStorageHandle::closeSyncAccessHandle(WebCore::FileSystemSyncAccessHandleIdentifier accessHandleIdentifier)
</ins><span class="cx"> {
</span><span class="cx">     if (!m_activeSyncAccessHandle || *m_activeSyncAccessHandle != accessHandleIdentifier)
</span><span class="cx">         return FileSystemStorageError::Unknown;
</span></span></pre></div>
<a id="trunkSourceWebKitNetworkProcessstorageFileSystemStorageHandleh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.h (287155 => 287156)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.h     2021-12-16 21:20:10 UTC (rev 287155)
+++ trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.h        2021-12-16 22:00:44 UTC (rev 287156)
</span><span class="lines">@@ -61,7 +61,7 @@
</span><span class="cx"> 
</span><span class="cx">     using AccessHandleInfo = std::pair<WebCore::FileSystemSyncAccessHandleIdentifier, IPC::SharedFileHandle>;
</span><span class="cx">     Expected<AccessHandleInfo, FileSystemStorageError> createSyncAccessHandle();
</span><del>-    std::optional<FileSystemStorageError> close(WebCore::FileSystemSyncAccessHandleIdentifier);
</del><ins>+    std::optional<FileSystemStorageError> closeSyncAccessHandle(WebCore::FileSystemSyncAccessHandleIdentifier);
</ins><span class="cx">     std::optional<WebCore::FileSystemSyncAccessHandleIdentifier> activeSyncAccessHandle() const { return m_activeSyncAccessHandle; }
</span><span class="cx"> 
</span><span class="cx"> private:
</span></span></pre></div>
<a id="trunkSourceWebKitNetworkProcessstorageFileSystemStorageManagercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageManager.cpp (287155 => 287156)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageManager.cpp  2021-12-16 21:20:10 UTC (rev 287155)
+++ trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageManager.cpp     2021-12-16 22:00:44 UTC (rev 287156)
</span><span class="lines">@@ -99,6 +99,10 @@
</span><span class="cx">     auto identifier = handle.identifier();
</span><span class="cx">     auto takenHandle = m_handles.take(identifier);
</span><span class="cx">     ASSERT(takenHandle.get() == &handle);
</span><ins>+    for (auto& handles : m_handlesByConnection.values()) {
+        if (handles.remove(identifier))
+            break;
+    }
</ins><span class="cx">     m_registry.unregisterHandle(identifier);
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKitNetworkProcessstorageNetworkStorageManagercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.cpp (287155 => 287156)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.cpp     2021-12-16 21:20:10 UTC (rev 287155)
+++ trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.cpp        2021-12-16 22:00:44 UTC (rev 287156)
</span><span class="lines">@@ -379,7 +379,7 @@
</span><span class="cx">     fileHandle.close();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void NetworkStorageManager::closeAccessHandle(WebCore::FileSystemHandleIdentifier identifier, WebCore::FileSystemSyncAccessHandleIdentifier accessHandleIdentifier, CompletionHandler<void(std::optional<FileSystemStorageError>)>&& completionHandler)
</del><ins>+void NetworkStorageManager::closeSyncAccessHandle(WebCore::FileSystemHandleIdentifier identifier, WebCore::FileSystemSyncAccessHandleIdentifier accessHandleIdentifier, CompletionHandler<void(std::optional<FileSystemStorageError>)>&& completionHandler)
</ins><span class="cx"> {
</span><span class="cx">     ASSERT(!RunLoop::isMain());
</span><span class="cx"> 
</span><span class="lines">@@ -387,7 +387,7 @@
</span><span class="cx">     if (!handle)
</span><span class="cx">         return completionHandler(FileSystemStorageError::Unknown);
</span><span class="cx"> 
</span><del>-    completionHandler(handle->close(accessHandleIdentifier));
</del><ins>+    completionHandler(handle->closeSyncAccessHandle(accessHandleIdentifier));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void NetworkStorageManager::getHandleNames(WebCore::FileSystemHandleIdentifier identifier, CompletionHandler<void(Expected<Vector<String>, FileSystemStorageError>)>&& completionHandler)
</span></span></pre></div>
<a id="trunkSourceWebKitNetworkProcessstorageNetworkStorageManagerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.h (287155 => 287156)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.h       2021-12-16 21:20:10 UTC (rev 287155)
+++ trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.h  2021-12-16 22:00:44 UTC (rev 287156)
</span><span class="lines">@@ -103,7 +103,7 @@
</span><span class="cx">     void getFile(WebCore::FileSystemHandleIdentifier, CompletionHandler<void(Expected<String, FileSystemStorageError>)>&&);
</span><span class="cx">     using AccessHandleInfo = std::pair<WebCore::FileSystemSyncAccessHandleIdentifier, IPC::SharedFileHandle>;
</span><span class="cx">     void createSyncAccessHandle(WebCore::FileSystemHandleIdentifier, CompletionHandler<void(Expected<AccessHandleInfo, FileSystemStorageError>)>&&);
</span><del>-    void closeAccessHandle(WebCore::FileSystemHandleIdentifier, WebCore::FileSystemSyncAccessHandleIdentifier, CompletionHandler<void(std::optional<FileSystemStorageError>)>&&);
</del><ins>+    void closeSyncAccessHandle(WebCore::FileSystemHandleIdentifier, WebCore::FileSystemSyncAccessHandleIdentifier, CompletionHandler<void(std::optional<FileSystemStorageError>)>&&);
</ins><span class="cx">     void getHandleNames(WebCore::FileSystemHandleIdentifier, CompletionHandler<void(Expected<Vector<String>, FileSystemStorageError>)>&&);
</span><span class="cx">     void getHandle(IPC::Connection&, WebCore::FileSystemHandleIdentifier, String&& name, CompletionHandler<void(Expected<std::pair<WebCore::FileSystemHandleIdentifier, bool>, FileSystemStorageError>)>&&);
</span><span class="cx">     
</span></span></pre></div>
<a id="trunkSourceWebKitNetworkProcessstorageNetworkStorageManagermessagesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.messages.in (287155 => 287156)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.messages.in     2021-12-16 21:20:10 UTC (rev 287155)
+++ trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.messages.in        2021-12-16 22:00:44 UTC (rev 287156)
</span><span class="lines">@@ -36,7 +36,7 @@
</span><span class="cx">     Move(WebCore::FileSystemHandleIdentifier identifier, WebCore::FileSystemHandleIdentifier destinationIdentifier, String newName) -> (std::optional<WebKit::FileSystemStorageError> result) Async
</span><span class="cx">     GetFile(WebCore::FileSystemHandleIdentifier identifier) -> (Expected<String, WebKit::FileSystemStorageError> result) Async
</span><span class="cx">     CreateSyncAccessHandle(WebCore::FileSystemHandleIdentifier identifier) -> (Expected<std::pair<WebCore::FileSystemSyncAccessHandleIdentifier, IPC::SharedFileHandle>, WebKit::FileSystemStorageError> result) Async
</span><del>-    CloseAccessHandle(WebCore::FileSystemHandleIdentifier identifier, WebCore::FileSystemSyncAccessHandleIdentifier accessHandleIdentifier) -> (std::optional<WebKit::FileSystemStorageError> result) Async
</del><ins>+    CloseSyncAccessHandle(WebCore::FileSystemHandleIdentifier identifier, WebCore::FileSystemSyncAccessHandleIdentifier accessHandleIdentifier) -> (std::optional<WebKit::FileSystemStorageError> result) Async
</ins><span class="cx">     GetHandleNames(WebCore::FileSystemHandleIdentifier identifier) -> (Expected<Vector<String>, WebKit::FileSystemStorageError> result) Async
</span><span class="cx">     GetHandle(WebCore::FileSystemHandleIdentifier identifier, String name) -> (Expected<std::pair<WebCore::FileSystemHandleIdentifier, bool>, WebKit::FileSystemStorageError> result) Async WantsConnection
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKitWebProcessWebCoreSupportWebFileSystemStorageConnectioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFileSystemStorageConnection.cpp (287155 => 287156)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFileSystemStorageConnection.cpp 2021-12-16 21:20:10 UTC (rev 287155)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFileSystemStorageConnection.cpp    2021-12-16 22:00:44 UTC (rev 287156)
</span><span class="lines">@@ -30,6 +30,7 @@
</span><span class="cx"> #include <WebCore/ExceptionOr.h>
</span><span class="cx"> #include <WebCore/FileSystemDirectoryHandle.h>
</span><span class="cx"> #include <WebCore/FileSystemFileHandle.h>
</span><ins>+#include <WebCore/FileSystemHandleCloseScope.h>
</ins><span class="cx"> #include <WebCore/ScriptExecutionContext.h>
</span><span class="cx"> #include <WebCore/WorkerFileSystemStorageConnection.h>
</span><span class="cx"> #include <WebCore/WorkerGlobalScope.h>
</span><span class="lines">@@ -78,13 +79,13 @@
</span><span class="cx">     if (!m_connection)
</span><span class="cx">         return completionHandler(WebCore::Exception { WebCore::UnknownError, "Connection is lost" });
</span><span class="cx"> 
</span><del>-    m_connection->sendWithAsyncReply(Messages::NetworkStorageManager::GetFileHandle(identifier, name, createIfNecessary), [name, completionHandler = WTFMove(completionHandler)](auto result) mutable {
</del><ins>+    m_connection->sendWithAsyncReply(Messages::NetworkStorageManager::GetFileHandle(identifier, name, createIfNecessary), [this, protectedThis = Ref { *this }, name, completionHandler = WTFMove(completionHandler)](auto result) mutable {
</ins><span class="cx">         if (!result)
</span><span class="cx">             return completionHandler(convertToException(result.error()));
</span><span class="cx"> 
</span><span class="cx">         auto identifier = result.value();
</span><span class="cx">         ASSERT(identifier.isValid());
</span><del>-        completionHandler(WTFMove(identifier));
</del><ins>+        completionHandler(WebCore::FileSystemHandleCloseScope::create(identifier, false, *this));
</ins><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -93,13 +94,13 @@
</span><span class="cx">     if (!m_connection)
</span><span class="cx">         return completionHandler(WebCore::Exception { WebCore::UnknownError, "Connection is lost" });
</span><span class="cx"> 
</span><del>-    m_connection->sendWithAsyncReply(Messages::NetworkStorageManager::GetDirectoryHandle(identifier, name, createIfNecessary), [name, completionHandler = WTFMove(completionHandler)](auto result) mutable {
</del><ins>+    m_connection->sendWithAsyncReply(Messages::NetworkStorageManager::GetDirectoryHandle(identifier, name, createIfNecessary), [this, protectedThis = Ref { *this }, name, completionHandler = WTFMove(completionHandler)](auto result) mutable {
</ins><span class="cx">         if (!result)
</span><span class="cx">             return completionHandler(convertToException(result.error()));
</span><span class="cx"> 
</span><span class="cx">         auto identifier = result.value();
</span><span class="cx">         ASSERT(identifier.isValid());
</span><del>-        completionHandler(WTFMove(identifier));
</del><ins>+        completionHandler(WebCore::FileSystemHandleCloseScope::create(identifier, true, *this));
</ins><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -153,12 +154,12 @@
</span><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void WebFileSystemStorageConnection::close(WebCore::FileSystemHandleIdentifier identifier, WebCore::FileSystemSyncAccessHandleIdentifier accessHandleIdentifier, VoidCallback&& completionHandler)
</del><ins>+void WebFileSystemStorageConnection::closeSyncAccessHandle(WebCore::FileSystemHandleIdentifier identifier, WebCore::FileSystemSyncAccessHandleIdentifier accessHandleIdentifier, VoidCallback&& completionHandler)
</ins><span class="cx"> {
</span><span class="cx">     if (!m_connection)
</span><span class="cx">         return completionHandler(WebCore::Exception { WebCore::UnknownError, "Connection is lost" });
</span><span class="cx"> 
</span><del>-    m_connection->sendWithAsyncReply(Messages::NetworkStorageManager::CloseAccessHandle(identifier, accessHandleIdentifier), [completionHandler = WTFMove(completionHandler)](auto error) mutable {
</del><ins>+    m_connection->sendWithAsyncReply(Messages::NetworkStorageManager::CloseSyncAccessHandle(identifier, accessHandleIdentifier), [completionHandler = WTFMove(completionHandler)](auto error) mutable {
</ins><span class="cx">         completionHandler(convertToExceptionOr(error));
</span><span class="cx">     });
</span><span class="cx"> }
</span><span class="lines">@@ -176,16 +177,18 @@
</span><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void WebFileSystemStorageConnection::getHandle(WebCore::FileSystemHandleIdentifier identifier, const String& name, FileSystemStorageConnection::GetHandleWithTypeCallback&& completionHandler)
</del><ins>+void WebFileSystemStorageConnection::getHandle(WebCore::FileSystemHandleIdentifier identifier, const String& name, FileSystemStorageConnection::GetHandleCallback&& completionHandler)
</ins><span class="cx"> {
</span><span class="cx">     if (!m_connection)
</span><span class="cx">         return completionHandler(WebCore::Exception { WebCore::UnknownError, "Connection is lost" });
</span><span class="cx"> 
</span><del>-    m_connection->sendWithAsyncReply(Messages::NetworkStorageManager::GetHandle(identifier, name), [completionHandler = WTFMove(completionHandler)](auto result) mutable {
</del><ins>+    m_connection->sendWithAsyncReply(Messages::NetworkStorageManager::GetHandle(identifier, name), [this, protectedThis = Ref { *this }, completionHandler = WTFMove(completionHandler)](auto result) mutable {
</ins><span class="cx">         if (!result)
</span><span class="cx">             return completionHandler(convertToException(result.error()));
</span><del>-
-        completionHandler(WTFMove(result.value()));
</del><ins>+        
+        auto [identifier, isDirectory] = result.value();
+        ASSERT(identifier.isValid());
+        completionHandler(WebCore::FileSystemHandleCloseScope::create(identifier, isDirectory, *this));
</ins><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKitWebProcessWebCoreSupportWebFileSystemStorageConnectionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFileSystemStorageConnection.h (287155 => 287156)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFileSystemStorageConnection.h   2021-12-16 21:20:10 UTC (rev 287155)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFileSystemStorageConnection.h      2021-12-16 22:00:44 UTC (rev 287156)
</span><span class="lines">@@ -81,11 +81,11 @@
</span><span class="cx">     void removeEntry(WebCore::FileSystemHandleIdentifier, const String& name, bool deleteRecursively, WebCore::FileSystemStorageConnection::VoidCallback&&) final;
</span><span class="cx">     void resolve(WebCore::FileSystemHandleIdentifier, WebCore::FileSystemHandleIdentifier, WebCore::FileSystemStorageConnection::ResolveCallback&&) final;
</span><span class="cx">     void getHandleNames(WebCore::FileSystemHandleIdentifier, FileSystemStorageConnection::GetHandleNamesCallback&&) final;
</span><del>-    void getHandle(WebCore::FileSystemHandleIdentifier, const String& name, FileSystemStorageConnection::GetHandleWithTypeCallback&&) final;
</del><ins>+    void getHandle(WebCore::FileSystemHandleIdentifier, const String& name, FileSystemStorageConnection::GetHandleCallback&&) final;
</ins><span class="cx">     void getFile(WebCore::FileSystemHandleIdentifier, StringCallback&&) final;
</span><span class="cx"> 
</span><span class="cx">     void createSyncAccessHandle(WebCore::FileSystemHandleIdentifier, WebCore::FileSystemStorageConnection::GetAccessHandleCallback&&) final;
</span><del>-    void close(WebCore::FileSystemHandleIdentifier, WebCore::FileSystemSyncAccessHandleIdentifier, WebCore::FileSystemStorageConnection::VoidCallback&&) final;
</del><ins>+    void closeSyncAccessHandle(WebCore::FileSystemHandleIdentifier, WebCore::FileSystemSyncAccessHandleIdentifier, WebCore::FileSystemStorageConnection::VoidCallback&&) final;
</ins><span class="cx">     void registerSyncAccessHandle(WebCore::FileSystemSyncAccessHandleIdentifier, WebCore::ScriptExecutionContextIdentifier) final;
</span><span class="cx">     void unregisterSyncAccessHandle(WebCore::FileSystemSyncAccessHandleIdentifier) final;
</span><span class="cx">     void invalidateAccessHandle(WebCore::FileSystemSyncAccessHandleIdentifier) final;
</span></span></pre>
</div>
</div>

</body>
</html>