Last user_story -> story change in telemetry.
[chromium-blink-merge.git] / chromecast / renderer / cast_render_process_observer.cc
blobcaba2442a0cbf04a3a5704af711609ad9f13a45a
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 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_) {
55 if (filter.get()) {
56 thread->RemoveFilter(filter.get());
57 filter = nullptr;
60 platform_message_filters_.clear();
63 } // namespace shell
64 } // namespace chromecast