OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2011 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 10 matching lines...) Expand all Loading... |
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
23 * THE POSSIBILITY OF SUCH DAMAGE. | 23 * THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #ifndef WTF_Functional_h | 26 #ifndef WTF_Functional_h |
27 #define WTF_Functional_h | 27 #define WTF_Functional_h |
28 | 28 |
29 #include "base/bind.h" | 29 #include "base/bind.h" |
30 #include "base/threading/thread_checker.h" | 30 #include "base/threading/thread_checker.h" |
31 #include "base/tuple.h" | |
32 #include "wtf/Allocator.h" | 31 #include "wtf/Allocator.h" |
33 #include "wtf/Assertions.h" | 32 #include "wtf/Assertions.h" |
34 #include "wtf/PassRefPtr.h" | 33 #include "wtf/PassRefPtr.h" |
35 #include "wtf/PtrUtil.h" | 34 #include "wtf/PtrUtil.h" |
36 #include "wtf/RefPtr.h" | 35 #include "wtf/RefPtr.h" |
37 #include "wtf/ThreadSafeRefCounted.h" | 36 #include "wtf/ThreadSafeRefCounted.h" |
38 #include "wtf/TypeTraits.h" | 37 #include "wtf/TypeTraits.h" |
39 #include "wtf/WeakPtr.h" | 38 #include "wtf/WeakPtr.h" |
40 #include <tuple> | |
41 #include <utility> | 39 #include <utility> |
42 | 40 |
43 namespace blink { | 41 namespace blink { |
44 template <typename T> class Member; | 42 template <typename T> class Member; |
45 template <typename T> class WeakMember; | 43 template <typename T> class WeakMember; |
46 } | 44 } |
47 | 45 |
48 namespace base { | 46 namespace base { |
49 | 47 |
50 template <typename T> | 48 template <typename T> |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 threadAffinity == SameThreadAffinity, | 239 threadAffinity == SameThreadAffinity, |
242 base::ThreadChecker, | 240 base::ThreadChecker, |
243 base::ThreadCheckerDoNothing>::type; | 241 base::ThreadCheckerDoNothing>::type; |
244 MaybeThreadChecker m_threadChecker; | 242 MaybeThreadChecker m_threadChecker; |
245 base::Callback<R(Args...)> m_callback; | 243 base::Callback<R(Args...)> m_callback; |
246 }; | 244 }; |
247 | 245 |
248 template <FunctionThreadAffinity threadAffinity, typename FunctionType, typename
... BoundParameters> | 246 template <FunctionThreadAffinity threadAffinity, typename FunctionType, typename
... BoundParameters> |
249 std::unique_ptr<Function<base::MakeUnboundRunType<FunctionType, BoundParameters.
..>, threadAffinity>> bindInternal(FunctionType function, BoundParameters&&... b
oundParameters) | 247 std::unique_ptr<Function<base::MakeUnboundRunType<FunctionType, BoundParameters.
..>, threadAffinity>> bindInternal(FunctionType function, BoundParameters&&... b
oundParameters) |
250 { | 248 { |
251 // Bound parameters' types are wrapped with std::tuple so we can pass two te
mplate parameter packs (bound | |
252 // parameters and unbound) to PartBoundFunctionImpl. Note that a tuple of th
is type isn't actually created; | |
253 // std::tuple<> is just for carrying the bound parameters' types. Any other
class template taking a type parameter | |
254 // pack can be used instead of std::tuple. std::tuple is used just because i
t's most convenient for this purpose. | |
255 using UnboundRunType = base::MakeUnboundRunType<FunctionType, BoundParameter
s...>; | 249 using UnboundRunType = base::MakeUnboundRunType<FunctionType, BoundParameter
s...>; |
256 return wrapUnique(new Function<UnboundRunType, threadAffinity>(base::Bind(fu
nction, typename ParamStorageTraits<typename std::decay<BoundParameters>::type>:
:StorageType(std::forward<BoundParameters>(boundParameters))...))); | 250 return wrapUnique(new Function<UnboundRunType, threadAffinity>(base::Bind(fu
nction, typename ParamStorageTraits<typename std::decay<BoundParameters>::type>:
:StorageType(std::forward<BoundParameters>(boundParameters))...))); |
257 } | 251 } |
258 | 252 |
259 template <typename FunctionType, typename... BoundParameters> | 253 template <typename FunctionType, typename... BoundParameters> |
260 std::unique_ptr<Function<base::MakeUnboundRunType<FunctionType, BoundParameters.
..>, SameThreadAffinity>> bind(FunctionType function, BoundParameters&&... bound
Parameters) | 254 std::unique_ptr<Function<base::MakeUnboundRunType<FunctionType, BoundParameters.
..>, SameThreadAffinity>> bind(FunctionType function, BoundParameters&&... bound
Parameters) |
261 { | 255 { |
262 return bindInternal<SameThreadAffinity>(function, std::forward<BoundParamete
rs>(boundParameters)...); | 256 return bindInternal<SameThreadAffinity>(function, std::forward<BoundParamete
rs>(boundParameters)...); |
263 } | 257 } |
264 | 258 |
265 typedef Function<void(), SameThreadAffinity> Closure; | 259 typedef Function<void(), SameThreadAffinity> Closure; |
266 typedef Function<void(), CrossThreadAffinity> CrossThreadClosure; | 260 typedef Function<void(), CrossThreadAffinity> CrossThreadClosure; |
267 | 261 |
268 } // namespace WTF | 262 } // namespace WTF |
269 | 263 |
270 using WTF::passed; | 264 using WTF::passed; |
271 using WTF::unretained; | 265 using WTF::unretained; |
272 using WTF::crossThreadUnretained; | 266 using WTF::crossThreadUnretained; |
273 | 267 |
274 using WTF::Function; | 268 using WTF::Function; |
275 using WTF::CrossThreadClosure; | 269 using WTF::CrossThreadClosure; |
276 | 270 |
277 #endif // WTF_Functional_h | 271 #endif // WTF_Functional_h |
OLD | NEW |