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_AUDIO_DEBUG_RECORDINGS_HANDLER_H_ |
| 6 #define CHROME_BROWSER_MEDIA_AUDIO_DEBUG_RECORDINGS_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 |
| 23 class Profile; |
| 24 |
| 25 // AudioDebugRecordingsHandler provides an interface to start and stop |
| 26 // AudioDebugRecordings, including WebRTC AEC dumps. |
| 27 class AudioDebugRecordingsHandler |
| 28 : public base::RefCountedThreadSafe<AudioDebugRecordingsHandler> { |
| 29 public: |
| 30 typedef base::Callback<void(bool, const std::string&)> GenericDoneCallback; |
| 31 typedef base::Callback<void(const std::string&)> RecordingErrorCallback; |
| 32 typedef base::Callback<void(const std::string&, bool, bool)> |
| 33 RecordingDoneCallback; |
| 34 |
| 35 // Key used to attach the handler to the RenderProcessHost |
| 36 static const char kAudioDebugRecordingsHandlerKey[]; |
| 37 |
| 38 explicit AudioDebugRecordingsHandler(Profile* profile); |
| 39 |
| 40 // Starts an audio debug recording. The recording lasts the given |delay|, |
| 41 // unless |delay| is zero, in which case recording will continue until |
| 42 // StopAudioDebugRecordings() is explicitly invoked. |
| 43 // |callback| is invoked once recording stops. If |delay| is zero |
| 44 // |callback| is invoked once recording starts. |
| 45 // If a recording was already in progress, |error_callback| is invoked instead |
| 46 // of |callback|. |
| 47 void StartAudioDebugRecordings(content::RenderProcessHost* host, |
| 48 base::TimeDelta delay, |
| 49 const RecordingDoneCallback& callback, |
| 50 const RecordingErrorCallback& error_callback); |
| 51 |
| 52 // Stops an audio debug recording. |callback| is invoked once recording |
| 53 // stops. If no recording was in progress, |error_callback| is invoked instead |
| 54 // of |callback|. |
| 55 void StopAudioDebugRecordings(content::RenderProcessHost* host, |
| 56 const RecordingDoneCallback& callback, |
| 57 const RecordingErrorCallback& error_callback); |
| 58 |
| 59 private: |
| 60 friend class base::RefCountedThreadSafe<AudioDebugRecordingsHandler>; |
| 61 |
| 62 virtual ~AudioDebugRecordingsHandler(); |
| 63 |
| 64 base::FilePath GetLogDirectoryAndEnsureExists(); |
| 65 |
| 66 // Helper for starting audio debug recordings. |
| 67 void DoStartAudioDebugRecordings(content::RenderProcessHost* host, |
| 68 base::TimeDelta delay, |
| 69 const RecordingDoneCallback& callback, |
| 70 const RecordingErrorCallback& error_callback, |
| 71 const base::FilePath& log_directory); |
| 72 |
| 73 // Helper for stopping audio debug recordings. |
| 74 void DoStopAudioDebugRecordings(content::RenderProcessHost* host, |
| 75 bool is_manual_stop, |
| 76 uint64_t audio_debug_recordings_id, |
| 77 const RecordingDoneCallback& callback, |
| 78 const RecordingErrorCallback& error_callback, |
| 79 const base::FilePath& log_directory); |
| 80 |
| 81 // The profile associated with our renderer process. |
| 82 Profile* const profile_; |
| 83 |
| 84 // Must be accessed on the UI thread. |
| 85 bool is_audio_debug_recordings_in_progress_; |
| 86 |
| 87 // This counter allows saving each debug recording in separate files. |
| 88 uint64_t current_audio_debug_recordings_id_; |
| 89 |
| 90 base::ThreadChecker thread_checker_; |
| 91 DISALLOW_COPY_AND_ASSIGN(AudioDebugRecordingsHandler); |
| 92 }; |
| 93 |
| 94 #endif // CHROME_BROWSER_MEDIA_AUDIO_DEBUG_RECORDINGS_HANDLER_H_ |
OLD | NEW |