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

Side by Side Diff: chrome/browser/media/webrtc_logging_handler_host.cc

Issue 264793017: Implements RTP header dumping. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: for Henrik's comments Created 6 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 "chrome/browser/media/webrtc_logging_handler_host.h" 5 #include "chrome/browser/media/webrtc_logging_handler_host.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/cpu.h" 11 #include "base/cpu.h"
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/prefs/pref_service.h" 14 #include "base/prefs/pref_service.h"
15 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
16 #include "base/sys_info.h" 16 #include "base/sys_info.h"
17 #include "base/time/time.h" 17 #include "base/time/time.h"
18 #include "chrome/browser/browser_process.h" 18 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/chromeos/settings/cros_settings.h" 19 #include "chrome/browser/chromeos/settings/cros_settings.h"
20 #include "chrome/browser/media/webrtc_log_list.h" 20 #include "chrome/browser/media/webrtc_log_list.h"
21 #include "chrome/browser/media/webrtc_log_uploader.h" 21 #include "chrome/browser/media/webrtc_log_uploader.h"
22 #include "chrome/browser/media/webrtc_rtp_dump_handler.h"
22 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/common/chrome_switches.h" 24 #include "chrome/common/chrome_switches.h"
24 #include "chrome/common/media/webrtc_logging_messages.h" 25 #include "chrome/common/media/webrtc_logging_messages.h"
25 #include "chrome/common/partial_circular_buffer.h" 26 #include "chrome/common/partial_circular_buffer.h"
26 #include "chrome/common/pref_names.h" 27 #include "chrome/common/pref_names.h"
27 #include "chromeos/settings/cros_settings_names.h" 28 #include "chromeos/settings/cros_settings_names.h"
28 #include "content/public/browser/browser_thread.h" 29 #include "content/public/browser/browser_thread.h"
29 #include "content/public/browser/content_browser_client.h" 30 #include "content/public/browser/content_browser_client.h"
30 #include "content/public/browser/gpu_data_manager.h" 31 #include "content/public/browser/gpu_data_manager.h"
31 #include "content/public/browser/render_process_host.h" 32 #include "content/public/browser/render_process_host.h"
32 #include "gpu/config/gpu_info.h" 33 #include "gpu/config/gpu_info.h"
33 #include "net/base/address_family.h" 34 #include "net/base/address_family.h"
34 #include "net/url_request/url_request_context_getter.h" 35 #include "net/url_request/url_request_context_getter.h"
35 36
36 #if defined(OS_LINUX) 37 #if defined(OS_LINUX)
37 #include "base/linux_util.h" 38 #include "base/linux_util.h"
38 #endif 39 #endif
39 40
40 #if defined(OS_MACOSX) 41 #if defined(OS_MACOSX)
41 #include "base/mac/mac_util.h" 42 #include "base/mac/mac_util.h"
42 #endif 43 #endif
43 44
44 #if defined(OS_CHROMEOS) 45 #if defined(OS_CHROMEOS)
45 #include "chromeos/system/statistics_provider.h" 46 #include "chromeos/system/statistics_provider.h"
46 #endif 47 #endif
47 48
48 using base::IntToString; 49 using base::IntToString;
49 using content::BrowserThread; 50 using content::BrowserThread;
50 51
52 namespace {
51 53
52 #if defined(OS_ANDROID) 54 #if defined(OS_ANDROID)
53 const size_t kWebRtcLogSize = 1 * 1024 * 1024; // 1 MB 55 const size_t kWebRtcLogSize = 1 * 1024 * 1024; // 1 MB
54 #else 56 #else
55 const size_t kWebRtcLogSize = 6 * 1024 * 1024; // 6 MB 57 const size_t kWebRtcLogSize = 6 * 1024 * 1024; // 6 MB
56 #endif 58 #endif
57 59
58 namespace {
59
60 const char kLogNotStoppedOrNoLogOpen[] = 60 const char kLogNotStoppedOrNoLogOpen[] =
61 "Logging not stopped or no log open."; 61 "Logging not stopped or no log open.";
62 62
63 // For privacy reasons when logging IP addresses. The returned "sensitive 63 // For privacy reasons when logging IP addresses. The returned "sensitive
64 // string" is for release builds a string with the end stripped away. Last 64 // string" is for release builds a string with the end stripped away. Last
65 // octet for IPv4 and last 80 bits (5 groups) for IPv6. String will be 65 // octet for IPv4 and last 80 bits (5 groups) for IPv6. String will be
66 // "1.2.3.x" and "1.2.3::" respectively. For debug builds, the string is 66 // "1.2.3.x" and "1.2.3::" respectively. For debug builds, the string is
67 // not stripped. 67 // not stripped.
68 std::string IPAddressToSensitiveString(const net::IPAddressNumber& address) { 68 std::string IPAddressToSensitiveString(const net::IPAddressNumber& address) {
69 #if defined(NDEBUG) 69 #if defined(NDEBUG)
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 176 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
177 DCHECK(!callback.is_null()); 177 DCHECK(!callback.is_null());
178 178
179 if (logging_state_ != STOPPED) { 179 if (logging_state_ != STOPPED) {
180 if (!callback.is_null()) { 180 if (!callback.is_null()) {
181 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, 181 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
182 base::Bind(callback, false, "", kLogNotStoppedOrNoLogOpen)); 182 base::Bind(callback, false, "", kLogNotStoppedOrNoLogOpen));
183 } 183 }
184 return; 184 return;
185 } 185 }
186 if (rtp_dump_handler_ && !rtp_dump_handler_->ReadyToRelease()) {
187 if (!callback.is_null()) {
188 content::BrowserThread::PostTask(
189 content::BrowserThread::UI,
190 FROM_HERE,
191 base::Bind(callback, false, "", "RTP dumping has not been stopped."));
192 }
193 return;
194 }
195
186 upload_callback_ = callback; 196 upload_callback_ = callback;
187 logging_state_ = UPLOADING; 197 logging_state_ = UPLOADING;
188 content::BrowserThread::PostTaskAndReplyWithResult( 198 content::BrowserThread::PostTaskAndReplyWithResult(
189 content::BrowserThread::FILE, 199 content::BrowserThread::FILE,
190 FROM_HERE, 200 FROM_HERE,
191 base::Bind(&WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists, 201 base::Bind(&WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists,
192 this), 202 this),
193 base::Bind(&WebRtcLoggingHandlerHost::TriggerUploadLog, this)); 203 base::Bind(&WebRtcLoggingHandlerHost::TriggerUpload, this));
194 } 204 }
195 205
196 void WebRtcLoggingHandlerHost::UploadLogDone() { 206 void WebRtcLoggingHandlerHost::UploadLogDone() {
197 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
198 logging_state_ = CLOSED; 208 logging_state_ = CLOSED;
199 } 209 }
200 210
201 void WebRtcLoggingHandlerHost::DiscardLog(const GenericDoneCallback& callback) { 211 void WebRtcLoggingHandlerHost::DiscardLog(const GenericDoneCallback& callback) {
202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 212 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
203 DCHECK(!callback.is_null()); 213 DCHECK(!callback.is_null());
204 214
205 GenericDoneCallback discard_callback = callback; 215 GenericDoneCallback discard_callback = callback;
206 if (logging_state_ != STOPPED) { 216 if (logging_state_ != STOPPED) {
207 FireGenericDoneCallback(&discard_callback, false, 217 FireGenericDoneCallback(&discard_callback, false,
208 kLogNotStoppedOrNoLogOpen); 218 kLogNotStoppedOrNoLogOpen);
209 return; 219 return;
210 } 220 }
211 g_browser_process->webrtc_log_uploader()->LoggingStoppedDontUpload(); 221 g_browser_process->webrtc_log_uploader()->LoggingStoppedDontUpload();
212 circular_buffer_.reset(); 222 circular_buffer_.reset();
213 log_buffer_.reset(); 223 log_buffer_.reset();
214 logging_state_ = CLOSED; 224 logging_state_ = CLOSED;
225 rtp_dump_handler_.reset();
215 FireGenericDoneCallback(&discard_callback, true, ""); 226 FireGenericDoneCallback(&discard_callback, true, "");
216 } 227 }
217 228
218 void WebRtcLoggingHandlerHost::LogMessage(const std::string& message) { 229 void WebRtcLoggingHandlerHost::LogMessage(const std::string& message) {
219 BrowserThread::PostTask( 230 BrowserThread::PostTask(
220 BrowserThread::IO, 231 BrowserThread::IO,
221 FROM_HERE, 232 FROM_HERE,
222 base::Bind( 233 base::Bind(
223 &WebRtcLoggingHandlerHost::AddLogMessageFromBrowser, 234 &WebRtcLoggingHandlerHost::AddLogMessageFromBrowser,
224 this, 235 this,
225 WebRtcLoggingMessageData(base::Time::Now(), message))); 236 WebRtcLoggingMessageData(base::Time::Now(), message)));
226 } 237 }
227 238
228 void WebRtcLoggingHandlerHost::StartRtpDump( 239 void WebRtcLoggingHandlerHost::StartRtpDump(
229 bool incoming, 240 RtpDumpType type,
230 bool outgoing, 241 const GenericDoneCallback& callback,
231 const GenericDoneCallback& callback) { 242 const content::RenderProcessHost::WebRtcStopRtpDumpCallback&
232 NOTIMPLEMENTED(); 243 stop_callback) {
244 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
245
246 stop_rtp_dump_callback_ = stop_callback;
247
248 if (!rtp_dump_handler_) {
249 content::BrowserThread::PostTaskAndReplyWithResult(
250 content::BrowserThread::FILE,
251 FROM_HERE,
252 base::Bind(&WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists,
253 this),
254 base::Bind(&WebRtcLoggingHandlerHost::CreateRtpDumpHandlerAndStart,
255 this,
256 type,
257 callback));
258 return;
259 }
260
261 GenericDoneCallback start_callback = callback;
262 DoStartRtpDump(type, &start_callback);
233 } 263 }
234 264
235 void WebRtcLoggingHandlerHost::StopRtpDump( 265 void WebRtcLoggingHandlerHost::StopRtpDump(
236 bool incoming, 266 RtpDumpType type,
237 bool outgoing,
238 const GenericDoneCallback& callback) { 267 const GenericDoneCallback& callback) {
239 NOTIMPLEMENTED(); 268 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
269 DCHECK(!callback.is_null());
270
271 if (!rtp_dump_handler_) {
272 GenericDoneCallback stop_callback = callback;
273 FireGenericDoneCallback(
274 &stop_callback, false, "RTP dump has not been started.");
275 return;
276 }
277
278 if (!stop_rtp_dump_callback_.is_null()) {
279 stop_rtp_dump_callback_.Run(
280 type == RTP_DUMP_INCOMING || type == RTP_DUMP_BOTH,
281 type == RTP_DUMP_OUTGOING || type == RTP_DUMP_BOTH);
282 }
283
284 rtp_dump_handler_->StopDump(type, callback);
285 }
286
287 void WebRtcLoggingHandlerHost::OnRtpPacket(const uint8* packet_header,
288 size_t header_length,
289 size_t packet_length,
290 bool incoming) {
291 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
292
293 scoped_ptr<uint8[]> header_data(new uint8[header_length]);
294 memcpy(header_data.get(), packet_header, header_length);
295
296 BrowserThread::PostTask(
297 BrowserThread::IO,
298 FROM_HERE,
299 base::Bind(&WebRtcLoggingHandlerHost::DumpRtpPacketOnIOThread,
300 this,
301 base::Passed(&header_data),
302 header_length,
303 packet_length,
304 incoming));
305 }
306
307 void WebRtcLoggingHandlerHost::DumpRtpPacketOnIOThread(
308 scoped_ptr<uint8[]> packet_header,
309 size_t header_length,
310 size_t packet_length,
311 bool incoming) {
312 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
313
314 if (rtp_dump_handler_) {
315 rtp_dump_handler_->OnRtpPacket(
316 packet_header.get(), header_length, packet_length, incoming);
317 }
240 } 318 }
241 319
242 void WebRtcLoggingHandlerHost::OnChannelClosing() { 320 void WebRtcLoggingHandlerHost::OnChannelClosing() {
243 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 321 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
244 if (logging_state_ == STARTED || logging_state_ == STOPPED) { 322 if (logging_state_ == STARTED || logging_state_ == STOPPED) {
245 if (upload_log_on_render_close_) { 323 if (upload_log_on_render_close_) {
246 logging_state_ = UPLOADING; 324 logging_state_ = UPLOADING;
247 logging_started_time_ = base::Time(); 325 logging_started_time_ = base::Time();
248 content::BrowserThread::PostTaskAndReplyWithResult( 326
249 content::BrowserThread::FILE, 327 if (!rtp_dump_handler_) {
250 FROM_HERE, 328 content::BrowserThread::PostTaskAndReplyWithResult(
251 base::Bind(&WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists, 329 content::BrowserThread::FILE,
252 this), 330 FROM_HERE,
253 base::Bind(&WebRtcLoggingHandlerHost::TriggerUploadLog, this)); 331 base::Bind(
332 &WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists,
333 this),
334 base::Bind(&WebRtcLoggingHandlerHost::TriggerUpload, this));
335 } else {
336 // The log directory has been ensured existing if |rtp_dump_handler_| is
337 // not NULL.
338 rtp_dump_handler_->StopOngoingDumps(
339 base::Bind(&WebRtcLoggingHandlerHost::TriggerUpload,
340 this,
341 profile_->GetPath()));
Henrik Grunell 2014/05/26 09:51:03 This is not the correct log path. Use WebRtcLogLis
jiayl 2014/05/27 20:41:41 Done.
342 }
254 } else { 343 } else {
255 g_browser_process->webrtc_log_uploader()->LoggingStoppedDontUpload(); 344 g_browser_process->webrtc_log_uploader()->LoggingStoppedDontUpload();
256 } 345 }
257 } 346 }
258 content::BrowserMessageFilter::OnChannelClosing(); 347 content::BrowserMessageFilter::OnChannelClosing();
259 } 348 }
260 349
261 void WebRtcLoggingHandlerHost::OnDestruct() const { 350 void WebRtcLoggingHandlerHost::OnDestruct() const {
262 BrowserThread::DeleteOnIOThread::Destruct(this); 351 BrowserThread::DeleteOnIOThread::Destruct(this);
263 } 352 }
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 base::FilePath log_dir_path = 534 base::FilePath log_dir_path =
446 WebRtcLogList::GetWebRtcLogDirectoryForProfile(profile_->GetPath()); 535 WebRtcLogList::GetWebRtcLogDirectoryForProfile(profile_->GetPath());
447 base::File::Error error; 536 base::File::Error error;
448 if (!base::CreateDirectoryAndGetError(log_dir_path, &error)) { 537 if (!base::CreateDirectoryAndGetError(log_dir_path, &error)) {
449 DLOG(ERROR) << "Could not create WebRTC log directory, error: " << error; 538 DLOG(ERROR) << "Could not create WebRTC log directory, error: " << error;
450 return base::FilePath(); 539 return base::FilePath();
451 } 540 }
452 return log_dir_path; 541 return log_dir_path;
453 } 542 }
454 543
455 void WebRtcLoggingHandlerHost::TriggerUploadLog( 544 void WebRtcLoggingHandlerHost::TriggerUpload(
456 const base::FilePath& log_directory) { 545 const base::FilePath& log_directory) {
457 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 546 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
458 DCHECK_EQ(logging_state_, UPLOADING); 547 DCHECK_EQ(logging_state_, UPLOADING);
459 548
549 DoUploadLogAndDumps(log_directory,
550 rtp_dump_handler_
551 ? rtp_dump_handler_->ReleaseDumps()
552 : WebRtcRtpDumpHandler::ReleasedDumps(
553 base::FilePath(), base::FilePath()));
554 }
555
556 void WebRtcLoggingHandlerHost::FireGenericDoneCallback(
557 GenericDoneCallback* callback,
558 bool success,
559 const std::string& error_message) {
560 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
561 DCHECK(!(*callback).is_null());
562 content::BrowserThread::PostTask(
563 content::BrowserThread::UI,
564 FROM_HERE,
565 base::Bind(*callback, success, error_message));
566 (*callback).Reset();
567 }
568
569 void WebRtcLoggingHandlerHost::CreateRtpDumpHandlerAndStart(
570 RtpDumpType type,
571 GenericDoneCallback callback,
572 const base::FilePath& dump_dir) {
573 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
574
575 // |rtp_dump_handler_| may be non-NULL if StartRtpDump is called again before
576 // GetLogDirectoryAndEnsureExists returns on the FILE thread for a previous
577 // StartRtpDump.
578 if (!rtp_dump_handler_)
579 rtp_dump_handler_.reset(new WebRtcRtpDumpHandler(dump_dir));
580
581 DoStartRtpDump(type, &callback);
582 }
583
584 void WebRtcLoggingHandlerHost::DoStartRtpDump(RtpDumpType type,
585 GenericDoneCallback* callback) {
586 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
587 DCHECK(rtp_dump_handler_);
588
589 std::string error;
590
591 bool result = rtp_dump_handler_->StartDump(type, &error);
592 FireGenericDoneCallback(callback, result, error);
593 }
594
595 void WebRtcLoggingHandlerHost::DoUploadLogAndDumps(
596 const base::FilePath& log_directory,
597 const WebRtcRtpDumpHandler::ReleasedDumps& rtp_dumps) {
460 WebRtcLogUploadDoneData upload_done_data; 598 WebRtcLogUploadDoneData upload_done_data;
461 upload_done_data.log_path = log_directory; 599 upload_done_data.log_path = log_directory;
600
601 if (!rtp_dumps.incoming_dump_path.empty()) {
602 upload_done_data.rtp_dumps.push_back(
603 WebRtcRtpDumpDescription("rtpdump_recv", rtp_dumps.incoming_dump_path));
604 }
605
606 if (!rtp_dumps.outgoing_dump_path.empty()) {
607 upload_done_data.rtp_dumps.push_back(
608 WebRtcRtpDumpDescription("rtpdump_send", rtp_dumps.outgoing_dump_path));
609 }
610
462 upload_done_data.callback = upload_callback_; 611 upload_done_data.callback = upload_callback_;
463 upload_done_data.host = this; 612 upload_done_data.host = this;
464 upload_callback_.Reset(); 613 upload_callback_.Reset();
465 614
466 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, base::Bind( 615 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, base::Bind(
467 &WebRtcLogUploader::LoggingStoppedDoUpload, 616 &WebRtcLogUploader::LoggingStoppedDoUpload,
468 base::Unretained(g_browser_process->webrtc_log_uploader()), 617 base::Unretained(g_browser_process->webrtc_log_uploader()),
469 Passed(&log_buffer_), 618 Passed(&log_buffer_),
470 kWebRtcLogSize, 619 kWebRtcLogSize,
471 meta_data_, 620 meta_data_,
472 upload_done_data)); 621 upload_done_data));
473 622
474 meta_data_.clear(); 623 meta_data_.clear();
475 circular_buffer_.reset(); 624 circular_buffer_.reset();
476 } 625 }
477
478 void WebRtcLoggingHandlerHost::FireGenericDoneCallback(
479 GenericDoneCallback* callback, bool success,
480 const std::string& error_message) {
481 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
482 DCHECK(!(*callback).is_null());
483 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
484 base::Bind(*callback, success,
485 error_message));
486 (*callback).Reset();
487 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698