| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/cast/cast_environment.h" | 5 #include "media/cast/cast_environment.h" |
| 6 | 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/location.h" |
| 7 #include "base/logging.h" | 9 #include "base/logging.h" |
| 8 | 10 |
| 9 using base::TaskRunner; | 11 using base::TaskRunner; |
| 10 | 12 |
| 13 namespace { |
| 14 |
| 15 void DeleteLoggingOnMainThread(scoped_ptr<media::cast::LoggingImpl> logging) { |
| 16 logging.reset(); |
| 17 } |
| 18 |
| 19 } // namespace |
| 20 |
| 11 namespace media { | 21 namespace media { |
| 12 namespace cast { | 22 namespace cast { |
| 13 | 23 |
| 14 CastEnvironment::CastEnvironment( | 24 CastEnvironment::CastEnvironment( |
| 15 base::TickClock* clock, | 25 base::TickClock* clock, |
| 16 scoped_refptr<TaskRunner> main_thread_proxy, | 26 scoped_refptr<TaskRunner> main_thread_proxy, |
| 17 scoped_refptr<TaskRunner> audio_encode_thread_proxy, | 27 scoped_refptr<TaskRunner> audio_encode_thread_proxy, |
| 18 scoped_refptr<TaskRunner> audio_decode_thread_proxy, | 28 scoped_refptr<TaskRunner> audio_decode_thread_proxy, |
| 19 scoped_refptr<TaskRunner> video_encode_thread_proxy, | 29 scoped_refptr<TaskRunner> video_encode_thread_proxy, |
| 20 scoped_refptr<TaskRunner> video_decode_thread_proxy, | 30 scoped_refptr<TaskRunner> video_decode_thread_proxy, |
| 21 scoped_refptr<TaskRunner> transport_thread_proxy, | 31 scoped_refptr<TaskRunner> transport_thread_proxy, |
| 22 const CastLoggingConfig& config) | 32 const CastLoggingConfig& config) |
| 23 : clock_(clock), | 33 : clock_(clock), |
| 24 main_thread_proxy_(main_thread_proxy), | 34 main_thread_proxy_(main_thread_proxy), |
| 25 audio_encode_thread_proxy_(audio_encode_thread_proxy), | 35 audio_encode_thread_proxy_(audio_encode_thread_proxy), |
| 26 audio_decode_thread_proxy_(audio_decode_thread_proxy), | 36 audio_decode_thread_proxy_(audio_decode_thread_proxy), |
| 27 video_encode_thread_proxy_(video_encode_thread_proxy), | 37 video_encode_thread_proxy_(video_encode_thread_proxy), |
| 28 video_decode_thread_proxy_(video_decode_thread_proxy), | 38 video_decode_thread_proxy_(video_decode_thread_proxy), |
| 29 transport_thread_proxy_(transport_thread_proxy), | 39 transport_thread_proxy_(transport_thread_proxy), |
| 30 logging_(new LoggingImpl(main_thread_proxy, config)) { | 40 logging_(new LoggingImpl(main_thread_proxy, config)) { |
| 31 DCHECK(main_thread_proxy) << "Main thread required"; | 41 DCHECK(main_thread_proxy) << "Main thread required"; |
| 32 } | 42 } |
| 33 | 43 |
| 34 CastEnvironment::~CastEnvironment() {} | 44 CastEnvironment::~CastEnvironment() { |
| 45 // Logging must be deleted on the main thread. |
| 46 if (main_thread_proxy_->RunsTasksOnCurrentThread()) { |
| 47 logging_.reset(); |
| 48 } else { |
| 49 main_thread_proxy_->PostTask( |
| 50 FROM_HERE, |
| 51 base::Bind(&DeleteLoggingOnMainThread, base::Passed(&logging_))); |
| 52 } |
| 53 } |
| 35 | 54 |
| 36 bool CastEnvironment::PostTask(ThreadId identifier, | 55 bool CastEnvironment::PostTask(ThreadId identifier, |
| 37 const tracked_objects::Location& from_here, | 56 const tracked_objects::Location& from_here, |
| 38 const base::Closure& task) { | 57 const base::Closure& task) { |
| 39 scoped_refptr<TaskRunner> task_runner = | 58 scoped_refptr<TaskRunner> task_runner = |
| 40 GetMessageTaskRunnerForThread(identifier); | 59 GetMessageTaskRunnerForThread(identifier); |
| 41 | 60 |
| 42 return task_runner->PostTask(from_here, task); | 61 return task_runner->PostTask(from_here, task); |
| 43 } | 62 } |
| 44 | 63 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 } | 117 } |
| 99 | 118 |
| 100 LoggingImpl* CastEnvironment::Logging() { | 119 LoggingImpl* CastEnvironment::Logging() { |
| 101 DCHECK(CurrentlyOn(CastEnvironment::MAIN)) << | 120 DCHECK(CurrentlyOn(CastEnvironment::MAIN)) << |
| 102 "Must be called from main thread"; | 121 "Must be called from main thread"; |
| 103 return logging_.get(); | 122 return logging_.get(); |
| 104 } | 123 } |
| 105 | 124 |
| 106 } // namespace cast | 125 } // namespace cast |
| 107 } // namespace media | 126 } // namespace media |
| OLD | NEW |