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

Side by Side Diff: third_party/WebKit/Source/wtf/Functional.h

Issue 2125003002: Move CrossThreadCopier from platform/ to wtf/ Base URL: https://chromium.googlesource.com/chromium/src.git@TRV_RemoveTupleInBind
Patch Set: Rebase Created 4 years, 5 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2011 Apple 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 12 matching lines...) Expand all
23 * THE POSSIBILITY OF SUCH DAMAGE. 23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #ifndef WTF_Functional_h 26 #ifndef WTF_Functional_h
27 #define WTF_Functional_h 27 #define WTF_Functional_h
28 28
29 #include "base/bind.h" 29 #include "base/bind.h"
30 #include "base/threading/thread_checker.h" 30 #include "base/threading/thread_checker.h"
31 #include "wtf/Allocator.h" 31 #include "wtf/Allocator.h"
32 #include "wtf/Assertions.h" 32 #include "wtf/Assertions.h"
33 #include "wtf/CrossThreadCopier.h"
33 #include "wtf/PassRefPtr.h" 34 #include "wtf/PassRefPtr.h"
34 #include "wtf/PtrUtil.h" 35 #include "wtf/PtrUtil.h"
35 #include "wtf/RefPtr.h" 36 #include "wtf/RefPtr.h"
36 #include "wtf/ThreadSafeRefCounted.h" 37 #include "wtf/ThreadSafeRefCounted.h"
37 #include "wtf/TypeTraits.h" 38 #include "wtf/TypeTraits.h"
38 #include "wtf/WeakPtr.h" 39 #include "wtf/WeakPtr.h"
39 #include <utility> 40 #include <utility>
40 41
41 namespace blink { 42 namespace blink {
42 template <typename T> class Member; 43 template <typename T> class Member;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 124
124 template <typename T> 125 template <typename T>
125 PassedWrapper<T> passed(T&& value) 126 PassedWrapper<T> passed(T&& value)
126 { 127 {
127 static_assert(!std::is_reference<T>::value, 128 static_assert(!std::is_reference<T>::value,
128 "You must pass an rvalue to passed() so it can be moved. Add std::move() if necessary."); 129 "You must pass an rvalue to passed() so it can be moved. Add std::move() if necessary.");
129 static_assert(!std::is_const<T>::value, "|value| must not be const so it can be moved."); 130 static_assert(!std::is_const<T>::value, "|value| must not be const so it can be moved.");
130 return PassedWrapper<T>(std::move(value)); 131 return PassedWrapper<T>(std::move(value));
131 } 132 }
132 133
134 template <typename T>
135 struct CrossThreadCopier<PassedWrapper<T>> {
136 STATIC_ONLY(CrossThreadCopier);
137 using Type = PassedWrapper<typename CrossThreadCopier<T>::Type>;
138 static Type copy(PassedWrapper<T>&& value) { return passed(CrossThreadCopier <T>::copy(value.moveOut())); }
139 };
140
133 template <typename T, FunctionThreadAffinity threadAffinity> 141 template <typename T, FunctionThreadAffinity threadAffinity>
134 class UnretainedWrapper final { 142 class UnretainedWrapper final {
135 public: 143 public:
136 explicit UnretainedWrapper(T* ptr) : m_ptr(ptr) { } 144 explicit UnretainedWrapper(T* ptr) : m_ptr(ptr) { }
137 T* value() const { return m_ptr; } 145 T* value() const { return m_ptr; }
138 146
139 private: 147 private:
140 T* m_ptr; 148 T* m_ptr;
141 }; 149 };
142 150
143 template <typename T> 151 template <typename T>
144 UnretainedWrapper<T, SameThreadAffinity> unretained(T* value) 152 UnretainedWrapper<T, SameThreadAffinity> unretained(T* value)
145 { 153 {
146 static_assert(!WTF::IsGarbageCollectedType<T>::value, "unretained() + GCed t ype is forbidden"); 154 static_assert(!WTF::IsGarbageCollectedType<T>::value, "unretained() + GCed t ype is forbidden");
147 return UnretainedWrapper<T, SameThreadAffinity>(value); 155 return UnretainedWrapper<T, SameThreadAffinity>(value);
148 } 156 }
149 157
150 template <typename T> 158 template <typename T>
151 UnretainedWrapper<T, CrossThreadAffinity> crossThreadUnretained(T* value) 159 UnretainedWrapper<T, CrossThreadAffinity> crossThreadUnretained(T* value)
152 { 160 {
153 static_assert(!WTF::IsGarbageCollectedType<T>::value, "crossThreadUnretained () + GCed type is forbidden"); 161 static_assert(!WTF::IsGarbageCollectedType<T>::value, "crossThreadUnretained () + GCed type is forbidden");
154 return UnretainedWrapper<T, CrossThreadAffinity>(value); 162 return UnretainedWrapper<T, CrossThreadAffinity>(value);
155 } 163 }
156 164
165 template<typename T>
166 struct CrossThreadCopier<UnretainedWrapper<T, CrossThreadAffinity>> : public Cro ssThreadCopierPassThrough<UnretainedWrapper<T, CrossThreadAffinity>> {
167 STATIC_ONLY(CrossThreadCopier);
168 };
169
157 template <typename T> 170 template <typename T>
158 struct ParamStorageTraits { 171 struct ParamStorageTraits {
159 typedef T StorageType; 172 typedef T StorageType;
160 173
161 static_assert(!std::is_pointer<T>::value, "Raw pointers are not allowed to b ind into WTF::Function. Wrap it with either wrapPersistent, wrapWeakPersistent, wrapCrossThreadPersistent, wrapCrossThreadWeakPersistent, RefPtr or unretained." ); 174 static_assert(!std::is_pointer<T>::value, "Raw pointers are not allowed to b ind into WTF::Function. Wrap it with either wrapPersistent, wrapWeakPersistent, wrapCrossThreadPersistent, wrapCrossThreadWeakPersistent, RefPtr or unretained." );
162 static_assert(!IsSubclassOfTemplate<T, blink::Member>::value && !IsSubclassO fTemplate<T, blink::WeakMember>::value, "Member and WeakMember are not allowed t o bind into WTF::Function. Wrap it with either wrapPersistent, wrapWeakPersisten t, wrapCrossThreadPersistent or wrapCrossThreadWeakPersistent."); 175 static_assert(!IsSubclassOfTemplate<T, blink::Member>::value && !IsSubclassO fTemplate<T, blink::WeakMember>::value, "Member and WeakMember are not allowed t o bind into WTF::Function. Wrap it with either wrapPersistent, wrapWeakPersisten t, wrapCrossThreadPersistent or wrapCrossThreadWeakPersistent.");
163 }; 176 };
164 177
165 template <typename T> 178 template <typename T>
166 struct ParamStorageTraits<PassRefPtr<T>> { 179 struct ParamStorageTraits<PassRefPtr<T>> {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 } // namespace WTF 275 } // namespace WTF
263 276
264 using WTF::passed; 277 using WTF::passed;
265 using WTF::unretained; 278 using WTF::unretained;
266 using WTF::crossThreadUnretained; 279 using WTF::crossThreadUnretained;
267 280
268 using WTF::Function; 281 using WTF::Function;
269 using WTF::CrossThreadClosure; 282 using WTF::CrossThreadClosure;
270 283
271 #endif // WTF_Functional_h 284 #endif // WTF_Functional_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698