Title: [287207] trunk/Source
Revision
287207
Author
[email protected]
Date
2021-12-17 14:25:08 -0800 (Fri, 17 Dec 2021)

Log Message

Add custom copy() method for Ref<T> to CrossThreadCopier
https://bugs.webkit.org/show_bug.cgi?id=234411

Reviewed by Youenn Fablet.

Source/WebCore:

* Modules/filesystemaccess/FileSystemStorageConnection.h:
* Modules/filesystemaccess/WorkerFileSystemStorageConnection.cpp:
(WebCore::WorkerFileSystemStorageConnection::getFileHandle):
(WebCore::WorkerFileSystemStorageConnection::getDirectoryHandle):
(WebCore::WorkerFileSystemStorageConnection::getHandle):
(WebCore::WorkerFileSystemStorageConnection::didGetHandleWithType): Deleted.
* Modules/filesystemaccess/WorkerFileSystemStorageConnection.h:

Source/WTF:

* wtf/CrossThreadCopier.cpp:
* wtf/CrossThreadCopier.h:

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (287206 => 287207)


--- trunk/Source/WTF/ChangeLog	2021-12-17 22:09:16 UTC (rev 287206)
+++ trunk/Source/WTF/ChangeLog	2021-12-17 22:25:08 UTC (rev 287207)
@@ -1,3 +1,13 @@
+2021-12-17  Sihui Liu  <[email protected]>
+
+        Add custom copy() method for Ref<T> to CrossThreadCopier
+        https://bugs.webkit.org/show_bug.cgi?id=234411
+
+        Reviewed by Youenn Fablet.
+
+        * wtf/CrossThreadCopier.cpp:
+        * wtf/CrossThreadCopier.h:
+
 2021-12-17  Fujii Hironori  <[email protected]>
 
         MSVC reports "wtf/RetainPtr.h(196): error C3861: 'CFAutorelease': identifier not found " with /permissive- on Windows

Modified: trunk/Source/WTF/wtf/CrossThreadCopier.cpp (287206 => 287207)


--- trunk/Source/WTF/wtf/CrossThreadCopier.cpp	2021-12-17 22:09:16 UTC (rev 287206)
+++ trunk/Source/WTF/wtf/CrossThreadCopier.cpp	2021-12-17 22:25:08 UTC (rev 287207)
@@ -40,16 +40,9 @@
 class CopierThreadSafeRefCountedTest : public ThreadSafeRefCounted<CopierThreadSafeRefCountedTest> {
 };
 
-COMPILE_ASSERT((std::is_same<
-                    RefPtr<CopierThreadSafeRefCountedTest>,
-                    CrossThreadCopier<RefPtr<CopierThreadSafeRefCountedTest>>::Type
-                >::value),
-                RefPtrTest);
-COMPILE_ASSERT((std::is_same<
-                    RefPtr<CopierThreadSafeRefCountedTest>,
-                    CrossThreadCopier<CopierThreadSafeRefCountedTest*>::Type
-                >::value),
-                RawPointerTest);
+COMPILE_ASSERT((std::is_same<RefPtr<CopierThreadSafeRefCountedTest>, CrossThreadCopier<RefPtr<CopierThreadSafeRefCountedTest>>::Type>::value), RefPtrTest);
+COMPILE_ASSERT((std::is_same<RefPtr<CopierThreadSafeRefCountedTest>, CrossThreadCopier<CopierThreadSafeRefCountedTest*>::Type>::value), RawPointerTest);
+COMPILE_ASSERT((std::is_same<Ref<CopierThreadSafeRefCountedTest>, CrossThreadCopier<Ref<CopierThreadSafeRefCountedTest>>::Type>::value), RawPointerTest);
 
 // Add specializations for RefCounted types which will let us verify that no other template matches.
 template<typename T> struct CrossThreadCopierBase<false, false, RefPtr<T>> {

Modified: trunk/Source/WTF/wtf/CrossThreadCopier.h (287206 => 287207)


--- trunk/Source/WTF/wtf/CrossThreadCopier.h	2021-12-17 22:09:16 UTC (rev 287206)
+++ trunk/Source/WTF/wtf/CrossThreadCopier.h	2021-12-17 22:25:08 UTC (rev 287207)
@@ -54,12 +54,16 @@
         typedef T Type;
     };
 
+    template<typename T> struct RemovePointer<Ref<T>> {
+        typedef T Type;
+    };
+
     template<typename T> struct IsEnumOrConvertibleToInteger {
         static constexpr bool value = std::is_integral<T>::value || std::is_enum<T>::value || std::is_convertible<T, long double>::value;
     };
 
     template<typename T> struct IsThreadSafeRefCountedPointer {
-        static constexpr bool value = std::is_convertible<typename RemovePointer<T>::Type*, ThreadSafeRefCounted<typename RemovePointer<T>::Type>*>::value;
+        static constexpr bool value = std::is_convertible<typename RemovePointer<T>::Type*, ThreadSafeRefCountedBase*>::value;
     };
 };
 
@@ -88,7 +92,7 @@
 // Custom copy methods.
 template<typename T> struct CrossThreadCopierBase<false, true, T> {
     typedef typename CrossThreadCopierBaseHelper::RemovePointer<T>::Type RefCountedType;
-    static_assert(std::is_convertible<RefCountedType*, ThreadSafeRefCounted<RefCountedType>*>::value, "T is not convertible to ThreadSafeRefCounted!");
+    static_assert(std::is_convertible<RefCountedType*, ThreadSafeRefCountedBase*>::value, "T is not convertible to ThreadSafeRefCounted!");
 
     typedef RefPtr<RefCountedType> Type;
     static Type copy(const T& refPtr)
@@ -97,6 +101,16 @@
     }
 };
 
+template<typename T> struct CrossThreadCopierBase<false, true, Ref<T>> {
+    static_assert(std::is_convertible<T*, ThreadSafeRefCountedBase*>::value, "T is not convertible to ThreadSafeRefCounted!");
+
+    typedef Ref<T> Type;
+    static Type copy(const Type& ref)
+    {
+        return ref;
+    }
+};
+
 template<> struct CrossThreadCopierBase<false, false, WTF::ASCIILiteral> {
     typedef WTF::ASCIILiteral Type;
     static Type copy(const Type& source)

Modified: trunk/Source/WebCore/ChangeLog (287206 => 287207)


--- trunk/Source/WebCore/ChangeLog	2021-12-17 22:09:16 UTC (rev 287206)
+++ trunk/Source/WebCore/ChangeLog	2021-12-17 22:25:08 UTC (rev 287207)
@@ -1,3 +1,18 @@
+2021-12-17  Sihui Liu  <[email protected]>
+
+        Add custom copy() method for Ref<T> to CrossThreadCopier
+        https://bugs.webkit.org/show_bug.cgi?id=234411
+
+        Reviewed by Youenn Fablet.
+
+        * Modules/filesystemaccess/FileSystemStorageConnection.h:
+        * Modules/filesystemaccess/WorkerFileSystemStorageConnection.cpp:
+        (WebCore::WorkerFileSystemStorageConnection::getFileHandle):
+        (WebCore::WorkerFileSystemStorageConnection::getDirectoryHandle):
+        (WebCore::WorkerFileSystemStorageConnection::getHandle):
+        (WebCore::WorkerFileSystemStorageConnection::didGetHandleWithType): Deleted.
+        * Modules/filesystemaccess/WorkerFileSystemStorageConnection.h:
+
 2021-12-17  Myles C. Maxfield  <[email protected]>
 
         Deduplicate code in RenderText::computePreferredLogicalWidths()

Modified: trunk/Source/WebCore/Modules/filesystemaccess/FileSystemStorageConnection.h (287206 => 287207)


--- trunk/Source/WebCore/Modules/filesystemaccess/FileSystemStorageConnection.h	2021-12-17 22:09:16 UTC (rev 287206)
+++ trunk/Source/WebCore/Modules/filesystemaccess/FileSystemStorageConnection.h	2021-12-17 22:25:08 UTC (rev 287207)
@@ -51,7 +51,6 @@
     using GetAccessHandleCallback = CompletionHandler<void(ExceptionOr<std::pair<FileSystemSyncAccessHandleIdentifier, FileSystem::PlatformFileHandle>>&&)>;
     using VoidCallback = CompletionHandler<void(ExceptionOr<void>&&)>;
     using GetHandleNamesCallback = CompletionHandler<void(ExceptionOr<Vector<String>>&&)>;
-    using GetHandleWithTypeCallback = CompletionHandler<void(ExceptionOr<std::pair<FileSystemHandleIdentifier, bool>>&&)>;
     using StringCallback = CompletionHandler<void(ExceptionOr<String>&&)>;
 
     virtual bool isWorker() const { return false; }

Modified: trunk/Source/WebCore/Modules/filesystemaccess/WorkerFileSystemStorageConnection.cpp (287206 => 287207)


--- trunk/Source/WebCore/Modules/filesystemaccess/WorkerFileSystemStorageConnection.cpp	2021-12-17 22:09:16 UTC (rev 287206)
+++ trunk/Source/WebCore/Modules/filesystemaccess/WorkerFileSystemStorageConnection.cpp	2021-12-17 22:25:08 UTC (rev 287207)
@@ -129,8 +129,7 @@
 
     callOnMainThread([callbackIdentifier, workerThread = Ref { m_scope->thread() }, mainThreadConnection = m_mainThreadConnection, identifier, name = name.isolatedCopy(), createIfNecessary]() mutable {
         auto mainThreadCallback = [callbackIdentifier, workerThread = WTFMove(workerThread)](auto result) mutable {
-            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 {
+            workerThread->runLoop().postTaskForMode([callbackIdentifier, result = crossThreadCopy(result)] (auto& scope) mutable {
                 if (auto connection = downcast<WorkerGlobalScope>(scope).fileSystemStorageConnection())
                     connection->didGetHandle(callbackIdentifier, WTFMove(result));
             }, WorkerRunLoop::defaultMode());
@@ -150,8 +149,7 @@
 
     callOnMainThread([callbackIdentifier, workerThread = Ref { m_scope->thread() }, mainThreadConnection = m_mainThreadConnection, identifier, name = name.isolatedCopy(), createIfNecessary]() mutable {
         auto mainThreadCallback = [callbackIdentifier, workerThread = WTFMove(workerThread)](auto result) mutable {
-            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 {
+            workerThread->runLoop().postTaskForMode([callbackIdentifier, result = crossThreadCopy(result)] (auto& scope) mutable {
                 if (auto connection = downcast<WorkerGlobalScope>(scope).fileSystemStorageConnection())
                     connection->didGetHandle(callbackIdentifier, WTFMove(result));
             }, WorkerRunLoop::defaultMode());
@@ -355,8 +353,7 @@
 
     callOnMainThread([callbackIdentifier, workerThread = Ref { m_scope->thread() }, mainThreadConnection = m_mainThreadConnection, identifier, name = name.isolatedCopy()]() mutable {
         auto mainThreadCallback = [callbackIdentifier, workerThread = WTFMove(workerThread)](auto result) mutable {
-            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 {
+            workerThread->runLoop().postTaskForMode([callbackIdentifier, result = crossThreadCopy(result)] (auto& scope) mutable {
                 if (auto connection = downcast<WorkerGlobalScope>(scope).fileSystemStorageConnection())
                     connection->didGetHandle(callbackIdentifier, WTFMove(result));
             }, WorkerRunLoop::defaultMode());
@@ -366,12 +363,6 @@
     });
 }
 
-void WorkerFileSystemStorageConnection::didGetHandleWithType(CallbackIdentifier callbackIdentifier, ExceptionOr<std::pair<FileSystemHandleIdentifier, bool>>&& result)
-{
-    if (auto callback = m_getHandleWithTypeCallbacks.take(callbackIdentifier))
-        callback(WTFMove(result));
-}
-
 void WorkerFileSystemStorageConnection::move(FileSystemHandleIdentifier identifier, FileSystemHandleIdentifier destinationIdentifier, const String& newName, VoidCallback&& callback)
 {
     if (!m_scope)

Modified: trunk/Source/WebCore/Modules/filesystemaccess/WorkerFileSystemStorageConnection.h (287206 => 287207)


--- trunk/Source/WebCore/Modules/filesystemaccess/WorkerFileSystemStorageConnection.h	2021-12-17 22:09:16 UTC (rev 287206)
+++ trunk/Source/WebCore/Modules/filesystemaccess/WorkerFileSystemStorageConnection.h	2021-12-17 22:25:08 UTC (rev 287207)
@@ -53,7 +53,6 @@
     void didCreateSyncAccessHandle(CallbackIdentifier, ExceptionOr<std::pair<FileSystemSyncAccessHandleIdentifier, FileSystem::PlatformFileHandle>>&&);
     void completeVoidCallback(CallbackIdentifier, ExceptionOr<void>&& result);
     void didGetHandleNames(CallbackIdentifier, ExceptionOr<Vector<String>>&&);
-    void didGetHandleWithType(CallbackIdentifier, ExceptionOr<std::pair<FileSystemHandleIdentifier, bool>>&&);
 
 private:
     WorkerFileSystemStorageConnection(WorkerGlobalScope&, Ref<FileSystemStorageConnection>&&);
@@ -84,7 +83,6 @@
     HashMap<CallbackIdentifier, FileSystemStorageConnection::GetAccessHandleCallback> m_getAccessHandlCallbacks;
     HashMap<CallbackIdentifier, FileSystemStorageConnection::VoidCallback> m_voidCallbacks;
     HashMap<CallbackIdentifier, FileSystemStorageConnection::GetHandleNamesCallback> m_getHandleNamesCallbacks;
-    HashMap<CallbackIdentifier, FileSystemStorageConnection::GetHandleWithTypeCallback> m_getHandleWithTypeCallbacks;
     HashMap<CallbackIdentifier, FileSystemStorageConnection::StringCallback> m_stringCallbacks;
     HashMap<FileSystemSyncAccessHandleIdentifier, Function<void()>> m_accessHandleInvalidationHandlers;
     HashMap<FileSystemSyncAccessHandleIdentifier, WeakPtr<FileSystemSyncAccessHandle>> m_syncAccessHandles;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to