Chromium Code Reviews| Index: media/cast/cast_environment.cc |
| diff --git a/media/cast/cast_environment.cc b/media/cast/cast_environment.cc |
| index 9b1a5696486d5c85187121c5bf7c95ea647ab4e6..8d3a9aa6519c16ed6bb6390bfba7f21695f078e4 100644 |
| --- a/media/cast/cast_environment.cc |
| +++ b/media/cast/cast_environment.cc |
| @@ -21,6 +21,10 @@ void DeleteLoggingOnMainThread(scoped_ptr<media::cast::LoggingImpl> logging) { |
| namespace media { |
| namespace cast { |
| +CastEnvironment::CastEnvironment(scoped_ptr<base::TickClock> clock, |
| + const CastLoggingConfig& logging_config) |
| + : clock_(clock.Pass()), logging_(new LoggingImpl(logging_config)) {} |
| + |
| CastEnvironment::CastEnvironment( |
| scoped_ptr<base::TickClock> clock, |
| scoped_refptr<SingleThreadTaskRunner> main_thread_proxy, |
| @@ -29,23 +33,21 @@ CastEnvironment::CastEnvironment( |
| scoped_refptr<SingleThreadTaskRunner> video_encode_thread_proxy, |
| scoped_refptr<SingleThreadTaskRunner> video_decode_thread_proxy, |
| scoped_refptr<SingleThreadTaskRunner> transport_thread_proxy, |
| - const CastLoggingConfig& config) |
| - : clock_(clock.Pass()), |
| - main_thread_proxy_(main_thread_proxy), |
| + const CastLoggingConfig& logging_config) |
| + : main_thread_proxy_(main_thread_proxy), |
| audio_encode_thread_proxy_(audio_encode_thread_proxy), |
| audio_decode_thread_proxy_(audio_decode_thread_proxy), |
| video_encode_thread_proxy_(video_encode_thread_proxy), |
| video_decode_thread_proxy_(video_decode_thread_proxy), |
| transport_thread_proxy_(transport_thread_proxy), |
| - logging_(new LoggingImpl(main_thread_proxy, config)) { |
| + clock_(clock.Pass()), |
| + logging_(new LoggingImpl(logging_config)) { |
| DCHECK(main_thread_proxy); |
| } |
| CastEnvironment::~CastEnvironment() { |
| // Logging must be deleted on the main thread. |
| - if (main_thread_proxy_->RunsTasksOnCurrentThread()) { |
| - logging_.reset(); |
| - } else { |
| + if (main_thread_proxy_ && !main_thread_proxy_->RunsTasksOnCurrentThread()) { |
| main_thread_proxy_->PostTask( |
| FROM_HERE, |
| base::Bind(&DeleteLoggingOnMainThread, base::Passed(&logging_))); |
| @@ -55,10 +57,7 @@ CastEnvironment::~CastEnvironment() { |
| bool CastEnvironment::PostTask(ThreadId identifier, |
| const tracked_objects::Location& from_here, |
| const base::Closure& task) { |
| - scoped_refptr<SingleThreadTaskRunner> task_runner = |
| - GetMessageSingleThreadTaskRunnerForThread(identifier); |
| - |
| - return task_runner->PostTask(from_here, task); |
| + return GetTaskRunner(identifier)->PostTask(from_here, task); |
| } |
| bool CastEnvironment::PostDelayedTask( |
| @@ -66,15 +65,11 @@ bool CastEnvironment::PostDelayedTask( |
| const tracked_objects::Location& from_here, |
| const base::Closure& task, |
| base::TimeDelta delay) { |
| - scoped_refptr<SingleThreadTaskRunner> task_runner = |
| - GetMessageSingleThreadTaskRunnerForThread(identifier); |
| - |
| - return task_runner->PostDelayedTask(from_here, task, delay); |
| + return GetTaskRunner(identifier)->PostDelayedTask(from_here, task, delay); |
| } |
| -scoped_refptr<SingleThreadTaskRunner> |
| -CastEnvironment::GetMessageSingleThreadTaskRunnerForThread( |
| - ThreadId identifier) { |
| +scoped_refptr<SingleThreadTaskRunner> CastEnvironment::GetTaskRunner( |
| + ThreadId identifier) const { |
| switch (identifier) { |
| case CastEnvironment::MAIN: |
| return main_thread_proxy_; |
| @@ -97,30 +92,28 @@ CastEnvironment::GetMessageSingleThreadTaskRunnerForThread( |
| bool CastEnvironment::CurrentlyOn(ThreadId identifier) { |
| switch (identifier) { |
| case CastEnvironment::MAIN: |
| - return main_thread_proxy_->RunsTasksOnCurrentThread(); |
| + return main_thread_proxy_ && |
|
hubbe
2014/03/06 19:54:43
Is this rebase stuff, or did you change this?
If y
miu
2014/03/07 22:40:29
I changed it. Three reasons:
1. The protected co
|
| + main_thread_proxy_->RunsTasksOnCurrentThread(); |
| case CastEnvironment::AUDIO_ENCODER: |
| - return audio_encode_thread_proxy_->RunsTasksOnCurrentThread(); |
| + return audio_encode_thread_proxy_ && |
| + audio_encode_thread_proxy_->RunsTasksOnCurrentThread(); |
| case CastEnvironment::AUDIO_DECODER: |
| - return audio_decode_thread_proxy_->RunsTasksOnCurrentThread(); |
| + return audio_decode_thread_proxy_ && |
| + audio_decode_thread_proxy_->RunsTasksOnCurrentThread(); |
| case CastEnvironment::VIDEO_ENCODER: |
| - return video_encode_thread_proxy_->RunsTasksOnCurrentThread(); |
| + return video_encode_thread_proxy_ && |
| + video_encode_thread_proxy_->RunsTasksOnCurrentThread(); |
| case CastEnvironment::VIDEO_DECODER: |
| - return video_decode_thread_proxy_->RunsTasksOnCurrentThread(); |
| + return video_decode_thread_proxy_ && |
| + video_decode_thread_proxy_->RunsTasksOnCurrentThread(); |
| case CastEnvironment::TRANSPORT: |
| - return transport_thread_proxy_->RunsTasksOnCurrentThread(); |
| + return transport_thread_proxy_ && |
| + transport_thread_proxy_->RunsTasksOnCurrentThread(); |
| default: |
| NOTREACHED() << "Invalid thread identifier"; |
| return false; |
| } |
| } |
| -base::TickClock* CastEnvironment::Clock() const { return clock_.get(); } |
| - |
| -LoggingImpl* CastEnvironment::Logging() { |
| - DCHECK(CurrentlyOn(CastEnvironment::MAIN)) |
| - << "Must be called from main thread"; |
| - return logging_.get(); |
| -} |
| - |
| } // namespace cast |
| } // namespace media |