| 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 <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 CrossThreadPersistent; |
| 44 } | 44 } |
| 45 | 45 |
| 46 namespace base { |
| 47 |
| 48 template <typename T> |
| 49 struct IsWeakReceiver<WTF::WeakPtr<T>> : std::true_type {}; |
| 50 |
| 51 } |
| 52 |
| 46 namespace WTF { | 53 namespace WTF { |
| 47 | 54 |
| 48 // Functional.h provides a very simple way to bind a function pointer and argume
nts together into a function object | 55 // Functional.h provides a very simple way to bind a function pointer and argume
nts together into a function object |
| 49 // that can be stored, copied and invoked, similar to how boost::bind and std::b
ind in C++11. | 56 // that can be stored, copied and invoked, similar to how boost::bind and std::b
ind in C++11. |
| 50 | 57 |
| 51 // Thread Safety: | 58 // Thread Safety: |
| 52 // | 59 // |
| 53 // WTF::bind() and SameThreadClosure should be used for same-thread closures | 60 // WTF::bind() and SameThreadClosure should be used for same-thread closures |
| 54 // only, i.e. the closures must be created, executed and destructed on | 61 // only, i.e. the closures must be created, executed and destructed on |
| 55 // the same thread. | 62 // the same thread. |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 public: | 161 public: |
| 155 typedef R ResultType; | 162 typedef R ResultType; |
| 156 // + 1 is for |this| as an argument. | 163 // + 1 is for |this| as an argument. |
| 157 static const size_t numberOfArguments = sizeof...(Parameters) + 1; | 164 static const size_t numberOfArguments = sizeof...(Parameters) + 1; |
| 158 | 165 |
| 159 explicit FunctionWrapper(R(C::*function)(Parameters...)) | 166 explicit FunctionWrapper(R(C::*function)(Parameters...)) |
| 160 : m_function(function) | 167 : m_function(function) |
| 161 { | 168 { |
| 162 } | 169 } |
| 163 | 170 |
| 164 template <typename... IncomingParameters> | 171 template <typename Receiver, typename... IncomingParameters> |
| 165 R operator()(C* c, IncomingParameters&&... parameters) | 172 R operator()(Receiver&& receiver, IncomingParameters&&... parameters) |
| 166 { | 173 { |
| 167 return (c->*m_function)(std::forward<IncomingParameters>(parameters)...)
; | 174 if (base::IsWeakReceiver<typename std::decay<Receiver>::type>::value &&
!receiver) { |
| 168 } | 175 return R(); |
| 176 } |
| 169 | 177 |
| 170 template <typename... IncomingParameters> | 178 C& c = *receiver; |
| 171 R operator()(const std::unique_ptr<C>& c, IncomingParameters&&... parameters
) | 179 return (c.*m_function)(std::forward<IncomingParameters>(parameters)...); |
| 172 { | |
| 173 return (c.get()->*m_function)(std::forward<IncomingParameters>(parameter
s)...); | |
| 174 } | |
| 175 | |
| 176 template <typename... IncomingParameters> | |
| 177 R operator()(const WeakPtr<C>& c, IncomingParameters&&... parameters) | |
| 178 { | |
| 179 C* obj = c.get(); | |
| 180 if (!obj) | |
| 181 return R(); | |
| 182 return (obj->*m_function)(std::forward<IncomingParameters>(parameters)..
.); | |
| 183 } | 180 } |
| 184 | 181 |
| 185 private: | 182 private: |
| 186 R(C::*m_function)(Parameters...); | 183 R(C::*m_function)(Parameters...); |
| 187 }; | 184 }; |
| 188 | 185 |
| 189 template <typename T> | 186 template <typename T> |
| 190 struct ParamStorageTraits { | 187 struct ParamStorageTraits { |
| 191 typedef T StorageType; | 188 typedef T StorageType; |
| 192 | 189 |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 | 370 |
| 374 } // namespace WTF | 371 } // namespace WTF |
| 375 | 372 |
| 376 using WTF::passed; | 373 using WTF::passed; |
| 377 using WTF::Function; | 374 using WTF::Function; |
| 378 using WTF::bind; | 375 using WTF::bind; |
| 379 using WTF::SameThreadClosure; | 376 using WTF::SameThreadClosure; |
| 380 using WTF::CrossThreadClosure; | 377 using WTF::CrossThreadClosure; |
| 381 | 378 |
| 382 #endif // WTF_Functional_h | 379 #endif // WTF_Functional_h |
| OLD | NEW |