Support for unpacked ARM packed relocations.
[chromium-blink-merge.git] / media / cast / cast_environment.cc
blob93eb8c72522fa28e5963b407cf1a0cd86bfb5d32
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/bind.h"
8 #include "base/location.h"
9 #include "base/logging.h"
11 using base::SingleThreadTaskRunner;
13 namespace {
15 void DeleteLoggingOnMainThread(scoped_ptr<media::cast::LoggingImpl> logging) {
16 logging.reset();
19 } // namespace
21 namespace media {
22 namespace cast {
24 CastEnvironment::CastEnvironment(
25 scoped_ptr<base::TickClock> clock,
26 scoped_refptr<SingleThreadTaskRunner> main_thread_proxy,
27 scoped_refptr<SingleThreadTaskRunner> audio_thread_proxy,
28 scoped_refptr<SingleThreadTaskRunner> video_thread_proxy)
29 : main_thread_proxy_(main_thread_proxy),
30 audio_thread_proxy_(audio_thread_proxy),
31 video_thread_proxy_(video_thread_proxy),
32 clock_(clock.Pass()),
33 logging_(new LoggingImpl) {}
35 CastEnvironment::~CastEnvironment() {
36 // Logging must be deleted on the main thread.
37 if (main_thread_proxy_ && !main_thread_proxy_->RunsTasksOnCurrentThread()) {
38 main_thread_proxy_->PostTask(
39 FROM_HERE,
40 base::Bind(&DeleteLoggingOnMainThread, base::Passed(&logging_)));
44 bool CastEnvironment::PostTask(ThreadId identifier,
45 const tracked_objects::Location& from_here,
46 const base::Closure& task) {
47 return GetTaskRunner(identifier)->PostTask(from_here, task);
50 bool CastEnvironment::PostDelayedTask(
51 ThreadId identifier,
52 const tracked_objects::Location& from_here,
53 const base::Closure& task,
54 base::TimeDelta delay) {
55 return GetTaskRunner(identifier)->PostDelayedTask(from_here, task, delay);
58 scoped_refptr<SingleThreadTaskRunner> CastEnvironment::GetTaskRunner(
59 ThreadId identifier) const {
60 switch (identifier) {
61 case CastEnvironment::MAIN:
62 return main_thread_proxy_;
63 case CastEnvironment::AUDIO:
64 return audio_thread_proxy_;
65 case CastEnvironment::VIDEO:
66 return video_thread_proxy_;
67 default:
68 NOTREACHED() << "Invalid Thread identifier";
69 return NULL;
73 bool CastEnvironment::CurrentlyOn(ThreadId identifier) {
74 switch (identifier) {
75 case CastEnvironment::MAIN:
76 return main_thread_proxy_ &&
77 main_thread_proxy_->RunsTasksOnCurrentThread();
78 case CastEnvironment::AUDIO:
79 return audio_thread_proxy_ &&
80 audio_thread_proxy_->RunsTasksOnCurrentThread();
81 case CastEnvironment::VIDEO:
82 return video_thread_proxy_ &&
83 video_thread_proxy_->RunsTasksOnCurrentThread();
84 default:
85 NOTREACHED() << "Invalid thread identifier";
86 return false;
90 } // namespace cast
91 } // namespace media