OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_CALLBACK_H_ | 5 #ifndef BASE_CALLBACK_H_ |
6 #define BASE_CALLBACK_H_ | 6 #define BASE_CALLBACK_H_ |
7 | 7 |
8 #include "base/callback_forward.h" | 8 #include "base/callback_forward.h" |
9 #include "base/callback_internal.h" | 9 #include "base/callback_internal.h" |
10 | 10 |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 // | 180 // |
181 // void Foo(int* arg) { cout << *arg << endl; } | 181 // void Foo(int* arg) { cout << *arg << endl; } |
182 // int* pn = new int(1); | 182 // int* pn = new int(1); |
183 // base::Closure foo_callback = base::Bind(&foo, base::Owned(pn)); | 183 // base::Closure foo_callback = base::Bind(&foo, base::Owned(pn)); |
184 // | 184 // |
185 // The parameter will be deleted when the callback is destroyed, even if it's | 185 // The parameter will be deleted when the callback is destroyed, even if it's |
186 // not run (like if you post a task during shutdown). | 186 // not run (like if you post a task during shutdown). |
187 // | 187 // |
188 // PASSING PARAMETERS AS A scoped_ptr | 188 // PASSING PARAMETERS AS A scoped_ptr |
189 // | 189 // |
190 // void TakesOwnership(scoped_ptr<Foo> arg) {} | 190 // void TakesOwnership(std::unique_ptr<Foo> arg) {} |
191 // scoped_ptr<Foo> f(new Foo); | 191 // std::unique_ptr<Foo> f(new Foo); |
192 // // f becomes null during the following call. | 192 // // f becomes null during the following call. |
193 // base::Closure cb = base::Bind(&TakesOwnership, base::Passed(&f)); | 193 // base::Closure cb = base::Bind(&TakesOwnership, base::Passed(&f)); |
194 // | 194 // |
195 // Ownership of the parameter will be with the callback until the it is run, | 195 // Ownership of the parameter will be with the callback until the it is run, |
196 // when ownership is passed to the callback function. This means the callback | 196 // when ownership is passed to the callback function. This means the callback |
197 // can only be run once. If the callback is never run, it will delete the | 197 // can only be run once. If the callback is never run, it will delete the |
198 // object when it's destroyed. | 198 // object when it's destroyed. |
199 // | 199 // |
200 // PASSING PARAMETERS AS A scoped_refptr | 200 // PASSING PARAMETERS AS A scoped_refptr |
201 // | 201 // |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 return f(this->bind_state_.get(), std::forward<Args>(args)...); | 397 return f(this->bind_state_.get(), std::forward<Args>(args)...); |
398 } | 398 } |
399 | 399 |
400 private: | 400 private: |
401 using PolymorphicInvoke = R (*)(internal::BindStateBase*, Args&&...); | 401 using PolymorphicInvoke = R (*)(internal::BindStateBase*, Args&&...); |
402 }; | 402 }; |
403 | 403 |
404 } // namespace base | 404 } // namespace base |
405 | 405 |
406 #endif // BASE_CALLBACK_H_ | 406 #endif // BASE_CALLBACK_H_ |
OLD | NEW |