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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | media/base/mock_task.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
2 // source code is governed by a BSD-style license that can be found in the
3 // LICENSE file.
4
5 // Some basic utilities for aiding in the management of Tasks and Callbacks.
6 // AutoTaskRunner, and its brother AutoCallbackRunner are the scoped_ptr
7 // equivalents for callbacks. They are useful for ensuring a callback is
8 // executed and delete in the face of multiple return points in a function.
9
10 #ifndef MEDIA_BASE_CALLBACK_
11 #define MEDIA_BASE_CALLBACK_
12
13 #include "base/scoped_ptr.h"
14 #include "base/task.h"
15
16 namespace media {
17
18 class AutoTaskRunner {
19 public:
20 // Takes ownership of the task.
21 explicit AutoTaskRunner(Task* task)
22 : task_(task) {
23 }
24
25 ~AutoTaskRunner() {
26 if (task_.get()) {
27 task_->Run();
28 }
29 }
30
31 Task* release() { return task_.release(); }
32
33 private:
34 scoped_ptr<Task> task_;
35
36 DISALLOW_COPY_AND_ASSIGN(AutoTaskRunner);
37 };
38
39 class AutoCallbackRunner {
40 public:
41 // Takes ownership of the callback.
42 explicit AutoCallbackRunner(Callback0::Type* callback)
43 : callback_(callback) {
44 }
45
46 ~AutoCallbackRunner() {
47 if (callback_.get()) {
48 callback_->Run();
49 }
50 }
51
52 Callback0::Type* release() { return callback_.release(); }
53
54 private:
55 scoped_ptr<Callback0::Type> callback_;
56
57 DISALLOW_COPY_AND_ASSIGN(AutoCallbackRunner);
58 };
59
60 } // namespace media
61
62 #endif // MEDIA_BASE_CALLBACK_
OLDNEW
« 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