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