OLD | NEW |
---|---|
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 14 matching lines...) Expand all Loading... | |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #ifndef CrossThreadCopier_h | 31 #ifndef CrossThreadCopier_h |
32 #define CrossThreadCopier_h | 32 #define CrossThreadCopier_h |
33 | 33 |
34 #include "platform/PlatformExport.h" | 34 #include "platform/PlatformExport.h" |
35 #include "platform/heap/Handle.h" | |
35 #include "wtf/Assertions.h" | 36 #include "wtf/Assertions.h" |
36 #include "wtf/Forward.h" | 37 #include "wtf/Forward.h" |
37 #include "wtf/PassOwnPtr.h" | 38 #include "wtf/PassOwnPtr.h" |
38 #include "wtf/PassRefPtr.h" | 39 #include "wtf/PassRefPtr.h" |
39 #include "wtf/RefPtr.h" | 40 #include "wtf/RefPtr.h" |
40 #include "wtf/ThreadSafeRefCounted.h" | 41 #include "wtf/ThreadSafeRefCounted.h" |
41 #include "wtf/TypeTraits.h" | 42 #include "wtf/TypeTraits.h" |
42 | 43 |
43 namespace WebCore { | 44 namespace WebCore { |
44 | 45 |
45 class IntRect; | 46 class IntRect; |
46 class IntSize; | 47 class IntSize; |
47 class KURL; | 48 class KURL; |
48 class ResourceError; | 49 class ResourceError; |
49 class ResourceRequest; | 50 class ResourceRequest; |
50 class ResourceResponse; | 51 class ResourceResponse; |
51 struct CrossThreadResourceResponseData; | 52 struct CrossThreadResourceResponseData; |
52 struct CrossThreadResourceRequestData; | 53 struct CrossThreadResourceRequestData; |
53 struct ThreadableLoaderOptions; | 54 struct ThreadableLoaderOptions; |
54 | 55 |
55 template<typename T> struct CrossThreadCopierPassThrough { | 56 template<typename T> struct CrossThreadCopierPassThrough { |
56 typedef T Type; | 57 typedef T Type; |
57 static Type copy(const T& parameter) | 58 static Type copy(const T& parameter) |
58 { | 59 { |
59 return parameter; | 60 return parameter; |
60 } | 61 } |
61 }; | 62 }; |
62 | 63 |
63 template<bool isConvertibleToInteger, bool isThreadSafeRefCounted, typename T> struct CrossThreadCopierBase; | 64 template<bool isConvertibleToInteger, bool isThreadSafeRefCounted, bool isGa rbageCollected, typename T> struct CrossThreadCopierBase; |
64 | 65 |
65 // Integers get passed through without any changes. | 66 // Integers get passed through without any changes. |
66 template<typename T> struct CrossThreadCopierBase<true, false, T> : public C rossThreadCopierPassThrough<T> { | 67 template<typename T> struct CrossThreadCopierBase<true, false, false, T> : p ublic CrossThreadCopierPassThrough<T> { |
67 }; | 68 }; |
68 | 69 |
69 // To allow a type to be passed across threads using its copy constructor, a dd a forward declaration of the type and | 70 // To allow a type to be passed across threads using its copy constructor, a dd a forward declaration of the type and |
70 // a CopyThreadCopierBase<false, false, TypeName> : public CrossThreadCopier PassThrough<TypeName> { }; to this file. | 71 // a CopyThreadCopierBase<false, false, TypeName> : public CrossThreadCopier PassThrough<TypeName> { }; to this file. |
71 template<> struct CrossThreadCopierBase<false, false, ThreadableLoaderOption s> : public CrossThreadCopierPassThrough<ThreadableLoaderOptions> { | 72 template<> struct CrossThreadCopierBase<false, false, false, ThreadableLoade rOptions> : public CrossThreadCopierPassThrough<ThreadableLoaderOptions> { |
72 }; | 73 }; |
73 | 74 |
74 template<> struct CrossThreadCopierBase<false, false, IntRect> : public Cros sThreadCopierPassThrough<IntRect> { | 75 template<> struct CrossThreadCopierBase<false, false, false, IntRect> : publ ic CrossThreadCopierPassThrough<IntRect> { |
75 }; | 76 }; |
76 | 77 |
77 template<> struct CrossThreadCopierBase<false, false, IntSize> : public Cros sThreadCopierPassThrough<IntSize> { | 78 template<> struct CrossThreadCopierBase<false, false, false, IntSize> : publ ic CrossThreadCopierPassThrough<IntSize> { |
78 }; | 79 }; |
79 | 80 |
80 // Custom copy methods. | 81 // Custom copy methods. |
81 template<typename T> struct CrossThreadCopierBase<false, true, T> { | 82 template<typename T> struct CrossThreadCopierBase<false, true, false, T> { |
82 typedef typename WTF::RemoveTemplate<T, RefPtr>::Type TypeWithoutRefPtr; | 83 typedef typename WTF::RemoveTemplate<T, RefPtr>::Type TypeWithoutRefPtr; |
83 typedef typename WTF::RemoveTemplate<TypeWithoutRefPtr, PassRefPtr>::Typ e TypeWithoutPassRefPtr; | 84 typedef typename WTF::RemoveTemplate<TypeWithoutRefPtr, PassRefPtr>::Typ e TypeWithoutPassRefPtr; |
84 typedef typename WTF::RemovePointer<TypeWithoutPassRefPtr>::Type RefCoun tedType; | 85 typedef typename WTF::RemovePointer<TypeWithoutPassRefPtr>::Type RefCoun tedType; |
85 | 86 |
86 // Verify that only one of the above did a change. | 87 // Verify that only one of the above did a change. |
87 COMPILE_ASSERT((WTF::IsSameType<RefPtr<RefCountedType>, T>::value | 88 COMPILE_ASSERT((WTF::IsSameType<RefPtr<RefCountedType>, T>::value |
88 || WTF::IsSameType<PassRefPtr<RefCountedType>, T>::value | 89 || WTF::IsSameType<PassRefPtr<RefCountedType>, T>::value |
89 || WTF::IsSameType<RefCountedType*, T>::value), | 90 || WTF::IsSameType<RefCountedType*, T>::value), |
90 OnlyAllowOneTypeModification); | 91 OnlyAllowOneTypeModification); |
91 | 92 |
92 typedef PassRefPtr<RefCountedType> Type; | 93 typedef PassRefPtr<RefCountedType> Type; |
93 static Type copy(const T& refPtr) | 94 static Type copy(const T& refPtr) |
94 { | 95 { |
95 return refPtr; | 96 return refPtr; |
96 } | 97 } |
97 }; | 98 }; |
98 | 99 |
99 template<typename T> struct CrossThreadCopierBase<false, false, PassOwnPtr<T > > { | 100 template<typename T> struct CrossThreadCopierBase<false, false, false, PassO wnPtr<T> > { |
100 typedef PassOwnPtr<T> Type; | 101 typedef PassOwnPtr<T> Type; |
101 static Type copy(Type ownPtr) | 102 static Type copy(Type ownPtr) |
102 { | 103 { |
103 return ownPtr; | 104 return ownPtr; |
104 } | 105 } |
105 }; | 106 }; |
106 | 107 |
107 template<> struct CrossThreadCopierBase<false, false, KURL> { | 108 template<> struct CrossThreadCopierBase<false, false, false, KURL> { |
108 typedef KURL Type; | 109 typedef KURL Type; |
109 PLATFORM_EXPORT static Type copy(const KURL&); | 110 PLATFORM_EXPORT static Type copy(const KURL&); |
110 }; | 111 }; |
111 | 112 |
112 template<> struct CrossThreadCopierBase<false, false, String> { | 113 template<> struct CrossThreadCopierBase<false, false, false, String> { |
113 typedef String Type; | 114 typedef String Type; |
114 PLATFORM_EXPORT static Type copy(const String&); | 115 PLATFORM_EXPORT static Type copy(const String&); |
115 }; | 116 }; |
116 | 117 |
117 template<> struct CrossThreadCopierBase<false, false, ResourceError> { | 118 template<> struct CrossThreadCopierBase<false, false, false, ResourceError> { |
118 typedef ResourceError Type; | 119 typedef ResourceError Type; |
119 PLATFORM_EXPORT static Type copy(const ResourceError&); | 120 PLATFORM_EXPORT static Type copy(const ResourceError&); |
120 }; | 121 }; |
121 | 122 |
122 template<> struct CrossThreadCopierBase<false, false, ResourceRequest> { | 123 template<> struct CrossThreadCopierBase<false, false, false, ResourceRequest > { |
123 typedef PassOwnPtr<CrossThreadResourceRequestData> Type; | 124 typedef PassOwnPtr<CrossThreadResourceRequestData> Type; |
124 PLATFORM_EXPORT static Type copy(const ResourceRequest&); | 125 PLATFORM_EXPORT static Type copy(const ResourceRequest&); |
125 }; | 126 }; |
126 | 127 |
127 template<> struct CrossThreadCopierBase<false, false, ResourceResponse> { | 128 template<> struct CrossThreadCopierBase<false, false, false, ResourceRespons e> { |
128 typedef PassOwnPtr<CrossThreadResourceResponseData> Type; | 129 typedef PassOwnPtr<CrossThreadResourceResponseData> Type; |
129 PLATFORM_EXPORT static Type copy(const ResourceResponse&); | 130 PLATFORM_EXPORT static Type copy(const ResourceResponse&); |
130 }; | 131 }; |
131 | 132 |
133 template<typename T> struct CrossThreadCopierBase<false, false, true, T> { | |
haraken
2014/05/08 09:09:03
This needs to match:
CrossThreadCopierBase<false,
| |
134 typedef typename WTF::RemoveTemplate2<T, Persistent>::Type TypeWithoutPe rsistent; | |
135 typedef typename WTF::RemovePointer<TypeWithoutPersistent>::Type Garbage CollectedType; | |
136 | |
137 typedef CrossThreadPersistent<GarbageCollectedType> Type; | |
138 static Type copy(const T& ptr) | |
139 { | |
140 return ptr; | |
141 } | |
142 }; | |
143 | |
132 template<typename T> struct CrossThreadCopier : public CrossThreadCopierBase <WTF::IsConvertibleToInteger<T>::value, | 144 template<typename T> struct CrossThreadCopier : public CrossThreadCopierBase <WTF::IsConvertibleToInteger<T>::value, |
133 WTF::IsSubclassOfTemplate<typename WTF::RemoveTemplate<T, RefPtr>::Type, Thread SafeRefCounted>::value | 145 WTF::IsSubclassOfTemplate<typename WTF::RemoveTemplate<T, RefPtr>::Type, ThreadSafeRefCounted>::value |
134 || WTF::IsSubclassOfTemplate<typename WTF::RemovePointer<T>::Type, ThreadSa feRefCounted>::value | 146 || WTF::IsSubclassOfTemplate<typename WTF::RemovePointer<T>::Type, T hreadSafeRefCounted>::value |
135 || WTF::IsSubclassOfTemplate<typename WTF::RemoveTemplate<T, PassRefPtr>::T ype, ThreadSafeRefCounted>::value, | 147 || WTF::IsSubclassOfTemplate<typename WTF::RemoveTemplate<T, PassRef Ptr>::Type, ThreadSafeRefCounted>::value, |
136 T> { | 148 WTF::IsSubclassOfTemplate<typename WTF::RemovePointer<T>::Type, GarbageC ollected>::value |
149 || WTF::IsSubclassOfTemplate<typename WTF::RemoveTemplate2<T, Persis tent>::Type, GarbageCollected>::value, | |
haraken
2014/05/08 09:09:03
This RemoveTemplate2 doesn't work. How can I get T
| |
150 T> { | |
137 }; | 151 }; |
138 | 152 |
139 template<typename T> struct AllowCrossThreadAccessWrapper { | 153 template<typename T> struct AllowCrossThreadAccessWrapper { |
140 public: | 154 public: |
141 explicit AllowCrossThreadAccessWrapper(T* value) : m_value(value) { } | 155 explicit AllowCrossThreadAccessWrapper(T* value) : m_value(value) { } |
142 T* value() const { return m_value; } | 156 T* value() const { return m_value; } |
143 private: | 157 private: |
144 T* m_value; | 158 T* m_value; |
145 }; | 159 }; |
146 | 160 |
147 template<typename T> struct CrossThreadCopierBase<false, false, AllowCrossTh readAccessWrapper<T> > { | 161 template<typename T> struct CrossThreadCopierBase<false, false, false, Allow CrossThreadAccessWrapper<T> > { |
148 typedef T* Type; | 162 typedef T* Type; |
149 static Type copy(const AllowCrossThreadAccessWrapper<T>& wrapper) { retu rn wrapper.value(); } | 163 static Type copy(const AllowCrossThreadAccessWrapper<T>& wrapper) { retu rn wrapper.value(); } |
150 }; | 164 }; |
151 | 165 |
152 template<typename T> AllowCrossThreadAccessWrapper<T> AllowCrossThreadAccess (T* value) | 166 template<typename T> AllowCrossThreadAccessWrapper<T> AllowCrossThreadAccess (T* value) |
153 { | 167 { |
154 return AllowCrossThreadAccessWrapper<T>(value); | 168 return AllowCrossThreadAccessWrapper<T>(value); |
155 } | 169 } |
156 | 170 |
157 // FIXME: Move to a different header file. AllowAccessLater is for cross-thr ead access | 171 // FIXME: Move to a different header file. AllowAccessLater is for cross-thr ead access |
158 // that is not cross-thread (tasks posted to a queue guaranteed to run on th e same thread). | 172 // that is not cross-thread (tasks posted to a queue guaranteed to run on th e same thread). |
159 template<typename T> struct AllowAccessLaterWrapper { | 173 template<typename T> struct AllowAccessLaterWrapper { |
160 public: | 174 public: |
161 explicit AllowAccessLaterWrapper(T* value) : m_value(value) { } | 175 explicit AllowAccessLaterWrapper(T* value) : m_value(value) { } |
162 T* value() const { return m_value; } | 176 T* value() const { return m_value; } |
163 private: | 177 private: |
164 T* m_value; | 178 T* m_value; |
165 }; | 179 }; |
166 | 180 |
167 template<typename T> struct CrossThreadCopierBase<false, false, AllowAccessL aterWrapper<T> > { | 181 template<typename T> struct CrossThreadCopierBase<false, false, false, Allow AccessLaterWrapper<T> > { |
168 typedef T* Type; | 182 typedef T* Type; |
169 static Type copy(const AllowAccessLaterWrapper<T>& wrapper) { return wra pper.value(); } | 183 static Type copy(const AllowAccessLaterWrapper<T>& wrapper) { return wra pper.value(); } |
170 }; | 184 }; |
171 | 185 |
172 template<typename T> AllowAccessLaterWrapper<T> AllowAccessLater(T* value) | 186 template<typename T> AllowAccessLaterWrapper<T> AllowAccessLater(T* value) |
173 { | 187 { |
174 return AllowAccessLaterWrapper<T>(value); | 188 return AllowAccessLaterWrapper<T>(value); |
175 } | 189 } |
176 | 190 |
177 | 191 |
178 } // namespace WebCore | 192 } // namespace WebCore |
179 | 193 |
180 #endif // CrossThreadCopier_h | 194 #endif // CrossThreadCopier_h |
OLD | NEW |