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 struct ResourceLoaderOptions; | 55 struct ResourceLoaderOptions; |
55 | 56 |
56 template<typename T> struct CrossThreadCopierPassThrough { | 57 template<typename T> struct CrossThreadCopierPassThrough { |
57 typedef T Type; | 58 typedef T Type; |
58 static Type copy(const T& parameter) | 59 static Type copy(const T& parameter) |
59 { | 60 { |
60 return parameter; | 61 return parameter; |
61 } | 62 } |
62 }; | 63 }; |
63 | 64 |
64 template<bool isConvertibleToInteger, bool isThreadSafeRefCounted, typename
T> struct CrossThreadCopierBase; | 65 template<bool isConvertibleToInteger, bool isThreadSafeRefCounted, bool isGa
rbageCollected, typename T> struct CrossThreadCopierBase; |
65 | 66 |
66 // Integers get passed through without any changes. | 67 // Integers get passed through without any changes. |
67 template<typename T> struct CrossThreadCopierBase<true, false, T> : public C
rossThreadCopierPassThrough<T> { | 68 template<typename T> struct CrossThreadCopierBase<true, false, false, T> : p
ublic CrossThreadCopierPassThrough<T> { |
68 }; | 69 }; |
69 | 70 |
70 // To allow a type to be passed across threads using its copy constructor, a
dd a forward declaration of the type and | 71 // To allow a type to be passed across threads using its copy constructor, a
dd a forward declaration of the type and |
71 // a CopyThreadCopierBase<false, false, TypeName> : public CrossThreadCopier
PassThrough<TypeName> { }; to this file. | 72 // a CopyThreadCopierBase<false, false, TypeName> : public CrossThreadCopier
PassThrough<TypeName> { }; to this file. |
72 template<> struct CrossThreadCopierBase<false, false, ThreadableLoaderOption
s> : public CrossThreadCopierPassThrough<ThreadableLoaderOptions> { | 73 template<> struct CrossThreadCopierBase<false, false, false, ThreadableLoade
rOptions> : public CrossThreadCopierPassThrough<ThreadableLoaderOptions> { |
73 }; | 74 }; |
74 | 75 |
75 template<> struct CrossThreadCopierBase<false, false, ResourceLoaderOptions>
: public CrossThreadCopierPassThrough<ResourceLoaderOptions> { | 76 template<> struct CrossThreadCopierBase<false, false, false, ResourceLoaderO
ptions> : public CrossThreadCopierPassThrough<ResourceLoaderOptions> { |
76 }; | 77 }; |
77 | 78 |
78 template<> struct CrossThreadCopierBase<false, false, IntRect> : public Cros
sThreadCopierPassThrough<IntRect> { | 79 template<> struct CrossThreadCopierBase<false, false, false, IntRect> : publ
ic CrossThreadCopierPassThrough<IntRect> { |
79 }; | 80 }; |
80 | 81 |
81 template<> struct CrossThreadCopierBase<false, false, IntSize> : public Cros
sThreadCopierPassThrough<IntSize> { | 82 template<> struct CrossThreadCopierBase<false, false, false, IntSize> : publ
ic CrossThreadCopierPassThrough<IntSize> { |
82 }; | 83 }; |
83 | 84 |
84 // Custom copy methods. | 85 // Custom copy methods. |
85 template<typename T> struct CrossThreadCopierBase<false, true, T> { | 86 template<typename T> struct CrossThreadCopierBase<false, true, false, T> { |
86 typedef typename WTF::RemoveTemplate<T, RefPtr>::Type TypeWithoutRefPtr; | 87 typedef typename WTF::RemoveTemplate<T, RefPtr>::Type TypeWithoutRefPtr; |
87 typedef typename WTF::RemoveTemplate<TypeWithoutRefPtr, PassRefPtr>::Typ
e TypeWithoutPassRefPtr; | 88 typedef typename WTF::RemoveTemplate<TypeWithoutRefPtr, PassRefPtr>::Typ
e TypeWithoutPassRefPtr; |
88 typedef typename WTF::RemovePointer<TypeWithoutPassRefPtr>::Type RefCoun
tedType; | 89 typedef typename WTF::RemovePointer<TypeWithoutPassRefPtr>::Type RefCoun
tedType; |
89 | 90 |
90 // Verify that only one of the above did a change. | 91 // Verify that only one of the above did a change. |
91 COMPILE_ASSERT((WTF::IsSameType<RefPtr<RefCountedType>, T>::value | 92 COMPILE_ASSERT((WTF::IsSameType<RefPtr<RefCountedType>, T>::value |
92 || WTF::IsSameType<PassRefPtr<RefCountedType>, T>::value | 93 || WTF::IsSameType<PassRefPtr<RefCountedType>, T>::value |
93 || WTF::IsSameType<RefCountedType*, T>::value), | 94 || WTF::IsSameType<RefCountedType*, T>::value), |
94 OnlyAllowOneTypeModification); | 95 OnlyAllowOneTypeModification); |
95 | 96 |
96 typedef PassRefPtr<RefCountedType> Type; | 97 typedef PassRefPtr<RefCountedType> Type; |
97 static Type copy(const T& refPtr) | 98 static Type copy(const T& refPtr) |
98 { | 99 { |
99 return refPtr; | 100 return refPtr; |
100 } | 101 } |
101 }; | 102 }; |
102 | 103 |
103 template<typename T> struct CrossThreadCopierBase<false, false, PassOwnPtr<T
> > { | 104 template<typename T> struct CrossThreadCopierBase<false, false, false, PassO
wnPtr<T> > { |
104 typedef PassOwnPtr<T> Type; | 105 typedef PassOwnPtr<T> Type; |
105 static Type copy(Type ownPtr) | 106 static Type copy(Type ownPtr) |
106 { | 107 { |
107 return ownPtr; | 108 return ownPtr; |
108 } | 109 } |
109 }; | 110 }; |
110 | 111 |
111 template<> struct CrossThreadCopierBase<false, false, KURL> { | 112 template<> struct CrossThreadCopierBase<false, false, false, KURL> { |
112 typedef KURL Type; | 113 typedef KURL Type; |
113 PLATFORM_EXPORT static Type copy(const KURL&); | 114 PLATFORM_EXPORT static Type copy(const KURL&); |
114 }; | 115 }; |
115 | 116 |
116 template<> struct CrossThreadCopierBase<false, false, String> { | 117 template<> struct CrossThreadCopierBase<false, false, false, String> { |
117 typedef String Type; | 118 typedef String Type; |
118 PLATFORM_EXPORT static Type copy(const String&); | 119 PLATFORM_EXPORT static Type copy(const String&); |
119 }; | 120 }; |
120 | 121 |
121 template<> struct CrossThreadCopierBase<false, false, ResourceError> { | 122 template<> struct CrossThreadCopierBase<false, false, false, ResourceError>
{ |
122 typedef ResourceError Type; | 123 typedef ResourceError Type; |
123 PLATFORM_EXPORT static Type copy(const ResourceError&); | 124 PLATFORM_EXPORT static Type copy(const ResourceError&); |
124 }; | 125 }; |
125 | 126 |
126 template<> struct CrossThreadCopierBase<false, false, ResourceRequest> { | 127 template<> struct CrossThreadCopierBase<false, false, false, ResourceRequest
> { |
127 typedef PassOwnPtr<CrossThreadResourceRequestData> Type; | 128 typedef PassOwnPtr<CrossThreadResourceRequestData> Type; |
128 PLATFORM_EXPORT static Type copy(const ResourceRequest&); | 129 PLATFORM_EXPORT static Type copy(const ResourceRequest&); |
129 }; | 130 }; |
130 | 131 |
131 template<> struct CrossThreadCopierBase<false, false, ResourceResponse> { | 132 template<> struct CrossThreadCopierBase<false, false, false, ResourceRespons
e> { |
132 typedef PassOwnPtr<CrossThreadResourceResponseData> Type; | 133 typedef PassOwnPtr<CrossThreadResourceResponseData> Type; |
133 PLATFORM_EXPORT static Type copy(const ResourceResponse&); | 134 PLATFORM_EXPORT static Type copy(const ResourceResponse&); |
134 }; | 135 }; |
135 | 136 |
| 137 template<typename T> struct CrossThreadCopierBase<false, false, true, T> { |
| 138 typedef typename WTF::RemovePointer<T>::Type TypeWithoutPointer; |
| 139 typedef PassRefPtrWillBeRawPtr<TypeWithoutPointer> Type; |
| 140 static Type copy(const T& ptr) |
| 141 { |
| 142 return ptr; |
| 143 } |
| 144 }; |
| 145 |
136 template<typename T> struct CrossThreadCopier : public CrossThreadCopierBase
<WTF::IsConvertibleToInteger<T>::value, | 146 template<typename T> struct CrossThreadCopier : public CrossThreadCopierBase
<WTF::IsConvertibleToInteger<T>::value, |
137
WTF::IsSubclassOfTemplate<typename WTF::RemoveTemplate<T, RefPtr>::Type, Thread
SafeRefCounted>::value | 147 WTF::IsSubclassOfTemplate<typename WTF::RemoveTemplate<T, RefPtr>::Type,
ThreadSafeRefCounted>::value |
138
|| WTF::IsSubclassOfTemplate<typename WTF::RemovePointer<T>::Type, ThreadSa
feRefCounted>::value | 148 || WTF::IsSubclassOfTemplate<typename WTF::RemovePointer<T>::Type, T
hreadSafeRefCounted>::value |
139
|| WTF::IsSubclassOfTemplate<typename WTF::RemoveTemplate<T, PassRefPtr>::T
ype, ThreadSafeRefCounted>::value, | 149 || WTF::IsSubclassOfTemplate<typename WTF::RemoveTemplate<T, PassRef
Ptr>::Type, ThreadSafeRefCounted>::value, |
140
T> { | 150 WTF::IsSubclassOfTemplate<typename WTF::RemovePointer<T>::Type, GarbageC
ollected>::value, |
| 151 T> { |
141 }; | 152 }; |
142 | 153 |
143 template<typename T> struct AllowCrossThreadAccessWrapper { | 154 template<typename T> struct AllowCrossThreadAccessWrapper { |
144 public: | 155 public: |
145 explicit AllowCrossThreadAccessWrapper(T* value) : m_value(value) { } | 156 explicit AllowCrossThreadAccessWrapper(T* value) : m_value(value) { } |
146 T* value() const { return m_value; } | 157 T* value() const { return m_value; } |
147 private: | 158 private: |
148 T* m_value; | 159 T* m_value; |
149 }; | 160 }; |
150 | 161 |
151 template<typename T> struct CrossThreadCopierBase<false, false, AllowCrossTh
readAccessWrapper<T> > { | 162 template<typename T> struct CrossThreadCopierBase<false, false, false, Allow
CrossThreadAccessWrapper<T> > { |
152 typedef T* Type; | 163 typedef T* Type; |
153 static Type copy(const AllowCrossThreadAccessWrapper<T>& wrapper) { retu
rn wrapper.value(); } | 164 static Type copy(const AllowCrossThreadAccessWrapper<T>& wrapper) { retu
rn wrapper.value(); } |
154 }; | 165 }; |
155 | 166 |
156 template<typename T> AllowCrossThreadAccessWrapper<T> AllowCrossThreadAccess
(T* value) | 167 template<typename T> AllowCrossThreadAccessWrapper<T> AllowCrossThreadAccess
(T* value) |
157 { | 168 { |
158 return AllowCrossThreadAccessWrapper<T>(value); | 169 return AllowCrossThreadAccessWrapper<T>(value); |
159 } | 170 } |
160 | 171 |
161 // FIXME: Move to a different header file. AllowAccessLater is for cross-thr
ead access | 172 // FIXME: Move to a different header file. AllowAccessLater is for cross-thr
ead access |
162 // that is not cross-thread (tasks posted to a queue guaranteed to run on th
e same thread). | 173 // that is not cross-thread (tasks posted to a queue guaranteed to run on th
e same thread). |
163 template<typename T> struct AllowAccessLaterWrapper { | 174 template<typename T> struct AllowAccessLaterWrapper { |
164 public: | 175 public: |
165 explicit AllowAccessLaterWrapper(T* value) : m_value(value) { } | 176 explicit AllowAccessLaterWrapper(T* value) : m_value(value) { } |
166 T* value() const { return m_value; } | 177 T* value() const { return m_value; } |
167 private: | 178 private: |
168 T* m_value; | 179 T* m_value; |
169 }; | 180 }; |
170 | 181 |
171 template<typename T> struct CrossThreadCopierBase<false, false, AllowAccessL
aterWrapper<T> > { | 182 template<typename T> struct CrossThreadCopierBase<false, false, false, Allow
AccessLaterWrapper<T> > { |
172 typedef T* Type; | 183 typedef T* Type; |
173 static Type copy(const AllowAccessLaterWrapper<T>& wrapper) { return wra
pper.value(); } | 184 static Type copy(const AllowAccessLaterWrapper<T>& wrapper) { return wra
pper.value(); } |
174 }; | 185 }; |
175 | 186 |
176 template<typename T> AllowAccessLaterWrapper<T> AllowAccessLater(T* value) | 187 template<typename T> AllowAccessLaterWrapper<T> AllowAccessLater(T* value) |
177 { | 188 { |
178 return AllowAccessLaterWrapper<T>(value); | 189 return AllowAccessLaterWrapper<T>(value); |
179 } | 190 } |
180 | 191 |
181 | 192 |
182 } // namespace WebCore | 193 } // namespace WebCore |
183 | 194 |
184 #endif // CrossThreadCopier_h | 195 #endif // CrossThreadCopier_h |
OLD | NEW |