OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_MEMORY_RAW_SCOPED_REFPTR_MISMATCH_CHECKER_H_ | 5 #ifndef BASE_MEMORY_RAW_SCOPED_REFPTR_MISMATCH_CHECKER_H_ |
6 #define BASE_MEMORY_RAW_SCOPED_REFPTR_MISMATCH_CHECKER_H_ | 6 #define BASE_MEMORY_RAW_SCOPED_REFPTR_MISMATCH_CHECKER_H_ |
7 | 7 |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/template_util.h" | 9 #include "base/template_util.h" |
10 #include "base/tuple.h" | 10 #include "base/tuple.h" |
11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
12 | 12 |
13 // It is dangerous to post a task with a T* argument where T is a subtype of | 13 // It is dangerous to post a task with a T* argument where T is a subtype of |
14 // RefCounted(Base|ThreadSafeBase), since by the time the parameter is used, the | 14 // RefCounted(Base|ThreadSafeBase), since by the time the parameter is used, the |
15 // object may already have been deleted since it was not held with a | 15 // object may already have been deleted since it was not held with a |
16 // scoped_refptr. Example: http://crbug.com/27191 | 16 // scoped_refptr. Example: http://crbug.com/27191 |
17 // The following set of traits are designed to generate a compile error | 17 // The following set of traits are designed to generate a compile error |
18 // whenever this antipattern is attempted. | 18 // whenever this antipattern is attempted. |
19 | 19 |
20 namespace base { | 20 namespace base { |
21 | 21 |
22 // This is a base internal implementation file used by task.h and callback.h. | 22 // This is a base internal implementation file used by task.h and callback.h. |
23 // Not for public consumption, so we wrap it in namespace internal. | 23 // Not for public consumption, so we wrap it in namespace internal. |
24 namespace internal { | 24 namespace internal { |
25 | 25 |
26 template <typename T> | 26 template <typename T> |
27 struct NeedsScopedRefptrButGetsRawPtr { | 27 struct NeedsScopedRefptrButGetsRawPtr { |
28 #if defined(OS_WIN) | |
29 enum { | |
30 value = base::false_type::value | |
31 }; | |
32 #else | |
33 enum { | 28 enum { |
34 // Human readable translation: you needed to be a scoped_refptr if you are a | 29 // Human readable translation: you needed to be a scoped_refptr if you are a |
35 // raw pointer type and are convertible to a RefCounted(Base|ThreadSafeBase) | 30 // raw pointer type and are convertible to a RefCounted(Base|ThreadSafeBase) |
36 // type. | 31 // type. |
37 value = (is_pointer<T>::value && | 32 value = (is_pointer<T>::value && |
38 (is_convertible<T, subtle::RefCountedBase*>::value || | 33 (is_convertible<T, subtle::RefCountedBase*>::value || |
39 is_convertible<T, subtle::RefCountedThreadSafeBase*>::value)) | 34 is_convertible<T, subtle::RefCountedThreadSafeBase*>::value)) |
40 }; | 35 }; |
41 #endif | |
42 }; | 36 }; |
43 | 37 |
44 template <typename Params> | 38 template <typename Params> |
45 struct ParamsUseScopedRefptrCorrectly { | 39 struct ParamsUseScopedRefptrCorrectly { |
46 enum { value = 0 }; | 40 enum { value = 0 }; |
47 }; | 41 }; |
48 | 42 |
49 template <> | 43 template <> |
50 struct ParamsUseScopedRefptrCorrectly<Tuple<>> { | 44 struct ParamsUseScopedRefptrCorrectly<Tuple<>> { |
51 enum { value = 1 }; | 45 enum { value = 1 }; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 NeedsScopedRefptrButGetsRawPtr<F>::value || | 114 NeedsScopedRefptrButGetsRawPtr<F>::value || |
121 NeedsScopedRefptrButGetsRawPtr<G>::value || | 115 NeedsScopedRefptrButGetsRawPtr<G>::value || |
122 NeedsScopedRefptrButGetsRawPtr<H>::value) }; | 116 NeedsScopedRefptrButGetsRawPtr<H>::value) }; |
123 }; | 117 }; |
124 | 118 |
125 } // namespace internal | 119 } // namespace internal |
126 | 120 |
127 } // namespace base | 121 } // namespace base |
128 | 122 |
129 #endif // BASE_MEMORY_RAW_SCOPED_REFPTR_MISMATCH_CHECKER_H_ | 123 #endif // BASE_MEMORY_RAW_SCOPED_REFPTR_MISMATCH_CHECKER_H_ |
OLD | NEW |