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_LOG_UPLOADER_H_ | 5 #ifndef CHROME_BROWSER_MEDIA_WEBRTC_LOG_UPLOADER_H_ |
6 #define CHROME_BROWSER_MEDIA_WEBRTC_LOG_UPLOADER_H_ | 6 #define CHROME_BROWSER_MEDIA_WEBRTC_LOG_UPLOADER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 11 matching lines...) Expand all Loading... |
22 } | 22 } |
23 | 23 |
24 namespace net { | 24 namespace net { |
25 class URLFetcher; | 25 class URLFetcher; |
26 } | 26 } |
27 | 27 |
28 typedef struct z_stream_s z_stream; | 28 typedef struct z_stream_s z_stream; |
29 | 29 |
30 // Used when uploading is done to perform post-upload actions. |log_path| is | 30 // Used when uploading is done to perform post-upload actions. |log_path| is |
31 // also used pre-upload. | 31 // also used pre-upload. |
32 struct WebRtcLogUploadDoneData { | 32 struct WebRtcLogUploadDoneData : public WebRtcLogPaths { |
33 WebRtcLogUploadDoneData(); | 33 WebRtcLogUploadDoneData(); |
34 ~WebRtcLogUploadDoneData(); | 34 ~WebRtcLogUploadDoneData(); |
35 | 35 |
36 base::FilePath log_path; | |
37 base::FilePath incoming_rtp_dump; | |
38 base::FilePath outgoing_rtp_dump; | |
39 WebRtcLoggingHandlerHost::UploadDoneCallback callback; | 36 WebRtcLoggingHandlerHost::UploadDoneCallback callback; |
40 scoped_refptr<WebRtcLoggingHandlerHost> host; | 37 scoped_refptr<WebRtcLoggingHandlerHost> host; |
41 std::string local_log_id; | 38 std::string local_log_id; |
42 }; | 39 }; |
43 | 40 |
44 // WebRtcLogUploader uploads WebRTC logs, keeps count of how many logs have | 41 // WebRtcLogUploader uploads WebRTC logs, keeps count of how many logs have |
45 // been started and denies further logs if a limit is reached. It also adds | 42 // been started and denies further logs if a limit is reached. It also adds |
46 // the timestamp and report ID of the uploded log to a text file. There must | 43 // the timestamp and report ID of the uploded log to a text file. There must |
47 // only be one object of this type. | 44 // only be one object of this type. |
48 class WebRtcLogUploader : public net::URLFetcherDelegate { | 45 class WebRtcLogUploader : public net::URLFetcherDelegate { |
(...skipping 19 matching lines...) Expand all Loading... |
68 void LoggingStoppedDontUpload(); | 65 void LoggingStoppedDontUpload(); |
69 | 66 |
70 // Notifies that that logging has stopped and that the log should be uploaded. | 67 // Notifies that that logging has stopped and that the log should be uploaded. |
71 // Decreases log count. May only be called if permission to log has been | 68 // Decreases log count. May only be called if permission to log has been |
72 // granted by calling ApplyForStartLogging() and getting true in return. After | 69 // granted by calling ApplyForStartLogging() and getting true in return. After |
73 // this function has been called, a new permission must be granted. Call | 70 // this function has been called, a new permission must be granted. Call |
74 // either this function or LoggingStoppedDontUpload(). | 71 // either this function or LoggingStoppedDontUpload(). |
75 // |upload_done_data.local_log_id| is set and used internally and should be | 72 // |upload_done_data.local_log_id| is set and used internally and should be |
76 // left empty. | 73 // left empty. |
77 void LoggingStoppedDoUpload( | 74 void LoggingStoppedDoUpload( |
78 scoped_ptr<unsigned char[]> log_buffer, | 75 scoped_ptr<WebRtcLogBuffer> log_buffer, |
79 uint32 length, | 76 scoped_ptr<MetaDataMap> meta_data, |
80 const std::map<std::string, std::string>& meta_data, | |
81 const WebRtcLogUploadDoneData& upload_done_data); | 77 const WebRtcLogUploadDoneData& upload_done_data); |
82 | 78 |
| 79 // Uploads a previously stored log (see LoggingStoppedDoStore()). |
| 80 void UploadStoredLog(const WebRtcLogUploadDoneData& upload_data); |
| 81 |
| 82 // Similarly to LoggingStoppedDoUpload(), we store the log in compressed |
| 83 // format on disk but add the option to specify a unique |log_id| for later |
| 84 // identification and potential upload. |
| 85 void LoggingStoppedDoStore( |
| 86 const WebRtcLogPaths& log_paths, |
| 87 const std::string& log_id, |
| 88 scoped_ptr<WebRtcLogBuffer> log_buffer, |
| 89 scoped_ptr<MetaDataMap> meta_data, |
| 90 const WebRtcLoggingHandlerHost::GenericDoneCallback& done_callback); |
| 91 |
83 // Cancels URL fetcher operation by deleting all URL fetchers. This cancels | 92 // Cancels URL fetcher operation by deleting all URL fetchers. This cancels |
84 // any pending uploads and releases SystemURLRequestContextGetter references. | 93 // any pending uploads and releases SystemURLRequestContextGetter references. |
85 // Sets |shutting_down_| which prevent new fetchers to be created. | 94 // Sets |shutting_down_| which prevent new fetchers to be created. |
86 void StartShutdown(); | 95 void StartShutdown(); |
87 | 96 |
88 // For testing purposes. If called, the multipart will not be uploaded, but | 97 // For testing purposes. If called, the multipart will not be uploaded, but |
89 // written to |post_data_| instead. | 98 // written to |post_data_| instead. |
90 void OverrideUploadWithBufferForTesting(std::string* post_data) { | 99 void OverrideUploadWithBufferForTesting(std::string* post_data) { |
91 DCHECK((post_data && !post_data_) || (!post_data && post_data_)); | 100 DCHECK((post_data && !post_data_) || (!post_data && post_data_)); |
92 post_data_ = post_data; | 101 post_data_ = post_data; |
93 } | 102 } |
94 | 103 |
95 private: | 104 private: |
96 FRIEND_TEST_ALL_PREFIXES(WebRtcLogUploaderTest, | 105 FRIEND_TEST_ALL_PREFIXES(WebRtcLogUploaderTest, |
97 AddLocallyStoredLogInfoToUploadListFile); | 106 AddLocallyStoredLogInfoToUploadListFile); |
98 FRIEND_TEST_ALL_PREFIXES(WebRtcLogUploaderTest, | 107 FRIEND_TEST_ALL_PREFIXES(WebRtcLogUploaderTest, |
99 AddUploadedLogInfoToUploadListFile); | 108 AddUploadedLogInfoToUploadListFile); |
100 | 109 |
101 // Sets up a multipart body to be uploaded. The body is produced according | 110 // Sets up a multipart body to be uploaded. The body is produced according |
102 // to RFC 2046. | 111 // to RFC 2046. |
103 void SetupMultipart(std::string* post_data, | 112 void SetupMultipart(std::string* post_data, |
104 const std::vector<uint8>& compressed_log, | 113 const std::string& compressed_log, |
105 const base::FilePath& incoming_rtp_dump, | 114 const base::FilePath& incoming_rtp_dump, |
106 const base::FilePath& outgoing_rtp_dump, | 115 const base::FilePath& outgoing_rtp_dump, |
107 const std::map<std::string, std::string>& meta_data); | 116 const std::map<std::string, std::string>& meta_data); |
108 | 117 |
109 void CompressLog(std::vector<uint8>* compressed_log, | 118 void CompressLog(std::string* compressed_log, |
110 uint8* input, | 119 WebRtcLogBuffer* buffer); |
111 uint32 input_size); | |
112 | 120 |
113 void ResizeForNextOutput(std::vector<uint8>* compressed_log, | 121 void ResizeForNextOutput(std::string* compressed_log, |
114 z_stream* stream); | 122 z_stream* stream); |
115 | 123 |
116 void CreateAndStartURLFetcher( | 124 void CreateAndStartURLFetcher( |
117 const WebRtcLogUploadDoneData& upload_done_data, | 125 const WebRtcLogUploadDoneData& upload_done_data, |
118 scoped_ptr<std::string> post_data); | 126 scoped_ptr<std::string> post_data); |
119 | 127 |
120 void DecreaseLogCount(); | 128 void DecreaseLogCount(); |
121 | 129 |
122 // Must be called on the FILE thread. | 130 // Must be called on the FILE thread. |
123 void WriteCompressedLogToFile(const std::vector<uint8>& compressed_log, | 131 void WriteCompressedLogToFile(const std::string& compressed_log, |
124 const base::FilePath& log_file_path); | 132 const base::FilePath& log_file_path); |
125 | 133 |
| 134 void UploadCompressedLog( |
| 135 const std::string& compressed_log, |
| 136 scoped_ptr<MetaDataMap> meta_data, |
| 137 const WebRtcLogUploadDoneData& upload_done_data); |
| 138 |
126 // Append information (upload time, report ID and local ID) about a log to a | 139 // Append information (upload time, report ID and local ID) about a log to a |
127 // log list file, limited to |kLogListLimitLines| entries. This list is used | 140 // log list file, limited to |kLogListLimitLines| entries. This list is used |
128 // for viewing the logs under chrome://webrtc-logs, see WebRtcLogUploadList. | 141 // for viewing the logs under chrome://webrtc-logs, see WebRtcLogUploadList. |
129 // The list has the format | 142 // The list has the format |
130 // upload_time,report_id,local_id | 143 // upload_time,report_id,local_id |
131 // upload_time,report_id,local_id | 144 // upload_time,report_id,local_id |
132 // etc. | 145 // etc. |
133 // where each line represents a log. "upload_time" is the time when the log | 146 // where each line represents a log. "upload_time" is the time when the log |
134 // was uploaded in Unix time. "report_id" is the ID reported back by the | 147 // was uploaded in Unix time. "report_id" is the ID reported back by the |
135 // server. "local_id" is the ID for the locally stored log. It's the time | 148 // server. "local_id" is the ID for the locally stored log. It's the time |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 // Only accessed on the UI thread. | 183 // Only accessed on the UI thread. |
171 UploadDoneDataMap upload_done_data_; | 184 UploadDoneDataMap upload_done_data_; |
172 | 185 |
173 // When shutting down, don't create new URLFetchers. | 186 // When shutting down, don't create new URLFetchers. |
174 bool shutting_down_; | 187 bool shutting_down_; |
175 | 188 |
176 DISALLOW_COPY_AND_ASSIGN(WebRtcLogUploader); | 189 DISALLOW_COPY_AND_ASSIGN(WebRtcLogUploader); |
177 }; | 190 }; |
178 | 191 |
179 #endif // CHROME_BROWSER_MEDIA_WEBRTC_LOG_UPLOADER_H_ | 192 #endif // CHROME_BROWSER_MEDIA_WEBRTC_LOG_UPLOADER_H_ |
OLD | NEW |