Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(252)

Side by Side Diff: chrome/browser/media/webrtc_logging_handler_host.h

Issue 927233005: Adding support for storing webrtc logs locally with an extension supplied unique id, for later uplo… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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" 10 #include "chrome/browser/media/rtp_dump_type.h"
11 #include "chrome/browser/media/webrtc_rtp_dump_handler.h" 11 #include "chrome/browser/media/webrtc_rtp_dump_handler.h"
12 #include "chrome/common/media/webrtc_logging_message_data.h" 12 #include "chrome/common/media/webrtc_logging_message_data.h"
13 #include "chrome/common/partial_circular_buffer.h"
13 #include "content/public/browser/browser_message_filter.h" 14 #include "content/public/browser/browser_message_filter.h"
14 #include "content/public/browser/render_process_host.h" 15 #include "content/public/browser/render_process_host.h"
15 #include "net/base/net_util.h" 16 #include "net/base/net_util.h"
16 17
17 namespace net { 18 namespace net {
18 class URLRequestContextGetter; 19 class URLRequestContextGetter;
19 } // namespace net 20 } // namespace net
20 21
21 class PartialCircularBuffer;
22 class Profile; 22 class Profile;
23 23
24 #if defined(OS_ANDROID)
25 const size_t kWebRtcLogSize = 1 * 1024 * 1024; // 1 MB
26 #else
27 const size_t kWebRtcLogSize = 6 * 1024 * 1024; // 6 MB
28 #endif
29
24 typedef std::map<std::string, std::string> MetaDataMap; 30 typedef std::map<std::string, std::string> MetaDataMap;
25 31
32 struct WebRtcLogPaths {
33 base::FilePath log_path; // todo: rename to directory.
34 base::FilePath incoming_rtp_dump;
35 base::FilePath outgoing_rtp_dump;
36 };
37
38 class WebRtcLogBuffer {
39 public:
40 WebRtcLogBuffer();
41 ~WebRtcLogBuffer();
42
43 void Log(const std::string& message);
44
45 // Returns a circular buffer instance for reading the internal log buffer.
46 // Must only be called after the log has been marked as complete
47 // (see SetComplete) and the caller must ensure that the WebRtcLogBuffer
48 // instance remains in scope for the lifetime of the returned circular buffer.
49 PartialCircularBuffer Read();
50
51 // Switches the buffer to read-only mode, where access to the internal
52 // buffer is allowed from different threads than were used to contribute
53 // to the log. Calls to Log() won't be allowed after calling
54 // SetComplete() and the call to SetComplete() must be done on the same
55 // thread as constructed the buffer and calls Log().
56 void SetComplete();
57
58 private:
59 base::ThreadChecker thread_checker_;
60 uint8 buffer_[kWebRtcLogSize];
61 PartialCircularBuffer circular_;
62 bool read_only_;
63 };
64
26 // WebRtcLoggingHandlerHost handles operations regarding the WebRTC logging: 65 // WebRtcLoggingHandlerHost handles operations regarding the WebRTC logging:
27 // - Opens a shared memory buffer that the handler in the render process 66 // - Opens a shared memory buffer that the handler in the render process
28 // writes to. 67 // writes to.
29 // - Writes basic machine info to the log. 68 // - Writes basic machine info to the log.
30 // - Informs the handler in the render process when to stop logging. 69 // - Informs the handler in the render process when to stop logging.
31 // - Closes the shared memory (and thereby discarding it) or triggers uploading 70 // - Closes the shared memory (and thereby discarding it) or triggers uploading
32 // of the log. 71 // of the log.
33 // - Detects when channel, i.e. renderer, is going away and possibly triggers 72 // - Detects when channel, i.e. renderer, is going away and possibly triggers
34 // uploading the log. 73 // uploading the log.
35 class WebRtcLoggingHandlerHost : public content::BrowserMessageFilter { 74 class WebRtcLoggingHandlerHost : public content::BrowserMessageFilter {
36 public: 75 public:
37 typedef base::Callback<void(bool, const std::string&)> GenericDoneCallback; 76 typedef base::Callback<void(bool, const std::string&)> GenericDoneCallback;
38 typedef base::Callback<void(bool, const std::string&, const std::string&)> 77 typedef base::Callback<void(bool, const std::string&, const std::string&)>
39 UploadDoneCallback; 78 UploadDoneCallback;
40 79
41 explicit WebRtcLoggingHandlerHost(Profile* profile); 80 explicit WebRtcLoggingHandlerHost(Profile* profile);
42 81
43 // Sets meta data that will be uploaded along with the log and also written 82 // Sets meta data that will be uploaded along with the log and also written
44 // in the beginning of the log. Must be called on the IO thread before calling 83 // in the beginning of the log. Must be called on the IO thread before calling
45 // StartLogging. 84 // StartLogging.
46 void SetMetaData(const MetaDataMap& meta_data, 85 void SetMetaData(scoped_ptr<MetaDataMap> meta_data,
47 const GenericDoneCallback& callback); 86 const GenericDoneCallback& callback);
48 87
49 // Opens a log and starts logging. Must be called on the IO thread. 88 // Opens a log and starts logging. Must be called on the IO thread.
50 void StartLogging(const GenericDoneCallback& callback); 89 void StartLogging(const GenericDoneCallback& callback);
51 90
52 // Stops logging. Log will remain open until UploadLog or DiscardLog is 91 // Stops logging. Log will remain open until UploadLog or DiscardLog is
53 // called. Must be called on the IO thread. 92 // called. Must be called on the IO thread.
54 void StopLogging(const GenericDoneCallback& callback); 93 void StopLogging(const GenericDoneCallback& callback);
55 94
56 // Uploads the log and the RTP dumps. Discards the local copy. May only be 95 // Uploads the log and the RTP dumps. Discards the local copy. May only be
57 // called after logging has stopped. Must be called on the IO thread. 96 // called after logging has stopped. Must be called on the IO thread.
58 void UploadLog(const UploadDoneCallback& callback); 97 void UploadLog(const UploadDoneCallback& callback);
59 98
99 // Uploads a log that was previously saved via a call to StoreLog().
100 // Otherwise operates in the same way as UploadLog.
101 void UploadStoredLog(const std::string& log_id,
102 const UploadDoneCallback& callback);
103
60 // Called by WebRtcLogUploader when uploading has finished. Must be called on 104 // Called by WebRtcLogUploader when uploading has finished. Must be called on
61 // the IO thread. 105 // the IO thread.
62 void UploadLogDone(); 106 void UploadLogDone();
63 107
64 // Discards the log and the RTP dumps. May only be called after logging has 108 // Discards the log and the RTP dumps. May only be called after logging has
65 // stopped. Must be called on the IO thread. 109 // stopped. Must be called on the IO thread.
66 void DiscardLog(const GenericDoneCallback& callback); 110 void DiscardLog(const GenericDoneCallback& callback);
67 111
112 // Stores the log locally using a hash of log_id + security origin.
113 void StoreLog(const std::string& log_id, const GenericDoneCallback& callback);
114
68 // Adds a message to the log. 115 // Adds a message to the log.
69 void LogMessage(const std::string& message); 116 void LogMessage(const std::string& message);
70 117
71 // May be called on any thread. |upload_log_on_render_close_| is used 118 // May be called on any thread. |upload_log_on_render_close_| is used
72 // for decision making and it's OK if it changes before the execution based 119 // for decision making and it's OK if it changes before the execution based
73 // on that decision has finished. 120 // on that decision has finished.
74 void set_upload_log_on_render_close(bool should_upload) { 121 void set_upload_log_on_render_close(bool should_upload) {
75 upload_log_on_render_close_ = should_upload; 122 upload_log_on_render_close_ = should_upload;
76 } 123 }
77 124
(...skipping 29 matching lines...) Expand all
107 // Stop done: STOPPING -> STOPPED. 154 // Stop done: STOPPING -> STOPPED.
108 // UploadLog(): STOPPED -> UPLOADING. 155 // UploadLog(): STOPPED -> UPLOADING.
109 // Upload done: UPLOADING -> CLOSED. 156 // Upload done: UPLOADING -> CLOSED.
110 // DiscardLog(): STOPPED -> CLOSED. 157 // DiscardLog(): STOPPED -> CLOSED.
111 enum LoggingState { 158 enum LoggingState {
112 CLOSED, // Logging not started, no log in memory. 159 CLOSED, // Logging not started, no log in memory.
113 STARTING, // Start logging is in progress. 160 STARTING, // Start logging is in progress.
114 STARTED, // Logging started. 161 STARTED, // Logging started.
115 STOPPING, // Stop logging is in progress. 162 STOPPING, // Stop logging is in progress.
116 STOPPED, // Logging has been stopped, log still open in memory. 163 STOPPED, // Logging has been stopped, log still open in memory.
117 UPLOADING // Uploading log is in progress.
118 }; 164 };
119 165
120 friend class content::BrowserThread; 166 friend class content::BrowserThread;
121 friend class base::DeleteHelper<WebRtcLoggingHandlerHost>; 167 friend class base::DeleteHelper<WebRtcLoggingHandlerHost>;
122 168
123 ~WebRtcLoggingHandlerHost() override; 169 ~WebRtcLoggingHandlerHost() override;
124 170
125 // BrowserMessageFilter implementation. 171 // BrowserMessageFilter implementation.
126 void OnChannelClosing() override; 172 void OnChannelClosing() override;
127 void OnDestruct() const override; 173 void OnDestruct() const override;
128 bool OnMessageReceived(const IPC::Message& message) override; 174 bool OnMessageReceived(const IPC::Message& message) override;
129 175
130 // Handles log message requests from renderer process. 176 // Handles log message requests from renderer process.
131 void OnAddLogMessages(const std::vector<WebRtcLoggingMessageData>& messages); 177 void OnAddLogMessages(const std::vector<WebRtcLoggingMessageData>& messages);
132 void OnLoggingStoppedInRenderer(); 178 void OnLoggingStoppedInRenderer();
133 179
134 // Handles log message requests from browser process. 180 // Handles log message requests from browser process.
135 void AddLogMessageFromBrowser(const WebRtcLoggingMessageData& message); 181 void AddLogMessageFromBrowser(const WebRtcLoggingMessageData& message);
136 182
137 void StartLoggingIfAllowed(); 183 void StartLoggingIfAllowed(const GenericDoneCallback& callback);
138 void DoStartLogging(); 184 void DoStartLogging(bool permissions_granted,
139 void LogInitialInfoOnFileThread(); 185 const GenericDoneCallback& callback);
140 void LogInitialInfoOnIOThread(const net::NetworkInterfaceList& network_list); 186 void LogInitialInfoOnFileThread(const GenericDoneCallback& callback);
141 void NotifyLoggingStarted(); 187 void LogInitialInfoOnIOThread(const net::NetworkInterfaceList& network_list,
188 const GenericDoneCallback& callback);
189 void NotifyLoggingStarted(const GenericDoneCallback& callback);
190
191 // Called after stopping RTP dumps.
192 void StoreLogContinue(const std::string& log_id,
193 const GenericDoneCallback& callback);
142 194
143 // Writes a formatted log |message| to the |circular_buffer_|. 195 // Writes a formatted log |message| to the |circular_buffer_|.
144 void LogToCircularBuffer(const std::string& message); 196 void LogToCircularBuffer(const std::string& message);
145 197
146 // Gets the log directory path for |profile_| and ensure it exists. Must be 198 // Gets the log directory path for |profile_| and ensure it exists. Must be
147 // called on the FILE thread. 199 // called on the FILE thread.
148 base::FilePath GetLogDirectoryAndEnsureExists(); 200 base::FilePath GetLogDirectoryAndEnsureExists();
149 201
150 void TriggerUpload(const base::FilePath& log_directory); 202 void TriggerUpload(const UploadDoneCallback& callback,
203 const base::FilePath& log_directory);
204
205 void StoreLogInDirectory(const std::string& log_id,
206 scoped_ptr<WebRtcLogPaths> log_paths,
207 const GenericDoneCallback& done_callback,
208 const base::FilePath& directory);
209
210 void UploadStoredLogOnFileThread(const std::string& log_id,
211 const UploadDoneCallback& callback);
151 212
152 // A helper for TriggerUpload to do the real work. 213 // A helper for TriggerUpload to do the real work.
153 void DoUploadLogAndRtpDumps(const base::FilePath& log_directory); 214 void DoUploadLogAndRtpDumps(const base::FilePath& log_directory,
154 215 const UploadDoneCallback& callback);
155 void FireGenericDoneCallback(GenericDoneCallback* callback,
156 bool success,
157 const std::string& error_message);
158 216
159 // Create the RTP dump handler and start dumping. Must be called after making 217 // Create the RTP dump handler and start dumping. Must be called after making
160 // sure the log directory exists. 218 // sure the log directory exists.
161 void CreateRtpDumpHandlerAndStart(RtpDumpType type, 219 void CreateRtpDumpHandlerAndStart(RtpDumpType type,
162 GenericDoneCallback callback, 220 const GenericDoneCallback& callback,
163 const base::FilePath& dump_dir); 221 const base::FilePath& dump_dir);
164 222
165 // A helper for starting RTP dump assuming the RTP dump handler has been 223 // A helper for starting RTP dump assuming the RTP dump handler has been
166 // created. 224 // created.
167 void DoStartRtpDump(RtpDumpType type, GenericDoneCallback* callback); 225 void DoStartRtpDump(RtpDumpType type, const GenericDoneCallback& callback);
168 226
169 // Adds the packet to the dump on IO thread. 227 // Adds the packet to the dump on IO thread.
170 void DumpRtpPacketOnIOThread(scoped_ptr<uint8[]> packet_header, 228 void DumpRtpPacketOnIOThread(scoped_ptr<uint8[]> packet_header,
171 size_t header_length, 229 size_t header_length,
172 size_t packet_length, 230 size_t packet_length,
173 bool incoming); 231 bool incoming);
174 232
175 scoped_ptr<unsigned char[]> log_buffer_; 233 bool ReleaseRtpDumps(WebRtcLogPaths* log_paths);
176 scoped_ptr<PartialCircularBuffer> circular_buffer_; 234
235 scoped_ptr<WebRtcLogBuffer> log_buffer_;
177 236
178 // The profile associated with our renderer process. 237 // The profile associated with our renderer process.
179 Profile* profile_; 238 Profile* const profile_;
180 239
181 // These are only accessed on the IO thread, except when in STARTING state. In 240 // These are only accessed on the IO thread, except when in STARTING state. In
182 // this state we are protected since entering any function that alters the 241 // this state we are protected since entering any function that alters the
183 // state is not allowed. 242 // state is not allowed.
184 MetaDataMap meta_data_; 243 scoped_ptr<MetaDataMap> meta_data_;
185 244
186 // These are only accessed on the IO thread. 245 // These are only accessed on the IO thread.
187 GenericDoneCallback start_callback_;
188 GenericDoneCallback stop_callback_; 246 GenericDoneCallback stop_callback_;
189 UploadDoneCallback upload_callback_;
190 247
191 // Only accessed on the IO thread, except when in STARTING, STOPPING or 248 // Only accessed on the IO thread, except when in STARTING, STOPPING or
192 // UPLOADING state if the action fails and the state must be reset. In these 249 // UPLOADING state if the action fails and the state must be reset. In these
193 // states however, we are protected since entering any function that alters 250 // states however, we are protected since entering any function that alters
194 // the state is not allowed. 251 // the state is not allowed.
195 LoggingState logging_state_; 252 LoggingState logging_state_;
196 253
197 // Only accessed on the IO thread. 254 // Only accessed on the IO thread.
198 bool upload_log_on_render_close_; 255 bool upload_log_on_render_close_;
199 256
200 // This is the handle to be passed to the render process. It's stored so that 257 // This is the handle to be passed to the render process. It's stored so that
201 // it doesn't have to be passed on when posting messages between threads. 258 // it doesn't have to be passed on when posting messages between threads.
202 // It's only accessed on the IO thread. 259 // It's only accessed on the IO thread.
203 base::SharedMemoryHandle foreign_memory_handle_; 260 base::SharedMemoryHandle foreign_memory_handle_;
204 261
205 // The system time in ms when logging is started. Reset when logging_state_ 262 // The system time in ms when logging is started. Reset when logging_state_
206 // changes to STOPPED. 263 // changes to STOPPED.
207 base::Time logging_started_time_; 264 base::Time logging_started_time_;
208 265
209 // The RTP dump handler responsible for creating the RTP header dump files. 266 // The RTP dump handler responsible for creating the RTP header dump files.
210 scoped_ptr<WebRtcRtpDumpHandler> rtp_dump_handler_; 267 scoped_ptr<WebRtcRtpDumpHandler> rtp_dump_handler_;
211 268
212 // The callback to call when StopRtpDump is called. 269 // The callback to call when StopRtpDump is called.
213 content::RenderProcessHost::WebRtcStopRtpDumpCallback stop_rtp_dump_callback_; 270 content::RenderProcessHost::WebRtcStopRtpDumpCallback stop_rtp_dump_callback_;
214 271
215 DISALLOW_COPY_AND_ASSIGN(WebRtcLoggingHandlerHost); 272 DISALLOW_COPY_AND_ASSIGN(WebRtcLoggingHandlerHost);
216 }; 273 };
217 274
218 #endif // CHROME_BROWSER_MEDIA_WEBRTC_LOGGING_HANDLER_HOST_H_ 275 #endif // CHROME_BROWSER_MEDIA_WEBRTC_LOGGING_HANDLER_HOST_H_
OLDNEW
« no previous file with comments | « chrome/browser/media/webrtc_log_uploader_unittest.cc ('k') | chrome/browser/media/webrtc_logging_handler_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698