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 : io_message_loop_(io_message_loop),
16 log_message_delegate_(NULL),
18 // May be null in a browsertest using MockRenderThread.
19 if (io_message_loop_.get()) {
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::Sender* sender) {
43 DCHECK(!io_message_loop_.get() || io_message_loop_->BelongsToCurrentThread());
47 void WebRtcLoggingMessageFilter::OnFilterRemoved() {
48 DCHECK(!io_message_loop_.get() || io_message_loop_->BelongsToCurrentThread());
50 log_message_delegate_->OnFilterRemoved();
53 void WebRtcLoggingMessageFilter::OnChannelClosing() {
54 DCHECK(!io_message_loop_.get() || io_message_loop_->BelongsToCurrentThread());
56 log_message_delegate_->OnFilterRemoved();
59 void WebRtcLoggingMessageFilter::AddLogMessages(
60 const std::vector<WebRtcLoggingMessageData>& messages) {
61 DCHECK(io_message_loop_->BelongsToCurrentThread());
62 Send(new WebRtcLoggingMsg_AddLogMessages(messages));
65 void WebRtcLoggingMessageFilter::LoggingStopped() {
66 DCHECK(!io_message_loop_.get() || io_message_loop_->BelongsToCurrentThread());
67 Send(new WebRtcLoggingMsg_LoggingStopped());
70 void WebRtcLoggingMessageFilter::CreateLoggingHandler() {
71 DCHECK(!io_message_loop_.get() || io_message_loop_->BelongsToCurrentThread());
72 log_message_delegate_ =
73 new ChromeWebRtcLogMessageDelegate(io_message_loop_, this);
76 void WebRtcLoggingMessageFilter::OnStartLogging() {
77 DCHECK(!io_message_loop_.get() || io_message_loop_->BelongsToCurrentThread());
78 log_message_delegate_->OnStartLogging();
81 void WebRtcLoggingMessageFilter::OnStopLogging() {
82 DCHECK(!io_message_loop_.get() || io_message_loop_->BelongsToCurrentThread());
83 log_message_delegate_->OnStopLogging();
86 void WebRtcLoggingMessageFilter::Send(IPC::Message* message) {
87 DCHECK(!io_message_loop_.get() || io_message_loop_->BelongsToCurrentThread());
89 DLOG(ERROR) << "IPC sender not available.";
92 sender_->Send(message);