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

Side by Side Diff: third_party/WebKit/Source/platform/CrossThreadCopier.h

Issue 1904283004: Replace threadSafeBind() + GCed pointers with CrossThreadPersistent (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@temp1912053002
Patch Set: Rebase Created 4 years, 7 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 /* 1 /*
2 * Copyright (C) 2009, 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2009, 2010 Google 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 template <typename T> 64 template <typename T>
65 struct CrossThreadCopierPassThrough { 65 struct CrossThreadCopierPassThrough {
66 STATIC_ONLY(CrossThreadCopierPassThrough); 66 STATIC_ONLY(CrossThreadCopierPassThrough);
67 typedef T Type; 67 typedef T Type;
68 static Type copy(const T& parameter) 68 static Type copy(const T& parameter)
69 { 69 {
70 return parameter; 70 return parameter;
71 } 71 }
72 }; 72 };
73 73
74 template <typename T, bool isArithmeticOrEnum, bool isThreadSafeRefCounted, bool isGarbageCollected> 74 template <typename T, bool isArithmeticOrEnum, bool isThreadSafeRefCounted>
75 struct CrossThreadCopierBase; 75 struct CrossThreadCopierBase;
76 76
77 // Arithmetic values (integers or floats) and enums can be safely copied. 77 // Arithmetic values (integers or floats) and enums can be safely copied.
78 template <typename T, bool isThreadSafeRefCounted, bool isGarbageCollected> 78 template <typename T, bool isThreadSafeRefCounted>
79 struct CrossThreadCopierBase<T, true, isThreadSafeRefCounted, isGarbageCollected > : public CrossThreadCopierPassThrough<T> { 79 struct CrossThreadCopierBase<T, true, isThreadSafeRefCounted> : public CrossThre adCopierPassThrough<T> {
80 STATIC_ONLY(CrossThreadCopierBase); 80 STATIC_ONLY(CrossThreadCopierBase);
81 }; 81 };
82 82
83 // Custom copy method for ThreadSafeRefCounted. 83 // Custom copy method for ThreadSafeRefCounted.
84 template <typename T, bool isGarbageCollected> 84 template <typename T>
85 struct CrossThreadCopierBase<T, false, true, isGarbageCollected> { 85 struct CrossThreadCopierBase<T, false, true> {
86 STATIC_ONLY(CrossThreadCopierBase); 86 STATIC_ONLY(CrossThreadCopierBase);
87 typedef typename WTF::RemoveTemplate<T, RefPtr>::Type TypeWithoutRefPtr; 87 typedef typename WTF::RemoveTemplate<T, RefPtr>::Type TypeWithoutRefPtr;
88 typedef typename WTF::RemoveTemplate<TypeWithoutRefPtr, PassRefPtr>::Type Ty peWithoutPassRefPtr; 88 typedef typename WTF::RemoveTemplate<TypeWithoutRefPtr, PassRefPtr>::Type Ty peWithoutPassRefPtr;
89 typedef typename std::remove_pointer<TypeWithoutPassRefPtr>::type RefCounted Type; 89 typedef typename std::remove_pointer<TypeWithoutPassRefPtr>::type RefCounted Type;
90 90
91 // Verify that only one of the above did a change. 91 // Verify that only one of the above did a change.
92 static_assert((std::is_same<RefPtr<RefCountedType>, T>::value 92 static_assert((std::is_same<RefPtr<RefCountedType>, T>::value
93 || std::is_same<PassRefPtr<RefCountedType>, T>::value 93 || std::is_same<PassRefPtr<RefCountedType>, T>::value
94 || std::is_same<RefCountedType*, T>::value), 94 || std::is_same<RefCountedType*, T>::value),
95 "only one type modification should be allowed"); 95 "only one type modification should be allowed");
96 96
97 typedef PassRefPtr<RefCountedType> Type; 97 typedef PassRefPtr<RefCountedType> Type;
98 static Type copy(const T& refPtr) 98 static Type copy(const T& refPtr)
99 { 99 {
100 return refPtr; 100 return refPtr;
101 } 101 }
102 }; 102 };
103 103
104 // A pointer to GarbageCollected.
105 template <typename T>
106 struct CrossThreadCopierBase<T, false, false, true> {
107 STATIC_ONLY(CrossThreadCopierBase);
108 typedef typename std::remove_pointer<T>::type TypeWithoutPointer;
109 typedef TypeWithoutPointer* Type;
110 static Type copy(const T& ptr)
111 {
112 return ptr;
113 }
114 };
115
116 template <typename T> 104 template <typename T>
117 struct CrossThreadCopier : public CrossThreadCopierBase< 105 struct CrossThreadCopier : public CrossThreadCopierBase<
118 T, 106 T,
119 std::is_arithmetic<T>::value || std::is_enum<T>::value, 107 std::is_arithmetic<T>::value || std::is_enum<T>::value,
120 WTF::IsSubclassOfTemplate<typename WTF::RemoveTemplate<T, RefPtr>::Type, Thr eadSafeRefCounted>::value 108 WTF::IsSubclassOfTemplate<typename WTF::RemoveTemplate<T, RefPtr>::Type, Thr eadSafeRefCounted>::value
121 || WTF::IsSubclassOfTemplate<typename std::remove_pointer<T>::type, ThreadSa feRefCounted>::value 109 || WTF::IsSubclassOfTemplate<typename std::remove_pointer<T>::type, ThreadSa feRefCounted>::value
122 || WTF::IsSubclassOfTemplate<typename WTF::RemoveTemplate<T, PassRefPtr>::Ty pe, ThreadSafeRefCounted>::value 110 || WTF::IsSubclassOfTemplate<typename WTF::RemoveTemplate<T, PassRefPtr>::Ty pe, ThreadSafeRefCounted>::value
123 || std::is_base_of<SkRefCnt, typename WTF::RemoveTemplate<T, RefPtr>::Type>: :value 111 || std::is_base_of<SkRefCnt, typename WTF::RemoveTemplate<T, RefPtr>::Type>: :value
124 || std::is_base_of<SkRefCnt, typename std::remove_pointer<T>::type>::value 112 || std::is_base_of<SkRefCnt, typename std::remove_pointer<T>::type>::value
125 || std::is_base_of<SkRefCnt, typename WTF::RemoveTemplate<T, PassRefPtr>::Ty pe>::value, 113 || std::is_base_of<SkRefCnt, typename WTF::RemoveTemplate<T, PassRefPtr>::Ty pe>::value> {
126 WTF::IsSubclassOfTemplate<typename std::remove_pointer<T>::type, GarbageColl ected>::value> {
127 STATIC_ONLY(CrossThreadCopier); 114 STATIC_ONLY(CrossThreadCopier);
128 }; 115 };
129 116
130 // CrossThreadCopier specializations follow. 117 // CrossThreadCopier specializations follow.
131 118
132 // nullptr_t can be passed through without any changes. 119 // nullptr_t can be passed through without any changes.
133 template <> 120 template <>
134 struct CrossThreadCopier<std::nullptr_t> : public CrossThreadCopierPassThrough<s td::nullptr_t> { 121 struct CrossThreadCopier<std::nullptr_t> : public CrossThreadCopierPassThrough<s td::nullptr_t> {
135 STATIC_ONLY(CrossThreadCopier); 122 STATIC_ONLY(CrossThreadCopier);
136 }; 123 };
(...skipping 23 matching lines...) Expand all
160 template <typename T> 147 template <typename T>
161 struct CrossThreadCopier<std::unique_ptr<T>> { 148 struct CrossThreadCopier<std::unique_ptr<T>> {
162 STATIC_ONLY(CrossThreadCopier); 149 STATIC_ONLY(CrossThreadCopier);
163 using Type = std::unique_ptr<T>; 150 using Type = std::unique_ptr<T>;
164 static std::unique_ptr<T> copy(std::unique_ptr<T> pointer) 151 static std::unique_ptr<T> copy(std::unique_ptr<T> pointer)
165 { 152 {
166 return pointer; // This is in fact a move. 153 return pointer; // This is in fact a move.
167 } 154 }
168 }; 155 };
169 156
157 template<typename T>
158 struct CrossThreadCopier<CrossThreadPersistent<T>> : public CrossThreadCopierPas sThrough<CrossThreadPersistent<T>> {
159 STATIC_ONLY(CrossThreadCopier);
160 };
161
170 template <typename T> 162 template <typename T>
171 struct CrossThreadCopier<WTF::PassedWrapper<T>> { 163 struct CrossThreadCopier<WTF::PassedWrapper<T>> {
172 STATIC_ONLY(CrossThreadCopier); 164 STATIC_ONLY(CrossThreadCopier);
173 using Type = WTF::PassedWrapper<typename CrossThreadCopier<T>::Type>; 165 using Type = WTF::PassedWrapper<typename CrossThreadCopier<T>::Type>;
174 static Type copy(WTF::PassedWrapper<T>&& value) { return passed(CrossThreadC opier<T>::copy(value.moveOut())); } 166 static Type copy(WTF::PassedWrapper<T>&& value) { return passed(CrossThreadC opier<T>::copy(value.moveOut())); }
175 }; 167 };
176 168
177 template<typename T> 169 template<typename T>
178 struct CrossThreadCopier<CrossThreadWeakPersistentThisPointer<T>> : public Cross ThreadCopierPassThrough<CrossThreadWeakPersistentThisPointer<T>> { 170 struct CrossThreadCopier<CrossThreadWeakPersistentThisPointer<T>> : public Cross ThreadCopierPassThrough<CrossThreadWeakPersistentThisPointer<T>> {
179 STATIC_ONLY(CrossThreadCopier); 171 STATIC_ONLY(CrossThreadCopier);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 255
264 template <typename T> 256 template <typename T>
265 AllowCrossThreadAccessWrapper<const WeakPtr<T>&> AllowCrossThreadAccess(const We akPtr<T>& value) 257 AllowCrossThreadAccessWrapper<const WeakPtr<T>&> AllowCrossThreadAccess(const We akPtr<T>& value)
266 { 258 {
267 return AllowCrossThreadAccessWrapper<const WeakPtr<T>&>(value); 259 return AllowCrossThreadAccessWrapper<const WeakPtr<T>&>(value);
268 } 260 }
269 261
270 } // namespace blink 262 } // namespace blink
271 263
272 #endif // CrossThreadCopier_h 264 #endif // CrossThreadCopier_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698