Managed bookmarks for supervised users.
[chromium-blink-merge.git] / media / cast / cast_environment.h
blobd3c9474fa3f54eff7704699d79715dbf57a3c53c
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 #ifndef MEDIA_CAST_CAST_ENVIRONMENT_H_
6 #define MEDIA_CAST_CAST_ENVIRONMENT_H_
8 #include "base/basictypes.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/single_thread_task_runner.h"
12 #include "base/time/tick_clock.h"
13 #include "base/time/time.h"
14 #include "media/cast/logging/logging_defines.h"
15 #include "media/cast/logging/logging_impl.h"
17 namespace media {
18 namespace cast {
20 class CastEnvironment : public base::RefCountedThreadSafe<CastEnvironment> {
21 public:
22 // An enumeration of the cast threads.
23 enum ThreadId {
24 // The main thread is where the cast system is configured and where timers
25 // and network IO is performed.
26 MAIN,
27 // The audio thread is where all send side audio processing is done,
28 // primarily encoding / decoding but also re-sampling.
29 AUDIO,
30 // The video encoder thread is where the video processing is done.
31 VIDEO,
34 CastEnvironment(
35 scoped_ptr<base::TickClock> clock,
36 scoped_refptr<base::SingleThreadTaskRunner> main_thread_proxy,
37 scoped_refptr<base::SingleThreadTaskRunner> audio_thread_proxy,
38 scoped_refptr<base::SingleThreadTaskRunner> video_thread_proxy);
40 // These are the same methods in message_loop.h, but are guaranteed to either
41 // get posted to the MessageLoop if it's still alive, or be deleted otherwise.
42 // They return true iff the thread existed and the task was posted. Note that
43 // even if the task is posted, there's no guarantee that it will run, since
44 // the target thread may already have a Quit message in its queue.
45 bool PostTask(ThreadId identifier,
46 const tracked_objects::Location& from_here,
47 const base::Closure& task);
49 bool PostDelayedTask(ThreadId identifier,
50 const tracked_objects::Location& from_here,
51 const base::Closure& task,
52 base::TimeDelta delay);
54 bool CurrentlyOn(ThreadId identifier);
56 // All of the media::cast implementation must use this TickClock.
57 base::TickClock* Clock() const { return clock_.get(); }
59 // Logging is not thread safe. Its methods should always be called from the
60 // main thread.
61 // TODO(hubbe): Logging should be a thread-safe interface.
62 LoggingImpl* Logging() const { return logging_.get(); }
64 scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner(
65 ThreadId identifier) const;
67 bool HasAudioThread() { return audio_thread_proxy_.get() ? true : false; }
69 bool HasVideoThread() { return video_thread_proxy_.get() ? true : false; }
71 protected:
72 virtual ~CastEnvironment();
74 // Subclasses may override these.
75 scoped_refptr<base::SingleThreadTaskRunner> main_thread_proxy_;
76 scoped_refptr<base::SingleThreadTaskRunner> audio_thread_proxy_;
77 scoped_refptr<base::SingleThreadTaskRunner> video_thread_proxy_;
78 scoped_ptr<base::TickClock> clock_;
79 scoped_ptr<LoggingImpl> logging_;
81 private:
82 friend class base::RefCountedThreadSafe<CastEnvironment>;
84 DISALLOW_COPY_AND_ASSIGN(CastEnvironment);
87 } // namespace cast
88 } // namespace media
90 #endif // MEDIA_CAST_CAST_ENVIRONMENT_H_