Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / chromecast / renderer / cast_render_process_observer.cc
blobb64a7c4bd8de682e89437e2f9ba12db2f786c606
1 // Copyright 2014 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 "chromecast/renderer/cast_render_process_observer.h"
7 #include "chromecast/renderer/media/capabilities_message_filter.h"
8 #include "chromecast/renderer/media/cma_message_filter_proxy.h"
9 #include "content/public/renderer/render_thread.h"
11 namespace chromecast {
12 namespace shell {
14 CastRenderProcessObserver::CastRenderProcessObserver() {
15 content::RenderThread* thread = content::RenderThread::Get();
16 thread->AddObserver(this);
17 CreateCustomFilters();
20 CastRenderProcessObserver::~CastRenderProcessObserver() {
21 // CastRenderProcessObserver outlives content::RenderThread.
22 // No need to explicitly call RemoveObserver in teardown.
25 void CastRenderProcessObserver::CreateCustomFilters() {
26 content::RenderThread* thread = content::RenderThread::Get();
27 #if !defined(OS_ANDROID)
28 cma_message_filter_proxy_ =
29 new media::CmaMessageFilterProxy(thread->GetIOMessageLoopProxy());
30 thread->AddFilter(cma_message_filter_proxy_.get());
31 #endif // !defined(OS_ANDROID)
32 capabilities_message_filter_ = new CapabilitiesMessageFilter;
33 thread->AddFilter(capabilities_message_filter_.get());
36 void CastRenderProcessObserver::OnRenderProcessShutdown() {
37 content::RenderThread* thread = content::RenderThread::Get();
38 #if !defined(OS_ANDROID)
39 if (cma_message_filter_proxy_.get()) {
40 thread->RemoveFilter(cma_message_filter_proxy_.get());
41 cma_message_filter_proxy_ = nullptr;
43 #endif // !defined(OS_ANDROID)
44 if (capabilities_message_filter_.get()) {
45 thread->RemoveFilter(capabilities_message_filter_.get());
46 capabilities_message_filter_ = nullptr;
50 } // namespace shell
51 } // namespace chromecast