Chromium Code Reviews| Index: media/base/pipeline_impl.cc |
| diff --git a/media/base/pipeline_impl.cc b/media/base/pipeline_impl.cc |
| index c75b74007dc03f82b574fd93a520b7aacd8c8960..092305e59b045aa3e617cbe9e104f9e2d61b3f63 100644 |
| --- a/media/base/pipeline_impl.cc |
| +++ b/media/base/pipeline_impl.cc |
| @@ -24,15 +24,15 @@ const char kRawMediaScheme[] = "x-raw-media"; |
| PipelineStatusNotification::PipelineStatusNotification() |
| : cv_(&lock_), status_(PIPELINE_OK), notified_(false) { |
| - callback_.reset(NewCallback(this, &PipelineStatusNotification::Notify)); |
| } |
| PipelineStatusNotification::~PipelineStatusNotification() { |
| DCHECK(notified_); |
| } |
| -media::PipelineStatusCallback* PipelineStatusNotification::Callback() { |
| - return callback_.release(); |
| +PipelineStatusCB PipelineStatusNotification::Callback() { |
| + return base::Bind(&PipelineStatusNotification::Notify, |
| + base::Unretained(this)); |
| } |
| void PipelineStatusNotification::Notify(media::PipelineStatus status) { |
| @@ -78,22 +78,21 @@ PipelineImpl::~PipelineImpl() { |
| DCHECK(!seek_pending_); |
| } |
| -void PipelineImpl::Init(PipelineStatusCallback* ended_callback, |
| - PipelineStatusCallback* error_callback, |
| - PipelineStatusCallback* network_callback) { |
| +void PipelineImpl::Init(const PipelineStatusCB& ended_callback, |
| + const PipelineStatusCB& error_callback, |
| + const PipelineStatusCB& network_callback) { |
| DCHECK(!IsRunning()) |
| << "Init() should be called before the pipeline has started"; |
| - ended_callback_.reset(ended_callback); |
| - error_callback_.reset(error_callback); |
| - network_callback_.reset(network_callback); |
| + ended_callback_ = ended_callback; |
| + error_callback_ = error_callback; |
| + network_callback_ = network_callback; |
| } |
| // Creates the PipelineInternal and calls it's start method. |
| bool PipelineImpl::Start(FilterCollection* collection, |
| const std::string& url, |
| - PipelineStatusCallback* start_callback) { |
| + const PipelineStatusCB& start_callback) { |
| base::AutoLock auto_lock(lock_); |
| - scoped_ptr<PipelineStatusCallback> callback(start_callback); |
| scoped_ptr<FilterCollection> filter_collection(collection); |
| if (running_) { |
| @@ -113,13 +112,12 @@ bool PipelineImpl::Start(FilterCollection* collection, |
| &PipelineImpl::StartTask, |
| filter_collection.release(), |
| url, |
| - callback.release())); |
| + start_callback)); |
| return true; |
| } |
| -void PipelineImpl::Stop(PipelineStatusCallback* stop_callback) { |
| +void PipelineImpl::Stop(const PipelineStatusCB& stop_callback) { |
| base::AutoLock auto_lock(lock_); |
| - scoped_ptr<PipelineStatusCallback> callback(stop_callback); |
| if (!running_) { |
| VLOG(1) << "Media pipeline has already stopped"; |
| return; |
| @@ -127,13 +125,12 @@ void PipelineImpl::Stop(PipelineStatusCallback* stop_callback) { |
| // Stop the pipeline, which will set |running_| to false on behalf. |
| message_loop_->PostTask(FROM_HERE, |
| - NewRunnableMethod(this, &PipelineImpl::StopTask, callback.release())); |
| + NewRunnableMethod(this, &PipelineImpl::StopTask, stop_callback)); |
| } |
| void PipelineImpl::Seek(base::TimeDelta time, |
| - PipelineStatusCallback* seek_callback) { |
| + const PipelineStatusCB& seek_callback) { |
| base::AutoLock auto_lock(lock_); |
| - scoped_ptr<PipelineStatusCallback> callback(seek_callback); |
| if (!running_) { |
| VLOG(1) << "Media pipeline must be running"; |
| return; |
| @@ -141,7 +138,7 @@ void PipelineImpl::Seek(base::TimeDelta time, |
| message_loop_->PostTask(FROM_HERE, |
| NewRunnableMethod(this, &PipelineImpl::SeekTask, time, |
|
scherkus (not reviewing)
2011/07/23 01:51:32
nit: fit on one line?
acolwell GONE FROM CHROMIUM
2011/07/27 16:17:04
Done.
|
| - callback.release())); |
| + seek_callback)); |
| } |
| bool PipelineImpl::IsRunning() const { |
| @@ -419,9 +416,9 @@ void PipelineImpl::FinishInitialization() { |
| DCHECK_EQ(MessageLoop::current(), message_loop_); |
| // Execute the seek callback, if present. Note that this might be the |
| // initial callback passed into Start(). |
| - if (seek_callback_.get()) { |
| - seek_callback_->Run(status_); |
| - seek_callback_.reset(); |
| + if (!seek_callback_.is_null()) { |
| + seek_callback_.Run(status_); |
| + seek_callback_.Reset(); |
| } |
| } |
| @@ -606,12 +603,12 @@ void PipelineImpl::OnUpdateStatistics(const PipelineStatistics& stats) { |
| void PipelineImpl::StartTask(FilterCollection* filter_collection, |
| const std::string& url, |
| - PipelineStatusCallback* start_callback) { |
| + const PipelineStatusCB& start_callback) { |
| DCHECK_EQ(MessageLoop::current(), message_loop_); |
| DCHECK_EQ(kCreated, state_); |
| filter_collection_.reset(filter_collection); |
| url_ = url; |
| - seek_callback_.reset(start_callback); |
| + seek_callback_ = start_callback; |
| // Kick off initialization. |
| pipeline_init_state_.reset(new PipelineInitState()); |
| @@ -744,15 +741,14 @@ void PipelineImpl::InitializeTask() { |
| // TODO(scherkus): beware! this can get posted multiple times since we post |
| // Stop() tasks even if we've already stopped. Perhaps this should no-op for |
| // additional calls, however most of this logic will be changing. |
| -void PipelineImpl::StopTask(PipelineStatusCallback* stop_callback) { |
| +void PipelineImpl::StopTask(const PipelineStatusCB& stop_callback) { |
| DCHECK_EQ(MessageLoop::current(), message_loop_); |
| DCHECK(!IsPipelineStopPending()); |
| DCHECK_NE(state_, kStopped); |
| if (state_ == kStopped) { |
| // Already stopped so just run callback. |
| - stop_callback->Run(status_); |
| - delete stop_callback; |
| + stop_callback.Run(status_); |
| return; |
| } |
| @@ -766,7 +762,7 @@ void PipelineImpl::StopTask(PipelineStatusCallback* stop_callback) { |
| error_caused_teardown_ = false; |
| } |
| - stop_callback_.reset(stop_callback); |
| + stop_callback_ = stop_callback; |
| stop_pending_ = true; |
| if (!IsPipelineSeeking() && !IsPipelineTearingDown()) { |
| @@ -840,7 +836,7 @@ void PipelineImpl::PreloadChangedTask(Preload preload) { |
| } |
| void PipelineImpl::SeekTask(base::TimeDelta time, |
| - PipelineStatusCallback* seek_callback) { |
| + const PipelineStatusCB& seek_callback) { |
| DCHECK_EQ(MessageLoop::current(), message_loop_); |
| DCHECK(!IsPipelineStopPending()); |
| @@ -850,7 +846,6 @@ void PipelineImpl::SeekTask(base::TimeDelta time, |
| // will only execute the first Seek() request. |
| VLOG(1) << "Media pipeline has not started, ignoring seek to " |
| << time.InMicroseconds(); |
| - delete seek_callback; |
| return; |
| } |
| @@ -866,7 +861,7 @@ void PipelineImpl::SeekTask(base::TimeDelta time, |
| // kStarted |
| set_state(kPausing); |
| seek_timestamp_ = time; |
| - seek_callback_.reset(seek_callback); |
| + seek_callback_ = seek_callback; |
| // Kick off seeking! |
| { |
| @@ -909,15 +904,15 @@ void PipelineImpl::NotifyEndedTask() { |
| // Transition to ended, executing the callback if present. |
| set_state(kEnded); |
| - if (ended_callback_.get()) { |
| - ended_callback_->Run(status_); |
| + if (!ended_callback_.is_null()) { |
| + ended_callback_.Run(status_); |
| } |
| } |
| void PipelineImpl::NotifyNetworkEventTask() { |
| DCHECK_EQ(MessageLoop::current(), message_loop_); |
| - if (network_callback_.get()) { |
| - network_callback_->Run(status_); |
| + if (!network_callback_.is_null()) { |
| + network_callback_.Run(status_); |
| } |
| } |
| @@ -1062,16 +1057,17 @@ void PipelineImpl::FinishDestroyingFiltersTask() { |
| pipeline_filter_ = NULL; |
| - if (error_caused_teardown_ && !IsPipelineOk() && error_callback_.get()) |
| - error_callback_->Run(status_); |
| + if (error_caused_teardown_ && !IsPipelineOk() && !error_callback_.is_null()) |
| + error_callback_.Run(status_); |
| if (stop_pending_) { |
| stop_pending_ = false; |
| ResetState(); |
| - scoped_ptr<PipelineStatusCallback> stop_callback(stop_callback_.release()); |
| + PipelineStatusCB stop_cb; |
| + std::swap(stop_cb, stop_callback_); |
| // Notify the client that stopping has finished. |
| - if (stop_callback.get()) { |
| - stop_callback->Run(status_); |
| + if (!stop_cb.is_null()) { |
| + stop_cb.Run(status_); |
| } |
| } |