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 "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/shared_memory.h" | 9 #include "base/memory/shared_memory.h" |
| 10 #include "chrome/browser/media/rtp_dump_type.h" |
| 11 #include "chrome/browser/media/webrtc_rtp_dump_handler.h" |
10 #include "chrome/common/media/webrtc_logging_message_data.h" | 12 #include "chrome/common/media/webrtc_logging_message_data.h" |
11 #include "content/public/browser/browser_message_filter.h" | 13 #include "content/public/browser/browser_message_filter.h" |
| 14 #include "content/public/browser/render_process_host.h" |
12 #include "net/base/net_util.h" | 15 #include "net/base/net_util.h" |
13 | 16 |
14 namespace net { | 17 namespace net { |
15 class URLRequestContextGetter; | 18 class URLRequestContextGetter; |
16 } // namespace net | 19 } // namespace net |
17 | 20 |
18 class PartialCircularBuffer; | 21 class PartialCircularBuffer; |
19 class Profile; | 22 class Profile; |
20 class RenderProcessHost; | |
21 | 23 |
22 typedef std::map<std::string, std::string> MetaDataMap; | 24 typedef std::map<std::string, std::string> MetaDataMap; |
23 | 25 |
24 // WebRtcLoggingHandlerHost handles operations regarding the WebRTC logging: | 26 // WebRtcLoggingHandlerHost handles operations regarding the WebRTC logging: |
25 // - Opens a shared memory buffer that the handler in the render process | 27 // - Opens a shared memory buffer that the handler in the render process |
26 // writes to. | 28 // writes to. |
27 // - Writes basic machine info to the log. | 29 // - Writes basic machine info to the log. |
28 // - Informs the handler in the render process when to stop logging. | 30 // - Informs the handler in the render process when to stop logging. |
29 // - Closes the shared memory (and thereby discarding it) or triggers uploading | 31 // - Closes the shared memory (and thereby discarding it) or triggers uploading |
30 // of the log. | 32 // of the log. |
(...skipping 13 matching lines...) Expand all Loading... |
44 void SetMetaData(const MetaDataMap& meta_data, | 46 void SetMetaData(const MetaDataMap& meta_data, |
45 const GenericDoneCallback& callback); | 47 const GenericDoneCallback& callback); |
46 | 48 |
47 // Opens a log and starts logging. Must be called on the IO thread. | 49 // Opens a log and starts logging. Must be called on the IO thread. |
48 void StartLogging(const GenericDoneCallback& callback); | 50 void StartLogging(const GenericDoneCallback& callback); |
49 | 51 |
50 // Stops logging. Log will remain open until UploadLog or DiscardLog is | 52 // Stops logging. Log will remain open until UploadLog or DiscardLog is |
51 // called. Must be called on the IO thread. | 53 // called. Must be called on the IO thread. |
52 void StopLogging(const GenericDoneCallback& callback); | 54 void StopLogging(const GenericDoneCallback& callback); |
53 | 55 |
54 // Uploads the log and discards the local copy. May only be called after | 56 // Uploads the log and the RTP dumps. Discards the local copy. May only be |
55 // logging has stopped. Must be called on the IO thread. | 57 // called after logging has stopped. Must be called on the IO thread. |
56 void UploadLog(const UploadDoneCallback& callback); | 58 void UploadLog(const UploadDoneCallback& callback); |
57 | 59 |
58 // Called by WebRtcLogUploader when uploading has finished. Must be called on | 60 // Called by WebRtcLogUploader when uploading has finished. Must be called on |
59 // the IO thread. | 61 // the IO thread. |
60 void UploadLogDone(); | 62 void UploadLogDone(); |
61 | 63 |
62 // Discards the log. May only be called after logging has stopped. Must be | 64 // Discards the log and the RTP dumps. May only be called after logging has |
63 // called on the IO thread. | 65 // stopped. Must be called on the IO thread. |
64 void DiscardLog(const GenericDoneCallback& callback); | 66 void DiscardLog(const GenericDoneCallback& callback); |
65 | 67 |
66 // Adds a message to the log. | 68 // Adds a message to the log. |
67 void LogMessage(const std::string& message); | 69 void LogMessage(const std::string& message); |
68 | 70 |
69 // May be called on any thread. |upload_log_on_render_close_| is used | 71 // May be called on any thread. |upload_log_on_render_close_| is used |
70 // for decision making and it's OK if it changes before the execution based | 72 // for decision making and it's OK if it changes before the execution based |
71 // on that decision has finished. | 73 // on that decision has finished. |
72 void set_upload_log_on_render_close(bool should_upload) { | 74 void set_upload_log_on_render_close(bool should_upload) { |
73 upload_log_on_render_close_ = should_upload; | 75 upload_log_on_render_close_ = should_upload; |
74 } | 76 } |
75 | 77 |
76 // Starts dumping the RTP headers for the specified direction. Must be called | 78 // Starts dumping the RTP headers for the specified direction. Must be called |
77 // on the IO thread. |incoming| and |outgoing| specifies which direction(s) of | 79 // on the IO thread. |type| specifies which direction(s) of RTP packets should |
78 // RTP packets should be dumped. |callback| will be called when starting the | 80 // be dumped. |callback| will be called when starting the dump is done. |
79 // dump is done. | 81 // |stop_callback| will be called when StopRtpDump is called. |
80 void StartRtpDump(bool incoming, | 82 void StartRtpDump(RtpDumpType type, |
81 bool outgoing, | 83 const GenericDoneCallback& callback, |
82 const GenericDoneCallback& callback); | 84 const content::RenderProcessHost::WebRtcStopRtpDumpCallback& |
| 85 stop_callback); |
83 | 86 |
84 // Stops dumping the RTP headers for the specified direction. Must be called | 87 // Stops dumping the RTP headers for the specified direction. Must be called |
85 // on the IO thread. |incoming| and |outgoing| specifies which direction(s) of | 88 // on the IO thread. |type| specifies which direction(s) of RTP packet dumping |
86 // RTP packet dumping should be stopped. |callback| will be called when | 89 // should be stopped. |callback| will be called when stopping the dump is |
87 // stopping the dump is done. | 90 // done. |
88 void StopRtpDump(bool incoming, | 91 void StopRtpDump(RtpDumpType type, const GenericDoneCallback& callback); |
89 bool outgoing, | 92 |
90 const GenericDoneCallback& callback); | 93 // Called when an RTP packet is sent or received. Must be called on the UI |
| 94 // thread. |
| 95 void OnRtpPacket(const uint8* packet_header, |
| 96 size_t header_length, |
| 97 size_t packet_length, |
| 98 bool incoming); |
91 | 99 |
92 private: | 100 private: |
93 // States used for protecting from function calls made at non-allowed points | 101 // States used for protecting from function calls made at non-allowed points |
94 // in time. For example, StartLogging() is only allowed in CLOSED state. | 102 // in time. For example, StartLogging() is only allowed in CLOSED state. |
95 // Transitions: SetMetaData(): CLOSED -> CLOSED. | 103 // Transitions: SetMetaData(): CLOSED -> CLOSED. |
96 // StartLogging(): CLOSED -> STARTING. | 104 // StartLogging(): CLOSED -> STARTING. |
97 // Start done: STARTING -> STARTED. | 105 // Start done: STARTING -> STARTED. |
98 // StopLogging(): STARTED -> STOPPING. | 106 // StopLogging(): STARTED -> STOPPING. |
99 // Stop done: STOPPING -> STOPPED. | 107 // Stop done: STOPPING -> STOPPED. |
100 // UploadLog(): STOPPED -> UPLOADING. | 108 // UploadLog(): STOPPED -> UPLOADING. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 void LogInitialInfoOnIOThread(const net::NetworkInterfaceList& network_list); | 141 void LogInitialInfoOnIOThread(const net::NetworkInterfaceList& network_list); |
134 void NotifyLoggingStarted(); | 142 void NotifyLoggingStarted(); |
135 | 143 |
136 // Writes a formatted log |message| to the |circular_buffer_|. | 144 // Writes a formatted log |message| to the |circular_buffer_|. |
137 void LogToCircularBuffer(const std::string& message); | 145 void LogToCircularBuffer(const std::string& message); |
138 | 146 |
139 // Gets the log directory path for |profile_| and ensure it exists. Must be | 147 // Gets the log directory path for |profile_| and ensure it exists. Must be |
140 // called on the FILE thread. | 148 // called on the FILE thread. |
141 base::FilePath GetLogDirectoryAndEnsureExists(); | 149 base::FilePath GetLogDirectoryAndEnsureExists(); |
142 | 150 |
143 void TriggerUploadLog(const base::FilePath& log_directory); | 151 void TriggerUpload(const base::FilePath& log_directory); |
| 152 |
| 153 // A helper for TriggerUpload to do the real work. |
| 154 void DoUploadLogAndRtpDumps(const base::FilePath& log_directory); |
144 | 155 |
145 void FireGenericDoneCallback(GenericDoneCallback* callback, | 156 void FireGenericDoneCallback(GenericDoneCallback* callback, |
146 bool success, | 157 bool success, |
147 const std::string& error_message); | 158 const std::string& error_message); |
148 | 159 |
| 160 // Create the RTP dump handler and start dumping. Must be called after making |
| 161 // sure the log directory exists. |
| 162 void CreateRtpDumpHandlerAndStart(RtpDumpType type, |
| 163 GenericDoneCallback callback, |
| 164 const base::FilePath& dump_dir); |
| 165 |
| 166 // A helper for starting RTP dump assuming the RTP dump handler has been |
| 167 // created. |
| 168 void DoStartRtpDump(RtpDumpType type, GenericDoneCallback* callback); |
| 169 |
| 170 // Adds the packet to the dump on IO thread. |
| 171 void DumpRtpPacketOnIOThread(scoped_ptr<uint8[]> packet_header, |
| 172 size_t header_length, |
| 173 size_t packet_length, |
| 174 bool incoming); |
| 175 |
149 scoped_ptr<unsigned char[]> log_buffer_; | 176 scoped_ptr<unsigned char[]> log_buffer_; |
150 scoped_ptr<PartialCircularBuffer> circular_buffer_; | 177 scoped_ptr<PartialCircularBuffer> circular_buffer_; |
151 | 178 |
152 // The profile associated with our renderer process. | 179 // The profile associated with our renderer process. |
153 Profile* profile_; | 180 Profile* profile_; |
154 | 181 |
155 // These are only accessed on the IO thread, except when in STARTING state. In | 182 // These are only accessed on the IO thread, except when in STARTING state. In |
156 // this state we are protected since entering any function that alters the | 183 // this state we are protected since entering any function that alters the |
157 // state is not allowed. | 184 // state is not allowed. |
158 MetaDataMap meta_data_; | 185 MetaDataMap meta_data_; |
(...skipping 14 matching lines...) Expand all Loading... |
173 | 200 |
174 // This is the handle to be passed to the render process. It's stored so that | 201 // This is the handle to be passed to the render process. It's stored so that |
175 // it doesn't have to be passed on when posting messages between threads. | 202 // it doesn't have to be passed on when posting messages between threads. |
176 // It's only accessed on the IO thread. | 203 // It's only accessed on the IO thread. |
177 base::SharedMemoryHandle foreign_memory_handle_; | 204 base::SharedMemoryHandle foreign_memory_handle_; |
178 | 205 |
179 // The system time in ms when logging is started. Reset when logging_state_ | 206 // The system time in ms when logging is started. Reset when logging_state_ |
180 // changes to STOPPED. | 207 // changes to STOPPED. |
181 base::Time logging_started_time_; | 208 base::Time logging_started_time_; |
182 | 209 |
| 210 // The RTP dump handler responsible for creating the RTP header dump files. |
| 211 scoped_ptr<WebRtcRtpDumpHandler> rtp_dump_handler_; |
| 212 |
| 213 // The callback to call when StopRtpDump is called. |
| 214 content::RenderProcessHost::WebRtcStopRtpDumpCallback stop_rtp_dump_callback_; |
| 215 |
183 DISALLOW_COPY_AND_ASSIGN(WebRtcLoggingHandlerHost); | 216 DISALLOW_COPY_AND_ASSIGN(WebRtcLoggingHandlerHost); |
184 }; | 217 }; |
185 | 218 |
186 #endif // CHROME_BROWSER_MEDIA_WEBRTC_LOGGING_HANDLER_HOST_H_ | 219 #endif // CHROME_BROWSER_MEDIA_WEBRTC_LOGGING_HANDLER_HOST_H_ |
OLD | NEW |