Index: content/renderer/media/webrtc_logging.cc |
diff --git a/content/renderer/media/webrtc_logging.cc b/content/renderer/media/webrtc_logging.cc |
index 17e5c5745420d96fcd68aefd64911bdf1f9c5140..204c2c99ab37e62b55a21edb83a3a9bde100ae05 100644 |
--- a/content/renderer/media/webrtc_logging.cc |
+++ b/content/renderer/media/webrtc_logging.cc |
@@ -5,19 +5,22 @@ |
#include "content/renderer/media/webrtc_logging.h" |
#include "base/time/time.h" |
+#include "base/lazy_instance.h" |
+#include "base/threading/thread_local.h" |
#include "content/public/renderer/webrtc_log_message_delegate.h" |
#include "third_party/webrtc/overrides/webrtc/base/logging.h" |
namespace content { |
-// Shall only be set once and never go back to NULL. |
-WebRtcLogMessageDelegate* g_webrtc_logging_delegate = NULL; |
+// Shall only be set once within a RenderThread and never go back to NULL. |
+base::LazyInstance<base::ThreadLocalPointer<WebRtcLogMessageDelegate> >::Leaky |
+ g_webrtc_logging_delegate_tls = LAZY_INSTANCE_INITIALIZER; |
void InitWebRtcLoggingDelegate(WebRtcLogMessageDelegate* delegate) { |
- CHECK(!g_webrtc_logging_delegate); |
+ CHECK(!g_webrtc_logging_delegate_tls.Pointer()->Get()); |
CHECK(delegate); |
- g_webrtc_logging_delegate = delegate; |
+ g_webrtc_logging_delegate_tls.Pointer()->Set(delegate); |
} |
void InitWebRtcLogging() { |
@@ -26,8 +29,8 @@ void InitWebRtcLogging() { |
} |
void WebRtcLogMessage(const std::string& message) { |
- if (g_webrtc_logging_delegate) |
- g_webrtc_logging_delegate->LogMessage(message); |
+ if (g_webrtc_logging_delegate_tls.Pointer()->Get()) |
+ g_webrtc_logging_delegate_tls.Pointer()->Get()->LogMessage(message); |
} |
} // namespace content |