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