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
{
14 CastRenderProcessObserver::CastRenderProcessObserver(
15 const std::vector
<scoped_refptr
<IPC::MessageFilter
>>&
16 platform_message_filters
)
17 : platform_message_filters_(platform_message_filters
) {
18 content::RenderThread
* thread
= content::RenderThread::Get();
19 thread
->AddObserver(this);
20 CreateCustomFilters();
23 CastRenderProcessObserver::~CastRenderProcessObserver() {
24 // CastRenderProcessObserver outlives content::RenderThread.
25 // No need to explicitly call RemoveObserver in teardown.
28 void CastRenderProcessObserver::CreateCustomFilters() {
29 content::RenderThread
* thread
= content::RenderThread::Get();
30 #if !defined(OS_ANDROID)
31 cma_message_filter_proxy_
=
32 new media::CmaMessageFilterProxy(thread
->GetIOMessageLoopProxy());
33 thread
->AddFilter(cma_message_filter_proxy_
.get());
34 #endif // !defined(OS_ANDROID)
35 capabilities_message_filter_
= new CapabilitiesMessageFilter
;
36 thread
->AddFilter(capabilities_message_filter_
.get());
37 for (const auto& filter
: platform_message_filters_
) {
38 thread
->AddFilter(filter
.get());
42 void CastRenderProcessObserver::OnRenderProcessShutdown() {
43 content::RenderThread
* thread
= content::RenderThread::Get();
44 #if !defined(OS_ANDROID)
45 if (cma_message_filter_proxy_
.get()) {
46 thread
->RemoveFilter(cma_message_filter_proxy_
.get());
47 cma_message_filter_proxy_
= nullptr;
49 #endif // !defined(OS_ANDROID)
50 if (capabilities_message_filter_
.get()) {
51 thread
->RemoveFilter(capabilities_message_filter_
.get());
52 capabilities_message_filter_
= nullptr;
54 for (auto& filter
: platform_message_filters_
) {
56 thread
->RemoveFilter(filter
.get());
60 platform_message_filters_
.clear();
64 } // namespace chromecast