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_BIND_H_ | 5 #ifndef BASE_BIND_H_ |
6 #define BASE_BIND_H_ | 6 #define BASE_BIND_H_ |
7 | 7 |
8 #include "base/bind_internal.h" | 8 #include "base/bind_internal.h" |
9 #include "base/callback_internal.h" | 9 #include "base/callback_internal.h" |
10 | 10 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 // checks should below for bound references need to know what the actual | 82 // checks should below for bound references need to know what the actual |
83 // functor is going to interpret the argument as. | 83 // functor is going to interpret the argument as. |
84 typedef typename RunnableType::RunType BoundRunType; | 84 typedef typename RunnableType::RunType BoundRunType; |
85 | 85 |
86 // Do not allow binding a non-const reference parameter. Non-const reference | 86 // Do not allow binding a non-const reference parameter. Non-const reference |
87 // parameters are disallowed by the Google style guide. Also, binding a | 87 // parameters are disallowed by the Google style guide. Also, binding a |
88 // non-const reference parameter can make for subtle bugs because the | 88 // non-const reference parameter can make for subtle bugs because the |
89 // invoked function will receive a reference to the stored copy of the | 89 // invoked function will receive a reference to the stored copy of the |
90 // argument and not the original. | 90 // argument and not the original. |
91 static_assert(!internal::HasNonConstReferenceParam<BoundRunType>::value, | 91 static_assert(!internal::HasNonConstReferenceParam<BoundRunType>::value, |
92 "do_not_bind_functions_with_nonconst_ref"); | 92 "do not bind functions with nonconst ref"); |
93 | 93 |
94 const bool is_method = internal::HasIsMethodTag<RunnableType>::value; | 94 const bool is_method = internal::HasIsMethodTag<RunnableType>::value; |
95 | 95 |
96 // For methods, we need to be careful for parameter 1. We do not require | 96 // For methods, we need to be careful for parameter 1. We do not require |
97 // a scoped_refptr because BindState<> itself takes care of AddRef() for | 97 // a scoped_refptr because BindState<> itself takes care of AddRef() for |
98 // methods. We also disallow binding of an array as the method's target | 98 // methods. We also disallow binding of an array as the method's target |
99 // object. | 99 // object. |
100 static_assert(!internal::BindsArrayToFirstArg<is_method, Args...>::value, | 100 static_assert(!internal::BindsArrayToFirstArg<is_method, Args...>::value, |
101 "first_bound_argument_to_method_cannot_be_array"); | 101 "first bound argument to method cannot be array"); |
102 static_assert( | 102 static_assert( |
103 !internal::HasRefCountedParamAsRawPtr<is_method, Args...>::value, | 103 !internal::HasRefCountedParamAsRawPtr<is_method, Args...>::value, |
104 "a_parameter_is_refcounted_type_and_needs_scoped_refptr"); | 104 "a parameter is a refcounted type and needs scoped_refptr"); |
105 | 105 |
106 typedef internal::BindState< | 106 typedef internal::BindState< |
107 RunnableType, RunType, | 107 RunnableType, RunType, |
108 internal::TypeList< | 108 internal::TypeList< |
109 typename internal::CallbackParamTraits<Args>::StorageType...>> | 109 typename internal::CallbackParamTraits<Args>::StorageType...>> |
110 BindState; | 110 BindState; |
111 | 111 |
112 return Callback<typename BindState::UnboundRunType>( | 112 return Callback<typename BindState::UnboundRunType>( |
113 new BindState(internal::MakeRunnable(functor), args...)); | 113 new BindState(internal::MakeRunnable(functor), args...)); |
114 } | 114 } |
115 | 115 |
116 } // namespace base | 116 } // namespace base |
117 | 117 |
118 #endif // BASE_BIND_H_ | 118 #endif // BASE_BIND_H_ |
OLD | NEW |