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 #include "chrome/browser/media/webrtc_log_uploader.h" | 5 #include "chrome/browser/media/webrtc_log_uploader.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/files/file_enumerator.h" | 8 #include "base/files/file_enumerator.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 const uint32 kIntermediateCompressionBufferBytes = 256 * 1024; // 256 KB | 29 const uint32 kIntermediateCompressionBufferBytes = 256 * 1024; // 256 KB |
| 30 const int kLogListLimitLines = 50; | 30 const int kLogListLimitLines = 50; |
| 31 | 31 |
| 32 const char kUploadURL[] = "https://clients2.google.com/cr/report"; | 32 const char kUploadURL[] = "https://clients2.google.com/cr/report"; |
| 33 const char kUploadContentType[] = "multipart/form-data"; | 33 const char kUploadContentType[] = "multipart/form-data"; |
| 34 const char kMultipartBoundary[] = | 34 const char kMultipartBoundary[] = |
| 35 "----**--yradnuoBgoLtrapitluMklaTelgooG--**----"; | 35 "----**--yradnuoBgoLtrapitluMklaTelgooG--**----"; |
| 36 | 36 |
| 37 const int kHttpResponseOk = 200; | 37 const int kHttpResponseOk = 200; |
| 38 | 38 |
| 39 // Adds the header section for a gzip file to the multipart |post_data|. | |
| 40 void AddMultipartFileContentHeader(std::string* post_data, | |
| 41 const std::string& content_name, | |
| 42 const std::string& file_name) { | |
| 43 post_data->append("--"); | |
| 44 post_data->append(kMultipartBoundary); | |
| 45 post_data->append("\r\n"); | |
| 46 post_data->append("Content-Disposition: form-data; name=\""); | |
| 47 post_data->append(content_name); | |
| 48 post_data->append("\""); | |
| 49 post_data->append("; filename=\""); | |
| 50 post_data->append(file_name); | |
| 51 post_data->append("\"\r\n"); | |
| 52 post_data->append("Content-Type: application/gzip\r\n\r\n"); | |
| 53 } | |
| 54 | |
| 55 // Adds |compressed_log| to |post_data|. | |
| 56 void AddLogData(std::string* post_data, | |
| 57 const std::vector<uint8>& compressed_log) { | |
| 58 AddMultipartFileContentHeader(post_data, "webrtc_log", "webrtc_log.gz"); | |
| 59 post_data->append(reinterpret_cast<const char*>(&compressed_log[0]), | |
| 60 compressed_log.size()); | |
| 61 post_data->append("\r\n"); | |
| 62 } | |
| 63 | |
| 64 // Adds the RTP dump data to |post_data|. | |
| 65 void AddRtpDumpData(std::string* post_data, | |
| 66 const std::string& name, | |
| 67 const std::string& dump_data) { | |
| 68 AddMultipartFileContentHeader(post_data, name, name + ".gz"); | |
| 69 post_data->append(dump_data.data(), dump_data.size()); | |
| 70 post_data->append("\r\n"); | |
| 71 } | |
| 72 | |
| 39 } // namespace | 73 } // namespace |
| 40 | 74 |
| 75 WebRtcRtpDumpDescription::WebRtcRtpDumpDescription(const std::string& name, | |
| 76 const base::FilePath& path) | |
| 77 : name(name), path(path) { | |
| 78 } | |
| 79 | |
| 41 WebRtcLogUploadDoneData::WebRtcLogUploadDoneData() {} | 80 WebRtcLogUploadDoneData::WebRtcLogUploadDoneData() {} |
| 42 | 81 |
| 43 WebRtcLogUploadDoneData::~WebRtcLogUploadDoneData() {} | 82 WebRtcLogUploadDoneData::~WebRtcLogUploadDoneData() {} |
| 44 | 83 |
| 45 WebRtcLogUploader::WebRtcLogUploader() | 84 WebRtcLogUploader::WebRtcLogUploader() |
| 46 : log_count_(0), | 85 : log_count_(0), |
| 47 post_data_(NULL), | 86 post_data_(NULL), |
| 48 shutting_down_(false) { | 87 shutting_down_(false) { |
| 49 file_thread_checker_.DetachFromThread(); | 88 file_thread_checker_.DetachFromThread(); |
| 50 } | 89 } |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 base::FilePath log_list_path = | 171 base::FilePath log_list_path = |
| 133 WebRtcLogList::GetWebRtcLogListFileForDirectory( | 172 WebRtcLogList::GetWebRtcLogListFileForDirectory( |
| 134 upload_done_data.log_path); | 173 upload_done_data.log_path); |
| 135 AddLocallyStoredLogInfoToUploadListFile(log_list_path, local_log_id); | 174 AddLocallyStoredLogInfoToUploadListFile(log_list_path, local_log_id); |
| 136 } | 175 } |
| 137 | 176 |
| 138 WebRtcLogUploadDoneData upload_done_data_with_log_id = upload_done_data; | 177 WebRtcLogUploadDoneData upload_done_data_with_log_id = upload_done_data; |
| 139 upload_done_data_with_log_id.local_log_id = local_log_id; | 178 upload_done_data_with_log_id.local_log_id = local_log_id; |
| 140 | 179 |
| 141 scoped_ptr<std::string> post_data(new std::string()); | 180 scoped_ptr<std::string> post_data(new std::string()); |
| 142 SetupMultipart(post_data.get(), compressed_log, meta_data); | 181 SetupMultipart( |
| 182 post_data.get(), compressed_log, upload_done_data.rtp_dumps, meta_data); | |
|
Henrik Grunell
2014/05/13 09:12:31
|upload_done_data| contains info that's needed aft
jiayl
2014/05/13 21:48:17
The dump paths are needed to add them to the chrom
Henrik Grunell
2014/05/14 12:14:12
Ah, right, it's the path and not the actual data i
| |
| 143 | 183 |
| 144 // If a test has set the test string pointer, write to it and skip uploading. | 184 // If a test has set the test string pointer, write to it and skip uploading. |
| 145 // Still fire the upload callback so that we can run an extension API test | 185 // Still fire the upload callback so that we can run an extension API test |
| 146 // using the test framework for that without hanging. | 186 // using the test framework for that without hanging. |
| 147 // TODO(grunell): Remove this when the api test for this feature is fully | 187 // TODO(grunell): Remove this when the api test for this feature is fully |
| 148 // implemented according to the test plan. http://crbug.com/257329. | 188 // implemented according to the test plan. http://crbug.com/257329. |
| 149 if (post_data_) { | 189 if (post_data_) { |
| 150 *post_data_ = *post_data; | 190 *post_data_ = *post_data; |
| 151 NotifyUploadDone(kHttpResponseOk, "", upload_done_data_with_log_id); | 191 NotifyUploadDone(kHttpResponseOk, "", upload_done_data_with_log_id); |
| 152 return; | 192 return; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 174 ++it) { | 214 ++it) { |
| 175 delete it->first; | 215 delete it->first; |
| 176 } | 216 } |
| 177 upload_done_data_.clear(); | 217 upload_done_data_.clear(); |
| 178 shutting_down_ = true; | 218 shutting_down_ = true; |
| 179 } | 219 } |
| 180 | 220 |
| 181 void WebRtcLogUploader::SetupMultipart( | 221 void WebRtcLogUploader::SetupMultipart( |
| 182 std::string* post_data, | 222 std::string* post_data, |
| 183 const std::vector<uint8>& compressed_log, | 223 const std::vector<uint8>& compressed_log, |
| 224 const std::vector<WebRtcRtpDumpDescription>& rtp_dumps, | |
| 184 const std::map<std::string, std::string>& meta_data) { | 225 const std::map<std::string, std::string>& meta_data) { |
| 185 #if defined(OS_WIN) | 226 #if defined(OS_WIN) |
| 186 const char product[] = "Chrome"; | 227 const char product[] = "Chrome"; |
| 187 #elif defined(OS_MACOSX) | 228 #elif defined(OS_MACOSX) |
| 188 const char product[] = "Chrome_Mac"; | 229 const char product[] = "Chrome_Mac"; |
| 189 #elif defined(OS_LINUX) | 230 #elif defined(OS_LINUX) |
| 190 #if !defined(ADDRESS_SANITIZER) | 231 #if !defined(ADDRESS_SANITIZER) |
| 191 const char product[] = "Chrome_Linux"; | 232 const char product[] = "Chrome_Linux"; |
| 192 #else | 233 #else |
| 193 const char product[] = "Chrome_Linux_ASan"; | 234 const char product[] = "Chrome_Linux_ASan"; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 210 "", post_data); | 251 "", post_data); |
| 211 | 252 |
| 212 // Add custom meta data. | 253 // Add custom meta data. |
| 213 std::map<std::string, std::string>::const_iterator it = meta_data.begin(); | 254 std::map<std::string, std::string>::const_iterator it = meta_data.begin(); |
| 214 for (; it != meta_data.end(); ++it) { | 255 for (; it != meta_data.end(); ++it) { |
| 215 net::AddMultipartValueForUpload(it->first, it->second, kMultipartBoundary, | 256 net::AddMultipartValueForUpload(it->first, it->second, kMultipartBoundary, |
| 216 "", post_data); | 257 "", post_data); |
| 217 } | 258 } |
| 218 | 259 |
| 219 AddLogData(post_data, compressed_log); | 260 AddLogData(post_data, compressed_log); |
| 261 | |
| 262 // Add the rtp dumps if any. | |
| 263 // TODO(jiayl): adds the RTP dump records to chrome://webrtc-logs. | |
| 264 for (std::vector<WebRtcRtpDumpDescription>::const_iterator it = | |
| 265 rtp_dumps.begin(); | |
| 266 it != rtp_dumps.end(); | |
| 267 ++it) { | |
| 268 if (it->path.empty() || !base::PathExists(it->path)) | |
| 269 break; | |
|
Henrik Grunell
2014/05/13 09:12:31
Maybe log a warning?
jiayl
2014/05/13 21:48:17
Done. Also changed RtpDumpHandler and RtpDumpWrite
| |
| 270 | |
| 271 std::string dump_data; | |
| 272 if (base::ReadFileToString(it->path, &dump_data)) { | |
| 273 AddRtpDumpData(post_data, it->name, dump_data); | |
| 274 } | |
| 275 } | |
| 276 | |
| 220 net::AddMultipartFinalDelimiterForUpload(kMultipartBoundary, post_data); | 277 net::AddMultipartFinalDelimiterForUpload(kMultipartBoundary, post_data); |
| 221 } | 278 } |
| 222 | 279 |
| 223 void WebRtcLogUploader::AddLogData(std::string* post_data, | |
| 224 const std::vector<uint8>& compressed_log) { | |
| 225 post_data->append("--"); | |
| 226 post_data->append(kMultipartBoundary); | |
| 227 post_data->append("\r\n"); | |
| 228 post_data->append("Content-Disposition: form-data; name=\"webrtc_log\""); | |
| 229 post_data->append("; filename=\"webrtc_log.gz\"\r\n"); | |
| 230 post_data->append("Content-Type: application/gzip\r\n\r\n"); | |
| 231 post_data->append(reinterpret_cast<const char*>(&compressed_log[0]), | |
| 232 compressed_log.size()); | |
| 233 post_data->append("\r\n"); | |
| 234 } | |
| 235 | |
| 236 void WebRtcLogUploader::CompressLog(std::vector<uint8>* compressed_log, | 280 void WebRtcLogUploader::CompressLog(std::vector<uint8>* compressed_log, |
| 237 uint8* input, | 281 uint8* input, |
| 238 uint32 input_size) { | 282 uint32 input_size) { |
| 239 PartialCircularBuffer read_pcb(input, input_size); | 283 PartialCircularBuffer read_pcb(input, input_size); |
| 240 | 284 |
| 241 z_stream stream = {0}; | 285 z_stream stream = {0}; |
| 242 int result = deflateInit2(&stream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, | 286 int result = deflateInit2(&stream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, |
| 243 // windowBits = 15 is default, 16 is added to | 287 // windowBits = 15 is default, 16 is added to |
| 244 // produce a gzip header + trailer. | 288 // produce a gzip header + trailer. |
| 245 15 + 16, | 289 15 + 16, |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 417 if (!success) { | 461 if (!success) { |
| 418 error_message = "Uploading failed, response code: " + | 462 error_message = "Uploading failed, response code: " + |
| 419 base::IntToString(response_code); | 463 base::IntToString(response_code); |
| 420 } | 464 } |
| 421 content::BrowserThread::PostTask( | 465 content::BrowserThread::PostTask( |
| 422 content::BrowserThread::UI, FROM_HERE, | 466 content::BrowserThread::UI, FROM_HERE, |
| 423 base::Bind(upload_done_data.callback, success, report_id, | 467 base::Bind(upload_done_data.callback, success, report_id, |
| 424 error_message)); | 468 error_message)); |
| 425 } | 469 } |
| 426 } | 470 } |
| OLD | NEW |