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

Side by Side Diff: trunk/Source/platform/CrossThreadCopier.h

Issue 309503013: Revert 174956 "Oilpan: Move ThreadableWebSocketChannelClientWrap..." (Closed) Base URL: svn://svn.chromium.org/blink/
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
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 14 matching lines...) Expand all
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"
36 #include "wtf/Assertions.h" 35 #include "wtf/Assertions.h"
37 #include "wtf/Forward.h" 36 #include "wtf/Forward.h"
38 #include "wtf/PassOwnPtr.h" 37 #include "wtf/PassOwnPtr.h"
39 #include "wtf/PassRefPtr.h" 38 #include "wtf/PassRefPtr.h"
40 #include "wtf/RefPtr.h" 39 #include "wtf/RefPtr.h"
41 #include "wtf/ThreadSafeRefCounted.h" 40 #include "wtf/ThreadSafeRefCounted.h"
42 #include "wtf/TypeTraits.h" 41 #include "wtf/TypeTraits.h"
43 42
44 namespace WebCore { 43 namespace WebCore {
45 44
46 class IntRect; 45 class IntRect;
47 class IntSize; 46 class IntSize;
48 class KURL; 47 class KURL;
49 class ResourceError; 48 class ResourceError;
50 class ResourceRequest; 49 class ResourceRequest;
51 class ResourceResponse; 50 class ResourceResponse;
52 struct CrossThreadResourceResponseData; 51 struct CrossThreadResourceResponseData;
53 struct CrossThreadResourceRequestData; 52 struct CrossThreadResourceRequestData;
54 struct ThreadableLoaderOptions; 53 struct ThreadableLoaderOptions;
55 54
56 template<typename T> struct CrossThreadCopierPassThrough { 55 template<typename T> struct CrossThreadCopierPassThrough {
57 typedef T Type; 56 typedef T Type;
58 static Type copy(const T& parameter) 57 static Type copy(const T& parameter)
59 { 58 {
60 return parameter; 59 return parameter;
61 } 60 }
62 }; 61 };
63 62
64 template<bool isConvertibleToInteger, bool isThreadSafeRefCounted, bool isGa rbageCollected, typename T> struct CrossThreadCopierBase; 63 template<bool isConvertibleToInteger, bool isThreadSafeRefCounted, typename T> struct CrossThreadCopierBase;
65 64
66 // Integers get passed through without any changes. 65 // Integers get passed through without any changes.
67 template<typename T> struct CrossThreadCopierBase<true, false, false, T> : p ublic CrossThreadCopierPassThrough<T> { 66 template<typename T> struct CrossThreadCopierBase<true, false, T> : public C rossThreadCopierPassThrough<T> {
68 }; 67 };
69 68
70 // To allow a type to be passed across threads using its copy constructor, a dd a forward declaration of the type and 69 // 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. 70 // a CopyThreadCopierBase<false, false, TypeName> : public CrossThreadCopier PassThrough<TypeName> { }; to this file.
72 template<> struct CrossThreadCopierBase<false, false, false, ThreadableLoade rOptions> : public CrossThreadCopierPassThrough<ThreadableLoaderOptions> { 71 template<> struct CrossThreadCopierBase<false, false, ThreadableLoaderOption s> : public CrossThreadCopierPassThrough<ThreadableLoaderOptions> {
73 }; 72 };
74 73
75 template<> struct CrossThreadCopierBase<false, false, false, IntRect> : publ ic CrossThreadCopierPassThrough<IntRect> { 74 template<> struct CrossThreadCopierBase<false, false, IntRect> : public Cros sThreadCopierPassThrough<IntRect> {
76 }; 75 };
77 76
78 template<> struct CrossThreadCopierBase<false, false, false, IntSize> : publ ic CrossThreadCopierPassThrough<IntSize> { 77 template<> struct CrossThreadCopierBase<false, false, IntSize> : public Cros sThreadCopierPassThrough<IntSize> {
79 }; 78 };
80 79
81 // Custom copy methods. 80 // Custom copy methods.
82 template<typename T> struct CrossThreadCopierBase<false, true, false, T> { 81 template<typename T> struct CrossThreadCopierBase<false, true, T> {
83 typedef typename WTF::RemoveTemplate<T, RefPtr>::Type TypeWithoutRefPtr; 82 typedef typename WTF::RemoveTemplate<T, RefPtr>::Type TypeWithoutRefPtr;
84 typedef typename WTF::RemoveTemplate<TypeWithoutRefPtr, PassRefPtr>::Typ e TypeWithoutPassRefPtr; 83 typedef typename WTF::RemoveTemplate<TypeWithoutRefPtr, PassRefPtr>::Typ e TypeWithoutPassRefPtr;
85 typedef typename WTF::RemovePointer<TypeWithoutPassRefPtr>::Type RefCoun tedType; 84 typedef typename WTF::RemovePointer<TypeWithoutPassRefPtr>::Type RefCoun tedType;
86 85
87 // Verify that only one of the above did a change. 86 // Verify that only one of the above did a change.
88 COMPILE_ASSERT((WTF::IsSameType<RefPtr<RefCountedType>, T>::value 87 COMPILE_ASSERT((WTF::IsSameType<RefPtr<RefCountedType>, T>::value
89 || WTF::IsSameType<PassRefPtr<RefCountedType>, T>::value 88 || WTF::IsSameType<PassRefPtr<RefCountedType>, T>::value
90 || WTF::IsSameType<RefCountedType*, T>::value), 89 || WTF::IsSameType<RefCountedType*, T>::value),
91 OnlyAllowOneTypeModification); 90 OnlyAllowOneTypeModification);
92 91
93 typedef PassRefPtr<RefCountedType> Type; 92 typedef PassRefPtr<RefCountedType> Type;
94 static Type copy(const T& refPtr) 93 static Type copy(const T& refPtr)
95 { 94 {
96 return refPtr; 95 return refPtr;
97 } 96 }
98 }; 97 };
99 98
100 template<typename T> struct CrossThreadCopierBase<false, false, false, PassO wnPtr<T> > { 99 template<typename T> struct CrossThreadCopierBase<false, false, PassOwnPtr<T > > {
101 typedef PassOwnPtr<T> Type; 100 typedef PassOwnPtr<T> Type;
102 static Type copy(Type ownPtr) 101 static Type copy(Type ownPtr)
103 { 102 {
104 return ownPtr; 103 return ownPtr;
105 } 104 }
106 }; 105 };
107 106
108 template<> struct CrossThreadCopierBase<false, false, false, KURL> { 107 template<> struct CrossThreadCopierBase<false, false, KURL> {
109 typedef KURL Type; 108 typedef KURL Type;
110 PLATFORM_EXPORT static Type copy(const KURL&); 109 PLATFORM_EXPORT static Type copy(const KURL&);
111 }; 110 };
112 111
113 template<> struct CrossThreadCopierBase<false, false, false, String> { 112 template<> struct CrossThreadCopierBase<false, false, String> {
114 typedef String Type; 113 typedef String Type;
115 PLATFORM_EXPORT static Type copy(const String&); 114 PLATFORM_EXPORT static Type copy(const String&);
116 }; 115 };
117 116
118 template<> struct CrossThreadCopierBase<false, false, false, ResourceError> { 117 template<> struct CrossThreadCopierBase<false, false, ResourceError> {
119 typedef ResourceError Type; 118 typedef ResourceError Type;
120 PLATFORM_EXPORT static Type copy(const ResourceError&); 119 PLATFORM_EXPORT static Type copy(const ResourceError&);
121 }; 120 };
122 121
123 template<> struct CrossThreadCopierBase<false, false, false, ResourceRequest > { 122 template<> struct CrossThreadCopierBase<false, false, ResourceRequest> {
124 typedef PassOwnPtr<CrossThreadResourceRequestData> Type; 123 typedef PassOwnPtr<CrossThreadResourceRequestData> Type;
125 PLATFORM_EXPORT static Type copy(const ResourceRequest&); 124 PLATFORM_EXPORT static Type copy(const ResourceRequest&);
126 }; 125 };
127 126
128 template<> struct CrossThreadCopierBase<false, false, false, ResourceRespons e> { 127 template<> struct CrossThreadCopierBase<false, false, ResourceResponse> {
129 typedef PassOwnPtr<CrossThreadResourceResponseData> Type; 128 typedef PassOwnPtr<CrossThreadResourceResponseData> Type;
130 PLATFORM_EXPORT static Type copy(const ResourceResponse&); 129 PLATFORM_EXPORT static Type copy(const ResourceResponse&);
131 }; 130 };
132 131
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
142 template<typename T> struct CrossThreadCopier : public CrossThreadCopierBase <WTF::IsConvertibleToInteger<T>::value, 132 template<typename T> struct CrossThreadCopier : public CrossThreadCopierBase <WTF::IsConvertibleToInteger<T>::value,
143 WTF::IsSubclassOfTemplate<typename WTF::RemoveTemplate<T, RefPtr>::Type, ThreadSafeRefCounted>::value 133 WTF::IsSubclassOfTemplate<typename WTF::RemoveTemplate<T, RefPtr>::Type, Thread SafeRefCounted>::value
144 || WTF::IsSubclassOfTemplate<typename WTF::RemovePointer<T>::Type, T hreadSafeRefCounted>::value 134 || WTF::IsSubclassOfTemplate<typename WTF::RemovePointer<T>::Type, ThreadSa feRefCounted>::value
145 || WTF::IsSubclassOfTemplate<typename WTF::RemoveTemplate<T, PassRef Ptr>::Type, ThreadSafeRefCounted>::value, 135 || WTF::IsSubclassOfTemplate<typename WTF::RemoveTemplate<T, PassRefPtr>::T ype, ThreadSafeRefCounted>::value,
146 WTF::IsSubclassOfTemplate<typename WTF::RemovePointer<T>::Type, GarbageC ollected>::value, 136 T> {
147 T> {
148 }; 137 };
149 138
150 template<typename T> struct AllowCrossThreadAccessWrapper { 139 template<typename T> struct AllowCrossThreadAccessWrapper {
151 public: 140 public:
152 explicit AllowCrossThreadAccessWrapper(T* value) : m_value(value) { } 141 explicit AllowCrossThreadAccessWrapper(T* value) : m_value(value) { }
153 T* value() const { return m_value; } 142 T* value() const { return m_value; }
154 private: 143 private:
155 T* m_value; 144 T* m_value;
156 }; 145 };
157 146
158 template<typename T> struct CrossThreadCopierBase<false, false, false, Allow CrossThreadAccessWrapper<T> > { 147 template<typename T> struct CrossThreadCopierBase<false, false, AllowCrossTh readAccessWrapper<T> > {
159 typedef T* Type; 148 typedef T* Type;
160 static Type copy(const AllowCrossThreadAccessWrapper<T>& wrapper) { retu rn wrapper.value(); } 149 static Type copy(const AllowCrossThreadAccessWrapper<T>& wrapper) { retu rn wrapper.value(); }
161 }; 150 };
162 151
163 template<typename T> AllowCrossThreadAccessWrapper<T> AllowCrossThreadAccess (T* value) 152 template<typename T> AllowCrossThreadAccessWrapper<T> AllowCrossThreadAccess (T* value)
164 { 153 {
165 return AllowCrossThreadAccessWrapper<T>(value); 154 return AllowCrossThreadAccessWrapper<T>(value);
166 } 155 }
167 156
168 // FIXME: Move to a different header file. AllowAccessLater is for cross-thr ead access 157 // FIXME: Move to a different header file. AllowAccessLater is for cross-thr ead access
169 // that is not cross-thread (tasks posted to a queue guaranteed to run on th e same thread). 158 // that is not cross-thread (tasks posted to a queue guaranteed to run on th e same thread).
170 template<typename T> struct AllowAccessLaterWrapper { 159 template<typename T> struct AllowAccessLaterWrapper {
171 public: 160 public:
172 explicit AllowAccessLaterWrapper(T* value) : m_value(value) { } 161 explicit AllowAccessLaterWrapper(T* value) : m_value(value) { }
173 T* value() const { return m_value; } 162 T* value() const { return m_value; }
174 private: 163 private:
175 T* m_value; 164 T* m_value;
176 }; 165 };
177 166
178 template<typename T> struct CrossThreadCopierBase<false, false, false, Allow AccessLaterWrapper<T> > { 167 template<typename T> struct CrossThreadCopierBase<false, false, AllowAccessL aterWrapper<T> > {
179 typedef T* Type; 168 typedef T* Type;
180 static Type copy(const AllowAccessLaterWrapper<T>& wrapper) { return wra pper.value(); } 169 static Type copy(const AllowAccessLaterWrapper<T>& wrapper) { return wra pper.value(); }
181 }; 170 };
182 171
183 template<typename T> AllowAccessLaterWrapper<T> AllowAccessLater(T* value) 172 template<typename T> AllowAccessLaterWrapper<T> AllowAccessLater(T* value)
184 { 173 {
185 return AllowAccessLaterWrapper<T>(value); 174 return AllowAccessLaterWrapper<T>(value);
186 } 175 }
187 176
188 177
189 } // namespace WebCore 178 } // namespace WebCore
190 179
191 #endif // CrossThreadCopier_h 180 #endif // CrossThreadCopier_h
OLDNEW
« no previous file with comments | « trunk/Source/modules/websockets/WorkerThreadableWebSocketChannel.cpp ('k') | trunk/Source/platform/CrossThreadCopier.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698