| 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 25 matching lines...) Expand all Loading... |
| 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 <utility> | 39 #include <utility> |
| 40 | 40 |
| 41 namespace blink { | 41 namespace blink { |
| 42 template <typename T> class Member; | 42 template <typename T> class Member; |
| 43 template <typename T> class WeakMember; | 43 template <typename T> class WeakMember; |
| 44 } | 44 } |
| 45 | 45 |
| 46 namespace base { | |
| 47 | |
| 48 template <typename T> | |
| 49 struct IsWeakReceiver<WTF::WeakPtr<T>> : std::true_type {}; | |
| 50 | |
| 51 } | |
| 52 | |
| 53 namespace WTF { | 46 namespace WTF { |
| 54 | 47 |
| 55 // Functional.h provides a very simple way to bind a function pointer and argume
nts together into a function object | 48 // Functional.h provides a very simple way to bind a function pointer and argume
nts together into a function object |
| 56 // that can be stored, copied and invoked, similar to how boost::bind and std::b
ind in C++11. | 49 // that can be stored, copied and invoked, similar to how boost::bind and std::b
ind in C++11. |
| 57 | 50 |
| 58 // Thread Safety: | 51 // Thread Safety: |
| 59 // | 52 // |
| 60 // WTF::bind() and WTF::Closure should be used for same-thread closures | 53 // WTF::bind() and WTF::Closure should be used for same-thread closures |
| 61 // only, i.e. the closures must be created, executed and destructed on | 54 // only, i.e. the closures must be created, executed and destructed on |
| 62 // the same thread. | 55 // the same thread. |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 template <typename T> | 158 template <typename T> |
| 166 struct ParamStorageTraits<PassRefPtr<T>> { | 159 struct ParamStorageTraits<PassRefPtr<T>> { |
| 167 typedef RefPtr<T> StorageType; | 160 typedef RefPtr<T> StorageType; |
| 168 }; | 161 }; |
| 169 | 162 |
| 170 template <typename T> | 163 template <typename T> |
| 171 struct ParamStorageTraits<RefPtr<T>> { | 164 struct ParamStorageTraits<RefPtr<T>> { |
| 172 typedef RefPtr<T> StorageType; | 165 typedef RefPtr<T> StorageType; |
| 173 }; | 166 }; |
| 174 | 167 |
| 175 template <typename T> | |
| 176 T* Unwrap(const RefPtr<T>& wrapped) | |
| 177 { | |
| 178 return wrapped.get(); | |
| 179 } | |
| 180 | |
| 181 template <typename> class RetainPtr; | 168 template <typename> class RetainPtr; |
| 182 | 169 |
| 183 template <typename T> | 170 template <typename T> |
| 184 struct ParamStorageTraits<RetainPtr<T>> { | 171 struct ParamStorageTraits<RetainPtr<T>> { |
| 185 typedef RetainPtr<T> StorageType; | 172 typedef RetainPtr<T> StorageType; |
| 186 }; | 173 }; |
| 187 | 174 |
| 188 template <typename T> | 175 template <typename T> |
| 189 struct ParamStorageTraits<PassedWrapper<T>> { | 176 struct ParamStorageTraits<PassedWrapper<T>> { |
| 190 typedef PassedWrapper<T> StorageType; | 177 typedef PassedWrapper<T> StorageType; |
| 191 }; | 178 }; |
| 192 | 179 |
| 193 template <typename T> | |
| 194 T Unwrap(const PassedWrapper<T>& wrapped) | |
| 195 { | |
| 196 return wrapped.moveOut(); | |
| 197 } | |
| 198 | |
| 199 template <typename T, FunctionThreadAffinity threadAffinity> | 180 template <typename T, FunctionThreadAffinity threadAffinity> |
| 200 struct ParamStorageTraits<UnretainedWrapper<T, threadAffinity>> { | 181 struct ParamStorageTraits<UnretainedWrapper<T, threadAffinity>> { |
| 201 typedef UnretainedWrapper<T, threadAffinity> StorageType; | 182 typedef UnretainedWrapper<T, threadAffinity> StorageType; |
| 202 }; | 183 }; |
| 203 | 184 |
| 204 template <typename T, FunctionThreadAffinity threadAffinity> | |
| 205 T* Unwrap(const UnretainedWrapper<T, threadAffinity>& wrapped) | |
| 206 { | |
| 207 return wrapped.value(); | |
| 208 } | |
| 209 | |
| 210 template<typename Signature, FunctionThreadAffinity threadAffinity = SameThreadA
ffinity> | 185 template<typename Signature, FunctionThreadAffinity threadAffinity = SameThreadA
ffinity> |
| 211 class Function; | 186 class Function; |
| 212 | 187 |
| 213 template<typename R, typename... Args, FunctionThreadAffinity threadAffinity> | 188 template<typename R, typename... Args, FunctionThreadAffinity threadAffinity> |
| 214 class Function<R(Args...), threadAffinity> { | 189 class Function<R(Args...), threadAffinity> { |
| 215 USING_FAST_MALLOC(Function); | 190 USING_FAST_MALLOC(Function); |
| 216 WTF_MAKE_NONCOPYABLE(Function); | 191 WTF_MAKE_NONCOPYABLE(Function); |
| 217 public: | 192 public: |
| 218 Function(base::Callback<R(Args...)> callback) | 193 Function(base::Callback<R(Args...)> callback) |
| 219 : m_callback(std::move(callback)) { } | 194 : m_callback(std::move(callback)) { } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 std::unique_ptr<Function<base::MakeUnboundRunType<FunctionType, BoundParameters.
..>, SameThreadAffinity>> bind(FunctionType function, BoundParameters&&... bound
Parameters) | 229 std::unique_ptr<Function<base::MakeUnboundRunType<FunctionType, BoundParameters.
..>, SameThreadAffinity>> bind(FunctionType function, BoundParameters&&... bound
Parameters) |
| 255 { | 230 { |
| 256 return bindInternal<SameThreadAffinity>(function, std::forward<BoundParamete
rs>(boundParameters)...); | 231 return bindInternal<SameThreadAffinity>(function, std::forward<BoundParamete
rs>(boundParameters)...); |
| 257 } | 232 } |
| 258 | 233 |
| 259 typedef Function<void(), SameThreadAffinity> Closure; | 234 typedef Function<void(), SameThreadAffinity> Closure; |
| 260 typedef Function<void(), CrossThreadAffinity> CrossThreadClosure; | 235 typedef Function<void(), CrossThreadAffinity> CrossThreadClosure; |
| 261 | 236 |
| 262 } // namespace WTF | 237 } // namespace WTF |
| 263 | 238 |
| 239 namespace base { |
| 240 |
| 241 template <typename T> |
| 242 struct IsWeakReceiver<WTF::WeakPtr<T>> : std::true_type {}; |
| 243 |
| 244 template <typename T> |
| 245 struct BindUnwrapTraits<WTF::RefPtr<T>> { |
| 246 static T* Unwrap(const WTF::RefPtr<T>& wrapped) |
| 247 { |
| 248 return wrapped.get(); |
| 249 } |
| 250 }; |
| 251 |
| 252 template <typename T> |
| 253 struct BindUnwrapTraits<WTF::PassedWrapper<T>> { |
| 254 static T Unwrap(const WTF::PassedWrapper<T>& wrapped) |
| 255 { |
| 256 return wrapped.moveOut(); |
| 257 } |
| 258 }; |
| 259 |
| 260 template <typename T, WTF::FunctionThreadAffinity threadAffinity> |
| 261 struct BindUnwrapTraits<WTF::UnretainedWrapper<T, threadAffinity>> { |
| 262 static T* Unwrap(const WTF::UnretainedWrapper<T, threadAffinity>& wrapped) |
| 263 { |
| 264 return wrapped.value(); |
| 265 } |
| 266 }; |
| 267 |
| 268 } // namespace base |
| 269 |
| 264 using WTF::passed; | 270 using WTF::passed; |
| 265 using WTF::unretained; | 271 using WTF::unretained; |
| 266 using WTF::crossThreadUnretained; | 272 using WTF::crossThreadUnretained; |
| 267 | 273 |
| 268 using WTF::Function; | 274 using WTF::Function; |
| 269 using WTF::CrossThreadClosure; | 275 using WTF::CrossThreadClosure; |
| 270 | 276 |
| 271 #endif // WTF_Functional_h | 277 #endif // WTF_Functional_h |
| OLD | NEW |