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

Side by Side Diff: media/base/callback_util.h

Issue 10830146: Replace RunInSeries() and RunInParallel() with CallbackSeries helper class. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src
Patch Set: comments Created 8 years, 4 months 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | media/base/callback_util.cc » ('j') | media/base/callback_util.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 MEDIA_BASE_CALLBACK_UTIL_H_ 5 #ifndef MEDIA_BASE_CALLBACK_UTIL_H_
6 #define MEDIA_BASE_CALLBACK_UTIL_H_ 6 #define MEDIA_BASE_CALLBACK_UTIL_H_
7 7
8 #include <queue> 8 #include <queue>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
12 #include "media/base/pipeline_status.h" 14 #include "media/base/pipeline_status.h"
13 15
16 namespace base {
17 class MessageLoopProxy;
18 }
19
14 namespace media { 20 namespace media {
15 21
16 typedef base::Callback<void(const base::Closure&)> ClosureFunc; 22 // Why the odd looking typedef? SerialCallbackRunner requires callbacks to
Ami GONE FROM CHROMIUM 2012/08/03 19:29:01 This comment doesn't explain *why* SCR would want
scherkus (not reviewing) 2012/08/03 20:19:04 Done although I'm sad at losing our funk
23 // functions that accept a PipelineStatusCB, not PipelineStatusCBs themselves.
17 typedef base::Callback<void(const PipelineStatusCB&)> PipelineStatusCBFunc; 24 typedef base::Callback<void(const PipelineStatusCB&)> PipelineStatusCBFunc;
Ami GONE FROM CHROMIUM 2012/08/03 19:29:01 This typedef belongs at the top of the public: sec
scherkus (not reviewing) 2012/08/03 20:19:04 Done.
scherkus (not reviewing) 2012/08/03 20:19:04 Done.
18 25
19 // Executes the closures in FIFO order, executing |done_cb| when the last 26 class SerialCallbackRunner {
20 // closure has completed running. 27 public:
21 // 28 // Executes callbacks in |status_cbs| in series, executing |done_cb| when
Ami GONE FROM CHROMIUM 2012/08/03 19:29:01 s/callbacks in/bound functions from/ ?
scherkus (not reviewing) 2012/08/03 20:19:04 Done.
22 // All closures (including |done_cb|) are executed on same thread as the 29 // finished.
23 // calling thread. 30 //
24 void RunInSeries(scoped_ptr<std::queue<ClosureFunc> > closures, 31 // All callbacks are executed on the thread that Run() is called on, including
25 const base::Closure& done_cb); 32 // |done_cb|.
33 //
34 // Deleting the object will prevent execution of any unstarted callbacks,
35 // including |done_cb|.
36 static scoped_ptr<SerialCallbackRunner> Run(
37 scoped_ptr<std::queue<PipelineStatusCBFunc> > status_cbs,
38 const PipelineStatusCB& done_cb);
26 39
27 // Executes the closures in FIFO order, executing |done_cb| when the last 40 private:
28 // closure has completed running, reporting the final status code. 41 friend class scoped_ptr<SerialCallbackRunner>;
29 //
30 // Closures will stop being executed if a previous closure in the series
31 // returned an error status and |done_cb| will be executed prematurely.
32 //
33 // All closures (including |done_cb|) are executed on same thread as the
34 // calling thread.
35 void RunInSeriesWithStatus(
36 scoped_ptr<std::queue<PipelineStatusCBFunc> > status_cbs,
37 const PipelineStatusCB& done_cb);
38 42
39 // Executes the closures in parallel, executing |done_cb| when all closures have 43 SerialCallbackRunner(
40 // completed running. 44 scoped_ptr<std::queue<PipelineStatusCBFunc> > status_cbs,
41 // 45 const PipelineStatusCB& done_cb);
42 // No attempt is made to parallelize execution of the closures. In other words, 46 ~SerialCallbackRunner();
43 // this method will run all closures in FIFO order if said closures execute 47
44 // synchronously on the same call stack. 48 void RunNextInSeries(PipelineStatus last_status);
45 // 49
46 // All closures (including |done_cb|) are executed on same thread as the 50 base::WeakPtrFactory<SerialCallbackRunner> weak_this_;
47 // calling thread. 51 scoped_refptr<base::MessageLoopProxy> message_loop_;
48 void RunInParallel(scoped_ptr<std::queue<ClosureFunc> > closures, 52 scoped_ptr<std::queue<PipelineStatusCBFunc> > status_cbs_;
49 const base::Closure& done_cb); 53 PipelineStatusCB done_cb_;
54
55 DISALLOW_COPY_AND_ASSIGN(SerialCallbackRunner);
56 };
50 57
51 } // namespace media 58 } // namespace media
52 59
53 #endif // MEDIA_BASE_CALLBACK_UTIL_H_ 60 #endif // MEDIA_BASE_CALLBACK_UTIL_H_
OLDNEW
« no previous file with comments | « no previous file | media/base/callback_util.cc » ('j') | media/base/callback_util.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698