2 * Copyright (C) 2010 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef FileThreadTask_h
32 #define FileThreadTask_h
34 #include "CrossThreadCopier.h"
35 #include "CrossThreadTask.h"
36 #include "FileThread.h"
37 #include <wtf/PassOwnPtr.h>
38 #include <wtf/PassRefPtr.h>
43 class FileThreadTask0 : public FileThread::Task {
45 typedef void (T::*Method)();
46 typedef FileThreadTask0<T> FileThreadTaskImpl;
48 static PassOwnPtr<FileThreadTaskImpl> create(T* instance, Method method)
50 return adoptPtr(new FileThreadTaskImpl(instance, method));
54 FileThreadTask0(T* instance, Method method)
55 : FileThread::Task(instance)
60 virtual void performTask()
62 (*static_cast<T*>(instance()).*m_method)();
69 template<typename T, typename P1, typename MP1>
70 class FileThreadTask1 : public FileThread::Task {
72 typedef void (T::*Method)(MP1);
73 typedef FileThreadTask1<T, P1, MP1> FileThreadTaskImpl;
74 typedef typename CrossThreadTaskTraits<P1>::ParamType Param1;
76 static PassOwnPtr<FileThreadTaskImpl> create(T* instance, Method method, Param1 parameter1)
78 return adoptPtr(new FileThreadTaskImpl(instance, method, parameter1));
82 FileThreadTask1(T* instance, Method method, Param1 parameter1)
83 : FileThread::Task(instance)
85 , m_parameter1(parameter1)
89 virtual void performTask()
91 (*static_cast<T*>(instance()).*m_method)(m_parameter1);
99 template<typename T, typename P1, typename MP1, typename P2, typename MP2>
100 class FileThreadTask2 : public FileThread::Task {
102 typedef void (T::*Method)(MP1, MP2);
103 typedef FileThreadTask2<T, P1, MP1, P2, MP2> FileThreadTaskImpl;
104 typedef typename CrossThreadTaskTraits<P1>::ParamType Param1;
105 typedef typename CrossThreadTaskTraits<P2>::ParamType Param2;
107 static PassOwnPtr<FileThreadTaskImpl> create(T* instance, Method method, Param1 parameter1, Param2 parameter2)
109 return adoptPtr(new FileThreadTaskImpl(instance, method, parameter1, parameter2));
113 FileThreadTask2(T* instance, Method method, Param1 parameter1, Param2 parameter2)
114 : FileThread::Task(instance)
116 , m_parameter1(parameter1)
117 , m_parameter2(parameter2)
121 virtual void performTask()
123 (*static_cast<T*>(instance()).*m_method)(m_parameter1, m_parameter2);
132 template<typename T, typename P1, typename MP1, typename P2, typename MP2, typename P3, typename MP3>
133 class FileThreadTask3 : public FileThread::Task {
135 typedef void (T::*Method)(MP1, MP2, MP3);
136 typedef FileThreadTask3<T, P1, MP1, P2, MP2, P3, MP3> FileThreadTaskImpl;
137 typedef typename CrossThreadTaskTraits<P1>::ParamType Param1;
138 typedef typename CrossThreadTaskTraits<P2>::ParamType Param2;
139 typedef typename CrossThreadTaskTraits<P3>::ParamType Param3;
141 static PassOwnPtr<FileThreadTaskImpl> create(T* instance, Method method, Param1 parameter1, Param2 parameter2, Param3 parameter3)
143 return adoptPtr(new FileThreadTaskImpl(instance, method, parameter1, parameter2, parameter3));
147 FileThreadTask3(T* instance, Method method, Param1 parameter1, Param2 parameter2, Param3 parameter3)
148 : FileThread::Task(instance)
150 , m_parameter1(parameter1)
151 , m_parameter2(parameter2)
152 , m_parameter3(parameter3)
156 virtual void performTask()
158 (*static_cast<T*>(instance()).*m_method)(m_parameter1, m_parameter2, m_parameter3);
169 PassOwnPtr<FileThread::Task> createFileThreadTask(
171 void (T::*method)());
174 PassOwnPtr<FileThread::Task> createFileThreadTask(
178 return FileThreadTask0<T>::create(
183 template<typename T, typename P1, typename MP1>
184 PassOwnPtr<FileThread::Task> createFileThreadTask(
186 void (T::*method)(MP1),
187 const P1& parameter1)
189 return FileThreadTask1<T, typename CrossThreadCopier<P1>::Type, MP1>::create(
192 CrossThreadCopier<P1>::copy(parameter1));
195 template<typename T, typename P1, typename MP1, typename P2, typename MP2>
196 PassOwnPtr<FileThread::Task> createFileThreadTask(
198 void (T::*method)(MP1, MP2),
199 const P1& parameter1,
200 const P2& parameter2)
202 return FileThreadTask2<T, typename CrossThreadCopier<P1>::Type, MP1, typename CrossThreadCopier<P2>::Type, MP2>::create(
205 CrossThreadCopier<P1>::copy(parameter1),
206 CrossThreadCopier<P2>::copy(parameter2));
209 template<typename T, typename P1, typename MP1, typename P2, typename MP2, typename P3, typename MP3>
210 PassOwnPtr<FileThread::Task> createFileThreadTask(
212 void (T::*method)(MP1, MP2, MP3),
213 const P1& parameter1,
214 const P2& parameter2,
215 const P3& parameter3)
217 return FileThreadTask3<T, typename CrossThreadCopier<P1>::Type, MP1, typename CrossThreadCopier<P2>::Type, MP2, typename CrossThreadCopier<P3>::Type, MP3>::create(
220 CrossThreadCopier<P1>::copy(parameter1),
221 CrossThreadCopier<P2>::copy(parameter2),
222 CrossThreadCopier<P3>::copy(parameter3));
225 } // namespace WebCore
227 #endif // FileThreadTask_h