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

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

Issue 1999343002: Unify and provide one IsGarbageCollectedType<T> implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix unit test Created 4 years, 7 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 16 matching lines...) Expand all
27 #define WTF_Functional_h 27 #define WTF_Functional_h
28 28
29 #include "base/tuple.h" 29 #include "base/tuple.h"
30 #include "wtf/Allocator.h" 30 #include "wtf/Allocator.h"
31 #include "wtf/Assertions.h" 31 #include "wtf/Assertions.h"
32 #include "wtf/PassOwnPtr.h" 32 #include "wtf/PassOwnPtr.h"
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/WeakPtr.h" 38 #include "wtf/WeakPtr.h"
38 #include <tuple> 39 #include <tuple>
39 #include <utility> 40 #include <utility>
40 41
42 namespace blink {
43 template<typename T> class CrossThreadPersistent;
44 }
45
41 namespace WTF { 46 namespace WTF {
42 47
43 // Functional.h provides a very simple way to bind a function pointer and argume nts together into a function object 48 // Functional.h provides a very simple way to bind a function pointer and argume nts together into a function object
44 // that can be stored, copied and invoked, similar to how boost::bind and std::b ind in C++11. 49 // that can be stored, copied and invoked, similar to how boost::bind and std::b ind in C++11.
45 50
46 // Thread Safety: 51 // Thread Safety:
47 // 52 //
48 // WTF::bind() and SameThreadClosure should be used for same-thread closures 53 // WTF::bind() and SameThreadClosure should be used for same-thread closures
49 // only, i.e. the closures must be created, executed and destructed on 54 // only, i.e. the closures must be created, executed and destructed on
50 // the same thread. 55 // the same thread.
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 }; 230 };
226 231
227 template <typename T> 232 template <typename T>
228 struct ParamStorageTraits<PassedWrapper<T>> { 233 struct ParamStorageTraits<PassedWrapper<T>> {
229 typedef PassedWrapper<T> StorageType; 234 typedef PassedWrapper<T> StorageType;
230 235
231 static StorageType wrap(PassedWrapper<T>&& value) { return std::move(value); } 236 static StorageType wrap(PassedWrapper<T>&& value) { return std::move(value); }
232 static T unwrap(StorageType& value) { return value.moveOut(); } 237 static T unwrap(StorageType& value) { return value.moveOut(); }
233 }; 238 };
234 239
240 template<typename T, bool isGarbageCollected> struct PointerParamStorageTraits;
241
242 template<typename T>
243 struct PointerParamStorageTraits<T*, false> {
244 STATIC_ONLY(PointerParamStorageTraits);
245 using StorageType = T*;
246
247 static StorageType wrap(T* value) { return value; }
248 static T* unwrap(const StorageType& value) { return value; }
249 };
250
251 template<typename T>
252 struct PointerParamStorageTraits<T*, true> {
253 STATIC_ONLY(PointerParamStorageTraits);
254 using StorageType = blink::CrossThreadPersistent<T>;
255
256 static StorageType wrap(T* value) { return value; }
257 static T* unwrap(const StorageType& value) { return value.get(); }
258 };
259
260 template<typename T>
261 struct ParamStorageTraits<T*> : public PointerParamStorageTraits<T*, IsGarbageCo llectedType<T>::value> {
262 STATIC_ONLY(ParamStorageTraits);
263 };
264
235 enum FunctionThreadAffinity { 265 enum FunctionThreadAffinity {
236 CrossThreadAffinity, 266 CrossThreadAffinity,
237 SameThreadAffinity 267 SameThreadAffinity
238 }; 268 };
239 269
240 template<typename, FunctionThreadAffinity threadAffinity = SameThreadAffinity> 270 template<typename, FunctionThreadAffinity threadAffinity = SameThreadAffinity>
241 class Function; 271 class Function;
242 272
243 template<FunctionThreadAffinity threadAffinity, typename R, typename... Args> 273 template<FunctionThreadAffinity threadAffinity, typename R, typename... Args>
244 class Function<R(Args...), threadAffinity> { 274 class Function<R(Args...), threadAffinity> {
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 376
347 } // namespace WTF 377 } // namespace WTF
348 378
349 using WTF::passed; 379 using WTF::passed;
350 using WTF::Function; 380 using WTF::Function;
351 using WTF::bind; 381 using WTF::bind;
352 using WTF::SameThreadClosure; 382 using WTF::SameThreadClosure;
353 using WTF::CrossThreadClosure; 383 using WTF::CrossThreadClosure;
354 384
355 #endif // WTF_Functional_h 385 #endif // WTF_Functional_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/heap/HeapTest.cpp ('k') | third_party/WebKit/Source/wtf/TypeTraits.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698