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> { |
| 134 typedef typename WTF::RemovePointer<T>::Type TypeWithoutPointer; |
| 135 typedef PassRefPtrWillBeRawPtr<TypeWithoutPointer> Type; |
| 136 static Type copy(const T& ptr) |
| 137 { |
| 138 return ptr; |
| 139 } |
| 140 }; |
| 141 |
132 template<typename T> struct CrossThreadCopier : public CrossThreadCopierBase
<WTF::IsConvertibleToInteger<T>::value, | 142 template<typename T> struct CrossThreadCopier : public CrossThreadCopierBase
<WTF::IsConvertibleToInteger<T>::value, |
133
WTF::IsSubclassOfTemplate<typename WTF::RemoveTemplate<T, RefPtr>::Type, Thread
SafeRefCounted>::value | 143 WTF::IsSubclassOfTemplate<typename WTF::RemoveTemplate<T, RefPtr>::Type,
ThreadSafeRefCounted>::value |
134
|| WTF::IsSubclassOfTemplate<typename WTF::RemovePointer<T>::Type, ThreadSa
feRefCounted>::value | 144 || WTF::IsSubclassOfTemplate<typename WTF::RemovePointer<T>::Type, T
hreadSafeRefCounted>::value |
135
|| WTF::IsSubclassOfTemplate<typename WTF::RemoveTemplate<T, PassRefPtr>::T
ype, ThreadSafeRefCounted>::value, | 145 || WTF::IsSubclassOfTemplate<typename WTF::RemoveTemplate<T, PassRef
Ptr>::Type, ThreadSafeRefCounted>::value, |
136
T> { | 146 WTF::IsSubclassOfTemplate<typename WTF::RemovePointer<T>::Type, GarbageC
ollected>::value, |
| 147 T> { |
137 }; | 148 }; |
138 | 149 |
139 template<typename T> struct AllowCrossThreadAccessWrapper { | 150 template<typename T> struct AllowCrossThreadAccessWrapper { |
140 public: | 151 public: |
141 explicit AllowCrossThreadAccessWrapper(T* value) : m_value(value) { } | 152 explicit AllowCrossThreadAccessWrapper(T* value) : m_value(value) { } |
142 T* value() const { return m_value; } | 153 T* value() const { return m_value; } |
143 private: | 154 private: |
144 T* m_value; | 155 T* m_value; |
145 }; | 156 }; |
146 | 157 |
147 template<typename T> struct CrossThreadCopierBase<false, false, AllowCrossTh
readAccessWrapper<T> > { | 158 template<typename T> struct CrossThreadCopierBase<false, false, false, Allow
CrossThreadAccessWrapper<T> > { |
148 typedef T* Type; | 159 typedef T* Type; |
149 static Type copy(const AllowCrossThreadAccessWrapper<T>& wrapper) { retu
rn wrapper.value(); } | 160 static Type copy(const AllowCrossThreadAccessWrapper<T>& wrapper) { retu
rn wrapper.value(); } |
150 }; | 161 }; |
151 | 162 |
152 template<typename T> AllowCrossThreadAccessWrapper<T> AllowCrossThreadAccess
(T* value) | 163 template<typename T> AllowCrossThreadAccessWrapper<T> AllowCrossThreadAccess
(T* value) |
153 { | 164 { |
154 return AllowCrossThreadAccessWrapper<T>(value); | 165 return AllowCrossThreadAccessWrapper<T>(value); |
155 } | 166 } |
156 | 167 |
157 // FIXME: Move to a different header file. AllowAccessLater is for cross-thr
ead access | 168 // 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). | 169 // that is not cross-thread (tasks posted to a queue guaranteed to run on th
e same thread). |
159 template<typename T> struct AllowAccessLaterWrapper { | 170 template<typename T> struct AllowAccessLaterWrapper { |
160 public: | 171 public: |
161 explicit AllowAccessLaterWrapper(T* value) : m_value(value) { } | 172 explicit AllowAccessLaterWrapper(T* value) : m_value(value) { } |
162 T* value() const { return m_value; } | 173 T* value() const { return m_value; } |
163 private: | 174 private: |
164 T* m_value; | 175 T* m_value; |
165 }; | 176 }; |
166 | 177 |
167 template<typename T> struct CrossThreadCopierBase<false, false, AllowAccessL
aterWrapper<T> > { | 178 template<typename T> struct CrossThreadCopierBase<false, false, false, Allow
AccessLaterWrapper<T> > { |
168 typedef T* Type; | 179 typedef T* Type; |
169 static Type copy(const AllowAccessLaterWrapper<T>& wrapper) { return wra
pper.value(); } | 180 static Type copy(const AllowAccessLaterWrapper<T>& wrapper) { return wra
pper.value(); } |
170 }; | 181 }; |
171 | 182 |
172 template<typename T> AllowAccessLaterWrapper<T> AllowAccessLater(T* value) | 183 template<typename T> AllowAccessLaterWrapper<T> AllowAccessLater(T* value) |
173 { | 184 { |
174 return AllowAccessLaterWrapper<T>(value); | 185 return AllowAccessLaterWrapper<T>(value); |
175 } | 186 } |
176 | 187 |
177 | 188 |
178 } // namespace WebCore | 189 } // namespace WebCore |
179 | 190 |
180 #endif // CrossThreadCopier_h | 191 #endif // CrossThreadCopier_h |
OLD | NEW |