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

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

Issue 2096623002: Update ParamStorageTraits to disallow raw pointers and Member<> (2/5) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@unretained
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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 22 matching lines...) Expand all
33 #include "wtf/PassRefPtr.h" 33 #include "wtf/PassRefPtr.h"
34 #include "wtf/PtrUtil.h" 34 #include "wtf/PtrUtil.h"
35 #include "wtf/RefPtr.h" 35 #include "wtf/RefPtr.h"
36 #include "wtf/ThreadSafeRefCounted.h" 36 #include "wtf/ThreadSafeRefCounted.h"
37 #include "wtf/TypeTraits.h" 37 #include "wtf/TypeTraits.h"
38 #include "wtf/WeakPtr.h" 38 #include "wtf/WeakPtr.h"
39 #include <tuple> 39 #include <tuple>
40 #include <utility> 40 #include <utility>
41 41
42 namespace blink { 42 namespace blink {
43 template<typename T> class CrossThreadPersistent; 43 template <typename T> class Member;
44 } 44 }
45 45
46 namespace base { 46 namespace base {
47 47
48 template <typename T> 48 template <typename T>
49 struct IsWeakReceiver<WTF::WeakPtr<T>> : std::true_type {}; 49 struct IsWeakReceiver<WTF::WeakPtr<T>> : std::true_type {};
50 50
51 } 51 }
52 52
53 namespace WTF { 53 namespace WTF {
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 } 209 }
210 210
211 private: 211 private:
212 R(C::*m_function)(Parameters...); 212 R(C::*m_function)(Parameters...);
213 }; 213 };
214 214
215 template <typename T> 215 template <typename T>
216 struct ParamStorageTraits { 216 struct ParamStorageTraits {
217 typedef T StorageType; 217 typedef T StorageType;
218 218
219 static_assert(!std::is_pointer<T>::value, "Raw pointer is not allowed to bin d into WTF::Function. Wrap it with either Persistent, WeakPersistent, CrossThrea dPersistent, CrossThreadWeakPersistent, RefPtr or unretained.");
sof 2016/06/24 11:37:19 Shouldn't the error message be mentioning wrapPers
tzik 2016/06/24 13:13:33 OK, replaced them to wrap*.
220 static_assert(!IsSubclassOfTemplate<T, blink::Member>::value, "Member is not allowed to bind into WTF::Function. Wrap it with either Persistent, WeakPersist ent, CrossThreadPersistent or CrossThreadWeakPersistenst.");
sof 2016/06/24 11:37:19 Add a case for WeakMember<>?
tzik 2016/06/24 13:13:33 Done.
221
219 static StorageType wrap(const T& value) { return value; } // Copy. 222 static StorageType wrap(const T& value) { return value; } // Copy.
220 static StorageType wrap(T&& value) { return std::move(value); } 223 static StorageType wrap(T&& value) { return std::move(value); }
221 224
222 // Don't move out, because the functor may be called multiple times. 225 // Don't move out, because the functor may be called multiple times.
223 static const T& unwrap(const StorageType& value) { return value; } 226 static const T& unwrap(const StorageType& value) { return value; }
224 }; 227 };
225 228
226 template <typename T> 229 template <typename T>
227 struct ParamStorageTraits<PassRefPtr<T>> { 230 struct ParamStorageTraits<PassRefPtr<T>> {
228 typedef RefPtr<T> StorageType; 231 typedef RefPtr<T> StorageType;
(...skipping 29 matching lines...) Expand all
258 }; 261 };
259 262
260 template <typename T, FunctionThreadAffinity threadAffinity> 263 template <typename T, FunctionThreadAffinity threadAffinity>
261 struct ParamStorageTraits<UnretainedWrapper<T, threadAffinity>> { 264 struct ParamStorageTraits<UnretainedWrapper<T, threadAffinity>> {
262 typedef UnretainedWrapper<T, threadAffinity> StorageType; 265 typedef UnretainedWrapper<T, threadAffinity> StorageType;
263 266
264 static StorageType wrap(const UnretainedWrapper<T, threadAffinity>& value) { return value; } 267 static StorageType wrap(const UnretainedWrapper<T, threadAffinity>& value) { return value; }
265 static T* unwrap(const StorageType& value) { return value.value(); } 268 static T* unwrap(const StorageType& value) { return value.value(); }
266 }; 269 };
267 270
268 template<typename T, bool isGarbageCollected> struct PointerParamStorageTraits;
269
270 template<typename T>
271 struct PointerParamStorageTraits<T*, false> {
272 STATIC_ONLY(PointerParamStorageTraits);
273 using StorageType = T*;
274
275 static StorageType wrap(T* value) { return value; }
276 static T* unwrap(const StorageType& value) { return value; }
277 };
278
279 template<typename T>
280 struct PointerParamStorageTraits<T*, true> {
281 STATIC_ONLY(PointerParamStorageTraits);
282 using StorageType = blink::CrossThreadPersistent<T>;
283
284 static StorageType wrap(T* value) { return value; }
285 static T* unwrap(const StorageType& value) { return value.get(); }
286 };
287
288 template<typename T>
289 struct ParamStorageTraits<T*> : public PointerParamStorageTraits<T*, IsGarbageCo llectedType<T>::value> {
290 STATIC_ONLY(ParamStorageTraits);
291 };
292
293 template<typename, FunctionThreadAffinity threadAffinity = SameThreadAffinity> 271 template<typename, FunctionThreadAffinity threadAffinity = SameThreadAffinity>
294 class Function; 272 class Function;
295 273
296 template<FunctionThreadAffinity threadAffinity, typename R, typename... Args> 274 template<FunctionThreadAffinity threadAffinity, typename R, typename... Args>
297 class Function<R(Args...), threadAffinity> { 275 class Function<R(Args...), threadAffinity> {
298 USING_FAST_MALLOC(Function); 276 USING_FAST_MALLOC(Function);
299 WTF_MAKE_NONCOPYABLE(Function); 277 WTF_MAKE_NONCOPYABLE(Function);
300 public: 278 public:
301 virtual ~Function() { } 279 virtual ~Function() { }
302 virtual R operator()(Args... args) = 0; 280 virtual R operator()(Args... args) = 0;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 384
407 using WTF::passed; 385 using WTF::passed;
408 using WTF::unretained; 386 using WTF::unretained;
409 using WTF::crossThreadUnretained; 387 using WTF::crossThreadUnretained;
410 388
411 using WTF::Function; 389 using WTF::Function;
412 using WTF::SameThreadClosure; 390 using WTF::SameThreadClosure;
413 using WTF::CrossThreadClosure; 391 using WTF::CrossThreadClosure;
414 392
415 #endif // WTF_Functional_h 393 #endif // WTF_Functional_h
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698