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

Side by Side Diff: third_party/WebKit/Source/platform/CrossThreadCopier.h

Issue 1925583003: Replace AllowCrossThreadAccess() + non-GCed pointers with crossThreadUnretained() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Kuroneko_4
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) 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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 struct CrossThreadCopier<CrossThreadPersistent<T>> : public CrossThreadCopierPas sThrough<CrossThreadPersistent<T>> { 148 struct CrossThreadCopier<CrossThreadPersistent<T>> : public CrossThreadCopierPas sThrough<CrossThreadPersistent<T>> {
149 STATIC_ONLY(CrossThreadCopier); 149 STATIC_ONLY(CrossThreadCopier);
150 }; 150 };
151 151
152 template<typename T> 152 template<typename T>
153 struct CrossThreadCopier<CrossThreadWeakPersistent<T>> : public CrossThreadCopie rPassThrough<CrossThreadWeakPersistent<T>> { 153 struct CrossThreadCopier<CrossThreadWeakPersistent<T>> : public CrossThreadCopie rPassThrough<CrossThreadWeakPersistent<T>> {
154 STATIC_ONLY(CrossThreadCopier); 154 STATIC_ONLY(CrossThreadCopier);
155 }; 155 };
156 156
157 template<typename T> 157 template<typename T>
158 struct CrossThreadCopier<WTF::UnretainedWrapper<T, WTF::CrossThreadAffinity>> : public CrossThreadCopierPassThrough<WTF::UnretainedWrapper<T, WTF::CrossThreadAf finity>> {
159 STATIC_ONLY(CrossThreadCopier);
160 };
161
162 template<typename T>
158 struct CrossThreadCopier<WeakPtr<T>> : public CrossThreadCopierPassThrough<WeakP tr<T>> { 163 struct CrossThreadCopier<WeakPtr<T>> : public CrossThreadCopierPassThrough<WeakP tr<T>> {
159 STATIC_ONLY(CrossThreadCopier); 164 STATIC_ONLY(CrossThreadCopier);
160 }; 165 };
161 166
162 template <typename T> 167 template <typename T>
163 struct CrossThreadCopier<WTF::PassedWrapper<T>> { 168 struct CrossThreadCopier<WTF::PassedWrapper<T>> {
164 STATIC_ONLY(CrossThreadCopier); 169 STATIC_ONLY(CrossThreadCopier);
165 using Type = WTF::PassedWrapper<typename CrossThreadCopier<T>::Type>; 170 using Type = WTF::PassedWrapper<typename CrossThreadCopier<T>::Type>;
166 static Type copy(WTF::PassedWrapper<T>&& value) { return passed(CrossThreadC opier<T>::copy(value.moveOut())); } 171 static Type copy(WTF::PassedWrapper<T>&& value) { return passed(CrossThreadC opier<T>::copy(value.moveOut())); }
167 }; 172 };
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 struct CrossThreadCopier<Member<T>> { 215 struct CrossThreadCopier<Member<T>> {
211 STATIC_ONLY(CrossThreadCopier); 216 STATIC_ONLY(CrossThreadCopier);
212 static_assert(IsGarbageCollectedType<T>::value, "T must be a garbage-collect ed type."); 217 static_assert(IsGarbageCollectedType<T>::value, "T must be a garbage-collect ed type.");
213 typedef T* Type; 218 typedef T* Type;
214 static Type copy(const Member<T>& ptr) 219 static Type copy(const Member<T>& ptr)
215 { 220 {
216 return ptr; 221 return ptr;
217 } 222 }
218 }; 223 };
219 224
220 // |T| is a pointer type.
221 template <typename T>
222 struct AllowCrossThreadAccessWrapper {
223 STACK_ALLOCATED();
224 public:
225 T value() const { return m_value; }
226 private:
227 // Only constructible from AllowCrossThreadAccess*().
228 explicit AllowCrossThreadAccessWrapper(T value) : m_value(value) { }
229 template <typename U>
230 friend AllowCrossThreadAccessWrapper<U*> AllowCrossThreadAccess(U*);
231
232 // This raw pointer is safe since AllowCrossThreadAccessWrapper is
233 // always stack-allocated. Ideally this should be Member<T> if T is
234 // garbage-collected and T* otherwise, but we don't want to introduce
235 // another template magic just for distinguishing Member<T> from T*.
236 // From the perspective of GC, T* always works correctly.
237 GC_PLUGIN_IGNORE("")
238 T m_value;
239 };
240
241 template <typename T>
242 struct CrossThreadCopier<AllowCrossThreadAccessWrapper<T>> {
243 STATIC_ONLY(CrossThreadCopier);
244 typedef T Type;
245 static Type copy(const AllowCrossThreadAccessWrapper<T>& wrapper) { return w rapper.value(); }
246 };
247
248 template <typename T>
249 AllowCrossThreadAccessWrapper<T*> AllowCrossThreadAccess(T* value)
250 {
251 static_assert(!IsGarbageCollectedType<T>::value, "Use wrapCrossThreadPersist ent() instead for garbage-collected pointers");
252 static_assert(!WTF::IsSubclassOfTemplate<T, ThreadSafeRefCounted>::value, "U se PassRefPtr<T> instead for ThreadSafeRefCounted");
253 return AllowCrossThreadAccessWrapper<T*>(value);
254 }
255
256 } // namespace blink 225 } // namespace blink
257 226
258 #endif // CrossThreadCopier_h 227 #endif // CrossThreadCopier_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698