Chromium Code Reviews| 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/webrtc_rtp_dump_handler.h" | |
| 10 #include "chrome/common/media/webrtc_logging_message_data.h" | 11 #include "chrome/common/media/webrtc_logging_message_data.h" |
| 11 #include "content/public/browser/browser_message_filter.h" | 12 #include "content/public/browser/browser_message_filter.h" |
| 12 #include "net/base/net_util.h" | 13 #include "net/base/net_util.h" |
| 13 | 14 |
| 14 namespace net { | 15 namespace net { |
| 15 class URLRequestContextGetter; | 16 class URLRequestContextGetter; |
| 16 } // namespace net | 17 } // namespace net |
| 17 | 18 |
| 18 class PartialCircularBuffer; | 19 class PartialCircularBuffer; |
| 19 class Profile; | 20 class Profile; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 44 void SetMetaData(const MetaDataMap& meta_data, | 45 void SetMetaData(const MetaDataMap& meta_data, |
| 45 const GenericDoneCallback& callback); | 46 const GenericDoneCallback& callback); |
| 46 | 47 |
| 47 // Opens a log and starts logging. Must be called on the IO thread. | 48 // Opens a log and starts logging. Must be called on the IO thread. |
| 48 void StartLogging(const GenericDoneCallback& callback); | 49 void StartLogging(const GenericDoneCallback& callback); |
| 49 | 50 |
| 50 // Stops logging. Log will remain open until UploadLog or DiscardLog is | 51 // Stops logging. Log will remain open until UploadLog or DiscardLog is |
| 51 // called. Must be called on the IO thread. | 52 // called. Must be called on the IO thread. |
| 52 void StopLogging(const GenericDoneCallback& callback); | 53 void StopLogging(const GenericDoneCallback& callback); |
| 53 | 54 |
| 54 // Uploads the log and discards the local copy. May only be called after | 55 // 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. | 56 // called after logging has stopped. Must be called on the IO thread. |
| 56 void UploadLog(const UploadDoneCallback& callback); | 57 void UploadLog(const UploadDoneCallback& callback); |
| 57 | 58 |
| 58 // Called by WebRtcLogUploader when uploading has finished. Must be called on | 59 // Called by WebRtcLogUploader when uploading has finished. Must be called on |
| 59 // the IO thread. | 60 // the IO thread. |
| 60 void UploadLogDone(); | 61 void UploadLogDone(); |
| 61 | 62 |
| 62 // Discards the log. May only be called after logging has stopped. Must be | 63 // Discards the log and the RTP dumps. May only be called after logging has |
| 63 // called on the IO thread. | 64 // stopped. Must be called on the IO thread. |
| 64 void DiscardLog(const GenericDoneCallback& callback); | 65 void DiscardLog(const GenericDoneCallback& callback); |
| 65 | 66 |
| 66 // Adds a message to the log. | 67 // Adds a message to the log. |
| 67 void LogMessage(const std::string& message); | 68 void LogMessage(const std::string& message); |
| 68 | 69 |
| 69 // May be called on any thread. |upload_log_on_render_close_| is used | 70 // 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 | 71 // for decision making and it's OK if it changes before the execution based |
| 71 // on that decision has finished. | 72 // on that decision has finished. |
| 72 void set_upload_log_on_render_close(bool should_upload) { | 73 void set_upload_log_on_render_close(bool should_upload) { |
| 73 upload_log_on_render_close_ = should_upload; | 74 upload_log_on_render_close_ = should_upload; |
| 74 } | 75 } |
| 75 | 76 |
| 76 // Starts dumping the RTP headers for the specified direction. Must be called | 77 // 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 | 78 // on the IO thread. |incoming| and |outgoing| specifies which direction(s) of |
| 78 // RTP packets should be dumped. |callback| will be called when starting the | 79 // RTP packets should be dumped. |callback| will be called when starting the |
| 79 // dump is done. | 80 // dump is done. |
| 80 void StartRtpDump(bool incoming, | 81 void StartRtpDump(bool incoming, |
| 81 bool outgoing, | 82 bool outgoing, |
| 82 const GenericDoneCallback& callback); | 83 const GenericDoneCallback& callback); |
| 83 | 84 |
| 84 // Stops dumping the RTP headers for the specified direction. Must be called | 85 // 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 | 86 // on the IO thread. |incoming| and |outgoing| specifies which direction(s) of |
| 86 // RTP packet dumping should be stopped. |callback| will be called when | 87 // RTP packet dumping should be stopped. |callback| will be called when |
| 87 // stopping the dump is done. | 88 // stopping the dump is done. |
| 88 void StopRtpDump(bool incoming, | 89 void StopRtpDump(bool incoming, |
| 89 bool outgoing, | 90 bool outgoing, |
| 90 const GenericDoneCallback& callback); | 91 const GenericDoneCallback& callback); |
| 91 | 92 |
| 93 // Called when an RTP packet is sent or received. | |
| 94 // Can be called on any thread as it always posts to the IO thread. | |
| 95 void OnRtpPacket(const uint8* packet_header, | |
| 96 size_t header_length, | |
| 97 size_t packet_length, | |
| 98 bool incoming); | |
| 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. |
| 101 // Upload done: UPLOADING -> CLOSED. | 109 // Upload done: UPLOADING -> CLOSED. |
| (...skipping 31 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); |
| 144 | 152 |
| 145 void FireGenericDoneCallback(GenericDoneCallback* callback, | 153 void FireGenericDoneCallback(GenericDoneCallback* callback, |
| 146 bool success, | 154 bool success, |
| 147 const std::string& error_message); | 155 const std::string& error_message); |
| 148 | 156 |
| 157 // Create the RTP dump handler and start dumping. Must be called after making | |
| 158 // sure the log directory exists. | |
| 159 void CreateRtpDumpHandlerAndStart(bool incoming, | |
|
Henrik Grunell
2014/05/15 14:36:34
Can you use an enum instead of two bools?
jiayl
2014/05/15 23:06:22
Done.
| |
| 160 bool outgoing, | |
| 161 GenericDoneCallback callback, | |
| 162 const base::FilePath& dump_dir); | |
| 163 | |
| 164 // A helper for starting RTP dump assuming the RTP dump handler has been | |
| 165 // created. | |
| 166 void DoStartRtpDump(bool incoming, | |
| 167 bool outgoing, | |
| 168 GenericDoneCallback* callback); | |
| 169 | |
| 170 // A helper for uploading the log and RTP dumps after the | |
| 171 // WebRtcRtpDumpHandler::ReleaseDump callback. | |
| 172 void DoUploadLogAndDumps( | |
| 173 const base::FilePath& log_directory, | |
| 174 const WebRtcRtpDumpHandler::ReleasedDumps& rtp_dumps); | |
| 175 | |
| 176 // Pass the RTP packet to the RTP dump handler on the IO thread. | |
| 177 void DumpRtpPacketOnIOThread(scoped_ptr<uint8[]> packet_header, | |
| 178 size_t header_length, | |
| 179 size_t packet_length, | |
| 180 bool incoming); | |
| 181 | |
| 149 scoped_ptr<unsigned char[]> log_buffer_; | 182 scoped_ptr<unsigned char[]> log_buffer_; |
| 150 scoped_ptr<PartialCircularBuffer> circular_buffer_; | 183 scoped_ptr<PartialCircularBuffer> circular_buffer_; |
| 151 | 184 |
| 152 // The profile associated with our renderer process. | 185 // The profile associated with our renderer process. |
| 153 Profile* profile_; | 186 Profile* profile_; |
| 154 | 187 |
| 155 // These are only accessed on the IO thread, except when in STARTING state. In | 188 // 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 | 189 // this state we are protected since entering any function that alters the |
| 157 // state is not allowed. | 190 // state is not allowed. |
| 158 MetaDataMap meta_data_; | 191 MetaDataMap meta_data_; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 173 | 206 |
| 174 // This is the handle to be passed to the render process. It's stored so that | 207 // 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. | 208 // it doesn't have to be passed on when posting messages between threads. |
| 176 // It's only accessed on the IO thread. | 209 // It's only accessed on the IO thread. |
| 177 base::SharedMemoryHandle foreign_memory_handle_; | 210 base::SharedMemoryHandle foreign_memory_handle_; |
| 178 | 211 |
| 179 // The system time in ms when logging is started. Reset when logging_state_ | 212 // The system time in ms when logging is started. Reset when logging_state_ |
| 180 // changes to STOPPED. | 213 // changes to STOPPED. |
| 181 base::Time logging_started_time_; | 214 base::Time logging_started_time_; |
| 182 | 215 |
| 216 // The RTP dump handler responsible for creating the RTP header dump files. | |
| 217 scoped_ptr<WebRtcRtpDumpHandler> rtp_dump_handler_; | |
| 218 | |
| 183 DISALLOW_COPY_AND_ASSIGN(WebRtcLoggingHandlerHost); | 219 DISALLOW_COPY_AND_ASSIGN(WebRtcLoggingHandlerHost); |
| 184 }; | 220 }; |
| 185 | 221 |
| 186 #endif // CHROME_BROWSER_MEDIA_WEBRTC_LOGGING_HANDLER_HOST_H_ | 222 #endif // CHROME_BROWSER_MEDIA_WEBRTC_LOGGING_HANDLER_HOST_H_ |
| OLD | NEW |