| OLD | NEW |
| 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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 } | 183 } |
| 184 return; | 184 return; |
| 185 } | 185 } |
| 186 upload_callback_ = callback; | 186 upload_callback_ = callback; |
| 187 logging_state_ = UPLOADING; | 187 logging_state_ = UPLOADING; |
| 188 content::BrowserThread::PostTaskAndReplyWithResult( | 188 content::BrowserThread::PostTaskAndReplyWithResult( |
| 189 content::BrowserThread::FILE, | 189 content::BrowserThread::FILE, |
| 190 FROM_HERE, | 190 FROM_HERE, |
| 191 base::Bind(&WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists, | 191 base::Bind(&WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists, |
| 192 this), | 192 this), |
| 193 base::Bind(&WebRtcLoggingHandlerHost::TriggerUploadLog, this)); | 193 base::Bind(&WebRtcLoggingHandlerHost::TriggerUpload, this)); |
| 194 } | 194 } |
| 195 | 195 |
| 196 void WebRtcLoggingHandlerHost::UploadLogDone() { | 196 void WebRtcLoggingHandlerHost::UploadLogDone() { |
| 197 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 197 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 198 logging_state_ = CLOSED; | 198 logging_state_ = CLOSED; |
| 199 } | 199 } |
| 200 | 200 |
| 201 void WebRtcLoggingHandlerHost::DiscardLog(const GenericDoneCallback& callback) { | 201 void WebRtcLoggingHandlerHost::DiscardLog(const GenericDoneCallback& callback) { |
| 202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 203 DCHECK(!callback.is_null()); | 203 DCHECK(!callback.is_null()); |
| 204 | 204 |
| 205 GenericDoneCallback discard_callback = callback; | 205 GenericDoneCallback discard_callback = callback; |
| 206 if (logging_state_ != STOPPED) { | 206 if (logging_state_ != STOPPED) { |
| 207 FireGenericDoneCallback(&discard_callback, false, | 207 FireGenericDoneCallback(&discard_callback, false, |
| 208 kLogNotStoppedOrNoLogOpen); | 208 kLogNotStoppedOrNoLogOpen); |
| 209 return; | 209 return; |
| 210 } | 210 } |
| 211 g_browser_process->webrtc_log_uploader()->LoggingStoppedDontUpload(); | 211 g_browser_process->webrtc_log_uploader()->LoggingStoppedDontUpload(); |
| 212 circular_buffer_.reset(); | 212 circular_buffer_.reset(); |
| 213 log_buffer_.reset(); | 213 log_buffer_.reset(); |
| 214 logging_state_ = CLOSED; | 214 logging_state_ = CLOSED; |
| 215 rtp_dump_handler_.reset(); |
| 215 FireGenericDoneCallback(&discard_callback, true, ""); | 216 FireGenericDoneCallback(&discard_callback, true, ""); |
| 216 } | 217 } |
| 217 | 218 |
| 218 void WebRtcLoggingHandlerHost::LogMessage(const std::string& message) { | 219 void WebRtcLoggingHandlerHost::LogMessage(const std::string& message) { |
| 219 BrowserThread::PostTask( | 220 BrowserThread::PostTask( |
| 220 BrowserThread::IO, | 221 BrowserThread::IO, |
| 221 FROM_HERE, | 222 FROM_HERE, |
| 222 base::Bind( | 223 base::Bind( |
| 223 &WebRtcLoggingHandlerHost::AddLogMessageFromBrowser, | 224 &WebRtcLoggingHandlerHost::AddLogMessageFromBrowser, |
| 224 this, | 225 this, |
| 225 WebRtcLoggingMessageData(base::Time::Now(), message))); | 226 WebRtcLoggingMessageData(base::Time::Now(), message))); |
| 226 } | 227 } |
| 227 | 228 |
| 228 void WebRtcLoggingHandlerHost::StartRtpDump( | 229 void WebRtcLoggingHandlerHost::StartRtpDump( |
| 229 bool incoming, | 230 bool incoming, |
| 230 bool outgoing, | 231 bool outgoing, |
| 231 const GenericDoneCallback& callback) { | 232 const GenericDoneCallback& callback) { |
| 232 NOTIMPLEMENTED(); | 233 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 234 DCHECK(!callback.is_null()); |
| 235 |
| 236 GenericDoneCallback start_callback = callback; |
| 237 if (!incoming && !outgoing) { |
| 238 FireGenericDoneCallback( |
| 239 &start_callback, |
| 240 false, |
| 241 "Either incoming or outgoing argument must be true."); |
| 242 return; |
| 243 } |
| 244 |
| 245 if (!rtp_dump_handler_) { |
| 246 content::BrowserThread::PostTaskAndReplyWithResult( |
| 247 content::BrowserThread::FILE, |
| 248 FROM_HERE, |
| 249 base::Bind(&WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists, |
| 250 this), |
| 251 base::Bind(&WebRtcLoggingHandlerHost::CreateRtpDumpHandlerAndStart, |
| 252 this, |
| 253 incoming, |
| 254 outgoing, |
| 255 callback)); |
| 256 return; |
| 257 } |
| 258 |
| 259 DoStartRtpDump(incoming, outgoing, &start_callback); |
| 233 } | 260 } |
| 234 | 261 |
| 235 void WebRtcLoggingHandlerHost::StopRtpDump( | 262 void WebRtcLoggingHandlerHost::StopRtpDump( |
| 236 bool incoming, | 263 bool incoming, |
| 237 bool outgoing, | 264 bool outgoing, |
| 238 const GenericDoneCallback& callback) { | 265 const GenericDoneCallback& callback) { |
| 239 NOTIMPLEMENTED(); | 266 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 267 DCHECK(!callback.is_null()); |
| 268 |
| 269 GenericDoneCallback stop_callback = callback; |
| 270 if (!(incoming || outgoing) || !rtp_dump_handler_) { |
| 271 FireGenericDoneCallback(&stop_callback, false, "Invalid argument"); |
| 272 return; |
| 273 } |
| 274 |
| 275 WebRtcRtpDumpHandler::PacketType type = |
| 276 (incoming && outgoing) |
| 277 ? WebRtcRtpDumpHandler::PACKET_TYPE_BOTH |
| 278 : (incoming ? WebRtcRtpDumpHandler::PACKET_TYPE_INCOMING_ONLY |
| 279 : WebRtcRtpDumpHandler::PACKET_TYPE_OUTGOING_ONLY); |
| 280 |
| 281 rtp_dump_handler_->StopDump(type, callback); |
| 282 } |
| 283 |
| 284 void WebRtcLoggingHandlerHost::OnRtpPacket(const uint8* packet_header, |
| 285 size_t header_length, |
| 286 size_t packet_length, |
| 287 bool incoming) { |
| 288 scoped_ptr<uint8[]> header_data(new uint8[header_length]); |
| 289 memcpy(header_data.get(), packet_header, header_length); |
| 290 |
| 291 BrowserThread::PostTask( |
| 292 BrowserThread::IO, |
| 293 FROM_HERE, |
| 294 base::Bind(&WebRtcLoggingHandlerHost::DumpRtpPacketOnIOThread, |
| 295 this, |
| 296 base::Passed(&header_data), |
| 297 header_length, |
| 298 packet_length, |
| 299 incoming)); |
| 300 } |
| 301 |
| 302 void WebRtcLoggingHandlerHost::DumpRtpPacketOnIOThread( |
| 303 scoped_ptr<uint8[]> packet_header, |
| 304 size_t header_length, |
| 305 size_t packet_length, |
| 306 bool incoming) { |
| 307 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 308 |
| 309 if (rtp_dump_handler_) { |
| 310 rtp_dump_handler_->OnRtpPacket( |
| 311 packet_header.get(), header_length, packet_length, incoming); |
| 312 } |
| 240 } | 313 } |
| 241 | 314 |
| 242 void WebRtcLoggingHandlerHost::OnChannelClosing() { | 315 void WebRtcLoggingHandlerHost::OnChannelClosing() { |
| 243 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 316 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 244 if (logging_state_ == STARTED || logging_state_ == STOPPED) { | 317 if (logging_state_ == STARTED || logging_state_ == STOPPED) { |
| 245 if (upload_log_on_render_close_) { | 318 if (upload_log_on_render_close_) { |
| 246 logging_state_ = UPLOADING; | 319 logging_state_ = UPLOADING; |
| 247 logging_started_time_ = base::Time(); | 320 logging_started_time_ = base::Time(); |
| 248 content::BrowserThread::PostTaskAndReplyWithResult( | 321 content::BrowserThread::PostTaskAndReplyWithResult( |
| 249 content::BrowserThread::FILE, | 322 content::BrowserThread::FILE, |
| 250 FROM_HERE, | 323 FROM_HERE, |
| 251 base::Bind(&WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists, | 324 base::Bind(&WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists, |
| 252 this), | 325 this), |
| 253 base::Bind(&WebRtcLoggingHandlerHost::TriggerUploadLog, this)); | 326 base::Bind(&WebRtcLoggingHandlerHost::TriggerUpload, this)); |
| 254 } else { | 327 } else { |
| 255 g_browser_process->webrtc_log_uploader()->LoggingStoppedDontUpload(); | 328 g_browser_process->webrtc_log_uploader()->LoggingStoppedDontUpload(); |
| 256 } | 329 } |
| 257 } | 330 } |
| 258 content::BrowserMessageFilter::OnChannelClosing(); | 331 content::BrowserMessageFilter::OnChannelClosing(); |
| 259 } | 332 } |
| 260 | 333 |
| 261 void WebRtcLoggingHandlerHost::OnDestruct() const { | 334 void WebRtcLoggingHandlerHost::OnDestruct() const { |
| 262 BrowserThread::DeleteOnIOThread::Destruct(this); | 335 BrowserThread::DeleteOnIOThread::Destruct(this); |
| 263 } | 336 } |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 base::FilePath log_dir_path = | 518 base::FilePath log_dir_path = |
| 446 WebRtcLogList::GetWebRtcLogDirectoryForProfile(profile_->GetPath()); | 519 WebRtcLogList::GetWebRtcLogDirectoryForProfile(profile_->GetPath()); |
| 447 base::File::Error error; | 520 base::File::Error error; |
| 448 if (!base::CreateDirectoryAndGetError(log_dir_path, &error)) { | 521 if (!base::CreateDirectoryAndGetError(log_dir_path, &error)) { |
| 449 DLOG(ERROR) << "Could not create WebRTC log directory, error: " << error; | 522 DLOG(ERROR) << "Could not create WebRTC log directory, error: " << error; |
| 450 return base::FilePath(); | 523 return base::FilePath(); |
| 451 } | 524 } |
| 452 return log_dir_path; | 525 return log_dir_path; |
| 453 } | 526 } |
| 454 | 527 |
| 455 void WebRtcLoggingHandlerHost::TriggerUploadLog( | 528 void WebRtcLoggingHandlerHost::TriggerUpload( |
| 456 const base::FilePath& log_directory) { | 529 const base::FilePath& log_directory) { |
| 457 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 530 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 458 DCHECK_EQ(logging_state_, UPLOADING); | 531 DCHECK_EQ(logging_state_, UPLOADING); |
| 459 | 532 |
| 533 WebRtcRtpDumpHandler::ReleasedDumps dumps; |
| 534 if (rtp_dump_handler_) |
| 535 dumps = rtp_dump_handler_->ReleaseDumps(); |
| 536 |
| 537 DoUploadLogAndDumps(log_directory, dumps); |
| 538 } |
| 539 |
| 540 void WebRtcLoggingHandlerHost::FireGenericDoneCallback( |
| 541 GenericDoneCallback* callback, |
| 542 bool success, |
| 543 const std::string& error_message) { |
| 544 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 545 DCHECK(!(*callback).is_null()); |
| 546 content::BrowserThread::PostTask( |
| 547 content::BrowserThread::UI, |
| 548 FROM_HERE, |
| 549 base::Bind(*callback, success, error_message)); |
| 550 (*callback).Reset(); |
| 551 } |
| 552 |
| 553 void WebRtcLoggingHandlerHost::CreateRtpDumpHandlerAndStart( |
| 554 bool incoming, |
| 555 bool outgoing, |
| 556 GenericDoneCallback callback, |
| 557 const base::FilePath& dump_dir) { |
| 558 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 559 |
| 560 if (!rtp_dump_handler_) |
| 561 rtp_dump_handler_.reset(new WebRtcRtpDumpHandler(dump_dir)); |
| 562 |
| 563 DoStartRtpDump(incoming, outgoing, &callback); |
| 564 } |
| 565 |
| 566 void WebRtcLoggingHandlerHost::DoStartRtpDump(bool incoming, |
| 567 bool outgoing, |
| 568 GenericDoneCallback* callback) { |
| 569 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 570 DCHECK(rtp_dump_handler_); |
| 571 |
| 572 std::string error; |
| 573 WebRtcRtpDumpHandler::PacketType type = |
| 574 (incoming && outgoing) |
| 575 ? WebRtcRtpDumpHandler::PACKET_TYPE_BOTH |
| 576 : (incoming ? WebRtcRtpDumpHandler::PACKET_TYPE_INCOMING_ONLY |
| 577 : WebRtcRtpDumpHandler::PACKET_TYPE_OUTGOING_ONLY); |
| 578 |
| 579 bool result = rtp_dump_handler_->StartDump(type, &error); |
| 580 FireGenericDoneCallback(callback, result, error); |
| 581 } |
| 582 |
| 583 void WebRtcLoggingHandlerHost::DoUploadLogAndDumps( |
| 584 const base::FilePath& log_directory, |
| 585 const WebRtcRtpDumpHandler::ReleasedDumps& rtp_dumps) { |
| 460 WebRtcLogUploadDoneData upload_done_data; | 586 WebRtcLogUploadDoneData upload_done_data; |
| 461 upload_done_data.log_path = log_directory; | 587 upload_done_data.log_path = log_directory; |
| 588 |
| 589 if (!rtp_dumps.incoming_dump_path.empty()) { |
| 590 upload_done_data.rtp_dumps.push_back( |
| 591 WebRtcRtpDumpDescription("rtpdump_recv", rtp_dumps.incoming_dump_path)); |
| 592 } |
| 593 |
| 594 if (!rtp_dumps.outgoing_dump_path.empty()) { |
| 595 upload_done_data.rtp_dumps.push_back( |
| 596 WebRtcRtpDumpDescription("rtpdump_send", rtp_dumps.outgoing_dump_path)); |
| 597 } |
| 598 |
| 462 upload_done_data.callback = upload_callback_; | 599 upload_done_data.callback = upload_callback_; |
| 463 upload_done_data.host = this; | 600 upload_done_data.host = this; |
| 464 upload_callback_.Reset(); | 601 upload_callback_.Reset(); |
| 465 | 602 |
| 466 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, base::Bind( | 603 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, base::Bind( |
| 467 &WebRtcLogUploader::LoggingStoppedDoUpload, | 604 &WebRtcLogUploader::LoggingStoppedDoUpload, |
| 468 base::Unretained(g_browser_process->webrtc_log_uploader()), | 605 base::Unretained(g_browser_process->webrtc_log_uploader()), |
| 469 Passed(&log_buffer_), | 606 Passed(&log_buffer_), |
| 470 kWebRtcLogSize, | 607 kWebRtcLogSize, |
| 471 meta_data_, | 608 meta_data_, |
| 472 upload_done_data)); | 609 upload_done_data)); |
| 473 | 610 |
| 474 meta_data_.clear(); | 611 meta_data_.clear(); |
| 475 circular_buffer_.reset(); | 612 circular_buffer_.reset(); |
| 476 } | 613 } |
| 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 } | |
| OLD | NEW |