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. 4 5 #ifndef CHROME_RENDERER_MEDIA_WEBRTC_LOGGING_MESSAGE_FILTER_H_ 6 #define CHROME_RENDERER_MEDIA_WEBRTC_LOGGING_MESSAGE_FILTER_H_ 7 8 #include "chrome/common/media/webrtc_logging_message_data.h" 9 #include "ipc/message_filter.h" 10 11 namespace base { 12 class MessageLoopProxy; 13 } 14 15 class ChromeWebRtcLogMessageDelegate; 16 17 // Filter for WebRTC logging messages. Sits between 18 // ChromeWebRtcLogMessageDelegate (renderer process) and 19 // WebRtcLoggingHandlerHost (browser process). Must be called on the IO thread. 20 class WebRtcLoggingMessageFilter : public IPC::MessageFilter { 21 public: 22 explicit WebRtcLoggingMessageFilter( 23 const scoped_refptr<base::MessageLoopProxy>& io_message_loop); 24 25 virtual void AddLogMessages( 26 const std::vector<WebRtcLoggingMessageData>& messages); 27 virtual void LoggingStopped(); 28 29 const scoped_refptr<base::MessageLoopProxy>& io_message_loop() { 30 return io_message_loop_; 31 } 32 33 protected: 34 virtual ~WebRtcLoggingMessageFilter(); 35 36 scoped_refptr<base::MessageLoopProxy> io_message_loop_; 37 38 // Owned by this class. The only other pointer to it is in libjingle's logging 39 // file. That's a global pointer used on different threads, so we will leak 40 // this object when we go away to ensure that it outlives any log messages 41 // coming from libjingle. 42 // This is protected for unit test purposes. 43 // TODO(vrk): Remove ChromeWebRtcLogMessageDelegate's pointer to 44 // WebRtcLoggingMessageFilter so that we can write a unit test that doesn't 45 // need this accessor. 46 ChromeWebRtcLogMessageDelegate* log_message_delegate_; 47 48 private: 49 // IPC::MessageFilter implementation. 50 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 51 virtual void OnFilterAdded(IPC::Sender* sender) OVERRIDE; 52 virtual void OnFilterRemoved() OVERRIDE; 53 virtual void OnChannelClosing() OVERRIDE; 54 55 void CreateLoggingHandler(); 56 57 void OnStartLogging(); 58 void OnStopLogging(); 59 void Send(IPC::Message* message); 60 61 IPC::Sender* sender_; 62 63 DISALLOW_COPY_AND_ASSIGN(WebRtcLoggingMessageFilter); 64 }; 65 66 #endif // CHROME_RENDERER_MEDIA_WEBRTC_LOGGING_MESSAGE_FILTER_H_ 67