Chromium Code Reviews| Index: chrome/browser/media/webrtc_logging_handler_host.cc |
| diff --git a/chrome/browser/media/webrtc_logging_handler_host.cc b/chrome/browser/media/webrtc_logging_handler_host.cc |
| index 816be38e2ff876b0a4083f8f433931c5132631e0..55f2f60df67eee04e5bbb70be782dd78d563581f 100644 |
| --- a/chrome/browser/media/webrtc_logging_handler_host.cc |
| +++ b/chrome/browser/media/webrtc_logging_handler_host.cc |
| @@ -19,6 +19,7 @@ |
| #include "chrome/browser/chromeos/settings/cros_settings.h" |
| #include "chrome/browser/media/webrtc_log_list.h" |
| #include "chrome/browser/media/webrtc_log_uploader.h" |
| +#include "chrome/browser/media/webrtc_rtp_dump_handler.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/common/chrome_switches.h" |
| #include "chrome/common/media/webrtc_logging_messages.h" |
| @@ -48,6 +49,7 @@ |
| using base::IntToString; |
| using content::BrowserThread; |
| +namespace { |
| #if defined(OS_ANDROID) |
| const size_t kWebRtcLogSize = 1 * 1024 * 1024; // 1 MB |
| @@ -55,8 +57,6 @@ const size_t kWebRtcLogSize = 1 * 1024 * 1024; // 1 MB |
| const size_t kWebRtcLogSize = 6 * 1024 * 1024; // 6 MB |
| #endif |
| -namespace { |
| - |
| const char kLogNotStoppedOrNoLogOpen[] = |
| "Logging not stopped or no log open."; |
| @@ -190,7 +190,7 @@ void WebRtcLoggingHandlerHost::UploadLog(const UploadDoneCallback& callback) { |
| FROM_HERE, |
| base::Bind(&WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists, |
| this), |
| - base::Bind(&WebRtcLoggingHandlerHost::TriggerUploadLog, this)); |
| + base::Bind(&WebRtcLoggingHandlerHost::TriggerUpload, this)); |
| } |
| void WebRtcLoggingHandlerHost::UploadLogDone() { |
| @@ -212,6 +212,7 @@ void WebRtcLoggingHandlerHost::DiscardLog(const GenericDoneCallback& callback) { |
| circular_buffer_.reset(); |
| log_buffer_.reset(); |
| logging_state_ = CLOSED; |
| + rtp_dump_handler_.reset(); |
| FireGenericDoneCallback(&discard_callback, true, ""); |
| } |
| @@ -229,14 +230,80 @@ void WebRtcLoggingHandlerHost::StartRtpDump( |
| bool incoming, |
| bool outgoing, |
| const GenericDoneCallback& callback) { |
| - NOTIMPLEMENTED(); |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| + DCHECK(!callback.is_null()); |
| + |
| + GenericDoneCallback start_callback = callback; |
| + if (!incoming && !outgoing) { |
| + FireGenericDoneCallback(&start_callback, false, "Invalid argument."); |
|
Henrik Grunell
2014/05/14 12:14:12
This will end up in the javascript app, I think th
jiayl
2014/05/14 18:59:12
Done improving the error message.
How could we ch
Henrik Grunell
2014/05/15 14:36:34
I'd like a JS enum used in the JS API. We could do
jiayl
2014/05/15 23:06:22
Done.
|
| + return; |
| + } |
| + |
| + if (!rtp_dump_handler_) { |
| + content::BrowserThread::PostTaskAndReplyWithResult( |
| + content::BrowserThread::FILE, |
| + FROM_HERE, |
| + base::Bind(&WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists, |
| + this), |
| + base::Bind(&WebRtcLoggingHandlerHost::CreateRtpDumpHandlerAndStart, |
| + this, |
| + incoming, |
| + outgoing, |
| + callback)); |
| + return; |
| + } |
| + |
| + DoStartRtpDump(incoming, outgoing, &start_callback); |
| } |
| void WebRtcLoggingHandlerHost::StopRtpDump( |
| bool incoming, |
| bool outgoing, |
| const GenericDoneCallback& callback) { |
| - NOTIMPLEMENTED(); |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| + DCHECK(!callback.is_null()); |
| + |
| + GenericDoneCallback stop_callback = callback; |
| + if (!(incoming || outgoing) || !rtp_dump_handler_) { |
| + FireGenericDoneCallback(&stop_callback, false, "Invalid argument"); |
| + return; |
| + } |
| + |
| + WebRtcRtpDumpHandler::PacketType type(incoming, outgoing); |
| + rtp_dump_handler_->StopDump(type, callback); |
| +} |
| + |
| +void WebRtcLoggingHandlerHost::OnRtpPacket(const uint8* packet_header, |
| + size_t header_length, |
| + size_t packet_length, |
| + bool incoming) { |
| + // Can be called on any thread as it always posts to the IO thread. |
|
Henrik Grunell
2014/05/14 12:14:12
Move this comment to the declaration.
jiayl
2014/05/14 18:59:12
Done.
|
| + |
| + scoped_ptr<uint8[]> header_data(new uint8[header_length]); |
| + memcpy(header_data.get(), packet_header, header_length); |
| + |
| + BrowserThread::PostTask( |
| + BrowserThread::IO, |
| + FROM_HERE, |
| + base::Bind(&WebRtcLoggingHandlerHost::DumpRtpPacketOnIOThread, |
| + this, |
| + base::Passed(&header_data), |
| + header_length, |
| + packet_length, |
| + incoming)); |
| +} |
| + |
| +void WebRtcLoggingHandlerHost::DumpRtpPacketOnIOThread( |
| + scoped_ptr<uint8[]> packet_header, |
| + size_t header_length, |
| + size_t packet_length, |
| + bool incoming) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| + |
| + if (rtp_dump_handler_) { |
| + rtp_dump_handler_->OnRtpPacket( |
| + packet_header.get(), header_length, packet_length, incoming); |
| + } |
| } |
| void WebRtcLoggingHandlerHost::OnChannelClosing() { |
| @@ -250,7 +317,7 @@ void WebRtcLoggingHandlerHost::OnChannelClosing() { |
| FROM_HERE, |
| base::Bind(&WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists, |
| this), |
| - base::Bind(&WebRtcLoggingHandlerHost::TriggerUploadLog, this)); |
| + base::Bind(&WebRtcLoggingHandlerHost::TriggerUpload, this)); |
| } else { |
| g_browser_process->webrtc_log_uploader()->LoggingStoppedDontUpload(); |
| } |
| @@ -452,13 +519,73 @@ base::FilePath WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists() { |
| return log_dir_path; |
| } |
| -void WebRtcLoggingHandlerHost::TriggerUploadLog( |
| +void WebRtcLoggingHandlerHost::TriggerUpload( |
| const base::FilePath& log_directory) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| DCHECK_EQ(logging_state_, UPLOADING); |
| + WebRtcRtpDumpHandler::ReleasedDumps dumps; |
| + if (rtp_dump_handler_) { |
|
Henrik Grunell
2014/05/14 12:14:12
Remove {}
jiayl
2014/05/14 18:59:12
Done.
|
| + dumps = rtp_dump_handler_->ReleaseDumps(); |
| + } |
| + |
| + DoUploadLogAndDumps(log_directory, dumps); |
| +} |
| + |
| +void WebRtcLoggingHandlerHost::FireGenericDoneCallback( |
| + GenericDoneCallback* callback, |
| + bool success, |
| + const std::string& error_message) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| + DCHECK(!(*callback).is_null()); |
| + content::BrowserThread::PostTask( |
| + content::BrowserThread::UI, |
| + FROM_HERE, |
| + base::Bind(*callback, success, error_message)); |
| + (*callback).Reset(); |
| +} |
| + |
| +void WebRtcLoggingHandlerHost::CreateRtpDumpHandlerAndStart( |
| + bool incoming, |
| + bool outgoing, |
| + GenericDoneCallback callback, |
| + const base::FilePath& dump_dir) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| + |
| + if (!rtp_dump_handler_) |
| + rtp_dump_handler_.reset(new WebRtcRtpDumpHandler(dump_dir)); |
| + |
| + DoStartRtpDump(incoming, outgoing, &callback); |
| +} |
| + |
| +void WebRtcLoggingHandlerHost::DoStartRtpDump(bool incoming, |
| + bool outgoing, |
| + GenericDoneCallback* callback) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| + DCHECK(rtp_dump_handler_); |
| + |
| + std::string error; |
| + WebRtcRtpDumpHandler::PacketType type(incoming, outgoing); |
| + bool result = rtp_dump_handler_->StartDump(type, &error); |
| + FireGenericDoneCallback(callback, result, error); |
| +} |
| + |
| +void WebRtcLoggingHandlerHost::DoUploadLogAndDumps( |
| + const base::FilePath& log_directory, |
| + const WebRtcRtpDumpHandler::ReleasedDumps& rtp_dumps) { |
| WebRtcLogUploadDoneData upload_done_data; |
| upload_done_data.log_path = log_directory; |
| + |
| + if (!rtp_dumps.incoming_dump_path.empty()) { |
| + upload_done_data.rtp_dumps.push_back( |
| + WebRtcRtpDumpDescription("rtpdump_recv", rtp_dumps.incoming_dump_path)); |
| + } |
| + |
| + if (!rtp_dumps.outgoing_dump_path.empty()) { |
| + upload_done_data.rtp_dumps.push_back( |
| + WebRtcRtpDumpDescription("rtpdump_send", rtp_dumps.outgoing_dump_path)); |
| + } |
| + |
| upload_done_data.callback = upload_callback_; |
| upload_done_data.host = this; |
| upload_callback_.Reset(); |
| @@ -474,14 +601,3 @@ void WebRtcLoggingHandlerHost::TriggerUploadLog( |
| meta_data_.clear(); |
| circular_buffer_.reset(); |
| } |
| - |
| -void WebRtcLoggingHandlerHost::FireGenericDoneCallback( |
| - GenericDoneCallback* callback, bool success, |
| - const std::string& error_message) { |
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| - DCHECK(!(*callback).is_null()); |
| - content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
| - base::Bind(*callback, success, |
| - error_message)); |
| - (*callback).Reset(); |
| -} |