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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 | 109 |
110 // Returns a path name to be used as prefix for audio debug recordings files. | 110 // Returns a path name to be used as prefix for audio debug recordings files. |
111 base::FilePath GetAudioDebugRecordingsPrefixPath( | 111 base::FilePath GetAudioDebugRecordingsPrefixPath( |
112 const base::FilePath& directory, | 112 const base::FilePath& directory, |
113 uint64_t audio_debug_recordings_id) { | 113 uint64_t audio_debug_recordings_id) { |
114 static const char kAudioDebugRecordingsFilePrefix[] = "AudioDebugRecordings."; | 114 static const char kAudioDebugRecordingsFilePrefix[] = "AudioDebugRecordings."; |
115 return directory.AppendASCII(kAudioDebugRecordingsFilePrefix + | 115 return directory.AppendASCII(kAudioDebugRecordingsFilePrefix + |
116 base::Int64ToString(audio_debug_recordings_id)); | 116 base::Int64ToString(audio_debug_recordings_id)); |
117 } | 117 } |
118 | 118 |
| 119 // Returns a path name to be used as prefix for RTC event log files. |
| 120 base::FilePath GetRtcEventLogPrefixPath(const base::FilePath& directory, |
| 121 uint64_t rtc_event_log_id) { |
| 122 static const char kRtcEventLogFilePrefix[] = "RtcEventLog."; |
| 123 return directory.AppendASCII(kRtcEventLogFilePrefix + |
| 124 base::Int64ToString(rtc_event_log_id)); |
| 125 } |
| 126 |
119 } // namespace | 127 } // namespace |
120 | 128 |
121 WebRtcLogBuffer::WebRtcLogBuffer() | 129 WebRtcLogBuffer::WebRtcLogBuffer() |
122 : buffer_(), | 130 : buffer_(), |
123 circular_(&buffer_[0], sizeof(buffer_), sizeof(buffer_) / 2, false), | 131 circular_(&buffer_[0], sizeof(buffer_), sizeof(buffer_) / 2, false), |
124 read_only_(false) { | 132 read_only_(false) { |
125 } | 133 } |
126 | 134 |
127 WebRtcLogBuffer::~WebRtcLogBuffer() { | 135 WebRtcLogBuffer::~WebRtcLogBuffer() { |
128 DCHECK(read_only_ || thread_checker_.CalledOnValidThread()); | 136 DCHECK(read_only_ || thread_checker_.CalledOnValidThread()); |
(...skipping 24 matching lines...) Expand all Loading... |
153 | 161 |
154 WebRtcLoggingHandlerHost::WebRtcLoggingHandlerHost( | 162 WebRtcLoggingHandlerHost::WebRtcLoggingHandlerHost( |
155 Profile* profile, | 163 Profile* profile, |
156 WebRtcLogUploader* log_uploader) | 164 WebRtcLogUploader* log_uploader) |
157 : BrowserMessageFilter(WebRtcLoggingMsgStart), | 165 : BrowserMessageFilter(WebRtcLoggingMsgStart), |
158 profile_(profile), | 166 profile_(profile), |
159 logging_state_(CLOSED), | 167 logging_state_(CLOSED), |
160 upload_log_on_render_close_(false), | 168 upload_log_on_render_close_(false), |
161 log_uploader_(log_uploader), | 169 log_uploader_(log_uploader), |
162 is_audio_debug_recordings_in_progress_(false), | 170 is_audio_debug_recordings_in_progress_(false), |
163 current_audio_debug_recordings_id_(0) { | 171 current_audio_debug_recordings_id_(0), |
| 172 is_rtc_event_logging_in_progress_(false), |
| 173 current_rtc_event_log_id_(0) { |
164 DCHECK(profile_); | 174 DCHECK(profile_); |
165 DCHECK(log_uploader_); | 175 DCHECK(log_uploader_); |
166 } | 176 } |
167 | 177 |
168 WebRtcLoggingHandlerHost::~WebRtcLoggingHandlerHost() { | 178 WebRtcLoggingHandlerHost::~WebRtcLoggingHandlerHost() { |
169 // If we hit this, then we might be leaking a log reference count (see | 179 // If we hit this, then we might be leaking a log reference count (see |
170 // ApplyForStartLogging). | 180 // ApplyForStartLogging). |
171 DCHECK_EQ(CLOSED, logging_state_); | 181 DCHECK_EQ(CLOSED, logging_state_); |
172 } | 182 } |
173 | 183 |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 // create/ensure the log directory. | 449 // create/ensure the log directory. |
440 if (rtp_dump_handler_) { | 450 if (rtp_dump_handler_) { |
441 rtp_dump_handler_->OnRtpPacket( | 451 rtp_dump_handler_->OnRtpPacket( |
442 packet_header.get(), header_length, packet_length, incoming); | 452 packet_header.get(), header_length, packet_length, incoming); |
443 } | 453 } |
444 } | 454 } |
445 | 455 |
446 void WebRtcLoggingHandlerHost::StartAudioDebugRecordings( | 456 void WebRtcLoggingHandlerHost::StartAudioDebugRecordings( |
447 content::RenderProcessHost* host, | 457 content::RenderProcessHost* host, |
448 base::TimeDelta delay, | 458 base::TimeDelta delay, |
449 const AudioDebugRecordingsCallback& callback, | 459 const TimeLimitedRecordingCallback& callback, |
450 const AudioDebugRecordingsErrorCallback& error_callback) { | 460 const TimeLimitedRecordingErrorCallback& error_callback) { |
451 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 461 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
452 | 462 |
453 BrowserThread::PostTaskAndReplyWithResult( | 463 BrowserThread::PostTaskAndReplyWithResult( |
454 BrowserThread::FILE, FROM_HERE, | 464 BrowserThread::FILE, FROM_HERE, |
455 base::Bind(&WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists, | 465 base::Bind(&WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists, |
456 this), | 466 this), |
457 base::Bind(&WebRtcLoggingHandlerHost::DoStartAudioDebugRecordings, this, | 467 base::Bind(&WebRtcLoggingHandlerHost::DoStartAudioDebugRecordings, this, |
458 host, delay, callback, error_callback)); | 468 host, delay, callback, error_callback)); |
459 } | 469 } |
460 | 470 |
461 void WebRtcLoggingHandlerHost::StopAudioDebugRecordings( | 471 void WebRtcLoggingHandlerHost::StopAudioDebugRecordings( |
462 content::RenderProcessHost* host, | 472 content::RenderProcessHost* host, |
463 const AudioDebugRecordingsCallback& callback, | 473 const TimeLimitedRecordingCallback& callback, |
464 const AudioDebugRecordingsErrorCallback& error_callback) { | 474 const TimeLimitedRecordingErrorCallback& error_callback) { |
465 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 475 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
466 BrowserThread::PostTaskAndReplyWithResult( | 476 BrowserThread::PostTaskAndReplyWithResult( |
467 BrowserThread::FILE, FROM_HERE, | 477 BrowserThread::FILE, FROM_HERE, |
468 base::Bind(&WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists, | 478 base::Bind(&WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists, |
469 this), | 479 this), |
470 base::Bind(&WebRtcLoggingHandlerHost::DoStopAudioDebugRecordings, this, | 480 base::Bind(&WebRtcLoggingHandlerHost::DoStopAudioDebugRecordings, this, |
471 host, true /* manual stop */, | 481 host, true /* manual stop */, |
472 current_audio_debug_recordings_id_, callback, error_callback)); | 482 current_audio_debug_recordings_id_, callback, error_callback)); |
473 } | 483 } |
474 | 484 |
| 485 void WebRtcLoggingHandlerHost::StartRtcEventLogging( |
| 486 content::RenderProcessHost* host, |
| 487 base::TimeDelta delay, |
| 488 const TimeLimitedRecordingCallback& callback, |
| 489 const TimeLimitedRecordingErrorCallback& error_callback) { |
| 490 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 491 |
| 492 BrowserThread::PostTaskAndReplyWithResult( |
| 493 BrowserThread::FILE, FROM_HERE, |
| 494 base::Bind(&WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists, |
| 495 this), |
| 496 base::Bind(&WebRtcLoggingHandlerHost::DoStartRtcEventLogging, this, host, |
| 497 delay, callback, error_callback)); |
| 498 } |
| 499 |
| 500 void WebRtcLoggingHandlerHost::StopRtcEventLogging( |
| 501 content::RenderProcessHost* host, |
| 502 const TimeLimitedRecordingCallback& callback, |
| 503 const TimeLimitedRecordingErrorCallback& error_callback) { |
| 504 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 505 BrowserThread::PostTaskAndReplyWithResult( |
| 506 BrowserThread::FILE, FROM_HERE, |
| 507 base::Bind(&WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists, |
| 508 this), |
| 509 base::Bind(&WebRtcLoggingHandlerHost::DoStopRtcEventLogging, this, host, |
| 510 true /* manual stop */, current_audio_debug_recordings_id_, |
| 511 callback, error_callback)); |
| 512 } |
| 513 |
475 void WebRtcLoggingHandlerHost::OnChannelClosing() { | 514 void WebRtcLoggingHandlerHost::OnChannelClosing() { |
476 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 515 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
477 if (logging_state_ == STARTED || logging_state_ == STOPPED) { | 516 if (logging_state_ == STARTED || logging_state_ == STOPPED) { |
478 if (upload_log_on_render_close_) { | 517 if (upload_log_on_render_close_) { |
479 logging_started_time_ = base::Time(); | 518 logging_started_time_ = base::Time(); |
480 | 519 |
481 content::BrowserThread::PostTaskAndReplyWithResult( | 520 content::BrowserThread::PostTaskAndReplyWithResult( |
482 content::BrowserThread::FILE, | 521 content::BrowserThread::FILE, |
483 FROM_HERE, | 522 FROM_HERE, |
484 base::Bind(&WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists, | 523 base::Bind(&WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists, |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
805 | 844 |
806 content::BrowserThread::PostTask( | 845 content::BrowserThread::PostTask( |
807 content::BrowserThread::UI, | 846 content::BrowserThread::UI, |
808 FROM_HERE, | 847 FROM_HERE, |
809 base::Bind(callback, success, error_message_with_state)); | 848 base::Bind(callback, success, error_message_with_state)); |
810 } | 849 } |
811 | 850 |
812 void WebRtcLoggingHandlerHost::DoStartAudioDebugRecordings( | 851 void WebRtcLoggingHandlerHost::DoStartAudioDebugRecordings( |
813 content::RenderProcessHost* host, | 852 content::RenderProcessHost* host, |
814 base::TimeDelta delay, | 853 base::TimeDelta delay, |
815 const AudioDebugRecordingsCallback& callback, | 854 const TimeLimitedRecordingCallback& callback, |
816 const AudioDebugRecordingsErrorCallback& error_callback, | 855 const TimeLimitedRecordingErrorCallback& error_callback, |
817 const base::FilePath& log_directory) { | 856 const base::FilePath& log_directory) { |
818 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 857 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
819 | 858 |
820 if (is_audio_debug_recordings_in_progress_) { | 859 if (is_audio_debug_recordings_in_progress_) { |
821 error_callback.Run("Audio debug recordings already in progress"); | 860 error_callback.Run("Audio debug recordings already in progress"); |
822 return; | 861 return; |
823 } | 862 } |
824 | 863 |
825 is_audio_debug_recordings_in_progress_ = true; | 864 is_audio_debug_recordings_in_progress_ = true; |
826 base::FilePath prefix_path = GetAudioDebugRecordingsPrefixPath( | 865 base::FilePath prefix_path = GetAudioDebugRecordingsPrefixPath( |
(...skipping 12 matching lines...) Expand all Loading... |
839 host, false /* no manual stop */, | 878 host, false /* no manual stop */, |
840 current_audio_debug_recordings_id_, callback, error_callback, | 879 current_audio_debug_recordings_id_, callback, error_callback, |
841 prefix_path), | 880 prefix_path), |
842 delay); | 881 delay); |
843 } | 882 } |
844 | 883 |
845 void WebRtcLoggingHandlerHost::DoStopAudioDebugRecordings( | 884 void WebRtcLoggingHandlerHost::DoStopAudioDebugRecordings( |
846 content::RenderProcessHost* host, | 885 content::RenderProcessHost* host, |
847 bool is_manual_stop, | 886 bool is_manual_stop, |
848 uint64_t audio_debug_recordings_id, | 887 uint64_t audio_debug_recordings_id, |
849 const AudioDebugRecordingsCallback& callback, | 888 const TimeLimitedRecordingCallback& callback, |
850 const AudioDebugRecordingsErrorCallback& error_callback, | 889 const TimeLimitedRecordingErrorCallback& error_callback, |
851 const base::FilePath& log_directory) { | 890 const base::FilePath& log_directory) { |
852 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 891 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
853 DCHECK_LE(audio_debug_recordings_id, current_audio_debug_recordings_id_); | 892 DCHECK_LE(audio_debug_recordings_id, current_audio_debug_recordings_id_); |
854 | 893 |
855 base::FilePath prefix_path = GetAudioDebugRecordingsPrefixPath( | 894 base::FilePath prefix_path = GetAudioDebugRecordingsPrefixPath( |
856 log_directory, audio_debug_recordings_id); | 895 log_directory, audio_debug_recordings_id); |
857 // Prevent an old posted StopAudioDebugRecordings() call to stop a newer dump. | 896 // Prevent an old posted StopAudioDebugRecordings() call to stop a newer dump. |
858 // This could happen in a sequence like: | 897 // This could happen in a sequence like: |
859 // Start(10); //Start dump 1. Post Stop() to run after 10 seconds. | 898 // Start(10); //Start dump 1. Post Stop() to run after 10 seconds. |
860 // Stop(); // Manually stop dump 1 before 10 seconds; | 899 // Stop(); // Manually stop dump 1 before 10 seconds; |
861 // Start(20); // Start dump 2. Posted Stop() for 1 should not stop dump 2. | 900 // 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_) { | 901 if (audio_debug_recordings_id < current_audio_debug_recordings_id_) { |
863 callback.Run(prefix_path.AsUTF8Unsafe(), false /* not stopped */, | 902 callback.Run(prefix_path.AsUTF8Unsafe(), false /* not stopped */, |
864 is_manual_stop); | 903 is_manual_stop); |
865 return; | 904 return; |
866 } | 905 } |
867 | 906 |
868 if (!is_audio_debug_recordings_in_progress_) { | 907 if (!is_audio_debug_recordings_in_progress_) { |
869 error_callback.Run("No audio debug recording in progress"); | 908 error_callback.Run("No audio debug recording in progress"); |
870 return; | 909 return; |
871 } | 910 } |
872 | 911 |
873 host->DisableAudioDebugRecordings(); | 912 host->DisableAudioDebugRecordings(); |
874 is_audio_debug_recordings_in_progress_ = false; | 913 is_audio_debug_recordings_in_progress_ = false; |
875 callback.Run(prefix_path.AsUTF8Unsafe(), true /* stopped */, is_manual_stop); | 914 callback.Run(prefix_path.AsUTF8Unsafe(), true /* stopped */, is_manual_stop); |
876 } | 915 } |
| 916 |
| 917 void WebRtcLoggingHandlerHost::DoStartRtcEventLogging( |
| 918 content::RenderProcessHost* host, |
| 919 base::TimeDelta delay, |
| 920 const TimeLimitedRecordingCallback& callback, |
| 921 const TimeLimitedRecordingErrorCallback& error_callback, |
| 922 const base::FilePath& log_directory) { |
| 923 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 924 |
| 925 if (is_rtc_event_logging_in_progress_) { |
| 926 error_callback.Run("RTC event logging already in progress"); |
| 927 return; |
| 928 } |
| 929 |
| 930 is_rtc_event_logging_in_progress_ = true; |
| 931 base::FilePath prefix_path = |
| 932 GetRtcEventLogPrefixPath(log_directory, ++current_rtc_event_log_id_); |
| 933 host->EnableEventLogRecordings(prefix_path); |
| 934 |
| 935 if (delay.is_zero()) { |
| 936 callback.Run(prefix_path.AsUTF8Unsafe(), false /* not stopped */, |
| 937 false /* not manually stopped */); |
| 938 return; |
| 939 } |
| 940 |
| 941 BrowserThread::PostDelayedTask( |
| 942 BrowserThread::UI, FROM_HERE, |
| 943 base::Bind(&WebRtcLoggingHandlerHost::DoStopRtcEventLogging, this, host, |
| 944 false /* no manual stop */, current_rtc_event_log_id_, |
| 945 callback, error_callback, prefix_path), |
| 946 delay); |
| 947 } |
| 948 |
| 949 void WebRtcLoggingHandlerHost::DoStopRtcEventLogging( |
| 950 content::RenderProcessHost* host, |
| 951 bool is_manual_stop, |
| 952 uint64_t rtc_event_log_id, |
| 953 const TimeLimitedRecordingCallback& callback, |
| 954 const TimeLimitedRecordingErrorCallback& error_callback, |
| 955 const base::FilePath& log_directory) { |
| 956 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 957 DCHECK_LE(rtc_event_log_id, current_rtc_event_log_id_); |
| 958 |
| 959 base::FilePath prefix_path = |
| 960 GetRtcEventLogPrefixPath(log_directory, rtc_event_log_id); |
| 961 // Prevent an old posted DoStopRtcEventLogging() call to stop a newer dump. |
| 962 // This could happen in a sequence like: |
| 963 // Start(10); //Start dump 1. Post Stop() to run after 10 seconds. |
| 964 // Stop(); // Manually stop dump 1 before 10 seconds; |
| 965 // Start(20); // Start dump 2. Posted Stop() for 1 should not stop dump 2. |
| 966 if (rtc_event_log_id < current_rtc_event_log_id_) { |
| 967 callback.Run(prefix_path.AsUTF8Unsafe(), false /* not stopped */, |
| 968 is_manual_stop); |
| 969 return; |
| 970 } |
| 971 |
| 972 if (!is_rtc_event_logging_in_progress_) { |
| 973 error_callback.Run("No RTC event logging in progress"); |
| 974 return; |
| 975 } |
| 976 |
| 977 host->DisableEventLogRecordings(); |
| 978 is_rtc_event_logging_in_progress_ = false; |
| 979 callback.Run(prefix_path.AsUTF8Unsafe(), true /* stopped */, is_manual_stop); |
| 980 } |
OLD | NEW |