Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: content/browser/renderer_host/media/webrtc_logging_handler_host.cc

Issue 14329020: Implementing uploading of a WebRTC diagnostic log. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed two files Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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()
19 : shared_memory_(NULL) {
16 } 20 }
17 21
18 WebRtcLoggingHandlerHost::~WebRtcLoggingHandlerHost() { 22 WebRtcLoggingHandlerHost::~WebRtcLoggingHandlerHost() {
23 // |shared_memory_| should normally have been handed to the upload manager
24 // and thus be NULL now, see UploadLog. Delete it in case ownership hasn't
25 // been passed on.
26 delete shared_memory_;
19 } 27 }
20 28
21 void WebRtcLoggingHandlerHost::OnChannelClosing() { 29 void WebRtcLoggingHandlerHost::OnChannelClosing() {
30 UploadLog();
22 BrowserMessageFilter::OnChannelClosing(); 31 BrowserMessageFilter::OnChannelClosing();
23 } 32 }
24 33
25 void WebRtcLoggingHandlerHost::OnDestruct() const { 34 void WebRtcLoggingHandlerHost::OnDestruct() const {
26 BrowserThread::DeleteOnIOThread::Destruct(this); 35 BrowserThread::DeleteOnIOThread::Destruct(this);
27 } 36 }
28 37
29 bool WebRtcLoggingHandlerHost::OnMessageReceived(const IPC::Message& message, 38 bool WebRtcLoggingHandlerHost::OnMessageReceived(const IPC::Message& message,
30 bool* message_was_ok) { 39 bool* message_was_ok) {
31 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
32 bool handled = true; 41 bool handled = true;
33 IPC_BEGIN_MESSAGE_MAP_EX(WebRtcLoggingHandlerHost, message, *message_was_ok) 42 IPC_BEGIN_MESSAGE_MAP_EX(WebRtcLoggingHandlerHost, message, *message_was_ok)
34 IPC_MESSAGE_HANDLER(WebRtcLoggingMsg_OpenLog, OnOpenLog) 43 IPC_MESSAGE_HANDLER(WebRtcLoggingMsg_OpenLog, OnOpenLog)
35 IPC_MESSAGE_UNHANDLED(handled = false) 44 IPC_MESSAGE_UNHANDLED(handled = false)
36 IPC_END_MESSAGE_MAP_EX() 45 IPC_END_MESSAGE_MAP_EX()
37 46
38 return handled; 47 return handled;
39 } 48 }
40 49
41 void WebRtcLoggingHandlerHost::OnOpenLog() { 50 void WebRtcLoggingHandlerHost::OnOpenLog() {
42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
43 DCHECK(!base::SharedMemory::IsHandleValid(shared_memory_.handle()));
44 52
45 if (!shared_memory_.CreateAndMapAnonymous(kWebRtcLogSize)) { 53 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind(
54 &WebRtcLoggingHandlerHost::CheckLoggingAllowed, this));
55 }
56
57 void WebRtcLoggingHandlerHost::CheckLoggingAllowed() {
58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
59
60 if (!GetContentClient()->browser()->IsWebRtcLoggingAllowed())
61 return;
62
63 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind(
64 &WebRtcLoggingHandlerHost::DoOpenLog, this));
65 }
66
67 void WebRtcLoggingHandlerHost::DoOpenLog() {
68 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
69 DCHECK(!shared_memory_);
70
71 shared_memory_ = new base::SharedMemory();
72
73 if (!shared_memory_->CreateAndMapAnonymous(kWebRtcLogSize)) {
46 DLOG(ERROR) << "Failed to create shared memory."; 74 DLOG(ERROR) << "Failed to create shared memory.";
47 Send(new WebRtcLoggingMsg_OpenLogFailed()); 75 Send(new WebRtcLoggingMsg_OpenLogFailed());
48 return; 76 return;
49 } 77 }
50 78
51 base::SharedMemoryHandle foreign_memory_handle; 79 base::SharedMemoryHandle foreign_memory_handle;
52 if (!shared_memory_.ShareToProcess(peer_handle(), 80 if (!shared_memory_->ShareToProcess(peer_handle(),
53 &foreign_memory_handle)) { 81 &foreign_memory_handle)) {
54 Send(new WebRtcLoggingMsg_OpenLogFailed()); 82 Send(new WebRtcLoggingMsg_OpenLogFailed());
55 return; 83 return;
56 } 84 }
57 85
58 Send(new WebRtcLoggingMsg_LogOpened(foreign_memory_handle, kWebRtcLogSize)); 86 Send(new WebRtcLoggingMsg_LogOpened(foreign_memory_handle, kWebRtcLogSize));
59 } 87 }
60 88
89 void WebRtcLoggingHandlerHost::UploadLog() {
90 if (!shared_memory_)
91 return;
92
93 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, base::Bind(
94 &ContentBrowserClient::UploadWebRtcLog,
95 base::Unretained(GetContentClient()->browser()),
96 shared_memory_,
97 kWebRtcLogSize));
98
99 shared_memory_ = NULL;
100 }
101
61 } // namespace content 102 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698