Chromium Code Reviews| Index: media/base/callback_util.h |
| diff --git a/media/base/callback_util.h b/media/base/callback_util.h |
| index d831191c88b3ae162a6ddc5b7113fd41fe707ce2..03c9a475726f12025a555ffad57fd0f43e311e69 100644 |
| --- a/media/base/callback_util.h |
| +++ b/media/base/callback_util.h |
| @@ -8,45 +8,56 @@ |
| #include <queue> |
| #include "base/callback.h" |
| +#include "base/memory/ref_counted.h" |
| #include "base/memory/scoped_ptr.h" |
| +#include "base/memory/weak_ptr.h" |
| #include "media/base/pipeline_status.h" |
| +namespace base { |
| +class MessageLoopProxy; |
| +} |
| + |
| namespace media { |
| typedef base::Callback<void(const base::Closure&)> ClosureFunc; |
|
Ami GONE FROM CHROMIUM
2012/08/03 04:49:57
That's a terrible name :)
|
| typedef base::Callback<void(const PipelineStatusCB&)> PipelineStatusCBFunc; |
| -// Executes the closures in FIFO order, executing |done_cb| when the last |
| -// closure has completed running. |
| -// |
| -// All closures (including |done_cb|) are executed on same thread as the |
| -// calling thread. |
| -void RunInSeries(scoped_ptr<std::queue<ClosureFunc> > closures, |
| - const base::Closure& done_cb); |
| - |
| -// Executes the closures in FIFO order, executing |done_cb| when the last |
| -// closure has completed running, reporting the final status code. |
| -// |
| -// Closures will stop being executed if a previous closure in the series |
| -// returned an error status and |done_cb| will be executed prematurely. |
| -// |
| -// All closures (including |done_cb|) are executed on same thread as the |
| -// calling thread. |
| -void RunInSeriesWithStatus( |
| - scoped_ptr<std::queue<PipelineStatusCBFunc> > status_cbs, |
| - const PipelineStatusCB& done_cb); |
| - |
| -// Executes the closures in parallel, executing |done_cb| when all closures have |
| -// completed running. |
| -// |
| -// No attempt is made to parallelize execution of the closures. In other words, |
| -// this method will run all closures in FIFO order if said closures execute |
| -// synchronously on the same call stack. |
| -// |
| -// All closures (including |done_cb|) are executed on same thread as the |
| -// calling thread. |
| -void RunInParallel(scoped_ptr<std::queue<ClosureFunc> > closures, |
| - const base::Closure& done_cb); |
| +// Used to convert a ClosureFunc into a PipelineStatusCBFunc. Since closures |
| +// do not report a status, |status_cb| is executed with PIPELINE_OK. |
| +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.
|
| + const PipelineStatusCB& status_cb); |
| + |
| +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
|
| + public: |
| + // Executes closures in |status_cbs| in series, executing |done_cb| when |
| + // finished. |
| + // |
| + // All closures are executed on the thread that Run() is called on, including |
| + // |done_cb|. |
| + // |
| + // 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.
|
| + // |done_cb|. |
| + static scoped_ptr<CallbackSeries> Run( |
| + 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
|
| + const PipelineStatusCB& done_cb); |
| + |
|
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.
|
| + private: |
| + friend class scoped_ptr<CallbackSeries>; |
| + |
| + CallbackSeries( |
| + scoped_ptr<std::queue<PipelineStatusCBFunc> > status_cbs, |
| + const PipelineStatusCB& done_cb); |
| + ~CallbackSeries(); |
| + |
| + void RunNextInSeries(PipelineStatus last_status); |
| + |
| + base::WeakPtrFactory<CallbackSeries> weak_this_; |
| + scoped_refptr<base::MessageLoopProxy> message_loop_; |
| + scoped_ptr<std::queue<PipelineStatusCBFunc> > status_cbs_; |
| + PipelineStatusCB done_cb_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(CallbackSeries); |
| +}; |
| } // namespace media |