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 "content/renderer/media/webrtc_logging.h" | 5 #include "content/renderer/media/webrtc_logging.h" |
6 | 6 |
7 #include <iomanip> | |
8 #include <sstream> | |
9 | |
10 #include "base/time/time.h" | 7 #include "base/time/time.h" |
11 #include "content/public/renderer/webrtc_log_message_delegate.h" | 8 #include "content/public/renderer/webrtc_log_message_delegate.h" |
12 #include "third_party/libjingle/overrides/talk/base/logging.h" | 9 #include "third_party/libjingle/overrides/talk/base/logging.h" |
13 | 10 |
14 namespace content { | 11 namespace content { |
15 | 12 |
16 // Shall only be set once and never go back to NULL. | 13 // Shall only be set once and never go back to NULL. |
17 WebRtcLogMessageDelegate* g_webrtc_logging_delegate = NULL; | 14 WebRtcLogMessageDelegate* g_webrtc_logging_delegate = NULL; |
18 uint64 g_started_time_ms_ = 0; | 15 uint64 g_started_time_ms_ = 0; |
19 | 16 |
20 void InitWebRtcLoggingDelegate(WebRtcLogMessageDelegate* delegate) { | 17 void InitWebRtcLoggingDelegate(WebRtcLogMessageDelegate* delegate) { |
21 CHECK(!g_webrtc_logging_delegate); | 18 CHECK(!g_webrtc_logging_delegate); |
22 CHECK(delegate); | 19 CHECK(delegate); |
23 | 20 |
24 g_webrtc_logging_delegate = delegate; | 21 g_webrtc_logging_delegate = delegate; |
25 | 22 |
26 g_started_time_ms_ = base::Time::Now().ToInternalValue() / | 23 g_started_time_ms_ = base::Time::Now().ToInternalValue() / |
27 base::Time::kMicrosecondsPerMillisecond; | 24 base::Time::kMicrosecondsPerMillisecond; |
28 } | 25 } |
29 | 26 |
30 void WebRtcLogMessageWithTimestamp(const std::string& message) { | |
31 if (g_webrtc_logging_delegate) | |
32 g_webrtc_logging_delegate->LogMessage(message); | |
33 } | |
34 | |
35 void InitWebRtcLogging() { | 27 void InitWebRtcLogging() { |
36 // Log messages from Libjingle should always have timestamps. | 28 // Log messages from Libjingle should not have timestamps. |
37 talk_base::InitDiagnosticLoggingDelegateFunction( | 29 talk_base::InitDiagnosticLoggingDelegateFunction(WebRtcLogMessage); |
tommi (sloooow) - chröme
2014/04/02 15:17:59
nit: &WebRtcLoggingMessage
jiayl
2014/04/02 16:23:59
Done.
| |
38 WebRtcLogMessageWithTimestamp); | |
39 } | 30 } |
40 | 31 |
41 void WebRtcLogMessage(const std::string& message) { | 32 void WebRtcLogMessage(const std::string& message) { |
42 // Keep consistent with talk_base::DiagnosticLogMessage::CreateTimestamp. | 33 if (g_webrtc_logging_delegate) { |
43 // TODO(grunell): remove the duplicated code and unify the timestamp creation. | 34 g_webrtc_logging_delegate->LogMessage(message); |
44 uint64 now_us = base::Time::Now().ToInternalValue(); | 35 } |
45 uint64 interval_ms = now_us / base::Time::kMicrosecondsPerMillisecond - | |
46 g_started_time_ms_; | |
47 | |
48 std::ostringstream message_oss; | |
49 message_oss << "[" << std::setfill('0') << std::setw(3) | |
50 << (interval_ms / 1000) | |
51 << ":" << std::setw(3) | |
52 << (interval_ms % 1000) | |
53 << std::setfill(' ') << "] " << message; | |
54 | |
55 WebRtcLogMessageWithTimestamp(message_oss.str()); | |
56 } | 36 } |
57 | 37 |
58 } // namespace content | 38 } // namespace content |
OLD | NEW |