| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/renderer/media/chrome_webrtc_log_message_delegate.h" | 5 #include "chrome/renderer/media/chrome_webrtc_log_message_delegate.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/message_loop/message_loop_proxy.h" | 8 #include "base/message_loop/message_loop_proxy.h" |
| 9 #include "chrome/common/partial_circular_buffer.h" | 9 #include "chrome/common/partial_circular_buffer.h" |
| 10 #include "chrome/renderer/media/webrtc_logging_message_filter.h" | 10 #include "chrome/renderer/media/webrtc_logging_message_filter.h" |
| 11 | 11 |
| 12 ChromeWebRtcLogMessageDelegate::ChromeWebRtcLogMessageDelegate( | 12 ChromeWebRtcLogMessageDelegate::ChromeWebRtcLogMessageDelegate( |
| 13 const scoped_refptr<base::MessageLoopProxy>& io_message_loop, | 13 const scoped_refptr<base::MessageLoopProxy>& io_message_loop, |
| 14 WebRtcLoggingMessageFilter* message_filter) | 14 WebRtcLoggingMessageFilter* message_filter) |
| 15 : io_message_loop_(io_message_loop), | 15 : io_message_loop_(io_message_loop), |
| 16 message_filter_(message_filter), | 16 message_filter_(message_filter) { |
| 17 log_initialized_(false) { | |
| 18 content::InitWebRtcLoggingDelegate(this); | 17 content::InitWebRtcLoggingDelegate(this); |
| 19 } | 18 } |
| 20 | 19 |
| 21 ChromeWebRtcLogMessageDelegate::~ChromeWebRtcLogMessageDelegate() { | 20 ChromeWebRtcLogMessageDelegate::~ChromeWebRtcLogMessageDelegate() { |
| 22 DCHECK(CalledOnValidThread()); | 21 DCHECK(CalledOnValidThread()); |
| 23 } | 22 } |
| 24 | 23 |
| 25 void ChromeWebRtcLogMessageDelegate::InitLogging( | |
| 26 const std::string& app_session_id, | |
| 27 const std::string& app_url) { | |
| 28 DCHECK(CalledOnValidThread()); | |
| 29 | |
| 30 if (!log_initialized_) { | |
| 31 log_initialized_ = true; | |
| 32 message_filter_->InitLogging(app_session_id, app_url); | |
| 33 } | |
| 34 } | |
| 35 | |
| 36 void ChromeWebRtcLogMessageDelegate::LogMessage(const std::string& message) { | 24 void ChromeWebRtcLogMessageDelegate::LogMessage(const std::string& message) { |
| 37 if (!CalledOnValidThread()) { | 25 if (!CalledOnValidThread()) { |
| 38 io_message_loop_->PostTask( | 26 io_message_loop_->PostTask( |
| 39 FROM_HERE, base::Bind( | 27 FROM_HERE, base::Bind( |
| 40 &ChromeWebRtcLogMessageDelegate::LogMessage, | 28 &ChromeWebRtcLogMessageDelegate::LogMessage, |
| 41 base::Unretained(this), | 29 base::Unretained(this), |
| 42 message)); | 30 message)); |
| 43 return; | 31 return; |
| 44 } | 32 } |
| 45 | 33 |
| 46 if (circular_buffer_) { | 34 if (circular_buffer_) { |
| 47 circular_buffer_->Write(message.c_str(), message.length()); | 35 circular_buffer_->Write(message.c_str(), message.length()); |
| 48 const char eol = '\n'; | 36 const char eol = '\n'; |
| 49 circular_buffer_->Write(&eol, 1); | 37 circular_buffer_->Write(&eol, 1); |
| 50 } | 38 } |
| 51 } | 39 } |
| 52 | 40 |
| 53 void ChromeWebRtcLogMessageDelegate::OnFilterRemoved() { | 41 void ChromeWebRtcLogMessageDelegate::OnFilterRemoved() { |
| 54 DCHECK(CalledOnValidThread()); | 42 DCHECK(CalledOnValidThread()); |
| 55 message_filter_ = NULL; | 43 message_filter_ = NULL; |
| 56 } | 44 } |
| 57 | 45 |
| 58 void ChromeWebRtcLogMessageDelegate::OnLogOpened( | 46 void ChromeWebRtcLogMessageDelegate::OnStartLogging( |
| 59 base::SharedMemoryHandle handle, | 47 base::SharedMemoryHandle handle, |
| 60 uint32 length) { | 48 uint32 length) { |
| 61 DCHECK(CalledOnValidThread()); | 49 DCHECK(CalledOnValidThread()); |
| 50 DCHECK(!shared_memory_ && !circular_buffer_); |
| 62 | 51 |
| 63 shared_memory_.reset(new base::SharedMemory(handle, false)); | 52 shared_memory_.reset(new base::SharedMemory(handle, false)); |
| 64 CHECK(shared_memory_->Map(length)); | 53 CHECK(shared_memory_->Map(length)); |
| 65 circular_buffer_.reset( | 54 circular_buffer_.reset( |
| 66 new PartialCircularBuffer(shared_memory_->memory(), | 55 new PartialCircularBuffer(shared_memory_->memory(), |
| 67 length, | 56 length, |
| 68 length / 2, | 57 length / 2, |
| 69 true)); | 58 true)); |
| 59 |
| 60 content::InitWebRtcLogging(); |
| 70 } | 61 } |
| 71 | 62 |
| 72 void ChromeWebRtcLogMessageDelegate::OnOpenLogFailed() { | 63 void ChromeWebRtcLogMessageDelegate::OnStopLogging() { |
| 73 DCHECK(CalledOnValidThread()); | 64 DCHECK(CalledOnValidThread()); |
| 74 DLOG(ERROR) << "Could not open log."; | 65 DCHECK(shared_memory_ && circular_buffer_); |
| 75 // TODO(grunell): Implement. | 66 |
| 76 NOTIMPLEMENTED(); | 67 if (message_filter_) { |
| 68 circular_buffer_.reset(NULL); |
| 69 shared_memory_.reset(NULL); |
| 70 message_filter_->LoggingStopped(); |
| 71 } |
| 77 } | 72 } |
| OLD | NEW |