Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: chrome/renderer/media/chrome_webrtc_log_message_delegate.cc

Issue 218403004: Fix the timestamp generation for webrtc native log. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 10
12 ChromeWebRtcLogMessageDelegate::ChromeWebRtcLogMessageDelegate( 11 ChromeWebRtcLogMessageDelegate::ChromeWebRtcLogMessageDelegate(
13 const scoped_refptr<base::MessageLoopProxy>& io_message_loop, 12 const scoped_refptr<base::MessageLoopProxy>& io_message_loop,
14 WebRtcLoggingMessageFilter* message_filter) 13 WebRtcLoggingMessageFilter* message_filter)
15 : io_message_loop_(io_message_loop), 14 : io_message_loop_(io_message_loop),
16 logging_started_(false), 15 logging_started_(false),
17 message_filter_(message_filter) { 16 message_filter_(message_filter) {
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::LogMessage(const std::string& message) { 24 void ChromeWebRtcLogMessageDelegate::LogMessage(const std::string& message) {
25 WebRtcLoggingMessage message_with_timestamp;
26 message_with_timestamp.timestamp_ms = base::Time::Now().ToInternalValue() /
27 base::Time::kMicrosecondsPerMillisecond;
28 message_with_timestamp.message = message;
29
26 io_message_loop_->PostTask( 30 io_message_loop_->PostTask(
27 FROM_HERE, base::Bind( 31 FROM_HERE, base::Bind(
28 &ChromeWebRtcLogMessageDelegate::LogMessageOnIOThread, 32 &ChromeWebRtcLogMessageDelegate::LogMessageOnIOThread,
29 base::Unretained(this), 33 base::Unretained(this),
30 message)); 34 message_with_timestamp));
31 } 35 }
32 36
33 void ChromeWebRtcLogMessageDelegate::LogMessageOnIOThread( 37 void ChromeWebRtcLogMessageDelegate::LogMessageOnIOThread(
34 const std::string& message) { 38 const WebRtcLoggingMessage& message) {
35 DCHECK(CalledOnValidThread()); 39 DCHECK(CalledOnValidThread());
40
36 if (logging_started_ && message_filter_) { 41 if (logging_started_ && message_filter_) {
37 if (!log_buffer_.empty()) { 42 if (!log_buffer_.empty()) {
38 // A delayed task has already been posted for sending the buffer contents. 43 // A delayed task has already been posted for sending the buffer contents.
39 // Just add the message to the buffer. 44 // Just add the message to the buffer.
40 log_buffer_ += "\n" + message; 45 log_buffer_.push_back(message);
46 return;
47 }
48
49 log_buffer_.push_back(message);
50
51 if (base::TimeTicks::Now() - last_log_buffer_send_ >
52 base::TimeDelta::FromMilliseconds(100)) {
53 SendLogBuffer();
41 } else { 54 } else {
42 if (base::TimeTicks::Now() - last_log_buffer_send_ > 55 io_message_loop_->PostDelayedTask(
43 base::TimeDelta::FromMilliseconds(100)) { 56 FROM_HERE,
44 log_buffer_ = message; 57 base::Bind(&ChromeWebRtcLogMessageDelegate::SendLogBuffer,
45 SendLogBuffer(); 58 base::Unretained(this)),
46 } else { 59 base::TimeDelta::FromMilliseconds(200));
dcheng 2014/04/01 23:35:19 Out of scope for this patch, but is base::Unretain
47 log_buffer_ = message;
48 io_message_loop_->PostDelayedTask(
49 FROM_HERE,
50 base::Bind(&ChromeWebRtcLogMessageDelegate::SendLogBuffer,
51 base::Unretained(this)),
52 base::TimeDelta::FromMilliseconds(200));
53 }
54 } 60 }
55 } 61 }
56 } 62 }
57 63
58 void ChromeWebRtcLogMessageDelegate::OnFilterRemoved() { 64 void ChromeWebRtcLogMessageDelegate::OnFilterRemoved() {
59 DCHECK(CalledOnValidThread()); 65 DCHECK(CalledOnValidThread());
60 message_filter_ = NULL; 66 message_filter_ = NULL;
61 } 67 }
62 68
63 void ChromeWebRtcLogMessageDelegate::OnStartLogging() { 69 void ChromeWebRtcLogMessageDelegate::OnStartLogging() {
64 DCHECK(CalledOnValidThread()); 70 DCHECK(CalledOnValidThread());
65 logging_started_ = true; 71 logging_started_ = true;
66 content::InitWebRtcLogging(); 72 content::InitWebRtcLogging();
67 } 73 }
68 74
69 void ChromeWebRtcLogMessageDelegate::OnStopLogging() { 75 void ChromeWebRtcLogMessageDelegate::OnStopLogging() {
70 DCHECK(CalledOnValidThread()); 76 DCHECK(CalledOnValidThread());
71 if (!log_buffer_.empty()) 77 if (!log_buffer_.empty())
72 SendLogBuffer(); 78 SendLogBuffer();
73 if (message_filter_) 79 if (message_filter_)
74 message_filter_->LoggingStopped(); 80 message_filter_->LoggingStopped();
75 logging_started_ = false; 81 logging_started_ = false;
76 } 82 }
77 83
78 void ChromeWebRtcLogMessageDelegate::SendLogBuffer() { 84 void ChromeWebRtcLogMessageDelegate::SendLogBuffer() {
79 DCHECK(CalledOnValidThread()); 85 DCHECK(CalledOnValidThread());
80 if (logging_started_ && message_filter_) { 86 if (logging_started_ && message_filter_) {
dcheng 2014/04/01 23:35:19 Nit: This message_filter_ check is not actually ne
jiayl 2014/04/02 00:38:06 It can be null if SendLogBuffer is called from the
81 message_filter_->AddLogMessage(log_buffer_); 87 message_filter_->AddLogMessages(log_buffer_);
82 last_log_buffer_send_ = base::TimeTicks::Now(); 88 last_log_buffer_send_ = base::TimeTicks::Now();
83 } 89 }
84 log_buffer_.clear(); 90 log_buffer_.clear();
85 } 91 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698