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 #include "chrome/renderer/media/webrtc_logging_message_filter.h"
7 #include "base/logging.h"
8 #include "base/message_loop/message_loop_proxy.h"
9 #include "chrome/common/media/webrtc_logging_messages.h"
10 #include "chrome/renderer/media/chrome_webrtc_log_message_delegate.h"
11 #include "ipc/ipc_logging.h"
13 WebRtcLoggingMessageFilter::WebRtcLoggingMessageFilter(
14 const scoped_refptr<base::MessageLoopProxy>& io_message_loop)
15 : log_message_delegate_(NULL),
16 io_message_loop_(io_message_loop),
18 // May be null in a browsertest using MockRenderThread.
19 if (io_message_loop_) {
20 io_message_loop_->PostTask(
21 FROM_HERE, base::Bind(
22 &WebRtcLoggingMessageFilter::CreateLoggingHandler,
23 base::Unretained(this)));
27 WebRtcLoggingMessageFilter::~WebRtcLoggingMessageFilter() {
30 bool WebRtcLoggingMessageFilter::OnMessageReceived(
31 const IPC::Message& message) {
32 DCHECK(io_message_loop_->BelongsToCurrentThread());
34 IPC_BEGIN_MESSAGE_MAP(WebRtcLoggingMessageFilter, message)
35 IPC_MESSAGE_HANDLER(WebRtcLoggingMsg_StartLogging, OnStartLogging)
36 IPC_MESSAGE_HANDLER(WebRtcLoggingMsg_StopLogging, OnStopLogging)
37 IPC_MESSAGE_UNHANDLED(handled = false)
42 void WebRtcLoggingMessageFilter::OnFilterAdded(IPC::Channel* channel) {
43 DCHECK(!io_message_loop_ || io_message_loop_->BelongsToCurrentThread());
47 void WebRtcLoggingMessageFilter::OnFilterRemoved() {
48 DCHECK(!io_message_loop_ || io_message_loop_->BelongsToCurrentThread());
50 log_message_delegate_->OnFilterRemoved();
53 void WebRtcLoggingMessageFilter::OnChannelClosing() {
54 DCHECK(!io_message_loop_ || io_message_loop_->BelongsToCurrentThread());
56 log_message_delegate_->OnFilterRemoved();
59 void WebRtcLoggingMessageFilter::LoggingStopped() {
60 DCHECK(io_message_loop_->BelongsToCurrentThread());
61 Send(new WebRtcLoggingMsg_LoggingStopped());
64 void WebRtcLoggingMessageFilter::CreateLoggingHandler() {
65 DCHECK(!io_message_loop_ || io_message_loop_->BelongsToCurrentThread());
66 log_message_delegate_ =
67 new ChromeWebRtcLogMessageDelegate(io_message_loop_, this);
70 void WebRtcLoggingMessageFilter::OnStartLogging(
71 base::SharedMemoryHandle handle,
73 DCHECK(!io_message_loop_ || io_message_loop_->BelongsToCurrentThread());
74 log_message_delegate_->OnStartLogging(handle, length);
77 void WebRtcLoggingMessageFilter::OnStopLogging() {
78 DCHECK(io_message_loop_->BelongsToCurrentThread());
79 log_message_delegate_->OnStopLogging();
82 void WebRtcLoggingMessageFilter::Send(IPC::Message* message) {
83 DCHECK(!io_message_loop_ || io_message_loop_->BelongsToCurrentThread());
85 DLOG(ERROR) << "IPC channel not available.";
88 channel_->Send(message);