| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_MEDIA_WEBRTC_EVENT_LOG_HANDLER_H_ | |
| 6 #define CHROME_BROWSER_MEDIA_WEBRTC_EVENT_LOG_HANDLER_H_ | |
| 7 | |
| 8 #include <stddef.h> | |
| 9 #include <stdint.h> | |
| 10 | |
| 11 #include <string> | |
| 12 | |
| 13 #include "base/callback.h" | |
| 14 #include "base/files/file_path.h" | |
| 15 #include "base/memory/ref_counted.h" | |
| 16 #include "base/threading/thread_checker.h" | |
| 17 #include "base/time/time.h" | |
| 18 | |
| 19 namespace content { | |
| 20 class RenderProcessHost; | |
| 21 } // namespace content | |
| 22 class Profile; | |
| 23 | |
| 24 // WebRtcEventLogHandler provides an interface to start and stop | |
| 25 // the WebRTC event log. | |
| 26 class WebRtcEventLogHandler | |
| 27 : public base::RefCountedThreadSafe<WebRtcEventLogHandler> { | |
| 28 public: | |
| 29 typedef base::Callback<void(bool, const std::string&)> GenericDoneCallback; | |
| 30 typedef base::Callback<void(const std::string&)> RecordingErrorCallback; | |
| 31 typedef base::Callback<void(const std::string&, bool, bool)> | |
| 32 RecordingDoneCallback; | |
| 33 | |
| 34 // Key used to attach the handler to the RenderProcessHost. | |
| 35 static const char kWebRtcEventLogHandlerKey[]; | |
| 36 | |
| 37 explicit WebRtcEventLogHandler(Profile* profile); | |
| 38 | |
| 39 // Starts an RTC event log for each peerconnection on the specified |host|. | |
| 40 // The call writes the most recent events to a file and then starts logging | |
| 41 // events for the given |delay|. | |
| 42 // If |delay| is zero, the logging will continue until | |
| 43 // StopWebRtcEventLogging() | |
| 44 // is explicitly invoked. | |
| 45 // |callback| is invoked once recording stops. If |delay| is zero | |
| 46 // |callback| is invoked once recording starts. | |
| 47 // If a recording was already in progress, |error_callback| is invoked instead | |
| 48 // of |callback|. | |
| 49 void StartWebRtcEventLogging(content::RenderProcessHost* host, | |
| 50 base::TimeDelta delay, | |
| 51 const RecordingDoneCallback& callback, | |
| 52 const RecordingErrorCallback& error_callback); | |
| 53 | |
| 54 // Stops an RTC event log. |callback| is invoked once recording | |
| 55 // stops. If no recording was in progress, |error_callback| is invoked instead | |
| 56 // of |callback|. | |
| 57 void StopWebRtcEventLogging(content::RenderProcessHost* host, | |
| 58 const RecordingDoneCallback& callback, | |
| 59 const RecordingErrorCallback& error_callback); | |
| 60 | |
| 61 private: | |
| 62 friend class base::RefCountedThreadSafe<WebRtcEventLogHandler>; | |
| 63 virtual ~WebRtcEventLogHandler(); | |
| 64 | |
| 65 base::FilePath GetLogDirectoryAndEnsureExists(); | |
| 66 | |
| 67 // Helper for starting RTC event logs. | |
| 68 void DoStartWebRtcEventLogging(content::RenderProcessHost* host, | |
| 69 base::TimeDelta delay, | |
| 70 const RecordingDoneCallback& callback, | |
| 71 const RecordingErrorCallback& error_callback, | |
| 72 const base::FilePath& log_directory); | |
| 73 | |
| 74 // Helper for stopping RTC event logs. | |
| 75 void DoStopWebRtcEventLogging(content::RenderProcessHost* host, | |
| 76 bool is_manual_stop, | |
| 77 uint64_t audio_debug_recordings_id, | |
| 78 const RecordingDoneCallback& callback, | |
| 79 const RecordingErrorCallback& error_callback, | |
| 80 const base::FilePath& log_directory); | |
| 81 | |
| 82 // The profile associated with our renderer process. | |
| 83 Profile* const profile_; | |
| 84 | |
| 85 // This counter allows saving each log in a separate file. | |
| 86 uint64_t current_rtc_event_log_id_; | |
| 87 | |
| 88 base::ThreadChecker thread_checker_; | |
| 89 DISALLOW_COPY_AND_ASSIGN(WebRtcEventLogHandler); | |
| 90 }; | |
| 91 | |
| 92 #endif // CHROME_BROWSER_MEDIA_WEBRTC_EVENT_LOG_HANDLER_H_ | |
| OLD | NEW |