Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Unified Diff: media/base/callback.h

Issue 465044: Refactor FFmpegVideoDecoder to try and generalize code common to all video decoders. (Closed)
Patch Set: Fix SCOPED_TRACE since VS faults on %zd. Created 11 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | media/base/mock_task.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/base/callback.h
diff --git a/media/base/callback.h b/media/base/callback.h
new file mode 100644
index 0000000000000000000000000000000000000000..553c84282ca2c643892762e4b4da754f72cd92df
--- /dev/null
+++ b/media/base/callback.h
@@ -0,0 +1,62 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
+// source code is governed by a BSD-style license that can be found in the
+// LICENSE file.
+
+// Some basic utilities for aiding in the management of Tasks and Callbacks.
+// AutoTaskRunner, and its brother AutoCallbackRunner are the scoped_ptr
+// equivalents for callbacks. They are useful for ensuring a callback is
+// executed and delete in the face of multiple return points in a function.
+
+#ifndef MEDIA_BASE_CALLBACK_
+#define MEDIA_BASE_CALLBACK_
+
+#include "base/scoped_ptr.h"
+#include "base/task.h"
+
+namespace media {
+
+class AutoTaskRunner {
+ public:
+ // Takes ownership of the task.
+ explicit AutoTaskRunner(Task* task)
+ : task_(task) {
+ }
+
+ ~AutoTaskRunner() {
+ if (task_.get()) {
+ task_->Run();
+ }
+ }
+
+ Task* release() { return task_.release(); }
+
+ private:
+ scoped_ptr<Task> task_;
+
+ DISALLOW_COPY_AND_ASSIGN(AutoTaskRunner);
+};
+
+class AutoCallbackRunner {
+ public:
+ // Takes ownership of the callback.
+ explicit AutoCallbackRunner(Callback0::Type* callback)
+ : callback_(callback) {
+ }
+
+ ~AutoCallbackRunner() {
+ if (callback_.get()) {
+ callback_->Run();
+ }
+ }
+
+ Callback0::Type* release() { return callback_.release(); }
+
+ private:
+ scoped_ptr<Callback0::Type> callback_;
+
+ DISALLOW_COPY_AND_ASSIGN(AutoCallbackRunner);
+};
+
+} // namespace media
+
+#endif // MEDIA_BASE_CALLBACK_
« no previous file with comments | « no previous file | media/base/mock_task.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698