Index: content/browser/renderer_host/media/webrtc_logging_handler_host.cc |
diff --git a/content/browser/renderer_host/media/webrtc_logging_handler_host.cc b/content/browser/renderer_host/media/webrtc_logging_handler_host.cc |
index 10e2101c80590cd4d69afe0697c576a3c96b13c7..02d1c56c286a419e7e5725fb40dabe41a7ddf21d 100644 |
--- a/content/browser/renderer_host/media/webrtc_logging_handler_host.cc |
+++ b/content/browser/renderer_host/media/webrtc_logging_handler_host.cc |
@@ -6,7 +6,11 @@ |
#include "base/bind.h" |
#include "base/logging.h" |
+#include "base/shared_memory.h" |
#include "content/common/media/webrtc_logging_messages.h" |
+#include "content/public/browser/browser_thread.h" |
+#include "content/public/browser/content_browser_client.h" |
+#include "content/public/browser/render_process_host.h" |
namespace content { |
@@ -16,13 +20,14 @@ const size_t kWebRtcLogSize = 1 * 1024 * 1024; // 1 MB |
const size_t kWebRtcLogSize = 6 * 1024 * 1024; // 6 MB |
#endif |
-WebRtcLoggingHandlerHost::WebRtcLoggingHandlerHost() { |
-} |
+WebRtcLoggingHandlerHost::WebRtcLoggingHandlerHost( |
+ RenderProcessHost* render_process_host) |
+ : render_process_host_(render_process_host) {} |
-WebRtcLoggingHandlerHost::~WebRtcLoggingHandlerHost() { |
-} |
+WebRtcLoggingHandlerHost::~WebRtcLoggingHandlerHost() {} |
void WebRtcLoggingHandlerHost::OnChannelClosing() { |
+ UploadLog(); |
BrowserMessageFilter::OnChannelClosing(); |
} |
@@ -45,24 +50,56 @@ bool WebRtcLoggingHandlerHost::OnMessageReceived(const IPC::Message& message, |
void WebRtcLoggingHandlerHost::OnOpenLog(const std::string& app_session_id, |
const std::string& app_url) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
- DCHECK(!base::SharedMemory::IsHandleValid(shared_memory_.handle())); |
+ app_session_id_ = app_session_id; |
+ app_url_ = app_url; |
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
+ &WebRtcLoggingHandlerHost::OpenLogIfAllowed, this)); |
+} |
+ |
+void WebRtcLoggingHandlerHost::OpenLogIfAllowed() { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ |
+ if (!GetContentClient()->browser()->IsWebRtcLoggingAllowed()) |
+ return; |
+ |
+ BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( |
+ &WebRtcLoggingHandlerHost::DoOpenLog, this)); |
+} |
- if (!shared_memory_.CreateAndMapAnonymous(kWebRtcLogSize)) { |
+void WebRtcLoggingHandlerHost::DoOpenLog() { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
+ DCHECK(!shared_memory_); |
+ |
+ shared_memory_.reset(new base::SharedMemory()); |
+ |
+ if (!shared_memory_->CreateAndMapAnonymous(kWebRtcLogSize)) { |
DLOG(ERROR) << "Failed to create shared memory."; |
Send(new WebRtcLoggingMsg_OpenLogFailed()); |
return; |
} |
base::SharedMemoryHandle foreign_memory_handle; |
- if (!shared_memory_.ShareToProcess(peer_handle(), |
+ if (!shared_memory_->ShareToProcess(peer_handle(), |
&foreign_memory_handle)) { |
Send(new WebRtcLoggingMsg_OpenLogFailed()); |
return; |
} |
- app_session_id_ = app_session_id; |
- app_url_ = app_url; |
Send(new WebRtcLoggingMsg_LogOpened(foreign_memory_handle, kWebRtcLogSize)); |
} |
+void WebRtcLoggingHandlerHost::UploadLog() { |
+ if (!shared_memory_) |
+ return; |
+ |
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
+ &ContentBrowserClient::UploadWebRtcLog, |
+ base::Unretained(GetContentClient()->browser()), |
+ render_process_host_->GetBrowserContext(), |
+ Passed(&shared_memory_), |
+ kWebRtcLogSize, |
+ app_session_id_, |
+ app_url_)); |
+} |
+ |
} // namespace content |