| OLD | NEW |
| 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 #include "media/base/serial_runner.h" | 5 #include "media/base/serial_runner.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
| 11 | 11 |
| 12 namespace media { | 12 namespace media { |
| 13 | 13 |
| 14 // Converts a bound function accepting a Closure into a bound function | 14 // Converts a bound function accepting a Closure into a bound function |
| 15 // accepting a PipelineStatusCB. Since closures have no way of reporting a | 15 // accepting a PipelineStatusCB. Since closures have no way of reporting a |
| 16 // status |status_cb| is executed with PIPELINE_OK. | 16 // status |status_cb| is executed with PIPELINE_OK. |
| 17 static void RunBoundClosure( | 17 static void RunBoundClosure( |
| 18 const SerialRunner::BoundClosure& bound_closure, | 18 const SerialRunner::BoundClosure& bound_closure, |
| 19 const PipelineStatusCB& status_cb) { | 19 const PipelineStatusCB& status_cb) { |
| 20 bound_closure.Run(base::Bind(status_cb, PIPELINE_OK)); | 20 bound_closure.Run(base::Bind(status_cb, PIPELINE_OK)); |
| 21 } | 21 } |
| 22 | 22 |
| 23 // Runs |status_cb| with |last_status| on |message_loop|, trampolining if | 23 // Runs |status_cb| with |last_status| on |message_loop|. |
| 24 // necessary. | |
| 25 static void RunOnMessageLoop( | 24 static void RunOnMessageLoop( |
| 26 const scoped_refptr<base::MessageLoopProxy>& message_loop, | 25 const scoped_refptr<base::MessageLoopProxy>& message_loop, |
| 27 const PipelineStatusCB& status_cb, | 26 const PipelineStatusCB& status_cb, |
| 28 PipelineStatus last_status) { | 27 PipelineStatus last_status) { |
| 29 if (!message_loop->BelongsToCurrentThread()) { | 28 // Force post to permit cancellation of a series in the scenario where all |
| 30 message_loop->PostTask(FROM_HERE, base::Bind( | 29 // bound functions run on the same thread. |
| 31 &RunOnMessageLoop, message_loop, status_cb, last_status)); | 30 message_loop->PostTask(FROM_HERE, base::Bind(status_cb, last_status)); |
| 32 return; | |
| 33 } | |
| 34 status_cb.Run(last_status); | |
| 35 } | 31 } |
| 36 | 32 |
| 37 SerialRunner::Queue::Queue() {} | 33 SerialRunner::Queue::Queue() {} |
| 38 SerialRunner::Queue::~Queue() {} | 34 SerialRunner::Queue::~Queue() {} |
| 39 | 35 |
| 40 void SerialRunner::Queue::Push( | 36 void SerialRunner::Queue::Push( |
| 41 const BoundClosure& bound_closure) { | 37 const BoundClosure& bound_closure) { |
| 42 bound_fns_.push(base::Bind(&RunBoundClosure, bound_closure)); | 38 bound_fns_.push(base::Bind(&RunBoundClosure, bound_closure)); |
| 43 } | 39 } |
| 44 | 40 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 base::ResetAndReturn(&done_cb_).Run(last_status); | 81 base::ResetAndReturn(&done_cb_).Run(last_status); |
| 86 return; | 82 return; |
| 87 } | 83 } |
| 88 | 84 |
| 89 BoundPipelineStatusCB bound_fn = bound_fns_.Pop(); | 85 BoundPipelineStatusCB bound_fn = bound_fns_.Pop(); |
| 90 bound_fn.Run(base::Bind(&RunOnMessageLoop, message_loop_, base::Bind( | 86 bound_fn.Run(base::Bind(&RunOnMessageLoop, message_loop_, base::Bind( |
| 91 &SerialRunner::RunNextInSeries, weak_this_.GetWeakPtr()))); | 87 &SerialRunner::RunNextInSeries, weak_this_.GetWeakPtr()))); |
| 92 } | 88 } |
| 93 | 89 |
| 94 } // namespace media | 90 } // namespace media |
| OLD | NEW |