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/cma_message_filter_proxy.h"
8 #include "content/public/renderer/render_thread.h"
10 namespace chromecast
{
13 CastRenderProcessObserver::CastRenderProcessObserver(
14 const std::vector
<scoped_refptr
<IPC::MessageFilter
>>&
15 platform_message_filters
)
16 : platform_message_filters_(platform_message_filters
) {
17 content::RenderThread
* thread
= content::RenderThread::Get();
18 thread
->AddObserver(this);
19 CreateCustomFilters();
22 CastRenderProcessObserver::~CastRenderProcessObserver() {
23 // CastRenderProcessObserver outlives content::RenderThread.
24 // No need to explicitly call RemoveObserver in teardown.
27 void CastRenderProcessObserver::CreateCustomFilters() {
28 content::RenderThread
* thread
= content::RenderThread::Get();
29 #if !defined(OS_ANDROID)
30 cma_message_filter_proxy_
=
31 new media::CmaMessageFilterProxy(thread
->GetIOMessageLoopProxy());
32 thread
->AddFilter(cma_message_filter_proxy_
.get());
33 #endif // !defined(OS_ANDROID)
34 for (const auto& filter
: platform_message_filters_
) {
35 thread
->AddFilter(filter
.get());
39 void CastRenderProcessObserver::OnRenderProcessShutdown() {
40 content::RenderThread
* thread
= content::RenderThread::Get();
41 #if !defined(OS_ANDROID)
42 if (cma_message_filter_proxy_
.get()) {
43 thread
->RemoveFilter(cma_message_filter_proxy_
.get());
44 cma_message_filter_proxy_
= NULL
;
46 #endif // !defined(OS_ANDROID)
47 for (auto& filter
: platform_message_filters_
) {
49 thread
->RemoveFilter(filter
.get());
53 platform_message_filters_
.clear();
57 } // namespace chromecast