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 13 matching lines...) Expand all Loading... |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
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 <wtf/Assertions.h> |
34 #include <wtf/Forward.h> | 35 #include <wtf/Forward.h> |
35 #include <wtf/PassOwnPtr.h> | 36 #include <wtf/PassOwnPtr.h> |
36 #include <wtf/PassRefPtr.h> | 37 #include <wtf/PassRefPtr.h> |
37 #include <wtf/RefPtr.h> | 38 #include <wtf/RefPtr.h> |
38 #include <wtf/Threading.h> | 39 #include <wtf/Threading.h> |
39 #include <wtf/TypeTraits.h> | 40 #include <wtf/TypeTraits.h> |
40 | 41 |
41 namespace WebCore { | 42 namespace WebCore { |
42 | 43 |
43 class KURL; | 44 class KURL; |
(...skipping 17 matching lines...) Expand all Loading... |
61 // Integers get passed through without any changes. | 62 // Integers get passed through without any changes. |
62 template<typename T> struct CrossThreadCopierBase<true, false, T> : public C
rossThreadCopierPassThrough<T> { | 63 template<typename T> struct CrossThreadCopierBase<true, false, T> : public C
rossThreadCopierPassThrough<T> { |
63 }; | 64 }; |
64 | 65 |
65 template<> struct CrossThreadCopierBase<false, false, ThreadableLoaderOption
s> : public CrossThreadCopierPassThrough<ThreadableLoaderOptions> { | 66 template<> struct CrossThreadCopierBase<false, false, ThreadableLoaderOption
s> : public CrossThreadCopierPassThrough<ThreadableLoaderOptions> { |
66 }; | 67 }; |
67 | 68 |
68 // Custom copy methods. | 69 // Custom copy methods. |
69 template<typename T> struct CrossThreadCopierBase<false, true, T> { | 70 template<typename T> struct CrossThreadCopierBase<false, true, T> { |
70 typedef typename WTF::RemoveTemplate<T, RefPtr>::Type TypeWithoutRefPtr; | 71 typedef typename WTF::RemoveTemplate<T, RefPtr>::Type TypeWithoutRefPtr; |
71 typedef typename WTF::RemoveTemplate<TypeWithoutRefPtr, PassRefPtr>::Typ
e RefCountedType; | 72 typedef typename WTF::RemoveTemplate<TypeWithoutRefPtr, PassRefPtr>::Typ
e TypeWithoutPassRefPtr; |
| 73 typedef typename WTF::RemovePointer<TypeWithoutPassRefPtr>::Type RefCoun
tedType; |
| 74 |
| 75 // Verify that only one of the above did a change. |
| 76 COMPILE_ASSERT((WTF::IsSameType<RefPtr<RefCountedType>, T>::value |
| 77 || WTF::IsSameType<PassRefPtr<RefCountedType>, T>::value |
| 78 || WTF::IsSameType<RefCountedType*, T>::value), |
| 79 OnlyAllowOneTypeModification); |
| 80 |
72 typedef PassRefPtr<RefCountedType> Type; | 81 typedef PassRefPtr<RefCountedType> Type; |
73 static Type copy(const T& refPtr) | 82 static Type copy(const T& refPtr) |
74 { | 83 { |
75 return refPtr.get(); | 84 return refPtr; |
76 } | 85 } |
77 }; | 86 }; |
78 | 87 |
79 template<typename T> struct CrossThreadCopierBase<false, false, PassOwnPtr<T
> > { | 88 template<typename T> struct CrossThreadCopierBase<false, false, PassOwnPtr<T
> > { |
80 typedef PassOwnPtr<T> Type; | 89 typedef PassOwnPtr<T> Type; |
81 static Type copy(Type ownPtr) | 90 static Type copy(Type ownPtr) |
82 { | 91 { |
83 return ownPtr; | 92 return ownPtr; |
84 } | 93 } |
85 }; | 94 }; |
(...skipping 18 matching lines...) Expand all Loading... |
104 static Type copy(const ResourceRequest&); | 113 static Type copy(const ResourceRequest&); |
105 }; | 114 }; |
106 | 115 |
107 template<> struct CrossThreadCopierBase<false, false, ResourceResponse> { | 116 template<> struct CrossThreadCopierBase<false, false, ResourceResponse> { |
108 typedef PassOwnPtr<CrossThreadResourceResponseData> Type; | 117 typedef PassOwnPtr<CrossThreadResourceResponseData> Type; |
109 static Type copy(const ResourceResponse&); | 118 static Type copy(const ResourceResponse&); |
110 }; | 119 }; |
111 | 120 |
112 template<typename T> struct CrossThreadCopier : public CrossThreadCopierBase
<WTF::IsConvertibleToInteger<T>::value, | 121 template<typename T> struct CrossThreadCopier : public CrossThreadCopierBase
<WTF::IsConvertibleToInteger<T>::value, |
113
WTF::IsSubclassOfTemplate<typename WTF::RemoveTemplate<T, RefPtr>::Type, Thread
SafeRefCounted>::value | 122
WTF::IsSubclassOfTemplate<typename WTF::RemoveTemplate<T, RefPtr>::Type, Thread
SafeRefCounted>::value |
| 123
|| WTF::IsSubclassOfTemplate<typename WTF::RemovePointer<T>::Type, ThreadSa
feRefCounted>::value |
114
|| WTF::IsSubclassOfTemplate<typename WTF::RemoveTemplate<T, PassRefPtr>::T
ype, ThreadSafeRefCounted>::value, | 124
|| WTF::IsSubclassOfTemplate<typename WTF::RemoveTemplate<T, PassRefPtr>::T
ype, ThreadSafeRefCounted>::value, |
115
T> { | 125
T> { |
116 }; | 126 }; |
117 | 127 |
118 template<typename T> struct AllowCrossThreadAccessWrapper { | 128 template<typename T> struct AllowCrossThreadAccessWrapper { |
119 public: | 129 public: |
120 explicit AllowCrossThreadAccessWrapper(T* value) : m_value(value) { } | 130 explicit AllowCrossThreadAccessWrapper(T* value) : m_value(value) { } |
121 T* value() const { return m_value; } | 131 T* value() const { return m_value; } |
122 private: | 132 private: |
123 T* m_value; | 133 T* m_value; |
(...skipping 26 matching lines...) Expand all Loading... |
150 | 160 |
151 template<typename T> AllowAccessLaterWrapper<T> AllowAccessLater(T* value) | 161 template<typename T> AllowAccessLaterWrapper<T> AllowAccessLater(T* value) |
152 { | 162 { |
153 return AllowAccessLaterWrapper<T>(value); | 163 return AllowAccessLaterWrapper<T>(value); |
154 } | 164 } |
155 | 165 |
156 | 166 |
157 } // namespace WebCore | 167 } // namespace WebCore |
158 | 168 |
159 #endif // CrossThreadCopier_h | 169 #endif // CrossThreadCopier_h |
OLD | NEW |