Report errors from ChromiumEnv::GetChildren in Posix.
[chromium-blink-merge.git] / media / cast / cast_environment.cc
blobdddec1649f57ec3972f6ee54f31128a4367c4eba
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
3 // found in the LICENSE file.
5 #include "media/cast/cast_environment.h"
7 #include "base/logging.h"
9 using base::TaskRunner;
11 namespace media {
12 namespace cast {
14 CastEnvironment::CastEnvironment(
15 base::TickClock* clock,
16 scoped_refptr<TaskRunner> main_thread_proxy,
17 scoped_refptr<TaskRunner> audio_encode_thread_proxy,
18 scoped_refptr<TaskRunner> audio_decode_thread_proxy,
19 scoped_refptr<TaskRunner> video_encode_thread_proxy,
20 scoped_refptr<TaskRunner> video_decode_thread_proxy)
21 : clock_(clock),
22 main_thread_proxy_(main_thread_proxy),
23 audio_encode_thread_proxy_(audio_encode_thread_proxy),
24 audio_decode_thread_proxy_(audio_decode_thread_proxy),
25 video_encode_thread_proxy_(video_encode_thread_proxy),
26 video_decode_thread_proxy_(video_decode_thread_proxy) {
27 DCHECK(main_thread_proxy) << "Main thread required";
30 CastEnvironment::~CastEnvironment() {}
32 bool CastEnvironment::PostTask(ThreadId identifier,
33 const tracked_objects::Location& from_here,
34 const base::Closure& task) {
35 scoped_refptr<TaskRunner> task_runner =
36 GetMessageTaskRunnerForThread(identifier);
38 return task_runner->PostTask(from_here, task);
41 bool CastEnvironment::PostDelayedTask(ThreadId identifier,
42 const tracked_objects::Location& from_here,
43 const base::Closure& task,
44 base::TimeDelta delay) {
45 scoped_refptr<TaskRunner> task_runner =
46 GetMessageTaskRunnerForThread(identifier);
48 return task_runner->PostDelayedTask(from_here, task, delay);
51 scoped_refptr<TaskRunner> CastEnvironment::GetMessageTaskRunnerForThread(
52 ThreadId identifier) {
53 switch (identifier) {
54 case CastEnvironment::MAIN:
55 return main_thread_proxy_;
56 case CastEnvironment::AUDIO_ENCODER:
57 return audio_encode_thread_proxy_;
58 case CastEnvironment::AUDIO_DECODER:
59 return audio_decode_thread_proxy_;
60 case CastEnvironment::VIDEO_ENCODER:
61 return video_encode_thread_proxy_;
62 case CastEnvironment::VIDEO_DECODER:
63 return video_decode_thread_proxy_;
64 default:
65 NOTREACHED() << "Invalid Thread ID.";
66 return NULL;
70 bool CastEnvironment::CurrentlyOn(ThreadId identifier) {
71 switch (identifier) {
72 case CastEnvironment::MAIN:
73 return main_thread_proxy_->RunsTasksOnCurrentThread();
74 case CastEnvironment::AUDIO_ENCODER:
75 return audio_encode_thread_proxy_->RunsTasksOnCurrentThread();
76 case CastEnvironment::AUDIO_DECODER:
77 return audio_decode_thread_proxy_->RunsTasksOnCurrentThread();
78 case CastEnvironment::VIDEO_ENCODER:
79 return video_encode_thread_proxy_->RunsTasksOnCurrentThread();
80 case CastEnvironment::VIDEO_DECODER:
81 return video_decode_thread_proxy_->RunsTasksOnCurrentThread();
82 default:
83 NOTREACHED() << "Wrong thread identifier";
84 return false;
88 base::TickClock* CastEnvironment::Clock() {
89 return clock_;
92 } // namespace cast
93 } // namespace media