| 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 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 const MetaDataMap& meta_data, | 100 const MetaDataMap& meta_data, |
| 101 std::string* message) { | 101 std::string* message) { |
| 102 for (MetaDataMap::const_iterator it = meta_data.begin(); | 102 for (MetaDataMap::const_iterator it = meta_data.begin(); |
| 103 it != meta_data.end(); ++it) { | 103 it != meta_data.end(); ++it) { |
| 104 *message += it->first + ": " + it->second + '\n'; | 104 *message += it->first + ": " + it->second + '\n'; |
| 105 } | 105 } |
| 106 // Remove last '\n'. | 106 // Remove last '\n'. |
| 107 message->resize(message->size() - 1); | 107 message->resize(message->size() - 1); |
| 108 } | 108 } |
| 109 | 109 |
| 110 // Returns a path name to be used as prefix for audio debug recordings files. | |
| 111 base::FilePath GetAudioDebugRecordingsPrefixPath( | |
| 112 const base::FilePath& directory, | |
| 113 uint64_t audio_debug_recordings_id) { | |
| 114 static const char kAudioDebugRecordingsFilePrefix[] = "AudioDebugRecordings."; | |
| 115 return directory.AppendASCII(kAudioDebugRecordingsFilePrefix + | |
| 116 base::Int64ToString(audio_debug_recordings_id)); | |
| 117 } | |
| 118 | |
| 119 } // namespace | 110 } // namespace |
| 120 | 111 |
| 121 WebRtcLogBuffer::WebRtcLogBuffer() | 112 WebRtcLogBuffer::WebRtcLogBuffer() |
| 122 : buffer_(), | 113 : buffer_(), |
| 123 circular_(&buffer_[0], sizeof(buffer_), sizeof(buffer_) / 2, false), | 114 circular_(&buffer_[0], sizeof(buffer_), sizeof(buffer_) / 2, false), |
| 124 read_only_(false) { | 115 read_only_(false) { |
| 125 } | 116 } |
| 126 | 117 |
| 127 WebRtcLogBuffer::~WebRtcLogBuffer() { | 118 WebRtcLogBuffer::~WebRtcLogBuffer() { |
| 128 DCHECK(read_only_ || thread_checker_.CalledOnValidThread()); | 119 DCHECK(read_only_ || thread_checker_.CalledOnValidThread()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 151 thread_checker_.DetachFromThread(); | 142 thread_checker_.DetachFromThread(); |
| 152 } | 143 } |
| 153 | 144 |
| 154 WebRtcLoggingHandlerHost::WebRtcLoggingHandlerHost( | 145 WebRtcLoggingHandlerHost::WebRtcLoggingHandlerHost( |
| 155 Profile* profile, | 146 Profile* profile, |
| 156 WebRtcLogUploader* log_uploader) | 147 WebRtcLogUploader* log_uploader) |
| 157 : BrowserMessageFilter(WebRtcLoggingMsgStart), | 148 : BrowserMessageFilter(WebRtcLoggingMsgStart), |
| 158 profile_(profile), | 149 profile_(profile), |
| 159 logging_state_(CLOSED), | 150 logging_state_(CLOSED), |
| 160 upload_log_on_render_close_(false), | 151 upload_log_on_render_close_(false), |
| 161 log_uploader_(log_uploader), | 152 log_uploader_(log_uploader) { |
| 162 is_audio_debug_recordings_in_progress_(false), | |
| 163 current_audio_debug_recordings_id_(0) { | |
| 164 DCHECK(profile_); | 153 DCHECK(profile_); |
| 165 DCHECK(log_uploader_); | 154 DCHECK(log_uploader_); |
| 166 } | 155 } |
| 167 | 156 |
| 168 WebRtcLoggingHandlerHost::~WebRtcLoggingHandlerHost() { | 157 WebRtcLoggingHandlerHost::~WebRtcLoggingHandlerHost() { |
| 169 // If we hit this, then we might be leaking a log reference count (see | 158 // If we hit this, then we might be leaking a log reference count (see |
| 170 // ApplyForStartLogging). | 159 // ApplyForStartLogging). |
| 171 DCHECK_EQ(CLOSED, logging_state_); | 160 DCHECK_EQ(CLOSED, logging_state_); |
| 172 } | 161 } |
| 173 | 162 |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 425 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 437 | 426 |
| 438 // |rtp_dump_handler_| could be NULL if we are waiting for the FILE thread to | 427 // |rtp_dump_handler_| could be NULL if we are waiting for the FILE thread to |
| 439 // create/ensure the log directory. | 428 // create/ensure the log directory. |
| 440 if (rtp_dump_handler_) { | 429 if (rtp_dump_handler_) { |
| 441 rtp_dump_handler_->OnRtpPacket( | 430 rtp_dump_handler_->OnRtpPacket( |
| 442 packet_header.get(), header_length, packet_length, incoming); | 431 packet_header.get(), header_length, packet_length, incoming); |
| 443 } | 432 } |
| 444 } | 433 } |
| 445 | 434 |
| 446 void WebRtcLoggingHandlerHost::StartAudioDebugRecordings( | |
| 447 content::RenderProcessHost* host, | |
| 448 base::TimeDelta delay, | |
| 449 const AudioDebugRecordingsCallback& callback, | |
| 450 const AudioDebugRecordingsErrorCallback& error_callback) { | |
| 451 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 452 | |
| 453 BrowserThread::PostTaskAndReplyWithResult( | |
| 454 BrowserThread::FILE, FROM_HERE, | |
| 455 base::Bind(&WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists, | |
| 456 this), | |
| 457 base::Bind(&WebRtcLoggingHandlerHost::DoStartAudioDebugRecordings, this, | |
| 458 host, delay, callback, error_callback)); | |
| 459 } | |
| 460 | |
| 461 void WebRtcLoggingHandlerHost::StopAudioDebugRecordings( | |
| 462 content::RenderProcessHost* host, | |
| 463 const AudioDebugRecordingsCallback& callback, | |
| 464 const AudioDebugRecordingsErrorCallback& error_callback) { | |
| 465 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 466 BrowserThread::PostTaskAndReplyWithResult( | |
| 467 BrowserThread::FILE, FROM_HERE, | |
| 468 base::Bind(&WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists, | |
| 469 this), | |
| 470 base::Bind(&WebRtcLoggingHandlerHost::DoStopAudioDebugRecordings, this, | |
| 471 host, true /* manual stop */, | |
| 472 current_audio_debug_recordings_id_, callback, error_callback)); | |
| 473 } | |
| 474 | |
| 475 void WebRtcLoggingHandlerHost::OnChannelClosing() { | 435 void WebRtcLoggingHandlerHost::OnChannelClosing() { |
| 476 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 436 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 477 if (logging_state_ == STARTED || logging_state_ == STOPPED) { | 437 if (logging_state_ == STARTED || logging_state_ == STOPPED) { |
| 478 if (upload_log_on_render_close_) { | 438 if (upload_log_on_render_close_) { |
| 479 logging_started_time_ = base::Time(); | 439 logging_started_time_ = base::Time(); |
| 480 | 440 |
| 481 content::BrowserThread::PostTaskAndReplyWithResult( | 441 content::BrowserThread::PostTaskAndReplyWithResult( |
| 482 content::BrowserThread::FILE, | 442 content::BrowserThread::FILE, |
| 483 FROM_HERE, | 443 FROM_HERE, |
| 484 base::Bind(&WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists, | 444 base::Bind(&WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists, |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 801 case STOPPED: | 761 case STOPPED: |
| 802 error_message_with_state += " State=stopped."; | 762 error_message_with_state += " State=stopped."; |
| 803 break; | 763 break; |
| 804 } | 764 } |
| 805 | 765 |
| 806 content::BrowserThread::PostTask( | 766 content::BrowserThread::PostTask( |
| 807 content::BrowserThread::UI, | 767 content::BrowserThread::UI, |
| 808 FROM_HERE, | 768 FROM_HERE, |
| 809 base::Bind(callback, success, error_message_with_state)); | 769 base::Bind(callback, success, error_message_with_state)); |
| 810 } | 770 } |
| 811 | |
| 812 void WebRtcLoggingHandlerHost::DoStartAudioDebugRecordings( | |
| 813 content::RenderProcessHost* host, | |
| 814 base::TimeDelta delay, | |
| 815 const AudioDebugRecordingsCallback& callback, | |
| 816 const AudioDebugRecordingsErrorCallback& error_callback, | |
| 817 const base::FilePath& log_directory) { | |
| 818 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 819 | |
| 820 if (is_audio_debug_recordings_in_progress_) { | |
| 821 error_callback.Run("Audio debug recordings already in progress"); | |
| 822 return; | |
| 823 } | |
| 824 | |
| 825 is_audio_debug_recordings_in_progress_ = true; | |
| 826 base::FilePath prefix_path = GetAudioDebugRecordingsPrefixPath( | |
| 827 log_directory, ++current_audio_debug_recordings_id_); | |
| 828 host->EnableAudioDebugRecordings(prefix_path); | |
| 829 | |
| 830 if (delay.is_zero()) { | |
| 831 callback.Run(prefix_path.AsUTF8Unsafe(), false /* not stopped */, | |
| 832 false /* not manually stopped */); | |
| 833 return; | |
| 834 } | |
| 835 | |
| 836 BrowserThread::PostDelayedTask( | |
| 837 BrowserThread::UI, FROM_HERE, | |
| 838 base::Bind(&WebRtcLoggingHandlerHost::DoStopAudioDebugRecordings, this, | |
| 839 host, false /* no manual stop */, | |
| 840 current_audio_debug_recordings_id_, callback, error_callback, | |
| 841 prefix_path), | |
| 842 delay); | |
| 843 } | |
| 844 | |
| 845 void WebRtcLoggingHandlerHost::DoStopAudioDebugRecordings( | |
| 846 content::RenderProcessHost* host, | |
| 847 bool is_manual_stop, | |
| 848 uint64_t audio_debug_recordings_id, | |
| 849 const AudioDebugRecordingsCallback& callback, | |
| 850 const AudioDebugRecordingsErrorCallback& error_callback, | |
| 851 const base::FilePath& log_directory) { | |
| 852 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 853 DCHECK_LE(audio_debug_recordings_id, current_audio_debug_recordings_id_); | |
| 854 | |
| 855 base::FilePath prefix_path = GetAudioDebugRecordingsPrefixPath( | |
| 856 log_directory, audio_debug_recordings_id); | |
| 857 // Prevent an old posted StopAudioDebugRecordings() call to stop a newer dump. | |
| 858 // This could happen in a sequence like: | |
| 859 // Start(10); //Start dump 1. Post Stop() to run after 10 seconds. | |
| 860 // Stop(); // Manually stop dump 1 before 10 seconds; | |
| 861 // Start(20); // Start dump 2. Posted Stop() for 1 should not stop dump 2. | |
| 862 if (audio_debug_recordings_id < current_audio_debug_recordings_id_) { | |
| 863 callback.Run(prefix_path.AsUTF8Unsafe(), false /* not stopped */, | |
| 864 is_manual_stop); | |
| 865 return; | |
| 866 } | |
| 867 | |
| 868 if (!is_audio_debug_recordings_in_progress_) { | |
| 869 error_callback.Run("No audio debug recording in progress"); | |
| 870 return; | |
| 871 } | |
| 872 | |
| 873 host->DisableAudioDebugRecordings(); | |
| 874 is_audio_debug_recordings_in_progress_ = false; | |
| 875 callback.Run(prefix_path.AsUTF8Unsafe(), true /* stopped */, is_manual_stop); | |
| 876 } | |
| OLD | NEW |