OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/browser/renderer_host/media/webrtc_logging_handler_host.h" | 5 #include "content/browser/renderer_host/media/webrtc_logging_handler_host.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/shared_memory.h" |
9 #include "content/common/media/webrtc_logging_messages.h" | 10 #include "content/common/media/webrtc_logging_messages.h" |
| 11 #include "content/public/browser/browser_thread.h" |
| 12 #include "content/public/browser/content_browser_client.h" |
| 13 #include "content/public/browser/render_process_host.h" |
10 | 14 |
11 namespace content { | 15 namespace content { |
12 | 16 |
13 #if defined(OS_ANDROID) | 17 #if defined(OS_ANDROID) |
14 const size_t kWebRtcLogSize = 1 * 1024 * 1024; // 1 MB | 18 const size_t kWebRtcLogSize = 1 * 1024 * 1024; // 1 MB |
15 #else | 19 #else |
16 const size_t kWebRtcLogSize = 6 * 1024 * 1024; // 6 MB | 20 const size_t kWebRtcLogSize = 6 * 1024 * 1024; // 6 MB |
17 #endif | 21 #endif |
18 | 22 |
19 WebRtcLoggingHandlerHost::WebRtcLoggingHandlerHost() { | 23 WebRtcLoggingHandlerHost::WebRtcLoggingHandlerHost( |
20 } | 24 RenderProcessHost* render_process_host) |
| 25 : render_process_host_(render_process_host) {} |
21 | 26 |
22 WebRtcLoggingHandlerHost::~WebRtcLoggingHandlerHost() { | 27 WebRtcLoggingHandlerHost::~WebRtcLoggingHandlerHost() {} |
23 } | |
24 | 28 |
25 void WebRtcLoggingHandlerHost::OnChannelClosing() { | 29 void WebRtcLoggingHandlerHost::OnChannelClosing() { |
| 30 UploadLog(); |
26 BrowserMessageFilter::OnChannelClosing(); | 31 BrowserMessageFilter::OnChannelClosing(); |
27 } | 32 } |
28 | 33 |
29 void WebRtcLoggingHandlerHost::OnDestruct() const { | 34 void WebRtcLoggingHandlerHost::OnDestruct() const { |
30 BrowserThread::DeleteOnIOThread::Destruct(this); | 35 BrowserThread::DeleteOnIOThread::Destruct(this); |
31 } | 36 } |
32 | 37 |
33 bool WebRtcLoggingHandlerHost::OnMessageReceived(const IPC::Message& message, | 38 bool WebRtcLoggingHandlerHost::OnMessageReceived(const IPC::Message& message, |
34 bool* message_was_ok) { | 39 bool* message_was_ok) { |
35 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
36 bool handled = true; | 41 bool handled = true; |
37 IPC_BEGIN_MESSAGE_MAP_EX(WebRtcLoggingHandlerHost, message, *message_was_ok) | 42 IPC_BEGIN_MESSAGE_MAP_EX(WebRtcLoggingHandlerHost, message, *message_was_ok) |
38 IPC_MESSAGE_HANDLER(WebRtcLoggingMsg_OpenLog, OnOpenLog) | 43 IPC_MESSAGE_HANDLER(WebRtcLoggingMsg_OpenLog, OnOpenLog) |
39 IPC_MESSAGE_UNHANDLED(handled = false) | 44 IPC_MESSAGE_UNHANDLED(handled = false) |
40 IPC_END_MESSAGE_MAP_EX() | 45 IPC_END_MESSAGE_MAP_EX() |
41 | 46 |
42 return handled; | 47 return handled; |
43 } | 48 } |
44 | 49 |
45 void WebRtcLoggingHandlerHost::OnOpenLog(const std::string& app_session_id, | 50 void WebRtcLoggingHandlerHost::OnOpenLog(const std::string& app_session_id, |
46 const std::string& app_url) { | 51 const std::string& app_url) { |
47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 52 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
48 DCHECK(!base::SharedMemory::IsHandleValid(shared_memory_.handle())); | 53 app_session_id_ = app_session_id; |
| 54 app_url_ = app_url; |
| 55 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
| 56 &WebRtcLoggingHandlerHost::OpenLogIfAllowed, this)); |
| 57 } |
49 | 58 |
50 if (!shared_memory_.CreateAndMapAnonymous(kWebRtcLogSize)) { | 59 void WebRtcLoggingHandlerHost::OpenLogIfAllowed() { |
| 60 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 61 |
| 62 if (!GetContentClient()->browser()->IsWebRtcLoggingAllowed()) |
| 63 return; |
| 64 |
| 65 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( |
| 66 &WebRtcLoggingHandlerHost::DoOpenLog, this)); |
| 67 } |
| 68 |
| 69 void WebRtcLoggingHandlerHost::DoOpenLog() { |
| 70 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 71 DCHECK(!shared_memory_); |
| 72 |
| 73 shared_memory_.reset(new base::SharedMemory()); |
| 74 |
| 75 if (!shared_memory_->CreateAndMapAnonymous(kWebRtcLogSize)) { |
51 DLOG(ERROR) << "Failed to create shared memory."; | 76 DLOG(ERROR) << "Failed to create shared memory."; |
52 Send(new WebRtcLoggingMsg_OpenLogFailed()); | 77 Send(new WebRtcLoggingMsg_OpenLogFailed()); |
53 return; | 78 return; |
54 } | 79 } |
55 | 80 |
56 base::SharedMemoryHandle foreign_memory_handle; | 81 base::SharedMemoryHandle foreign_memory_handle; |
57 if (!shared_memory_.ShareToProcess(peer_handle(), | 82 if (!shared_memory_->ShareToProcess(peer_handle(), |
58 &foreign_memory_handle)) { | 83 &foreign_memory_handle)) { |
59 Send(new WebRtcLoggingMsg_OpenLogFailed()); | 84 Send(new WebRtcLoggingMsg_OpenLogFailed()); |
60 return; | 85 return; |
61 } | 86 } |
62 | 87 |
63 app_session_id_ = app_session_id; | |
64 app_url_ = app_url; | |
65 Send(new WebRtcLoggingMsg_LogOpened(foreign_memory_handle, kWebRtcLogSize)); | 88 Send(new WebRtcLoggingMsg_LogOpened(foreign_memory_handle, kWebRtcLogSize)); |
66 } | 89 } |
67 | 90 |
| 91 void WebRtcLoggingHandlerHost::UploadLog() { |
| 92 if (!shared_memory_) |
| 93 return; |
| 94 |
| 95 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
| 96 &ContentBrowserClient::UploadWebRtcLog, |
| 97 base::Unretained(GetContentClient()->browser()), |
| 98 render_process_host_->GetBrowserContext(), |
| 99 Passed(&shared_memory_), |
| 100 kWebRtcLogSize, |
| 101 app_session_id_, |
| 102 app_url_)); |
| 103 } |
| 104 |
68 } // namespace content | 105 } // namespace content |
OLD | NEW |