OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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_EVENT_LOG_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_MEDIA_WEBRTC_EVENT_LOG_HANDLER_H_ |
6 #define CHROME_BROWSER_MEDIA_WEBRTC_EVENT_LOG_HANDLER_H_ | 6 #define CHROME_BROWSER_MEDIA_WEBRTC_EVENT_LOG_HANDLER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <set> | |
11 #include <string> | 12 #include <string> |
12 | 13 |
13 #include "base/callback.h" | 14 #include "base/callback.h" |
14 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
15 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
16 #include "base/threading/thread_checker.h" | 17 #include "base/threading/thread_checker.h" |
17 #include "base/time/time.h" | 18 #include "base/time/time.h" |
18 | 19 |
19 namespace content { | 20 namespace content { |
20 class RenderProcessHost; | 21 class RenderProcessHost; |
21 } // namespace content | 22 } // namespace content |
22 class Profile; | 23 class Profile; |
23 | 24 |
24 // WebRtcEventLogHandler provides an interface to start and stop | 25 // WebRtcEventLogHandler provides an interface to start and stop |
25 // the WebRTC event log. | 26 // the WebRTC event log. |
26 class WebRtcEventLogHandler | 27 class WebRtcEventLogHandler |
27 : public base::RefCountedThreadSafe<WebRtcEventLogHandler> { | 28 : public base::RefCountedThreadSafe<WebRtcEventLogHandler> { |
28 public: | 29 public: |
29 typedef base::Callback<void(bool, const std::string&)> GenericDoneCallback; | 30 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&)> RecordingErrorCallback; |
31 typedef base::Callback<void(const std::string&, bool, bool)> | 32 typedef base::Callback<void(const std::string&, bool, bool)> |
32 RecordingDoneCallback; | 33 RecordingDoneCallback; |
33 | 34 |
34 // Key used to attach the handler to the RenderProcessHost. | 35 // Key used to attach the handler to the RenderProcessHost. |
35 static const char kWebRtcEventLogHandlerKey[]; | 36 static const char kWebRtcEventLogHandlerKey[]; |
36 | 37 |
37 explicit WebRtcEventLogHandler(Profile* profile); | 38 WebRtcEventLogHandler(int host_id, Profile* profile); |
38 | 39 |
39 // Starts an RTC event log. The call writes the most recent events to a | 40 // Starts an RTC event log. The call writes the most recent events to a |
40 // file and then starts logging events for the given |delay|. | 41 // file and then starts logging events for the given |delay|. |
41 // If |delay| is zero, the logging will continue until | 42 // If |delay| is zero, the logging will continue until |
42 // StopWebRtcEventLogging() | 43 // StopWebRtcEventLogging() |
43 // is explicitly invoked. | 44 // is explicitly invoked. |
44 // |callback| is invoked once recording stops. If |delay| is zero | 45 // |callback| is invoked once recording stops. If |delay| is zero |
45 // |callback| is invoked once recording starts. | 46 // |callback| is invoked once recording starts. |
46 // If a recording was already in progress, |error_callback| is invoked instead | 47 // If a recording was already in progress, |error_callback| is invoked instead |
47 // of |callback|. | 48 // of |callback|. |
48 void StartWebRtcEventLogging(content::RenderProcessHost* host, | 49 void StartWebRtcEventLogging(content::RenderProcessHost* host, |
49 base::TimeDelta delay, | 50 base::TimeDelta delay, |
50 const RecordingDoneCallback& callback, | 51 const RecordingDoneCallback& callback, |
51 const RecordingErrorCallback& error_callback); | 52 const RecordingErrorCallback& error_callback); |
52 | 53 |
54 // Starts an RTC event log for each peerconnection on the specified |host|. | |
Henrik Grunell
2016/05/10 08:44:56
It's not clear to me how this function relates to
Ivo-OOO until feb 6
2016/05/12 13:23:23
Yes it does, I will add a comment to clarify that.
Henrik Grunell
2016/05/13 09:05:30
I also don't understand why one can specify either
| |
55 // A base file_path can be supplied, which will be extended to include several | |
56 // identifiers to ensure uniqueness. If a recording was already in progress, | |
57 // this call will be ignored. | |
58 void StartWebRtcEventLogging(content::RenderProcessHost* host, | |
59 const base::FilePath& file_path); | |
60 | |
53 // Stops an RTC event log. |callback| is invoked once recording | 61 // Stops an RTC event log. |callback| is invoked once recording |
54 // stops. If no recording was in progress, |error_callback| is invoked instead | 62 // stops. If no recording was in progress, |error_callback| is invoked instead |
55 // of |callback|. | 63 // of |callback|. |
56 void StopWebRtcEventLogging(content::RenderProcessHost* host, | 64 void StopWebRtcEventLogging(content::RenderProcessHost* host, |
57 const RecordingDoneCallback& callback, | 65 const RecordingDoneCallback& callback, |
58 const RecordingErrorCallback& error_callback); | 66 const RecordingErrorCallback& error_callback); |
59 | 67 |
68 // Stops an RTC event log for each peerconnection on the specified |host|. | |
69 // If no recording was in progress, this call has no effect. | |
70 void StopWebRtcEventLogging(content::RenderProcessHost* host); | |
71 | |
72 // Signal that a PeerConnection was added to the RenderProcessHost | |
73 // identified by |render_id|. | |
74 void OnPeerConnectionAdded(int render_id, int local_id); | |
dcheng
2016/05/10 06:48:17
Nit: Call this |process_id| to be consistent with
Ivo-OOO until feb 6
2016/05/12 13:23:23
Good idea, done. I changed the argument to the con
| |
75 | |
76 // Signal that a PeerConnection was removed from the RenderProcessHost | |
77 // identified by |render_id|. | |
78 void OnPeerConnectionRemoved(int render_id, int local_id); | |
79 | |
60 private: | 80 private: |
61 friend class base::RefCountedThreadSafe<WebRtcEventLogHandler>; | 81 friend class base::RefCountedThreadSafe<WebRtcEventLogHandler>; |
62 virtual ~WebRtcEventLogHandler(); | 82 virtual ~WebRtcEventLogHandler(); |
63 | 83 |
64 base::FilePath GetLogDirectoryAndEnsureExists(); | 84 base::FilePath GetLogDirectoryAndEnsureExists(); |
65 | 85 |
66 // Helper for starting RTC event logs. | 86 // Helper for starting RTC event logs. |
67 void DoStartWebRtcEventLogging(content::RenderProcessHost* host, | 87 void DoStartWebRtcEventLogging(content::RenderProcessHost* host, |
68 base::TimeDelta delay, | 88 base::TimeDelta delay, |
69 const RecordingDoneCallback& callback, | 89 const RecordingDoneCallback& callback, |
70 const RecordingErrorCallback& error_callback, | 90 const RecordingErrorCallback& error_callback, |
71 const base::FilePath& log_directory); | 91 const base::FilePath& log_directory); |
72 | 92 |
73 // Helper for stopping RTC event logs. | 93 // Helper for stopping RTC event logs. |
74 void DoStopWebRtcEventLogging(content::RenderProcessHost* host, | 94 void DoStopWebRtcEventLogging(content::RenderProcessHost* host, |
75 bool is_manual_stop, | 95 bool is_manual_stop, |
76 uint64_t audio_debug_recordings_id, | 96 uint64_t audio_debug_recordings_id, |
77 const RecordingDoneCallback& callback, | 97 const RecordingDoneCallback& callback, |
78 const RecordingErrorCallback& error_callback, | 98 const RecordingErrorCallback& error_callback, |
79 const base::FilePath& log_directory); | 99 const base::FilePath& log_directory); |
80 | 100 |
81 // The profile associated with our renderer process. | 101 // The profile associated with our renderer process. |
82 Profile* const profile_; | 102 Profile* const profile_; |
83 | 103 |
84 // Must be accessed on the UI thread. | 104 // Must be accessed on the UI thread. |
85 bool is_rtc_event_logging_in_progress_; | 105 bool is_rtc_event_logging_in_progress_; |
86 | 106 |
107 // In case new PeerConnections are created during logging, the path is needed | |
108 // to enable logging for them. | |
109 base::FilePath base_file_path_; | |
110 | |
111 // The local identifiers of all the currently active PeerConnections. | |
112 std::set<int> active_peer_connection_lid_; | |
Henrik Grunell
2016/05/10 08:44:56
Write out what "l" stands for. (local?)
Ivo-OOO until feb 6
2016/05/12 13:23:23
Done.
| |
113 | |
114 // Number of log files that can be created. | |
115 int number_log_files_; | |
Henrik Grunell
2016/05/10 08:44:56
So, this is the max number of files allowed? If so
Ivo-OOO until feb 6
2016/05/12 13:23:23
This is the not the maximum, but the number of fil
Henrik Grunell
2016/05/13 09:05:30
I think it's clearer to have this variable count t
| |
116 | |
87 // This counter allows saving each log in a separate file. | 117 // This counter allows saving each log in a separate file. |
88 uint64_t current_rtc_event_log_id_; | 118 uint64_t current_rtc_event_log_id_; |
89 | 119 |
90 base::ThreadChecker thread_checker_; | 120 base::ThreadChecker thread_checker_; |
91 DISALLOW_COPY_AND_ASSIGN(WebRtcEventLogHandler); | 121 DISALLOW_COPY_AND_ASSIGN(WebRtcEventLogHandler); |
92 }; | 122 }; |
93 | 123 |
94 #endif // CHROME_BROWSER_MEDIA_WEBRTC_EVENT_LOG_HANDLER_H_ | 124 #endif // CHROME_BROWSER_MEDIA_WEBRTC_EVENT_LOG_HANDLER_H_ |
OLD | NEW |