| 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 // This defines a set of argument wrappers and related factory methods that | 5 // This defines a set of argument wrappers and related factory methods that |
| 6 // can be used specify the refcounting and reference semantics of arguments | 6 // can be used specify the refcounting and reference semantics of arguments |
| 7 // that are bound by the Bind() function in base/bind.h. | 7 // that are bound by the Bind() function in base/bind.h. |
| 8 // | 8 // |
| 9 // It also defines a set of simple functions and utilities that people want | 9 // It also defines a set of simple functions and utilities that people want |
| 10 // when using Callback<> and Bind(). | 10 // when using Callback<> and Bind(). |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 // or if it is posted to a MessageLoopProxy. | 132 // or if it is posted to a MessageLoopProxy. |
| 133 // | 133 // |
| 134 // | 134 // |
| 135 // SIMPLE FUNCTIONS AND UTILITIES. | 135 // SIMPLE FUNCTIONS AND UTILITIES. |
| 136 // | 136 // |
| 137 // DoNothing() - Useful for creating a Closure that does nothing when called. | 137 // DoNothing() - Useful for creating a Closure that does nothing when called. |
| 138 // DeletePointer<T>() - Useful for creating a Closure that will delete a | 138 // DeletePointer<T>() - Useful for creating a Closure that will delete a |
| 139 // pointer when invoked. Only use this when necessary. | 139 // pointer when invoked. Only use this when necessary. |
| 140 // In most cases MessageLoop::DeleteSoon() is a better | 140 // In most cases MessageLoop::DeleteSoon() is a better |
| 141 // fit. | 141 // fit. |
| 142 // ScopedClosureRunner - Scoper object that runs the wrapped closure when it | |
| 143 // goes out of scope. It's conceptually similar to | |
| 144 // scoped_ptr<> but calls Run() instead of deleting | |
| 145 // the pointer. | |
| 146 | 142 |
| 147 #ifndef BASE_BIND_HELPERS_H_ | 143 #ifndef BASE_BIND_HELPERS_H_ |
| 148 #define BASE_BIND_HELPERS_H_ | 144 #define BASE_BIND_HELPERS_H_ |
| 149 | 145 |
| 150 #include "base/basictypes.h" | 146 #include "base/basictypes.h" |
| 151 #include "base/callback.h" | 147 #include "base/callback.h" |
| 152 #include "base/memory/weak_ptr.h" | 148 #include "base/memory/weak_ptr.h" |
| 153 #include "base/template_util.h" | 149 #include "base/template_util.h" |
| 154 | 150 |
| 155 namespace base { | 151 namespace base { |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 return internal::IgnoreResultHelper<Callback<T> >(data); | 532 return internal::IgnoreResultHelper<Callback<T> >(data); |
| 537 } | 533 } |
| 538 | 534 |
| 539 BASE_EXPORT void DoNothing(); | 535 BASE_EXPORT void DoNothing(); |
| 540 | 536 |
| 541 template<typename T> | 537 template<typename T> |
| 542 void DeletePointer(T* obj) { | 538 void DeletePointer(T* obj) { |
| 543 delete obj; | 539 delete obj; |
| 544 } | 540 } |
| 545 | 541 |
| 546 // ScopedClosureRunner is akin to scoped_ptr for Closures. It ensures that the | |
| 547 // Closure is executed and deleted no matter how the current scope exits. | |
| 548 class BASE_EXPORT ScopedClosureRunner { | |
| 549 public: | |
| 550 explicit ScopedClosureRunner(const Closure& closure); | |
| 551 ~ScopedClosureRunner(); | |
| 552 | |
| 553 Closure Release(); | |
| 554 | |
| 555 private: | |
| 556 Closure closure_; | |
| 557 | |
| 558 DISALLOW_IMPLICIT_CONSTRUCTORS(ScopedClosureRunner); | |
| 559 }; | |
| 560 | |
| 561 } // namespace base | 542 } // namespace base |
| 562 | 543 |
| 563 #endif // BASE_BIND_HELPERS_H_ | 544 #endif // BASE_BIND_HELPERS_H_ |
| OLD | NEW |