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

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

Issue 2371663002: Introduce an injection point to configure the internal pointer of WeakPtr
Patch Set: fix Created 4 years, 2 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/Heap.h" 8 #include "platform/heap/Heap.h"
9 #include "platform/heap/InlinedGlobalMarkingVisitor.h"
9 #include "platform/heap/Member.h" 10 #include "platform/heap/Member.h"
10 #include "platform/heap/PersistentNode.h" 11 #include "platform/heap/PersistentNode.h"
11 #include "platform/heap/Visitor.h" 12 #include "platform/heap/Visitor.h"
12 #include "wtf/Allocator.h" 13 #include "wtf/Allocator.h"
13 #include "wtf/Atomics.h" 14 #include "wtf/Atomics.h"
15 #include "wtf/WeakPtr.h"
14 16
15 namespace blink { 17 namespace blink {
16 18
17 // Marker used to annotate persistent objects and collections with, 19 // Marker used to annotate persistent objects and collections with,
18 // so as to enable reliable testing for persistent references via 20 // so as to enable reliable testing for persistent references via
19 // a type trait (see TypeTraits.h's IsPersistentReferenceType<>.) 21 // a type trait (see TypeTraits.h's IsPersistentReferenceType<>.)
20 #define IS_PERSISTENT_REFERENCE_TYPE() \ 22 #define IS_PERSISTENT_REFERENCE_TYPE() \
21 public: \ 23 public: \
22 using IsPersistentReferenceTypeMarker = int; \ 24 using IsPersistentReferenceTypeMarker = int; \
23 private: 25 private:
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 template<typename T, typename U> inline bool operator==(const Member<T>& a, cons t Member<U>& b) { return a.get() == b.get(); } 723 template<typename T, typename U> inline bool operator==(const Member<T>& a, cons t Member<U>& b) { return a.get() == b.get(); }
722 template<typename T, typename U> inline bool operator!=(const Member<T>& a, cons t Member<U>& b) { return a.get() != b.get(); } 724 template<typename T, typename U> inline bool operator!=(const Member<T>& a, cons t Member<U>& b) { return a.get() != b.get(); }
723 template<typename T, typename U> inline bool operator==(const Persistent<T>& a, const Persistent<U>& b) { return a.get() == b.get(); } 725 template<typename T, typename U> inline bool operator==(const Persistent<T>& a, const Persistent<U>& b) { return a.get() == b.get(); }
724 template<typename T, typename U> inline bool operator!=(const Persistent<T>& a, const Persistent<U>& b) { return a.get() != b.get(); } 726 template<typename T, typename U> inline bool operator!=(const Persistent<T>& a, const Persistent<U>& b) { return a.get() != b.get(); }
725 727
726 template<typename T, typename U> inline bool operator==(const Member<T>& a, cons t Persistent<U>& b) { return a.get() == b.get(); } 728 template<typename T, typename U> inline bool operator==(const Member<T>& a, cons t Persistent<U>& b) { return a.get() == b.get(); }
727 template<typename T, typename U> inline bool operator!=(const Member<T>& a, cons t Persistent<U>& b) { return a.get() != b.get(); } 729 template<typename T, typename U> inline bool operator!=(const Member<T>& a, cons t Persistent<U>& b) { return a.get() != b.get(); }
728 template<typename T, typename U> inline bool operator==(const Persistent<T>& a, const Member<U>& b) { return a.get() == b.get(); } 730 template<typename T, typename U> inline bool operator==(const Persistent<T>& a, const Member<U>& b) { return a.get() == b.get(); }
729 template<typename T, typename U> inline bool operator!=(const Persistent<T>& a, const Member<U>& b) { return a.get() != b.get(); } 731 template<typename T, typename U> inline bool operator!=(const Persistent<T>& a, const Member<U>& b) { return a.get() != b.get(); }
730 732
733 struct RevocableWeakPersistentTraits {
734 template <typename T>
735 struct PointerHolder {
736 protected:
737 PointerHolder(T* ptr)
738 : m_ptr(ptr)
739 {
740 }
741 void reset() { m_ptr = nullptr; }
742 T* get() const { return m_ptr.get(); }
743 private:
744 WeakPersistent<T> m_ptr;
745 };
746 };
747 struct RevocableCrossThreadWeakPersistentTraits {
748 template <typename T>
749 struct PointerHolder {
750 protected:
751 PointerHolder(T* ptr)
752 : m_ptr(ptr)
753 {
754 }
755 void reset() { m_ptr = nullptr; }
756 T* get() const { return m_ptr.get(); }
757 private:
758 CrossThreadWeakPersistent<T> m_ptr;
759 };
760 };
761 struct RevocableWeakMemberTraits {
762 template <typename T>
763 struct PointerHolder {
764 DISALLOW_NEW();
765
766 protected:
767 PointerHolder(T* ptr)
768 : m_ptr(ptr)
769 {
770 }
771 void reset() { m_ptr = nullptr; }
772 T* get() const { return m_ptr.get(); }
773 public:
774 DEFINE_INLINE_TRACE()
775 {
776 visitor->trace(m_ptr);
777 }
778
779 private:
780 WeakMember<T> m_ptr;
781 };
782 };
783
784 template <typename T>
785 using RevocableWeakPersistent = WTF::WeakPtr<T, RevocableWeakPersistentTraits>;
786 template <typename T>
787 using RevocableCrossThreadWeakPersistent = WTF::WeakPtr<T, RevocableCrossThreadW eakPersistentTraits>;
788 template <typename T>
789 using RevocableWeakMember = WTF::WeakPtr<T, RevocableWeakMemberTraits>;
790
791 template <typename T>
792 using RevocableWeakPersistentFactory = WTF::WeakPtrFactory<T, RevocableWeakPersi stentTraits>;
793 template <typename T>
794 using RevocableCrossThreadWeakPersistentFactory = WTF::WeakPtrFactory<T, Revocab leCrossThreadWeakPersistentTraits>;
795 template <typename T>
796 using RevocableWeakMemberFactory = WTF::WeakPtrFactory<T, RevocableWeakMemberTra its>;
797
731 } // namespace blink 798 } // namespace blink
732 799
733 namespace WTF { 800 namespace WTF {
734 801
735 template <typename T> 802 template <typename T>
736 struct DefaultHash<blink::Persistent<T>> { 803 struct DefaultHash<blink::Persistent<T>> {
737 STATIC_ONLY(DefaultHash); 804 STATIC_ONLY(DefaultHash);
738 using Hash = MemberHash<T>; 805 using Hash = MemberHash<T>;
739 }; 806 };
740 807
(...skipping 27 matching lines...) Expand all
768 835
769 template <typename T> 836 template <typename T>
770 struct BindUnwrapTraits<blink::CrossThreadWeakPersistent<T>> { 837 struct BindUnwrapTraits<blink::CrossThreadWeakPersistent<T>> {
771 static blink::CrossThreadPersistent<T> Unwrap(const blink::CrossThreadWeakPe rsistent<T>& wrapped) 838 static blink::CrossThreadPersistent<T> Unwrap(const blink::CrossThreadWeakPe rsistent<T>& wrapped)
772 { 839 {
773 blink::CrossThreadPersistentRegion::LockScope persistentLock(blink::Proc essHeap::crossThreadPersistentRegion()); 840 blink::CrossThreadPersistentRegion::LockScope persistentLock(blink::Proc essHeap::crossThreadPersistentRegion());
774 return blink::CrossThreadPersistent<T>(wrapped.get()); 841 return blink::CrossThreadPersistent<T>(wrapped.get());
775 } 842 }
776 }; 843 };
777 844
778 } 845 } // namespace base
779 846
780 #endif // Persistent_h 847 #endif // Persistent_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/CrossThreadCopier.h ('k') | third_party/WebKit/Source/wtf/WeakPtr.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698