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

Unified 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: more hotness 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | media/base/callback_util.cc » ('j') | media/base/callback_util.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/base/callback_util.h
diff --git a/media/base/callback_util.h b/media/base/callback_util.h
index d831191c88b3ae162a6ddc5b7113fd41fe707ce2..63c62d9d5f1a8ab1ee3fcfb3bce0c49206d6b1b4 100644
--- a/media/base/callback_util.h
+++ b/media/base/callback_util.h
@@ -8,45 +8,70 @@
#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;
-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);
+// Runs a series of bound functions accepting Closures or PipelineStatusCB.
+// SerialCallbackRunner doesn't use regular Closure/PipelineStatusCBs as it
+// late binds the completion callback as the series progresses.
+class SerialCallbackRunner {
+ public:
+ typedef base::Callback<void(const base::Closure&)> BoundClosure;
+ typedef base::Callback<void(const PipelineStatusCB&)> BoundPipelineStatusCB;
+
+ // Serial queue of bound functions to run.
+ class Queue {
scherkus (not reviewing) 2012/08/03 20:19:05 PTAL here + usage in pipeline.cc
+ public:
+ Queue();
+ ~Queue();
+
+ void Push(const BoundClosure& bound_fn);
+ void Push(const BoundPipelineStatusCB& bound_fn);
+
+ BoundPipelineStatusCB Pop();
+
+ bool empty() { return bound_fns_.empty(); }
+
+ private:
+ std::queue<BoundPipelineStatusCB> bound_fns_;
+
+ DISALLOW_COPY_AND_ASSIGN(Queue);
+ };
+
+ // Executes the bound functions in series, executing |done_cb| when finished.
+ //
+ // All bound functions are executed on the thread that Run() is called on,
+ // including |done_cb|.
+ //
+ // Deleting the object will prevent execution of any unstarted bound
+ // functions, including |done_cb|.
+ static scoped_ptr<SerialCallbackRunner> Run(
+ scoped_ptr<Queue> bound_fns, const PipelineStatusCB& done_cb);
Ami GONE FROM CHROMIUM 2012/08/03 20:31:43 copy ctor bound_fns per offline convo
+
+ private:
+ friend class scoped_ptr<SerialCallbackRunner>;
+
+ SerialCallbackRunner(
+ scoped_ptr<Queue> bound_fns, const PipelineStatusCB& done_cb);
+ ~SerialCallbackRunner();
+
+ void RunNextInSeries(PipelineStatus last_status);
+
+ base::WeakPtrFactory<SerialCallbackRunner> weak_this_;
+ scoped_refptr<base::MessageLoopProxy> message_loop_;
+ scoped_ptr<Queue> bound_fns_;
Ami GONE FROM CHROMIUM 2012/08/03 20:31:43 can drop the scoped_ptr here too if pass-by-copy.
+ PipelineStatusCB done_cb_;
+
+ DISALLOW_COPY_AND_ASSIGN(SerialCallbackRunner);
+};
} // namespace media
« 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