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 "content/public/renderer/webrtc_log_message_delegate.h" | 11 #include "content/public/renderer/webrtc_log_message_delegate.h" |
8 #include "third_party/libjingle/overrides/talk/base/logging.h" | 12 #include "third_party/libjingle/overrides/talk/base/logging.h" |
9 | 13 |
10 namespace content { | 14 namespace content { |
11 | 15 |
12 // Shall only be set once and never go back to NULL. | 16 // Shall only be set once and never go back to NULL. |
13 WebRtcLogMessageDelegate* g_webrtc_logging_delegate = NULL; | 17 WebRtcLogMessageDelegate* g_webrtc_logging_delegate = NULL; |
| 18 uint64 g_started_time_ms_ = 0; |
14 | 19 |
15 void InitWebRtcLoggingDelegate(WebRtcLogMessageDelegate* delegate) { | 20 void InitWebRtcLoggingDelegate(WebRtcLogMessageDelegate* delegate) { |
16 CHECK(!g_webrtc_logging_delegate); | 21 CHECK(!g_webrtc_logging_delegate); |
17 CHECK(delegate); | 22 CHECK(delegate); |
18 | 23 |
19 g_webrtc_logging_delegate = delegate; | 24 g_webrtc_logging_delegate = delegate; |
| 25 |
| 26 g_started_time_ms_ = base::Time::Now().ToInternalValue() / |
| 27 base::Time::kMicrosecondsPerMillisecond; |
20 } | 28 } |
21 | 29 |
22 void InitWebRtcLogging() { | 30 void WebRtcLogMessageWithTimestamp(const std::string& message) { |
23 talk_base::InitDiagnosticLoggingDelegateFunction(WebRtcLogMessage); | |
24 } | |
25 | |
26 void WebRtcLogMessage(const std::string& message) { | |
27 if (g_webrtc_logging_delegate) | 31 if (g_webrtc_logging_delegate) |
28 g_webrtc_logging_delegate->LogMessage(message); | 32 g_webrtc_logging_delegate->LogMessage(message); |
29 } | 33 } |
30 | 34 |
| 35 void InitWebRtcLogging() { |
| 36 // Log messages from Libjingle should always have timestamps. |
| 37 talk_base::InitDiagnosticLoggingDelegateFunction( |
| 38 WebRtcLogMessageWithTimestamp); |
| 39 } |
| 40 |
| 41 void WebRtcLogMessage(const std::string& message) { |
| 42 // Keep consistent with talk_base::DiagnosticLogMessage::CreateTimestamp. |
| 43 // TODO(grunell): remove the duplicated code and unify the timestamp creation. |
| 44 uint64 now_us = base::Time::Now().ToInternalValue(); |
| 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 } |
| 57 |
31 } // namespace content | 58 } // namespace content |
OLD | NEW |