summaryrefslogtreecommitdiffstats
path: root/base/callback_helpers.h
diff options
context:
space:
mode:
authoravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-30 02:04:04 +0000
committeravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-30 02:04:04 +0000
commit1c232c2bbc955bd58282cd815bc0fcc2bcf66aa1 (patch)
tree0ab63673a38ea13eb0659e48d542e49867062f50 /base/callback_helpers.h
parent85267b1f29294369994453d2b459b252db1fe556 (diff)
downloadchromium_src-1c232c2bbc955bd58282cd815bc0fcc2bcf66aa1.zip
chromium_src-1c232c2bbc955bd58282cd815bc0fcc2bcf66aa1.tar.gz
chromium_src-1c232c2bbc955bd58282cd815bc0fcc2bcf66aa1.tar.bz2
Move ScopedClosureRunner to callback_helpers, add Reset.
BUG=none TEST=none TBR=ben@chromium.org Review URL: https://chromiumcodereview.appspot.com/23514018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@220473 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/callback_helpers.h')
-rw-r--r--base/callback_helpers.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/base/callback_helpers.h b/base/callback_helpers.h
index 52cb71b..8481e3e 100644
--- a/base/callback_helpers.h
+++ b/base/callback_helpers.h
@@ -14,7 +14,9 @@
#ifndef BASE_CALLBACK_HELPERS_H_
#define BASE_CALLBACK_HELPERS_H_
+#include "base/basictypes.h"
#include "base/callback.h"
+#include "base/compiler_specific.h"
namespace base {
@@ -25,6 +27,24 @@ base::Callback<Sig> ResetAndReturn(base::Callback<Sig>* cb) {
return ret;
}
+// ScopedClosureRunner is akin to scoped_ptr for Closures. It ensures that the
+// Closure is executed and deleted no matter how the current scope exits.
+class BASE_EXPORT ScopedClosureRunner {
+ public:
+ ScopedClosureRunner();
+ explicit ScopedClosureRunner(const Closure& closure);
+ ~ScopedClosureRunner();
+
+ void Reset();
+ void Reset(const Closure& closure);
+ Closure Release() WARN_UNUSED_RESULT;
+
+ private:
+ Closure closure_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScopedClosureRunner);
+};
+
} // namespace base
#endif // BASE_CALLBACK_HELPERS_H_