Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: third_party/WebKit/Source/platform/heap/Persistent.h

Issue 2091713002: Specialize base::IsWeakReceiver for Blink weak pointers to support base::Bind (1/5) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: +test. rebase for WTF::unretained(). Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #ifndef Persistent_h 5 #ifndef Persistent_h
6 #define Persistent_h 6 #define Persistent_h
7 7
8 #include "platform/heap/Member.h" 8 #include "platform/heap/Member.h"
9 #include "platform/heap/PersistentNode.h" 9 #include "platform/heap/PersistentNode.h"
10 #include "wtf/Allocator.h" 10 #include "wtf/Allocator.h"
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 public: 633 public:
634 PersistentHeapDeque() { } 634 PersistentHeapDeque() { }
635 635
636 template<size_t otherCapacity> 636 template<size_t otherCapacity>
637 PersistentHeapDeque(const HeapDeque<T, otherCapacity>& other) 637 PersistentHeapDeque(const HeapDeque<T, otherCapacity>& other)
638 : PersistentHeapCollectionBase<HeapDeque<T, inlineCapacity>>(other) 638 : PersistentHeapCollectionBase<HeapDeque<T, inlineCapacity>>(other)
639 { 639 {
640 } 640 }
641 }; 641 };
642 642
643 // Only a very reduced form of weak heap object references can currently be held
644 // by WTF::Closure<>s. i.e., bound as a 'this' pointer only.
645 //
646 // TODO(sof): once wtf/Functional.h is able to work over platform/heap/ types
647 // (like CrossThreadWeakPersistent<>), drop the restriction on weak persistent
648 // use by function closures (and rename this ad-hoc type.)
649 template<typename T>
650 class WeakPersistentThisPointer {
651 STACK_ALLOCATED();
652 public:
653 explicit WeakPersistentThisPointer(T* value) : m_value(value) { }
654 WeakPersistent<T> value() const { return m_value; }
655 private:
656 WeakPersistent<T> m_value;
657 };
658
659 template<typename T>
660 class CrossThreadWeakPersistentThisPointer {
661 STACK_ALLOCATED();
662 public:
663 explicit CrossThreadWeakPersistentThisPointer(T* value) : m_value(value) { }
664 CrossThreadWeakPersistent<T> value() const { return m_value; }
665 private:
666 CrossThreadWeakPersistent<T> m_value;
667 };
668
669 template <typename T> 643 template <typename T>
670 Persistent<T> wrapPersistent(T* value) 644 Persistent<T> wrapPersistent(T* value)
671 { 645 {
672 return Persistent<T>(value); 646 return Persistent<T>(value);
673 } 647 }
674 648
675 template <typename T> 649 template <typename T>
650 WeakPersistent<T> wrapWeakPersistent(T* value)
651 {
652 return WeakPersistent<T>(value);
653 }
654
655 template <typename T>
676 CrossThreadPersistent<T> wrapCrossThreadPersistent(T* value) 656 CrossThreadPersistent<T> wrapCrossThreadPersistent(T* value)
677 { 657 {
678 return CrossThreadPersistent<T>(value); 658 return CrossThreadPersistent<T>(value);
679 } 659 }
680 660
661 template <typename T>
662 CrossThreadWeakPersistent<T> wrapCrossThreadWeakPersistent(T* value)
663 {
664 return CrossThreadWeakPersistent<T>(value);
665 }
666
681 // Comparison operators between (Weak)Members, Persistents, and UntracedMembers. 667 // Comparison operators between (Weak)Members, Persistents, and UntracedMembers.
682 template<typename T, typename U> inline bool operator==(const Member<T>& a, cons t Member<U>& b) { return a.get() == b.get(); } 668 template<typename T, typename U> inline bool operator==(const Member<T>& a, cons t Member<U>& b) { return a.get() == b.get(); }
683 template<typename T, typename U> inline bool operator!=(const Member<T>& a, cons t Member<U>& b) { return a.get() != b.get(); } 669 template<typename T, typename U> inline bool operator!=(const Member<T>& a, cons t Member<U>& b) { return a.get() != b.get(); }
684 template<typename T, typename U> inline bool operator==(const Persistent<T>& a, const Persistent<U>& b) { return a.get() == b.get(); } 670 template<typename T, typename U> inline bool operator==(const Persistent<T>& a, const Persistent<U>& b) { return a.get() == b.get(); }
685 template<typename T, typename U> inline bool operator!=(const Persistent<T>& a, const Persistent<U>& b) { return a.get() != b.get(); } 671 template<typename T, typename U> inline bool operator!=(const Persistent<T>& a, const Persistent<U>& b) { return a.get() != b.get(); }
686 672
687 template<typename T, typename U> inline bool operator==(const Member<T>& a, cons t Persistent<U>& b) { return a.get() == b.get(); } 673 template<typename T, typename U> inline bool operator==(const Member<T>& a, cons t Persistent<U>& b) { return a.get() == b.get(); }
688 template<typename T, typename U> inline bool operator!=(const Member<T>& a, cons t Persistent<U>& b) { return a.get() != b.get(); } 674 template<typename T, typename U> inline bool operator!=(const Member<T>& a, cons t Persistent<U>& b) { return a.get() != b.get(); }
689 template<typename T, typename U> inline bool operator==(const Persistent<T>& a, const Member<U>& b) { return a.get() == b.get(); } 675 template<typename T, typename U> inline bool operator==(const Persistent<T>& a, const Member<U>& b) { return a.get() == b.get(); }
690 template<typename T, typename U> inline bool operator!=(const Persistent<T>& a, const Member<U>& b) { return a.get() != b.get(); } 676 template<typename T, typename U> inline bool operator!=(const Persistent<T>& a, const Member<U>& b) { return a.get() != b.get(); }
(...skipping 19 matching lines...) Expand all
710 STATIC_ONLY(DefaultHash); 696 STATIC_ONLY(DefaultHash);
711 using Hash = MemberHash<T>; 697 using Hash = MemberHash<T>;
712 }; 698 };
713 699
714 template <typename T> 700 template <typename T>
715 struct DefaultHash<blink::CrossThreadWeakPersistent<T>> { 701 struct DefaultHash<blink::CrossThreadWeakPersistent<T>> {
716 STATIC_ONLY(DefaultHash); 702 STATIC_ONLY(DefaultHash);
717 using Hash = MemberHash<T>; 703 using Hash = MemberHash<T>;
718 }; 704 };
719 705
720 template<typename T>
721 struct ParamStorageTraits<blink::WeakPersistentThisPointer<T>> {
722 STATIC_ONLY(ParamStorageTraits);
723 static_assert(sizeof(T), "T must be fully defined");
724 using StorageType = blink::WeakPersistent<T>;
725
726 static StorageType wrap(const blink::WeakPersistentThisPointer<T>& value) { return value.value(); }
727
728 // WTF::FunctionWrapper<> handles WeakPtr<>, so recast this weak persistent
729 // into it.
730 //
731 // TODO(sof): remove this hack once wtf/Functional.h can also work with a ty pe like
732 // WeakPersistent<>.
733 static WeakPtr<T> unwrap(const StorageType& value) { return WeakPtr<T>(WeakR eference<T>::create(value.get())); }
734 };
735
736 template<typename T>
737 struct ParamStorageTraits<blink::CrossThreadWeakPersistentThisPointer<T>> {
738 STATIC_ONLY(ParamStorageTraits);
739 static_assert(sizeof(T), "T must be fully defined");
740 using StorageType = blink::CrossThreadWeakPersistent<T>;
741
742 static StorageType wrap(const blink::CrossThreadWeakPersistentThisPointer<T> & value) { return value.value(); }
743
744 // WTF::FunctionWrapper<> handles WeakPtr<>, so recast this weak persistent
745 // into it.
746 //
747 // TODO(sof): remove this hack once wtf/Functional.h can also work with a ty pe like
748 // CrossThreadWeakPersistent<>.
749 static WeakPtr<T> unwrap(const StorageType& value) { return WeakPtr<T>(WeakR eference<T>::create(value.get())); }
750 };
751
752 } // namespace WTF 706 } // namespace WTF
753 707
708 namespace base {
709
710 template <typename T>
711 struct IsWeakReceiver<blink::WeakPersistent<T>> : std::true_type {};
sof 2016/06/24 08:56:02 It would be good to have (HeapTest) unit tests for
tzik 2016/06/24 09:41:41 Done.
712
713 template <typename T>
714 struct IsWeakReceiver<blink::CrossThreadWeakPersistent<T>> : std::true_type {};
715
716 }
717
718
754 #endif // Persistent_h 719 #endif // Persistent_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698