Diff
Modified: trunk/Source/WebCore/ChangeLog (168609 => 168610)
--- trunk/Source/WebCore/ChangeLog 2014-05-12 06:30:37 UTC (rev 168609)
+++ trunk/Source/WebCore/ChangeLog 2014-05-12 07:01:24 UTC (rev 168610)
@@ -1,3 +1,38 @@
+2014-05-11 Zan Dobersek <zdober...@igalia.com>
+
+ Simplify FileThread::Task usage
+ https://bugs.webkit.org/show_bug.cgi?id=132798
+
+ Reviewed by Darin Adler.
+
+ Remove the createFileThreadTask functions and the related FileThreadTask helper classes.
+
+ Instead, the FileThread::Task class now has a templated constructor that takes in a pointer
+ to the object instance, a method, and a variadic pack of parameters. The pointer and the
+ cross-thread copies of all the parameters are then bound to the given method through std::bind().
+
+ Instead of createFileThreadTask, std::make_unique<>() should be used to construct unique pointers
+ that wrap FileThread::Task objects.
+
+ * WebCore.vcxproj/WebCore.vcxproj:
+ * WebCore.vcxproj/WebCore.vcxproj.filters:
+ * WebCore.xcodeproj/project.pbxproj:
+ * fileapi/AsyncFileStream.cpp:
+ (WebCore::AsyncFileStream::create):
+ (WebCore::AsyncFileStream::stop):
+ (WebCore::AsyncFileStream::getSize):
+ (WebCore::AsyncFileStream::openForRead):
+ (WebCore::AsyncFileStream::openForWrite):
+ (WebCore::AsyncFileStream::close):
+ (WebCore::AsyncFileStream::read):
+ (WebCore::AsyncFileStream::write):
+ (WebCore::AsyncFileStream::truncate):
+ * fileapi/FileThread.h:
+ (WebCore::FileThread::Task::Task):
+ (WebCore::FileThread::Task::performTask):
+ (WebCore::FileThread::Task::~Task): Deleted.
+ * fileapi/FileThreadTask.h: Removed.
+
2014-05-11 Benjamin Poulain <benja...@webkit.org>
Do not create a temporary string to append the SVGLength's unit
Modified: trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj (168609 => 168610)
--- trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj 2014-05-12 06:30:37 UTC (rev 168609)
+++ trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj 2014-05-12 07:01:24 UTC (rev 168610)
@@ -20514,7 +20514,6 @@
<ClInclude Include="..\fileapi\FileReaderLoaderClient.h" />
<ClInclude Include="..\fileapi\FileReaderSync.h" />
<ClInclude Include="..\fileapi\FileThread.h" />
- <ClInclude Include="..\fileapi\FileThreadTask.h" />
<ClInclude Include="..\html\FormAssociatedElement.h" />
<ClInclude Include="..\html\FormController.h" />
<ClInclude Include="..\html\FormDataList.h" />
Modified: trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters (168609 => 168610)
--- trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters 2014-05-12 06:30:37 UTC (rev 168609)
+++ trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters 2014-05-12 07:01:24 UTC (rev 168610)
@@ -10765,9 +10765,6 @@
<ClInclude Include="..\fileapi\FileThread.h">
<Filter>html</Filter>
</ClInclude>
- <ClInclude Include="..\fileapi\FileThreadTask.h">
- <Filter>html</Filter>
- </ClInclude>
<ClInclude Include="..\html\FormAssociatedElement.h">
<Filter>html</Filter>
</ClInclude>
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (168609 => 168610)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2014-05-12 06:30:37 UTC (rev 168609)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2014-05-12 07:01:24 UTC (rev 168610)
@@ -3393,7 +3393,6 @@
976D6C89122B8A3D001FD1F7 /* FileReader.h in Headers */ = {isa = PBXBuildFile; fileRef = 976D6C6A122B8A3D001FD1F7 /* FileReader.h */; };
976D6C8D122B8A3D001FD1F7 /* FileThread.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 976D6C6E122B8A3D001FD1F7 /* FileThread.cpp */; };
976D6C8E122B8A3D001FD1F7 /* FileThread.h in Headers */ = {isa = PBXBuildFile; fileRef = 976D6C6F122B8A3D001FD1F7 /* FileThread.h */; };
- 976D6C8F122B8A3D001FD1F7 /* FileThreadTask.h in Headers */ = {isa = PBXBuildFile; fileRef = 976D6C70122B8A3D001FD1F7 /* FileThreadTask.h */; };
976D6C94122B8A3D001FD1F7 /* ThreadableBlobRegistry.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 976D6C75122B8A3D001FD1F7 /* ThreadableBlobRegistry.cpp */; };
976D6C95122B8A3D001FD1F7 /* ThreadableBlobRegistry.h in Headers */ = {isa = PBXBuildFile; fileRef = 976D6C76122B8A3D001FD1F7 /* ThreadableBlobRegistry.h */; };
976F36EA14686225005E93B4 /* SecurityContext.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 976F36E814686225005E93B4 /* SecurityContext.cpp */; };
@@ -10440,7 +10439,6 @@
976D6C6A122B8A3D001FD1F7 /* FileReader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FileReader.h; path = fileapi/FileReader.h; sourceTree = "<group>"; };
976D6C6E122B8A3D001FD1F7 /* FileThread.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = FileThread.cpp; path = fileapi/FileThread.cpp; sourceTree = "<group>"; };
976D6C6F122B8A3D001FD1F7 /* FileThread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FileThread.h; path = fileapi/FileThread.h; sourceTree = "<group>"; };
- 976D6C70122B8A3D001FD1F7 /* FileThreadTask.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FileThreadTask.h; path = fileapi/FileThreadTask.h; sourceTree = "<group>"; };
976D6C75122B8A3D001FD1F7 /* ThreadableBlobRegistry.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ThreadableBlobRegistry.cpp; path = fileapi/ThreadableBlobRegistry.cpp; sourceTree = "<group>"; };
976D6C76122B8A3D001FD1F7 /* ThreadableBlobRegistry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ThreadableBlobRegistry.h; path = fileapi/ThreadableBlobRegistry.h; sourceTree = "<group>"; };
976F36E814686225005E93B4 /* SecurityContext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SecurityContext.cpp; sourceTree = "<group>"; };
@@ -17896,7 +17894,6 @@
E1AB1EBD14E9E3A800449E13 /* FileReaderSync.idl */,
976D6C6E122B8A3D001FD1F7 /* FileThread.cpp */,
976D6C6F122B8A3D001FD1F7 /* FileThread.h */,
- 976D6C70122B8A3D001FD1F7 /* FileThreadTask.h */,
976D6C75122B8A3D001FD1F7 /* ThreadableBlobRegistry.cpp */,
976D6C76122B8A3D001FD1F7 /* ThreadableBlobRegistry.h */,
976D6C5C122B8A3D001FD1F7 /* WebKitBlobBuilder.cpp */,
@@ -23916,7 +23913,6 @@
26C17A3E1491D2D400D12BA2 /* FileSystemIOS.h in Headers */,
976D6C8E122B8A3D001FD1F7 /* FileThread.h in Headers */,
1CC6B06D18F8526B0007ECCD /* WebProfilerAgent.h in Headers */,
- 976D6C8F122B8A3D001FD1F7 /* FileThreadTask.h in Headers */,
BC5EB69F0E81DAEB00B25965 /* FillLayer.h in Headers */,
845E72F80FD261EE00A87D79 /* Filter.h in Headers */,
08C9251A0FCC7C4A00480DEC /* FilterEffect.h in Headers */,
Modified: trunk/Source/WebCore/fileapi/AsyncFileStream.cpp (168609 => 168610)
--- trunk/Source/WebCore/fileapi/AsyncFileStream.cpp 2014-05-12 06:30:37 UTC (rev 168609)
+++ trunk/Source/WebCore/fileapi/AsyncFileStream.cpp 2014-05-12 07:01:24 UTC (rev 168610)
@@ -39,7 +39,6 @@
#include "FileStream.h"
#include "FileStreamClient.h"
#include "FileThread.h"
-#include "FileThreadTask.h"
#include "MainThreadTask.h"
#include <wtf/MainThread.h>
#include <wtf/text/WTFString.h>
@@ -80,7 +79,7 @@
// This is balanced by the deref in derefProxyOnContext below.
proxy->ref();
- fileThread()->postTask(createFileThreadTask(proxy.get(), &AsyncFileStream::startOnFileThread));
+ fileThread()->postTask(std::make_unique<FileThread::Task>(proxy.get(), &AsyncFileStream::startOnFileThread));
return proxy.release();
}
@@ -110,7 +109,7 @@
setClient(0);
fileThread()->unscheduleTasks(m_stream.get());
- fileThread()->postTask(createFileThreadTask(this, &AsyncFileStream::stopOnFileThread));
+ fileThread()->postTask(std::make_unique<FileThread::Task>(this, &AsyncFileStream::stopOnFileThread));
}
static void derefProxyOnMainThread(AsyncFileStream* proxy)
@@ -133,7 +132,7 @@
void AsyncFileStream::getSize(const String& path, double expectedModificationTime)
{
- fileThread()->postTask(createFileThreadTask(this, &AsyncFileStream::getSizeOnFileThread, path, expectedModificationTime));
+ fileThread()->postTask(std::make_unique<FileThread::Task>(this, &AsyncFileStream::getSizeOnFileThread, path, expectedModificationTime));
}
void AsyncFileStream::getSizeOnFileThread(const String& path, double expectedModificationTime)
@@ -150,7 +149,7 @@
void AsyncFileStream::openForRead(const String& path, long long offset, long long length)
{
- fileThread()->postTask(createFileThreadTask(this, &AsyncFileStream::openForReadOnFileThread, path, offset, length));
+ fileThread()->postTask(std::make_unique<FileThread::Task>(this, &AsyncFileStream::openForReadOnFileThread, path, offset, length));
}
void AsyncFileStream::openForReadOnFileThread(const String& path, long long offset, long long length)
@@ -161,9 +160,7 @@
void AsyncFileStream::openForWrite(const String& path)
{
- fileThread()->postTask(
- createFileThreadTask(this,
- &AsyncFileStream::openForWriteOnFileThread, path));
+ fileThread()->postTask(std::make_unique<FileThread::Task>(this, &AsyncFileStream::openForWriteOnFileThread, path));
}
void AsyncFileStream::openForWriteOnFileThread(const String& path)
@@ -174,7 +171,7 @@
void AsyncFileStream::close()
{
- fileThread()->postTask(createFileThreadTask(this, &AsyncFileStream::closeOnFileThread));
+ fileThread()->postTask(std::make_unique<FileThread::Task>(this, &AsyncFileStream::closeOnFileThread));
}
void AsyncFileStream::closeOnFileThread()
@@ -190,9 +187,7 @@
void AsyncFileStream::read(char* buffer, int length)
{
- fileThread()->postTask(
- createFileThreadTask(this, &AsyncFileStream::readOnFileThread,
- AllowCrossThreadAccess(buffer), length));
+ fileThread()->postTask(std::make_unique<FileThread::Task>(this, &AsyncFileStream::readOnFileThread, AllowCrossThreadAccess(buffer), length));
}
void AsyncFileStream::readOnFileThread(char* buffer, int length)
@@ -209,7 +204,7 @@
void AsyncFileStream::write(const URL& blobURL, long long position, int length)
{
- fileThread()->postTask(createFileThreadTask(this, &AsyncFileStream::writeOnFileThread, blobURL, position, length));
+ fileThread()->postTask(std::make_unique<FileThread::Task>(this, &AsyncFileStream::writeOnFileThread, blobURL, position, length));
}
void AsyncFileStream::writeOnFileThread(const URL& blobURL, long long position, int length)
@@ -226,7 +221,7 @@
void AsyncFileStream::truncate(long long position)
{
- fileThread()->postTask(createFileThreadTask(this, &AsyncFileStream::truncateOnFileThread, position));
+ fileThread()->postTask(std::make_unique<FileThread::Task>(this, &AsyncFileStream::truncateOnFileThread, position));
}
void AsyncFileStream::truncateOnFileThread(long long position)
Modified: trunk/Source/WebCore/fileapi/FileThread.h (168609 => 168610)
--- trunk/Source/WebCore/fileapi/FileThread.h 2014-05-12 06:30:37 UTC (rev 168609)
+++ trunk/Source/WebCore/fileapi/FileThread.h 2014-05-12 07:01:24 UTC (rev 168610)
@@ -33,6 +33,8 @@
#if ENABLE(BLOB)
+#include "CrossThreadCopier.h"
+#include <functional>
#include <wtf/MessageQueue.h>
#include <wtf/PassRefPtr.h>
#include <wtf/Threading.h>
@@ -56,11 +58,21 @@
class Task {
WTF_MAKE_NONCOPYABLE(Task);
public:
- virtual ~Task() { }
- virtual void performTask() = 0;
+ template<typename T, typename Method, typename... Parameters>
+ Task(T* instance, Method method, const Parameters&... parameters)
+ : m_task(std::bind(method, instance, typename CrossThreadCopier<Parameters>::Type(CrossThreadCopier<Parameters>::copy(parameters))...))
+ , m_instance(instance)
+ {
+ }
+
+ void performTask()
+ {
+ m_task();
+ }
void* instance() const { return m_instance; }
- protected:
- Task(void* instance) : m_instance(instance) { }
+
+ private:
+ std::function<void ()> m_task;
void* m_instance;
};
Deleted: trunk/Source/WebCore/fileapi/FileThreadTask.h (168609 => 168610)
--- trunk/Source/WebCore/fileapi/FileThreadTask.h 2014-05-12 06:30:37 UTC (rev 168609)
+++ trunk/Source/WebCore/fileapi/FileThreadTask.h 2014-05-12 07:01:24 UTC (rev 168610)
@@ -1,206 +0,0 @@
-/*
- * Copyright (C) 2010 Google 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:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * 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.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT
- * OWNER OR 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.
- */
-
-#ifndef FileThreadTask_h
-#define FileThreadTask_h
-
-#include "CrossThreadCopier.h"
-#include "CrossThreadTask.h"
-#include "FileThread.h"
-#include <wtf/PassRefPtr.h>
-
-namespace WebCore {
-
-template<typename T>
-class FileThreadTask0 : public FileThread::Task {
-public:
- typedef void (T::*Method)();
- typedef FileThreadTask0<T> FileThreadTaskImpl;
-
- FileThreadTask0(T* instance, Method method)
- : FileThread::Task(instance)
- , m_method(method)
- {
- }
-
-private:
- virtual void performTask() override
- {
- (*static_cast<T*>(instance()).*m_method)();
- }
-
-private:
- Method m_method;
-};
-
-template<typename T, typename P1, typename MP1>
-class FileThreadTask1 : public FileThread::Task {
-public:
- typedef void (T::*Method)(MP1);
- typedef FileThreadTask1<T, P1, MP1> FileThreadTaskImpl;
- typedef typename CrossThreadTaskTraits<P1>::ParamType Param1;
-
- FileThreadTask1(T* instance, Method method, Param1 parameter1)
- : FileThread::Task(instance)
- , m_method(method)
- , m_parameter1(parameter1)
- {
- }
-
-private:
- virtual void performTask() override
- {
- (*static_cast<T*>(instance()).*m_method)(m_parameter1);
- }
-
-private:
- Method m_method;
- P1 m_parameter1;
-};
-
-template<typename T, typename P1, typename MP1, typename P2, typename MP2>
-class FileThreadTask2 : public FileThread::Task {
-public:
- typedef void (T::*Method)(MP1, MP2);
- typedef FileThreadTask2<T, P1, MP1, P2, MP2> FileThreadTaskImpl;
- typedef typename CrossThreadTaskTraits<P1>::ParamType Param1;
- typedef typename CrossThreadTaskTraits<P2>::ParamType Param2;
-
- FileThreadTask2(T* instance, Method method, Param1 parameter1, Param2 parameter2)
- : FileThread::Task(instance)
- , m_method(method)
- , m_parameter1(parameter1)
- , m_parameter2(parameter2)
- {
- }
-
-private:
- virtual void performTask() override
- {
- (*static_cast<T*>(instance()).*m_method)(m_parameter1, m_parameter2);
- }
-
-private:
- Method m_method;
- P1 m_parameter1;
- P2 m_parameter2;
-};
-
-template<typename T, typename P1, typename MP1, typename P2, typename MP2, typename P3, typename MP3>
-class FileThreadTask3 : public FileThread::Task {
-public:
- typedef void (T::*Method)(MP1, MP2, MP3);
- typedef FileThreadTask3<T, P1, MP1, P2, MP2, P3, MP3> FileThreadTaskImpl;
- typedef typename CrossThreadTaskTraits<P1>::ParamType Param1;
- typedef typename CrossThreadTaskTraits<P2>::ParamType Param2;
- typedef typename CrossThreadTaskTraits<P3>::ParamType Param3;
-
- FileThreadTask3(T* instance, Method method, Param1 parameter1, Param2 parameter2, Param3 parameter3)
- : FileThread::Task(instance)
- , m_method(method)
- , m_parameter1(parameter1)
- , m_parameter2(parameter2)
- , m_parameter3(parameter3)
- {
- }
-
-private:
- virtual void performTask() override
- {
- (*static_cast<T*>(instance()).*m_method)(m_parameter1, m_parameter2, m_parameter3);
- }
-
-private:
- Method m_method;
- P1 m_parameter1;
- P2 m_parameter2;
- P3 m_parameter3;
-};
-
-template<typename T>
-std::unique_ptr<FileThread::Task> createFileThreadTask(
- T* const callee,
- void (T::*method)());
-
-template<typename T>
-std::unique_ptr<FileThread::Task> createFileThreadTask(
- T* const callee,
- void (T::*method)())
-{
- return std::make_unique<FileThreadTask0<T>>(
- callee,
- method);
-}
-
-template<typename T, typename P1, typename MP1>
-std::unique_ptr<FileThread::Task> createFileThreadTask(
- T* const callee,
- void (T::*method)(MP1),
- const P1& parameter1)
-{
- return std::make_unique<FileThreadTask1<T, typename CrossThreadCopier<P1>::Type, MP1>>(
- callee,
- method,
- CrossThreadCopier<P1>::copy(parameter1));
-}
-
-template<typename T, typename P1, typename MP1, typename P2, typename MP2>
-std::unique_ptr<FileThread::Task> createFileThreadTask(
- T* const callee,
- void (T::*method)(MP1, MP2),
- const P1& parameter1,
- const P2& parameter2)
-{
- return std::make_unique<FileThreadTask2<T, typename CrossThreadCopier<P1>::Type, MP1, typename CrossThreadCopier<P2>::Type, MP2>>(
- callee,
- method,
- CrossThreadCopier<P1>::copy(parameter1),
- CrossThreadCopier<P2>::copy(parameter2));
-}
-
-template<typename T, typename P1, typename MP1, typename P2, typename MP2, typename P3, typename MP3>
-std::unique_ptr<FileThread::Task> createFileThreadTask(
- T* const callee,
- void (T::*method)(MP1, MP2, MP3),
- const P1& parameter1,
- const P2& parameter2,
- const P3& parameter3)
-{
- return std::make_unique<FileThreadTask3<T, typename CrossThreadCopier<P1>::Type, MP1, typename CrossThreadCopier<P2>::Type, MP2, typename CrossThreadCopier<P3>::Type, MP3>>(
- callee,
- method,
- CrossThreadCopier<P1>::copy(parameter1),
- CrossThreadCopier<P2>::copy(parameter2),
- CrossThreadCopier<P3>::copy(parameter3));
-}
-
-} // namespace WebCore
-
-#endif // FileThreadTask_h