summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/media
diff options
context:
space:
mode:
authorgrunell@chromium.org <grunell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-31 23:58:31 +0000
committergrunell@chromium.org <grunell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-31 23:58:31 +0000
commit6ef98b5a0dabccfe9271697efee657316693cbee (patch)
tree7e219b96acacdbaab8c6e7d84e136a36df0a0362 /chrome/renderer/media
parent66d5ac0c4ff1e95e240d076c798300435891b58b (diff)
downloadchromium_src-6ef98b5a0dabccfe9271697efee657316693cbee.zip
chromium_src-6ef98b5a0dabccfe9271697efee657316693cbee.tar.gz
chromium_src-6ef98b5a0dabccfe9271697efee657316693cbee.tar.bz2
Moving WebRTC logging related files from content to chrome.
BUG=229829 Review URL: https://chromiumcodereview.appspot.com/15741003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@203516 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/media')
-rw-r--r--chrome/renderer/media/webrtc_logging_handler_impl.cc75
-rw-r--r--chrome/renderer/media/webrtc_logging_handler_impl.h56
-rw-r--r--chrome/renderer/media/webrtc_logging_handler_impl_unittest.cc46
-rw-r--r--chrome/renderer/media/webrtc_logging_message_filter.cc88
-rw-r--r--chrome/renderer/media/webrtc_logging_message_filter.h63
5 files changed, 328 insertions, 0 deletions
diff --git a/chrome/renderer/media/webrtc_logging_handler_impl.cc b/chrome/renderer/media/webrtc_logging_handler_impl.cc
new file mode 100644
index 0000000..b46ec73
--- /dev/null
+++ b/chrome/renderer/media/webrtc_logging_handler_impl.cc
@@ -0,0 +1,75 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/renderer/media/webrtc_logging_handler_impl.h"
+
+#include "base/logging.h"
+#include "base/message_loop_proxy.h"
+#include "chrome/common/partial_circular_buffer.h"
+#include "chrome/renderer/media/webrtc_logging_message_filter.h"
+
+WebRtcLoggingHandlerImpl::WebRtcLoggingHandlerImpl(
+ const scoped_refptr<base::MessageLoopProxy>& io_message_loop,
+ WebRtcLoggingMessageFilter* message_filter)
+ : io_message_loop_(io_message_loop),
+ message_filter_(message_filter),
+ log_initialized_(false) {
+ content::InitWebRtcLoggingDelegate(this);
+}
+
+WebRtcLoggingHandlerImpl::~WebRtcLoggingHandlerImpl() {
+ DCHECK(CalledOnValidThread());
+}
+
+void WebRtcLoggingHandlerImpl::InitLogging(const std::string& app_session_id,
+ const std::string& app_url) {
+ DCHECK(CalledOnValidThread());
+
+ if (!log_initialized_) {
+ log_initialized_ = true;
+ message_filter_->InitLogging(app_session_id, app_url);
+ }
+}
+
+void WebRtcLoggingHandlerImpl::LogMessage(const std::string& message) {
+ if (!CalledOnValidThread()) {
+ io_message_loop_->PostTask(
+ FROM_HERE, base::Bind(
+ &WebRtcLoggingHandlerImpl::LogMessage,
+ base::Unretained(this),
+ message));
+ return;
+ }
+
+ if (circular_buffer_) {
+ circular_buffer_->Write(message.c_str(), message.length());
+ const char eol = '\n';
+ circular_buffer_->Write(&eol, 1);
+ }
+}
+
+void WebRtcLoggingHandlerImpl::OnFilterRemoved() {
+ DCHECK(CalledOnValidThread());
+ message_filter_ = NULL;
+}
+
+void WebRtcLoggingHandlerImpl::OnLogOpened(
+ base::SharedMemoryHandle handle,
+ uint32 length) {
+ DCHECK(CalledOnValidThread());
+
+ shared_memory_.reset(new base::SharedMemory(handle, false));
+ CHECK(shared_memory_->Map(length));
+ circular_buffer_.reset(
+ new PartialCircularBuffer(shared_memory_->memory(),
+ length,
+ length / 2));
+}
+
+void WebRtcLoggingHandlerImpl::OnOpenLogFailed() {
+ DCHECK(CalledOnValidThread());
+ DLOG(ERROR) << "Could not open log.";
+ // TODO(grunell): Implement.
+ NOTIMPLEMENTED();
+}
diff --git a/chrome/renderer/media/webrtc_logging_handler_impl.h b/chrome/renderer/media/webrtc_logging_handler_impl.h
new file mode 100644
index 0000000..5a98143
--- /dev/null
+++ b/chrome/renderer/media/webrtc_logging_handler_impl.h
@@ -0,0 +1,56 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_RENDERER_MEDIA_WEBRTC_LOGGING_HANDLER_IMPL_H_
+#define CHROME_RENDERER_MEDIA_WEBRTC_LOGGING_HANDLER_IMPL_H_
+
+#include <string>
+
+#include "base/shared_memory.h"
+#include "content/public/renderer/webrtc_log_message_delegate.h"
+#include "ipc/ipc_channel_proxy.h"
+
+namespace base {
+class MessageLoopProxy;
+}
+
+class PartialCircularBuffer;
+class WebRtcLoggingMessageFilter;
+
+// WebRtcLoggingHandlerImpl handles WebRTC logging. There is one object per
+// render process, owned by WebRtcLoggingMessageFilter. It communicates with
+// WebRtcLoggingHandlerHost and receives logging messages from libjingle and
+// writes them to a shared memory buffer.
+class WebRtcLoggingHandlerImpl
+ : public content::WebRtcLogMessageDelegate,
+ public base::NonThreadSafe {
+ public:
+ WebRtcLoggingHandlerImpl(
+ const scoped_refptr<base::MessageLoopProxy>& io_message_loop,
+ WebRtcLoggingMessageFilter* message_filter);
+
+ virtual ~WebRtcLoggingHandlerImpl();
+
+ // content::WebRtcLogMessageDelegate implementation.
+ virtual void InitLogging(const std::string& app_session_id,
+ const std::string& app_url) OVERRIDE;
+ virtual void LogMessage(const std::string& message) OVERRIDE;
+
+ void OnFilterRemoved();
+
+ void OnLogOpened(base::SharedMemoryHandle handle, uint32 length);
+ void OnOpenLogFailed();
+
+ private:
+ scoped_refptr<base::MessageLoopProxy> io_message_loop_;
+ scoped_ptr<base::SharedMemory> shared_memory_;
+ scoped_ptr<PartialCircularBuffer> circular_buffer_;
+
+ WebRtcLoggingMessageFilter* message_filter_;
+ bool log_initialized_;
+
+ DISALLOW_COPY_AND_ASSIGN(WebRtcLoggingHandlerImpl);
+};
+
+#endif // CHROME_RENDERER_MEDIA_WEBRTC_LOGGING_HANDLER_IMPL_H_
diff --git a/chrome/renderer/media/webrtc_logging_handler_impl_unittest.cc b/chrome/renderer/media/webrtc_logging_handler_impl_unittest.cc
new file mode 100644
index 0000000..b12f622
--- /dev/null
+++ b/chrome/renderer/media/webrtc_logging_handler_impl_unittest.cc
@@ -0,0 +1,46 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <string>
+
+#include "base/process_util.h"
+#include "chrome/common/partial_circular_buffer.h"
+#include "chrome/renderer/media/webrtc_logging_handler_impl.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+TEST(WebRtcLoggingHandlerImplTest, Basic) {
+ const uint32 kTestLogSize = 1024; // 1 KB
+ const char kTestString[] = "abcdefghijklmnopqrstuvwxyz";
+
+ base::MessageLoop message_loop(base::MessageLoop::TYPE_IO);
+
+ scoped_ptr<WebRtcLoggingHandlerImpl> logging_handler(
+ new WebRtcLoggingHandlerImpl(message_loop.message_loop_proxy(), NULL));
+
+ base::SharedMemory shared_memory;
+ ASSERT_TRUE(shared_memory.CreateAndMapAnonymous(kTestLogSize));
+ base::SharedMemoryHandle new_handle;
+ ASSERT_TRUE(shared_memory.ShareToProcess(base::GetCurrentProcessHandle(),
+ &new_handle));
+ logging_handler->OnLogOpened(new_handle, kTestLogSize);
+
+ logging_handler->LogMessage(kTestString);
+ logging_handler->LogMessage(kTestString);
+
+ PartialCircularBuffer read_pcb(
+ reinterpret_cast<uint8*>(shared_memory.memory()), kTestLogSize);
+
+ // Size is calculated as (sizeof(kTestString) - 1 for terminating null
+ // + 1 for eol added for each log message in LogMessage) * 2 + 1 for
+ // terminating null.
+ char read_buffer[sizeof(kTestString) * 2 + 1] = {0};
+
+ uint32 read = read_pcb.Read(read_buffer, sizeof(read_buffer));
+ EXPECT_EQ(sizeof(read_buffer) - 1, read);
+ std::string ref_output = kTestString;
+ ref_output.append("\n");
+ ref_output.append(kTestString);
+ ref_output.append("\n");
+ EXPECT_STREQ(ref_output.c_str(), read_buffer);
+}
diff --git a/chrome/renderer/media/webrtc_logging_message_filter.cc b/chrome/renderer/media/webrtc_logging_message_filter.cc
new file mode 100644
index 0000000..f12c695
--- /dev/null
+++ b/chrome/renderer/media/webrtc_logging_message_filter.cc
@@ -0,0 +1,88 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/renderer/media/webrtc_logging_message_filter.h"
+
+#include "base/logging.h"
+#include "base/message_loop_proxy.h"
+#include "chrome/common/media/webrtc_logging_messages.h"
+#include "chrome/renderer/media/webrtc_logging_handler_impl.h"
+#include "ipc/ipc_logging.h"
+
+WebRtcLoggingMessageFilter::WebRtcLoggingMessageFilter(
+ const scoped_refptr<base::MessageLoopProxy>& io_message_loop)
+ : logging_handler_(NULL),
+ io_message_loop_(io_message_loop),
+ channel_(NULL) {
+ io_message_loop_->PostTask(
+ FROM_HERE, base::Bind(
+ &WebRtcLoggingMessageFilter::CreateLoggingHandler,
+ base::Unretained(this)));
+}
+
+WebRtcLoggingMessageFilter::~WebRtcLoggingMessageFilter() {
+}
+
+bool WebRtcLoggingMessageFilter::OnMessageReceived(
+ const IPC::Message& message) {
+ DCHECK(io_message_loop_->BelongsToCurrentThread());
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(WebRtcLoggingMessageFilter, message)
+ IPC_MESSAGE_HANDLER(WebRtcLoggingMsg_LogOpened, OnLogOpened)
+ IPC_MESSAGE_HANDLER(WebRtcLoggingMsg_OpenLogFailed, OnOpenLogFailed)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+}
+
+void WebRtcLoggingMessageFilter::OnFilterAdded(IPC::Channel* channel) {
+ DCHECK(io_message_loop_->BelongsToCurrentThread());
+ channel_ = channel;
+}
+
+void WebRtcLoggingMessageFilter::OnFilterRemoved() {
+ DCHECK(io_message_loop_->BelongsToCurrentThread());
+ channel_ = NULL;
+ logging_handler_->OnFilterRemoved();
+}
+
+void WebRtcLoggingMessageFilter::OnChannelClosing() {
+ DCHECK(io_message_loop_->BelongsToCurrentThread());
+ channel_ = NULL;
+ logging_handler_->OnFilterRemoved();
+}
+
+void WebRtcLoggingMessageFilter::InitLogging(
+ const std::string& app_session_id,
+ const std::string& app_url) {
+ DCHECK(io_message_loop_->BelongsToCurrentThread());
+ Send(new WebRtcLoggingMsg_OpenLog(app_session_id, app_url));
+}
+
+void WebRtcLoggingMessageFilter::CreateLoggingHandler() {
+ DCHECK(io_message_loop_->BelongsToCurrentThread());
+ logging_handler_ = new WebRtcLoggingHandlerImpl(io_message_loop_, this);
+}
+
+void WebRtcLoggingMessageFilter::OnLogOpened(
+ base::SharedMemoryHandle handle,
+ uint32 length) {
+ DCHECK(io_message_loop_->BelongsToCurrentThread());
+ logging_handler_->OnLogOpened(handle, length);
+}
+
+void WebRtcLoggingMessageFilter::OnOpenLogFailed() {
+ DCHECK(io_message_loop_->BelongsToCurrentThread());
+ logging_handler_->OnOpenLogFailed();
+}
+
+void WebRtcLoggingMessageFilter::Send(IPC::Message* message) {
+ DCHECK(io_message_loop_->BelongsToCurrentThread());
+ if (!channel_) {
+ DLOG(ERROR) << "IPC channel not available.";
+ delete message;
+ } else {
+ channel_->Send(message);
+ }
+}
diff --git a/chrome/renderer/media/webrtc_logging_message_filter.h b/chrome/renderer/media/webrtc_logging_message_filter.h
new file mode 100644
index 0000000..4466a1cd
--- /dev/null
+++ b/chrome/renderer/media/webrtc_logging_message_filter.h
@@ -0,0 +1,63 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_RENDERER_MEDIA_WEBRTC_LOGGING_MESSAGE_FILTER_H_
+#define CHROME_RENDERER_MEDIA_WEBRTC_LOGGING_MESSAGE_FILTER_H_
+
+#include "base/shared_memory.h"
+#include "ipc/ipc_channel_proxy.h"
+
+namespace base {
+class MessageLoopProxy;
+}
+
+class WebRtcLoggingHandlerImpl;
+
+// Filter for WebRTC logging messages. Sits between WebRtcLoggingHandlerImpl
+// (renderer process) and WebRtcLoggingHandlerHost (browser process). Must be
+// called on the IO thread.
+class WebRtcLoggingMessageFilter
+ : public IPC::ChannelProxy::MessageFilter {
+ public:
+ explicit WebRtcLoggingMessageFilter(
+ const scoped_refptr<base::MessageLoopProxy>& io_message_loop);
+
+ virtual void InitLogging(const std::string& app_session_id,
+ const std::string& app_url);
+
+ const scoped_refptr<base::MessageLoopProxy>& io_message_loop() {
+ return io_message_loop_;
+ }
+
+ protected:
+ virtual ~WebRtcLoggingMessageFilter();
+
+ private:
+ // IPC::ChannelProxy::MessageFilter implementation.
+ virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
+ virtual void OnFilterAdded(IPC::Channel* channel) OVERRIDE;
+ virtual void OnFilterRemoved() OVERRIDE;
+ virtual void OnChannelClosing() OVERRIDE;
+
+ void CreateLoggingHandler();
+
+ void OnLogOpened(base::SharedMemoryHandle handle, uint32 length);
+ void OnOpenLogFailed();
+
+ void Send(IPC::Message* message);
+
+ // Owned by this class. The only other pointer to it is in libjingle's logging
+ // file. That's a global pointer used on different threads, so we will leak
+ // this object when we go away to ensure that it outlives any log messages
+ // coming from libjingle.
+ WebRtcLoggingHandlerImpl* logging_handler_;
+
+ scoped_refptr<base::MessageLoopProxy> io_message_loop_;
+
+ IPC::Channel* channel_;
+
+ DISALLOW_COPY_AND_ASSIGN(WebRtcLoggingMessageFilter);
+};
+
+#endif // CHROME_RENDERER_MEDIA_WEBRTC_LOGGING_MESSAGE_FILTER_H_