Commit 1fb332dc authored by jinlong.zhai's avatar jinlong.zhai Committed by Commit bot

Change g_webrtc_logging_delegate from process-level to RenderThread-level

--single-process mode may happen crash in file of webrtc_logging.cc where code
is CHECK(!g_webrtc_logging_delegate). The orginal code is to expect there to
be only one g_webrtc_logging_delegate instance in a single render process.
g_webrtc_logging_delegate is created when a RenderThreadImpl is created.
But in --single-process model all RenderThreadImpl are created in browser
process and so g_webrtc_logging_delegate may be created many times in a single
process. Then CHECK(!g_webrtc_logging_delegate) will fail.

In this patch will change g_webrtc_logging_delegate from process-level to
RenderThread-Level. Since every render process will only keep one RenderThread.

BUG=455573

Review URL: https://codereview.chromium.org/889313003

Cr-Commit-Position: refs/heads/master@{#315131}
parent bb461c8f
...@@ -222,6 +222,7 @@ Jin Yang <jin.a.yang@intel.com> ...@@ -222,6 +222,7 @@ Jin Yang <jin.a.yang@intel.com>
Jincheol Jo <jincheol.jo@navercorp.com> Jincheol Jo <jincheol.jo@navercorp.com>
Jingwei Liu <kingweiliu@gmail.com> Jingwei Liu <kingweiliu@gmail.com>
Jingyi Wei <wjywbs@gmail.com> Jingyi Wei <wjywbs@gmail.com>
Jinlong Zhai <jinlong.zhai@samsung.com>
Jinho Bang <jinho.bang@samsung.com> Jinho Bang <jinho.bang@samsung.com>
Jinwoo Song <jinwoo7.song@samsung.com> Jinwoo Song <jinwoo7.song@samsung.com>
Jitendra Kumar Sahoo <jitendra.ks@samsung.com> Jitendra Kumar Sahoo <jitendra.ks@samsung.com>
......
...@@ -5,19 +5,22 @@ ...@@ -5,19 +5,22 @@
#include "content/renderer/media/webrtc_logging.h" #include "content/renderer/media/webrtc_logging.h"
#include "base/time/time.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 "content/public/renderer/webrtc_log_message_delegate.h"
#include "third_party/webrtc/overrides/webrtc/base/logging.h" #include "third_party/webrtc/overrides/webrtc/base/logging.h"
namespace content { namespace content {
// Shall only be set once and never go back to NULL. // Shall only be set once within a RenderThread and never go back to NULL.
WebRtcLogMessageDelegate* g_webrtc_logging_delegate = NULL; base::LazyInstance<base::ThreadLocalPointer<WebRtcLogMessageDelegate> >::Leaky
g_webrtc_logging_delegate_tls = LAZY_INSTANCE_INITIALIZER;
void InitWebRtcLoggingDelegate(WebRtcLogMessageDelegate* delegate) { void InitWebRtcLoggingDelegate(WebRtcLogMessageDelegate* delegate) {
CHECK(!g_webrtc_logging_delegate); CHECK(!g_webrtc_logging_delegate_tls.Pointer()->Get());
CHECK(delegate); CHECK(delegate);
g_webrtc_logging_delegate = delegate; g_webrtc_logging_delegate_tls.Pointer()->Set(delegate);
} }
void InitWebRtcLogging() { void InitWebRtcLogging() {
...@@ -26,8 +29,8 @@ void InitWebRtcLogging() { ...@@ -26,8 +29,8 @@ void InitWebRtcLogging() {
} }
void WebRtcLogMessage(const std::string& message) { void WebRtcLogMessage(const std::string& message) {
if (g_webrtc_logging_delegate) if (g_webrtc_logging_delegate_tls.Pointer()->Get())
g_webrtc_logging_delegate->LogMessage(message); g_webrtc_logging_delegate_tls.Pointer()->Get()->LogMessage(message);
} }
} // namespace content } // namespace content
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment