| 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 22 matching lines...) Expand all Loading... |
| 33 #include "wtf/PassRefPtr.h" | 33 #include "wtf/PassRefPtr.h" |
| 34 #include "wtf/PtrUtil.h" | 34 #include "wtf/PtrUtil.h" |
| 35 #include "wtf/RefPtr.h" | 35 #include "wtf/RefPtr.h" |
| 36 #include "wtf/ThreadSafeRefCounted.h" | 36 #include "wtf/ThreadSafeRefCounted.h" |
| 37 #include "wtf/TypeTraits.h" | 37 #include "wtf/TypeTraits.h" |
| 38 #include "wtf/WeakPtr.h" | 38 #include "wtf/WeakPtr.h" |
| 39 #include <tuple> | 39 #include <tuple> |
| 40 #include <utility> | 40 #include <utility> |
| 41 | 41 |
| 42 namespace blink { | 42 namespace blink { |
| 43 template<typename T> class CrossThreadPersistent; | 43 template <typename T> class Member; |
| 44 template <typename T> class WeakMember; |
| 44 } | 45 } |
| 45 | 46 |
| 46 namespace base { | 47 namespace base { |
| 47 | 48 |
| 48 template <typename T> | 49 template <typename T> |
| 49 struct IsWeakReceiver<WTF::WeakPtr<T>> : std::true_type {}; | 50 struct IsWeakReceiver<WTF::WeakPtr<T>> : std::true_type {}; |
| 50 | 51 |
| 51 } | 52 } |
| 52 | 53 |
| 53 namespace WTF { | 54 namespace WTF { |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 } | 210 } |
| 210 | 211 |
| 211 private: | 212 private: |
| 212 R(C::*m_function)(Parameters...); | 213 R(C::*m_function)(Parameters...); |
| 213 }; | 214 }; |
| 214 | 215 |
| 215 template <typename T> | 216 template <typename T> |
| 216 struct ParamStorageTraits { | 217 struct ParamStorageTraits { |
| 217 typedef T StorageType; | 218 typedef T StorageType; |
| 218 | 219 |
| 220 static_assert(!std::is_pointer<T>::value, "Raw pointers are not allowed to b
ind into WTF::Function. Wrap it with either wrapPersistent, wrapWeakPersistent,
wrapCrossThreadPersistent, wrapCrossThreadWeakPersistent, RefPtr or unretained."
); |
| 221 static_assert(!IsSubclassOfTemplate<T, blink::Member>::value && !IsSubclassO
fTemplate<T, blink::WeakMember>::value, "Member and WeakMember are not allowed t
o bind into WTF::Function. Wrap it with either wrapPersistent, wrapWeakPersisten
t, wrapCrossThreadPersistent or wrapCrossThreadWeakPersistent."); |
| 222 |
| 219 static StorageType wrap(const T& value) { return value; } // Copy. | 223 static StorageType wrap(const T& value) { return value; } // Copy. |
| 220 static StorageType wrap(T&& value) { return std::move(value); } | 224 static StorageType wrap(T&& value) { return std::move(value); } |
| 221 | 225 |
| 222 // Don't move out, because the functor may be called multiple times. | 226 // Don't move out, because the functor may be called multiple times. |
| 223 static const T& unwrap(const StorageType& value) { return value; } | 227 static const T& unwrap(const StorageType& value) { return value; } |
| 224 }; | 228 }; |
| 225 | 229 |
| 226 template <typename T> | 230 template <typename T> |
| 227 struct ParamStorageTraits<PassRefPtr<T>> { | 231 struct ParamStorageTraits<PassRefPtr<T>> { |
| 228 typedef RefPtr<T> StorageType; | 232 typedef RefPtr<T> StorageType; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 258 }; | 262 }; |
| 259 | 263 |
| 260 template <typename T, FunctionThreadAffinity threadAffinity> | 264 template <typename T, FunctionThreadAffinity threadAffinity> |
| 261 struct ParamStorageTraits<UnretainedWrapper<T, threadAffinity>> { | 265 struct ParamStorageTraits<UnretainedWrapper<T, threadAffinity>> { |
| 262 typedef UnretainedWrapper<T, threadAffinity> StorageType; | 266 typedef UnretainedWrapper<T, threadAffinity> StorageType; |
| 263 | 267 |
| 264 static StorageType wrap(const UnretainedWrapper<T, threadAffinity>& value) {
return value; } | 268 static StorageType wrap(const UnretainedWrapper<T, threadAffinity>& value) {
return value; } |
| 265 static T* unwrap(const StorageType& value) { return value.value(); } | 269 static T* unwrap(const StorageType& value) { return value.value(); } |
| 266 }; | 270 }; |
| 267 | 271 |
| 268 template<typename T, bool isGarbageCollected> struct PointerParamStorageTraits; | |
| 269 | |
| 270 template<typename T> | |
| 271 struct PointerParamStorageTraits<T*, false> { | |
| 272 STATIC_ONLY(PointerParamStorageTraits); | |
| 273 using StorageType = T*; | |
| 274 | |
| 275 static StorageType wrap(T* value) { return value; } | |
| 276 static T* unwrap(const StorageType& value) { return value; } | |
| 277 }; | |
| 278 | |
| 279 template<typename T> | |
| 280 struct PointerParamStorageTraits<T*, true> { | |
| 281 STATIC_ONLY(PointerParamStorageTraits); | |
| 282 using StorageType = blink::CrossThreadPersistent<T>; | |
| 283 | |
| 284 static StorageType wrap(T* value) { return value; } | |
| 285 static T* unwrap(const StorageType& value) { return value.get(); } | |
| 286 }; | |
| 287 | |
| 288 template<typename T> | |
| 289 struct ParamStorageTraits<T*> : public PointerParamStorageTraits<T*, IsGarbageCo
llectedType<T>::value> { | |
| 290 STATIC_ONLY(ParamStorageTraits); | |
| 291 }; | |
| 292 | |
| 293 template<typename, FunctionThreadAffinity threadAffinity = SameThreadAffinity> | 272 template<typename, FunctionThreadAffinity threadAffinity = SameThreadAffinity> |
| 294 class Function; | 273 class Function; |
| 295 | 274 |
| 296 template<FunctionThreadAffinity threadAffinity, typename R, typename... Args> | 275 template<FunctionThreadAffinity threadAffinity, typename R, typename... Args> |
| 297 class Function<R(Args...), threadAffinity> { | 276 class Function<R(Args...), threadAffinity> { |
| 298 USING_FAST_MALLOC(Function); | 277 USING_FAST_MALLOC(Function); |
| 299 WTF_MAKE_NONCOPYABLE(Function); | 278 WTF_MAKE_NONCOPYABLE(Function); |
| 300 public: | 279 public: |
| 301 virtual ~Function() { } | 280 virtual ~Function() { } |
| 302 virtual R operator()(Args... args) = 0; | 281 virtual R operator()(Args... args) = 0; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 | 385 |
| 407 using WTF::passed; | 386 using WTF::passed; |
| 408 using WTF::unretained; | 387 using WTF::unretained; |
| 409 using WTF::crossThreadUnretained; | 388 using WTF::crossThreadUnretained; |
| 410 | 389 |
| 411 using WTF::Function; | 390 using WTF::Function; |
| 412 using WTF::SameThreadClosure; | 391 using WTF::SameThreadClosure; |
| 413 using WTF::CrossThreadClosure; | 392 using WTF::CrossThreadClosure; |
| 414 | 393 |
| 415 #endif // WTF_Functional_h | 394 #endif // WTF_Functional_h |
| OLD | NEW |