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

Side by Side Diff: content/browser/renderer_host/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: Fixed pre-submit warnings/errors (including adding bzip2 to content/browser DEPS). 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/webrtc_logging_handler_host.h" 5 #include "content/browser/renderer_host/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"
10 #include "content/browser/webrtc_log_manager.h"
9 #include "content/common/webrtc_logging_messages.h" 11 #include "content/common/webrtc_logging_messages.h"
12 #include "content/public/browser/browser_thread.h"
13 #include "content/public/browser/content_browser_client.h"
10 14
11 namespace content { 15 namespace content {
12 16
13 const size_t kWebRtcLogSize = 6 * 1024 * 1024; // 6 MB 17 const size_t kWebRtcLogSize = 6 * 1024 * 1024; // 6 MB
14 18
15 WebRtcLoggingHandlerHost::WebRtcLoggingHandlerHost() { 19 WebRtcLoggingHandlerHost::WebRtcLoggingHandlerHost()
20 : shared_memory_(NULL),
21 log_file_compressed_(base::kInvalidPlatformFileValue) {
16 } 22 }
17 23
18 WebRtcLoggingHandlerHost::~WebRtcLoggingHandlerHost() { 24 WebRtcLoggingHandlerHost::~WebRtcLoggingHandlerHost() {
25 // |shared_memory_| should have been handed to upload manager (and NULL here).
26 // Delete it in case it wasn't.
27 delete shared_memory_;
19 } 28 }
20 29
21 void WebRtcLoggingHandlerHost::OnChannelClosing() { 30 void WebRtcLoggingHandlerHost::OnChannelClosing() {
31 UploadLog();
22 BrowserMessageFilter::OnChannelClosing(); 32 BrowserMessageFilter::OnChannelClosing();
23 } 33 }
24 34
25 void WebRtcLoggingHandlerHost::OnDestruct() const { 35 void WebRtcLoggingHandlerHost::OnDestruct() const {
26 BrowserThread::DeleteOnIOThread::Destruct(this); 36 BrowserThread::DeleteOnIOThread::Destruct(this);
27 } 37 }
28 38
29 bool WebRtcLoggingHandlerHost::OnMessageReceived(const IPC::Message& message, 39 bool WebRtcLoggingHandlerHost::OnMessageReceived(const IPC::Message& message,
30 bool* message_was_ok) { 40 bool* message_was_ok) {
31 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
32 bool handled = true; 42 bool handled = true;
33 IPC_BEGIN_MESSAGE_MAP_EX(WebRtcLoggingHandlerHost, message, *message_was_ok) 43 IPC_BEGIN_MESSAGE_MAP_EX(WebRtcLoggingHandlerHost, message, *message_was_ok)
34 IPC_MESSAGE_HANDLER(WebRtcLoggingMsg_OpenLog, OnOpenLog) 44 IPC_MESSAGE_HANDLER(WebRtcLoggingMsg_OpenLog, OnOpenLog)
35 IPC_MESSAGE_UNHANDLED(handled = false) 45 IPC_MESSAGE_UNHANDLED(handled = false)
36 IPC_END_MESSAGE_MAP_EX() 46 IPC_END_MESSAGE_MAP_EX()
37 47
38 return handled; 48 return handled;
39 } 49 }
40 50
41 void WebRtcLoggingHandlerHost::OnOpenLog() { 51 void WebRtcLoggingHandlerHost::OnOpenLog() {
42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 52 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
43 DCHECK(!base::SharedMemory::IsHandleValid(shared_memory_.handle())); 53 DCHECK(!shared_memory_);
54 DCHECK(log_file_compressed_ == base::kInvalidPlatformFileValue);
44 55
45 if (!shared_memory_.CreateAndMapAnonymous(kWebRtcLogSize)) { 56 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, base::Bind(
57 &WebRtcLoggingHandlerHost::CreateWebRtcLogFile, this));
58 }
59
60 void WebRtcLoggingHandlerHost::CreateWebRtcLogFile() {
61 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
62
63 // TODO(grunell): Maybe go through the log manager and have that keep track
64 // of maximum number of logs?
65 log_file_compressed_ = GetContentClient()->browser()->CreateWebRtcLogFile();
66 if (log_file_compressed_ == base::kInvalidPlatformFileValue)
67 return;
68
69 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind(
70 &WebRtcLoggingHandlerHost::FinishOpenLog, this));
71 }
72
73 void WebRtcLoggingHandlerHost::FinishOpenLog() {
74 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
75
76 shared_memory_ = new base::SharedMemory();
77
78 if (!shared_memory_->CreateAndMapAnonymous(kWebRtcLogSize)) {
46 DLOG(ERROR) << "Failed to create shared memory."; 79 DLOG(ERROR) << "Failed to create shared memory.";
47 Send(new WebRtcLoggingMsg_OpenLogFailed()); 80 Send(new WebRtcLoggingMsg_OpenLogFailed());
48 return; 81 return;
49 } 82 }
50 83
51 base::SharedMemoryHandle foreign_memory_handle; 84 base::SharedMemoryHandle foreign_memory_handle;
52 if (!shared_memory_.ShareToProcess(peer_handle(), 85 if (!shared_memory_->ShareToProcess(peer_handle(),
53 &foreign_memory_handle)) { 86 &foreign_memory_handle)) {
54 Send(new WebRtcLoggingMsg_OpenLogFailed()); 87 Send(new WebRtcLoggingMsg_OpenLogFailed());
55 return; 88 return;
56 } 89 }
57 90
58 Send(new WebRtcLoggingMsg_LogOpened(foreign_memory_handle, kWebRtcLogSize)); 91 Send(new WebRtcLoggingMsg_LogOpened(foreign_memory_handle, kWebRtcLogSize));
59 } 92 }
60 93
94 bool WebRtcLoggingHandlerHost::IsUploadingEnabled() {
95 // TODO(grunell): Move to chrome.
Jói 2013/05/02 16:47:31 Do you really want to move this fully to the embed
Henrik Grunell 2013/05/03 07:59:36 I've done some more changes/refactoring and cleani
96 /*
97 // If the user permits metrics reporting / crash uploading with the checkbox
98 // in the prefs, we allow uploading automatically. We disable uploading
99 // completely for non-official builds. This can be forced with a flag.
100 const CommandLine* command_line = CommandLine::ForCurrentProcess();
101 if (command_line->HasSwitch(switches::kEnableMetricsReportingForTesting))
102 return true;
103
104 bool enabled = false;
105
106 #if defined(GOOGLE_CHROME_BUILD)
107 #if defined(OS_CHROMEOS)
108 chromeos::CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref,
109 &enabled);
110 #else
111 // TODO(grunell): Fails, has to be on UI thread.
112 enabled = g_browser_process->local_state()->GetBoolean(
113 prefs::kMetricsReportingEnabled);
114 #endif // #if defined(OS_CHROMEOS)
115 #endif // defined(GOOGLE_CHROME_BUILD)
116
117 return enabled;
118 */
119 return true;
120 }
121
122 void WebRtcLoggingHandlerHost::UploadLog() {
123 // Check if logging has been enabled.
124 if (!shared_memory_)
125 return;
126
127 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, base::Bind(
128 &WebRtcLogManager::UploadLog,
129 base::Unretained(WebRtcLogManager::GetInstance()),
130 shared_memory_,
131 kWebRtcLogSize,
132 log_file_compressed_));
133
134 shared_memory_ = NULL;
135 }
136
61 } // namespace content 137 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698