OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This defines a set of argument wrappers and related factory methods that | 5 // This defines a set of argument wrappers and related factory methods that |
6 // can be used specify the refcounting and reference semantics of arguments | 6 // can be used specify the refcounting and reference semantics of arguments |
7 // that are bound by the Bind() function in base/bind.h. | 7 // that are bound by the Bind() function in base/bind.h. |
8 // | 8 // |
9 // It also defines a set of simple functions and utilities that people want | 9 // It also defines a set of simple functions and utilities that people want |
10 // when using Callback<> and Bind(). | 10 // when using Callback<> and Bind(). |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 namespace base { | 172 namespace base { |
173 | 173 |
174 template <typename T> | 174 template <typename T> |
175 struct IsWeakReceiver; | 175 struct IsWeakReceiver; |
176 | 176 |
177 template <typename> | 177 template <typename> |
178 struct BindUnwrapTraits; | 178 struct BindUnwrapTraits; |
179 | 179 |
180 namespace internal { | 180 namespace internal { |
181 | 181 |
182 template <typename Functor, typename SFINAE = void> | |
183 struct FunctorTraits; | |
184 | |
182 template <typename T> | 185 template <typename T> |
183 class UnretainedWrapper { | 186 class UnretainedWrapper { |
184 public: | 187 public: |
185 explicit UnretainedWrapper(T* o) : ptr_(o) {} | 188 explicit UnretainedWrapper(T* o) : ptr_(o) {} |
186 T* get() const { return ptr_; } | 189 T* get() const { return ptr_; } |
187 private: | 190 private: |
188 T* ptr_; | 191 T* ptr_; |
189 }; | 192 }; |
190 | 193 |
191 template <typename T> | 194 template <typename T> |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
514 } | 517 } |
515 }; | 518 }; |
516 | 519 |
517 template <typename T> | 520 template <typename T> |
518 struct BindUnwrapTraits<internal::PassedWrapper<T>> { | 521 struct BindUnwrapTraits<internal::PassedWrapper<T>> { |
519 static T Unwrap(const internal::PassedWrapper<T>& o) { | 522 static T Unwrap(const internal::PassedWrapper<T>& o) { |
520 return o.Take(); | 523 return o.Take(); |
521 } | 524 } |
522 }; | 525 }; |
523 | 526 |
527 // An injection point to support Callback::IsCancelled in a specific form of | |
528 // base::Bind. | |
529 // Specialize BindCancellationChecker to support Callback::IsCancelled, set | |
530 // is_cancellable to true in the specialization, and implement Run() method. | |
531 // BindCancellationChecker<>::Run() should return true if the resulting callback | |
532 // is cancelled. | |
533 template <typename Functor, typename BoundArgsTuple, typename SFINAE = void> | |
534 struct BindCancellationChecker { | |
dcheng
2016/11/10 06:29:23
My main thoughts are around naming.
Most of our i
tzik
2016/11/10 07:21:14
Done.
| |
535 static constexpr bool is_cancellable = false; | |
536 }; | |
537 | |
538 // Specialization for method bound to weak pointer receiver. | |
539 template <typename Functor, typename... BoundArgs> | |
540 struct BindCancellationChecker<Functor, | |
541 std::tuple<BoundArgs...>, | |
542 typename std::enable_if<internal::IsWeakMethod< | |
543 internal::FunctorTraits<Functor>::is_method, | |
544 BoundArgs...>::value>::type> { | |
545 static constexpr bool is_cancellable = true; | |
546 | |
547 template <typename Receiver, typename... Args> | |
548 static bool Run(const Functor&, const Receiver& receiver, const Args&...) { | |
dcheng
2016/11/10 06:29:23
Similarly, I think calling this Run() is a bit con
tzik
2016/11/10 07:21:14
Done.
| |
549 return !receiver; | |
550 } | |
551 }; | |
552 | |
553 // Specialization for a nested bind. | |
554 template <typename Signature, | |
555 typename... BoundArgs, | |
556 internal::CopyMode copy_mode, | |
557 internal::RepeatMode repeat_mode> | |
558 struct BindCancellationChecker<Callback<Signature, copy_mode, repeat_mode>, | |
559 std::tuple<BoundArgs...>> { | |
560 static constexpr bool is_cancellable = true; | |
561 | |
562 template <typename Functor> | |
563 static bool Run(const Functor& functor, const BoundArgs&...) { | |
564 return functor.IsCancelled(); | |
565 } | |
566 }; | |
567 | |
524 } // namespace base | 568 } // namespace base |
525 | 569 |
526 #endif // BASE_BIND_HELPERS_H_ | 570 #endif // BASE_BIND_HELPERS_H_ |
OLD | NEW |