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

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: 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/pipeline.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_
scherkus (not reviewing) 2012/08/02 22:17:04 I'll rename this file to callback_series.h in a fu
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 typedef base::Callback<void(const base::Closure&)> ClosureFunc;
Ami GONE FROM CHROMIUM 2012/08/03 04:49:57 That's a terrible name :)
17 typedef base::Callback<void(const PipelineStatusCB&)> PipelineStatusCBFunc; 23 typedef base::Callback<void(const PipelineStatusCB&)> PipelineStatusCBFunc;
18 24
19 // Executes the closures in FIFO order, executing |done_cb| when the last 25 // Used to convert a ClosureFunc into a PipelineStatusCBFunc. Since closures
20 // closure has completed running. 26 // do not report a status, |status_cb| is executed with PIPELINE_OK.
21 // 27 void RunClosureFunc(const ClosureFunc& closure,
Ami GONE FROM CHROMIUM 2012/08/03 04:49:57 Since this is used in only one file and this is ch
scherkus (not reviewing) 2012/08/03 18:08:50 Done.
22 // All closures (including |done_cb|) are executed on same thread as the 28 const PipelineStatusCB& status_cb);
23 // calling thread.
24 void RunInSeries(scoped_ptr<std::queue<ClosureFunc> > closures,
25 const base::Closure& done_cb);
26 29
27 // Executes the closures in FIFO order, executing |done_cb| when the last 30 class CallbackSeries {
Ami GONE FROM CHROMIUM 2012/08/03 04:49:57 inherit from NonThreadSafe and DCHECK BelongsToCur
Ami GONE FROM CHROMIUM 2012/08/03 04:49:57 SerialCallbackRunner?
scherkus (not reviewing) 2012/08/03 18:08:50 Done.
scherkus (not reviewing) 2012/08/03 18:08:50 isn't that accomplished via message_loop_->Belongs
28 // closure has completed running, reporting the final status code. 31 public:
29 // 32 // Executes closures in |status_cbs| in series, executing |done_cb| when
30 // Closures will stop being executed if a previous closure in the series 33 // finished.
31 // returned an error status and |done_cb| will be executed prematurely. 34 //
32 // 35 // All closures are executed on the thread that Run() is called on, including
33 // All closures (including |done_cb|) are executed on same thread as the 36 // |done_cb|.
34 // calling thread. 37 //
35 void RunInSeriesWithStatus( 38 // Deleting the object will terminate any pending closures, including
Ami GONE FROM CHROMIUM 2012/08/03 04:49:57 s/pending/unstarted/
Ami GONE FROM CHROMIUM 2012/08/03 04:49:57 s/closures/callbacks/
Ami GONE FROM CHROMIUM 2012/08/03 04:49:57 s/terminate/prevent execution of/
scherkus (not reviewing) 2012/08/03 18:08:50 Done.
scherkus (not reviewing) 2012/08/03 18:08:50 Done.
scherkus (not reviewing) 2012/08/03 18:08:50 Done.
36 scoped_ptr<std::queue<PipelineStatusCBFunc> > status_cbs, 39 // |done_cb|.
37 const PipelineStatusCB& done_cb); 40 static scoped_ptr<CallbackSeries> Run(
41 scoped_ptr<std::queue<PipelineStatusCBFunc> > status_cbs,
Ami GONE FROM CHROMIUM 2012/08/03 04:49:57 This seems unnecessarily complex. Why can this not
scherkus (not reviewing) 2012/08/03 18:08:50 PipelineStatusCBs are void(PipelineStatus) We wan
42 const PipelineStatusCB& done_cb);
38 43
scherkus (not reviewing) 2012/08/02 22:17:04 if we want I can add a running() helper that can b
Ami GONE FROM CHROMIUM 2012/08/03 04:49:57 No, that's usually a code smell.
39 // Executes the closures in parallel, executing |done_cb| when all closures have 44 private:
40 // completed running. 45 friend class scoped_ptr<CallbackSeries>;
41 // 46
42 // No attempt is made to parallelize execution of the closures. In other words, 47 CallbackSeries(
43 // this method will run all closures in FIFO order if said closures execute 48 scoped_ptr<std::queue<PipelineStatusCBFunc> > status_cbs,
44 // synchronously on the same call stack. 49 const PipelineStatusCB& done_cb);
45 // 50 ~CallbackSeries();
46 // All closures (including |done_cb|) are executed on same thread as the 51
47 // calling thread. 52 void RunNextInSeries(PipelineStatus last_status);
48 void RunInParallel(scoped_ptr<std::queue<ClosureFunc> > closures, 53
49 const base::Closure& done_cb); 54 base::WeakPtrFactory<CallbackSeries> weak_this_;
55 scoped_refptr<base::MessageLoopProxy> message_loop_;
56 scoped_ptr<std::queue<PipelineStatusCBFunc> > status_cbs_;
57 PipelineStatusCB done_cb_;
58
59 DISALLOW_COPY_AND_ASSIGN(CallbackSeries);
60 };
50 61
51 } // namespace media 62 } // namespace media
52 63
53 #endif // MEDIA_BASE_CALLBACK_UTIL_H_ 64 #endif // MEDIA_BASE_CALLBACK_UTIL_H_
OLDNEW
« no previous file with comments | « no previous file | media/base/callback_util.cc » ('j') | media/base/pipeline.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698