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 #ifndef CHROME_BROWSER_MEDIA_WEBRTC_LOGGING_HANDLER_HOST_H_ | 5 #ifndef CHROME_BROWSER_MEDIA_WEBRTC_LOGGING_HANDLER_HOST_H_ |
6 #define CHROME_BROWSER_MEDIA_WEBRTC_LOGGING_HANDLER_HOST_H_ | 6 #define CHROME_BROWSER_MEDIA_WEBRTC_LOGGING_HANDLER_HOST_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
| 11 #include <map> |
| 12 #include <string> |
| 13 #include <vector> |
| 14 |
11 #include "base/macros.h" | 15 #include "base/macros.h" |
12 #include "base/memory/shared_memory.h" | 16 #include "base/memory/shared_memory.h" |
13 #include "build/build_config.h" | 17 #include "build/build_config.h" |
14 #include "chrome/browser/media/rtp_dump_type.h" | 18 #include "chrome/browser/media/rtp_dump_type.h" |
15 #include "chrome/browser/media/webrtc_rtp_dump_handler.h" | 19 #include "chrome/browser/media/webrtc_rtp_dump_handler.h" |
16 #include "chrome/common/media/webrtc_logging_message_data.h" | 20 #include "chrome/common/media/webrtc_logging_message_data.h" |
17 #include "chrome/common/partial_circular_buffer.h" | 21 #include "chrome/common/partial_circular_buffer.h" |
18 #include "content/public/browser/browser_message_filter.h" | 22 #include "content/public/browser/browser_message_filter.h" |
19 #include "content/public/browser/render_process_host.h" | 23 #include "content/public/browser/render_process_host.h" |
20 #include "net/base/network_interfaces.h" | 24 #include "net/base/network_interfaces.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 // - Informs the handler in the render process when to stop logging. | 78 // - Informs the handler in the render process when to stop logging. |
75 // - Closes the shared memory (and thereby discarding it) or triggers uploading | 79 // - Closes the shared memory (and thereby discarding it) or triggers uploading |
76 // of the log. | 80 // of the log. |
77 // - Detects when channel, i.e. renderer, is going away and possibly triggers | 81 // - Detects when channel, i.e. renderer, is going away and possibly triggers |
78 // uploading the log. | 82 // uploading the log. |
79 class WebRtcLoggingHandlerHost : public content::BrowserMessageFilter { | 83 class WebRtcLoggingHandlerHost : public content::BrowserMessageFilter { |
80 public: | 84 public: |
81 typedef base::Callback<void(bool, const std::string&)> GenericDoneCallback; | 85 typedef base::Callback<void(bool, const std::string&)> GenericDoneCallback; |
82 typedef base::Callback<void(bool, const std::string&, const std::string&)> | 86 typedef base::Callback<void(bool, const std::string&, const std::string&)> |
83 UploadDoneCallback; | 87 UploadDoneCallback; |
84 typedef base::Callback<void(const std::string&)> | 88 |
85 AudioDebugRecordingsErrorCallback; | 89 // Key used to attach the handler to the RenderProcessHost. |
86 typedef base::Callback<void(const std::string&, bool, bool)> | 90 static const char kWebRtcLoggingHandlerHostKey[]; |
87 AudioDebugRecordingsCallback; | |
88 | 91 |
89 WebRtcLoggingHandlerHost(int render_process_id, | 92 WebRtcLoggingHandlerHost(int render_process_id, |
90 Profile* profile, | 93 Profile* profile, |
91 WebRtcLogUploader* log_uploader); | 94 WebRtcLogUploader* log_uploader); |
92 | 95 |
93 // Sets meta data that will be uploaded along with the log and also written | 96 // Sets meta data that will be uploaded along with the log and also written |
94 // in the beginning of the log. Must be called on the IO thread before calling | 97 // in the beginning of the log. Must be called on the IO thread before calling |
95 // StartLogging. | 98 // StartLogging. |
96 void SetMetaData(std::unique_ptr<MetaDataMap> meta_data, | 99 void SetMetaData(std::unique_ptr<MetaDataMap> meta_data, |
97 const GenericDoneCallback& callback); | 100 const GenericDoneCallback& callback); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 // done. | 152 // done. |
150 void StopRtpDump(RtpDumpType type, const GenericDoneCallback& callback); | 153 void StopRtpDump(RtpDumpType type, const GenericDoneCallback& callback); |
151 | 154 |
152 // Called when an RTP packet is sent or received. Must be called on the UI | 155 // Called when an RTP packet is sent or received. Must be called on the UI |
153 // thread. | 156 // thread. |
154 void OnRtpPacket(std::unique_ptr<uint8_t[]> packet_header, | 157 void OnRtpPacket(std::unique_ptr<uint8_t[]> packet_header, |
155 size_t header_length, | 158 size_t header_length, |
156 size_t packet_length, | 159 size_t packet_length, |
157 bool incoming); | 160 bool incoming); |
158 | 161 |
159 // Starts an audio debug recording. The recording lasts the given |delay|, | |
160 // unless |delay| is zero, in which case recording will continue until | |
161 // StopAudioDebugRecordings() is explicitly invoked. | |
162 // |callback| is invoked once recording stops. If |delay| is zero | |
163 // |callback| is invoked once recording starts. | |
164 // If a recording was already in progress, |error_callback| is invoked instead | |
165 // of |callback|. | |
166 void StartAudioDebugRecordings( | |
167 content::RenderProcessHost* host, | |
168 base::TimeDelta delay, | |
169 const AudioDebugRecordingsCallback& callback, | |
170 const AudioDebugRecordingsErrorCallback& error_callback); | |
171 | |
172 // Stops an audio debug recording. |callback| is invoked once recording | |
173 // stops. If no recording was in progress, |error_callback| is invoked instead | |
174 // of |callback|. | |
175 void StopAudioDebugRecordings( | |
176 content::RenderProcessHost* host, | |
177 const AudioDebugRecordingsCallback& callback, | |
178 const AudioDebugRecordingsErrorCallback& error_callback); | |
179 | |
180 private: | 162 private: |
181 // States used for protecting from function calls made at non-allowed points | 163 // States used for protecting from function calls made at non-allowed points |
182 // in time. For example, StartLogging() is only allowed in CLOSED state. | 164 // in time. For example, StartLogging() is only allowed in CLOSED state. |
183 // Transitions: SetMetaData(): CLOSED -> CLOSED. | 165 // Transitions: SetMetaData(): CLOSED -> CLOSED. |
184 // StartLogging(): CLOSED -> STARTING. | 166 // StartLogging(): CLOSED -> STARTING. |
185 // Start done: STARTING -> STARTED. | 167 // Start done: STARTING -> STARTED. |
186 // StopLogging(): STARTED -> STOPPING. | 168 // StopLogging(): STARTED -> STOPPING. |
187 // Stop done: STOPPING -> STOPPED. | 169 // Stop done: STOPPING -> STOPPED. |
188 // UploadLog(): STOPPED -> UPLOADING. | 170 // UploadLog(): STOPPED -> UPLOADING. |
189 // Upload done: UPLOADING -> CLOSED. | 171 // Upload done: UPLOADING -> CLOSED. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 size_t packet_length, | 241 size_t packet_length, |
260 bool incoming); | 242 bool incoming); |
261 | 243 |
262 bool ReleaseRtpDumps(WebRtcLogPaths* log_paths); | 244 bool ReleaseRtpDumps(WebRtcLogPaths* log_paths); |
263 | 245 |
264 void FireGenericDoneCallback( | 246 void FireGenericDoneCallback( |
265 const WebRtcLoggingHandlerHost::GenericDoneCallback& callback, | 247 const WebRtcLoggingHandlerHost::GenericDoneCallback& callback, |
266 bool success, | 248 bool success, |
267 const std::string& error_message); | 249 const std::string& error_message); |
268 | 250 |
269 // Helper for starting audio debug recordings. | |
270 void DoStartAudioDebugRecordings( | |
271 content::RenderProcessHost* host, | |
272 base::TimeDelta delay, | |
273 const AudioDebugRecordingsCallback& callback, | |
274 const AudioDebugRecordingsErrorCallback& error_callback, | |
275 const base::FilePath& log_directory); | |
276 | |
277 // Helper for stopping audio debug recordings. | |
278 void DoStopAudioDebugRecordings( | |
279 content::RenderProcessHost* host, | |
280 bool is_manual_stop, | |
281 uint64_t audio_debug_recordings_id, | |
282 const AudioDebugRecordingsCallback& callback, | |
283 const AudioDebugRecordingsErrorCallback& error_callback, | |
284 const base::FilePath& log_directory); | |
285 | |
286 std::unique_ptr<WebRtcLogBuffer> log_buffer_; | 251 std::unique_ptr<WebRtcLogBuffer> log_buffer_; |
287 | 252 |
288 // The profile associated with our renderer process. | 253 // The profile associated with our renderer process. |
289 Profile* const profile_; | 254 Profile* const profile_; |
290 | 255 |
291 // These are only accessed on the IO thread, except when in STARTING state. In | 256 // These are only accessed on the IO thread, except when in STARTING state. In |
292 // this state we are protected since entering any function that alters the | 257 // this state we are protected since entering any function that alters the |
293 // state is not allowed. | 258 // state is not allowed. |
294 std::unique_ptr<MetaDataMap> meta_data_; | 259 std::unique_ptr<MetaDataMap> meta_data_; |
295 | 260 |
(...skipping 21 matching lines...) Expand all Loading... |
317 // The RTP dump handler responsible for creating the RTP header dump files. | 282 // The RTP dump handler responsible for creating the RTP header dump files. |
318 std::unique_ptr<WebRtcRtpDumpHandler> rtp_dump_handler_; | 283 std::unique_ptr<WebRtcRtpDumpHandler> rtp_dump_handler_; |
319 | 284 |
320 // The callback to call when StopRtpDump is called. | 285 // The callback to call when StopRtpDump is called. |
321 content::RenderProcessHost::WebRtcStopRtpDumpCallback stop_rtp_dump_callback_; | 286 content::RenderProcessHost::WebRtcStopRtpDumpCallback stop_rtp_dump_callback_; |
322 | 287 |
323 // A pointer to the log uploader that's shared for all profiles. | 288 // A pointer to the log uploader that's shared for all profiles. |
324 // Ownership lies with the browser process. | 289 // Ownership lies with the browser process. |
325 WebRtcLogUploader* const log_uploader_; | 290 WebRtcLogUploader* const log_uploader_; |
326 | 291 |
327 // Must be accessed on the UI thread. | |
328 bool is_audio_debug_recordings_in_progress_; | |
329 | |
330 // This counter allows saving each debug recording in separate files. | |
331 uint64_t current_audio_debug_recordings_id_; | |
332 | |
333 // The render process ID this object belongs to. | 292 // The render process ID this object belongs to. |
334 int render_process_id_; | 293 int render_process_id_; |
335 | 294 |
336 DISALLOW_COPY_AND_ASSIGN(WebRtcLoggingHandlerHost); | 295 DISALLOW_COPY_AND_ASSIGN(WebRtcLoggingHandlerHost); |
337 }; | 296 }; |
338 | 297 |
339 #endif // CHROME_BROWSER_MEDIA_WEBRTC_LOGGING_HANDLER_HOST_H_ | 298 #endif // CHROME_BROWSER_MEDIA_WEBRTC_LOGGING_HANDLER_HOST_H_ |
OLD | NEW |