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" | |
10 | 13 |
11 namespace content { | 14 namespace content { |
12 | 15 |
13 const size_t kWebRtcLogSize = 6 * 1024 * 1024; // 6 MB | 16 const size_t kWebRtcLogSize = 6 * 1024 * 1024; // 6 MB |
14 | 17 |
15 WebRtcLoggingHandlerHost::WebRtcLoggingHandlerHost() { | 18 WebRtcLoggingHandlerHost::WebRtcLoggingHandlerHost() {} |
16 } | |
17 | 19 |
18 WebRtcLoggingHandlerHost::~WebRtcLoggingHandlerHost() { | 20 WebRtcLoggingHandlerHost::~WebRtcLoggingHandlerHost() {} |
19 } | |
20 | 21 |
21 void WebRtcLoggingHandlerHost::OnChannelClosing() { | 22 void WebRtcLoggingHandlerHost::OnChannelClosing() { |
23 UploadLog(); | |
22 BrowserMessageFilter::OnChannelClosing(); | 24 BrowserMessageFilter::OnChannelClosing(); |
23 } | 25 } |
24 | 26 |
25 void WebRtcLoggingHandlerHost::OnDestruct() const { | 27 void WebRtcLoggingHandlerHost::OnDestruct() const { |
26 BrowserThread::DeleteOnIOThread::Destruct(this); | 28 BrowserThread::DeleteOnIOThread::Destruct(this); |
27 } | 29 } |
28 | 30 |
29 bool WebRtcLoggingHandlerHost::OnMessageReceived(const IPC::Message& message, | 31 bool WebRtcLoggingHandlerHost::OnMessageReceived(const IPC::Message& message, |
30 bool* message_was_ok) { | 32 bool* message_was_ok) { |
31 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
32 bool handled = true; | 34 bool handled = true; |
33 IPC_BEGIN_MESSAGE_MAP_EX(WebRtcLoggingHandlerHost, message, *message_was_ok) | 35 IPC_BEGIN_MESSAGE_MAP_EX(WebRtcLoggingHandlerHost, message, *message_was_ok) |
34 IPC_MESSAGE_HANDLER(WebRtcLoggingMsg_OpenLog, OnOpenLog) | 36 IPC_MESSAGE_HANDLER(WebRtcLoggingMsg_OpenLog, OnOpenLog) |
35 IPC_MESSAGE_UNHANDLED(handled = false) | 37 IPC_MESSAGE_UNHANDLED(handled = false) |
36 IPC_END_MESSAGE_MAP_EX() | 38 IPC_END_MESSAGE_MAP_EX() |
37 | 39 |
38 return handled; | 40 return handled; |
39 } | 41 } |
40 | 42 |
41 void WebRtcLoggingHandlerHost::OnOpenLog() { | 43 void WebRtcLoggingHandlerHost::OnOpenLog() { |
42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
43 DCHECK(!base::SharedMemory::IsHandleValid(shared_memory_.handle())); | |
44 | 45 |
45 if (!shared_memory_.CreateAndMapAnonymous(kWebRtcLogSize)) { | 46 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
47 &WebRtcLoggingHandlerHost::CheckLoggingAllowed, this)); | |
48 } | |
49 | |
50 void WebRtcLoggingHandlerHost::CheckLoggingAllowed() { | |
Jói
2013/05/14 21:30:29
The name could be a bit more descriptive; how abou
Henrik Grunell
2013/05/15 20:17:53
sgtm, done.
| |
51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
52 | |
53 if (!GetContentClient()->browser()->IsWebRtcLoggingAllowed()) | |
54 return; | |
55 | |
56 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( | |
57 &WebRtcLoggingHandlerHost::DoOpenLog, this)); | |
58 } | |
59 | |
60 void WebRtcLoggingHandlerHost::DoOpenLog() { | |
61 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
62 DCHECK(!shared_memory_); | |
63 | |
64 shared_memory_.reset(new base::SharedMemory()); | |
65 | |
66 if (!shared_memory_->CreateAndMapAnonymous(kWebRtcLogSize)) { | |
46 DLOG(ERROR) << "Failed to create shared memory."; | 67 DLOG(ERROR) << "Failed to create shared memory."; |
47 Send(new WebRtcLoggingMsg_OpenLogFailed()); | 68 Send(new WebRtcLoggingMsg_OpenLogFailed()); |
48 return; | 69 return; |
49 } | 70 } |
50 | 71 |
51 base::SharedMemoryHandle foreign_memory_handle; | 72 base::SharedMemoryHandle foreign_memory_handle; |
52 if (!shared_memory_.ShareToProcess(peer_handle(), | 73 if (!shared_memory_->ShareToProcess(peer_handle(), |
53 &foreign_memory_handle)) { | 74 &foreign_memory_handle)) { |
54 Send(new WebRtcLoggingMsg_OpenLogFailed()); | 75 Send(new WebRtcLoggingMsg_OpenLogFailed()); |
55 return; | 76 return; |
56 } | 77 } |
57 | 78 |
58 Send(new WebRtcLoggingMsg_LogOpened(foreign_memory_handle, kWebRtcLogSize)); | 79 Send(new WebRtcLoggingMsg_LogOpened(foreign_memory_handle, kWebRtcLogSize)); |
59 } | 80 } |
60 | 81 |
82 void WebRtcLoggingHandlerHost::UploadLog() { | |
83 if (!shared_memory_) | |
84 return; | |
85 | |
86 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, base::Bind( | |
87 &ContentBrowserClient::UploadWebRtcLog, | |
88 base::Unretained(GetContentClient()->browser()), | |
89 Passed(&shared_memory_), | |
90 kWebRtcLogSize)); | |
91 } | |
92 | |
61 } // namespace content | 93 } // namespace content |
OLD | NEW |