| 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 <stddef.h> |
| 8 |
| 7 #include "base/files/file_enumerator.h" | 9 #include "base/files/file_enumerator.h" |
| 8 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 9 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 10 #include "base/logging.h" | 12 #include "base/logging.h" |
| 11 #include "base/pickle.h" | 13 #include "base/pickle.h" |
| 12 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/string_split.h" | 15 #include "base/strings/string_split.h" |
| 14 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 15 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 18 #include "build/build_config.h" |
| 16 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/media/media_url_constants.h" | 20 #include "chrome/browser/media/media_url_constants.h" |
| 18 #include "chrome/browser/media/webrtc_log_list.h" | 21 #include "chrome/browser/media/webrtc_log_list.h" |
| 19 #include "chrome/browser/media/webrtc_log_util.h" | 22 #include "chrome/browser/media/webrtc_log_util.h" |
| 20 #include "chrome/common/partial_circular_buffer.h" | 23 #include "chrome/common/partial_circular_buffer.h" |
| 21 #include "components/version_info/version_info.h" | 24 #include "components/version_info/version_info.h" |
| 22 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
| 23 #include "net/base/mime_util.h" | 26 #include "net/base/mime_util.h" |
| 24 #include "net/url_request/url_fetcher.h" | 27 #include "net/url_request/url_fetcher.h" |
| 25 #include "third_party/zlib/zlib.h" | 28 #include "third_party/zlib/zlib.h" |
| 26 | 29 |
| 27 using content::BrowserThread; | 30 using content::BrowserThread; |
| 28 | 31 |
| 29 namespace { | 32 namespace { |
| 30 | 33 |
| 31 const int kLogCountLimit = 5; | 34 const int kLogCountLimit = 5; |
| 32 const uint32 kIntermediateCompressionBufferBytes = 256 * 1024; // 256 KB | 35 const uint32_t kIntermediateCompressionBufferBytes = 256 * 1024; // 256 KB |
| 33 const int kLogListLimitLines = 50; | 36 const int kLogListLimitLines = 50; |
| 34 | 37 |
| 35 const char kUploadContentType[] = "multipart/form-data"; | 38 const char kUploadContentType[] = "multipart/form-data"; |
| 36 const char kMultipartBoundary[] = | 39 const char kMultipartBoundary[] = |
| 37 "----**--yradnuoBgoLtrapitluMklaTelgooG--**----"; | 40 "----**--yradnuoBgoLtrapitluMklaTelgooG--**----"; |
| 38 | 41 |
| 39 const int kHttpResponseOk = 200; | 42 const int kHttpResponseOk = 200; |
| 40 | 43 |
| 41 // Adds the header section for a gzip file to the multipart |post_data|. | 44 // Adds the header section for a gzip file to the multipart |post_data|. |
| 42 void AddMultipartFileContentHeader(std::string* post_data, | 45 void AddMultipartFileContentHeader(std::string* post_data, |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 base::Unretained(this), log_list_path, | 309 base::Unretained(this), log_list_path, |
| 307 it->second.local_log_id, report_id)); | 310 it->second.local_log_id, report_id)); |
| 308 } | 311 } |
| 309 NotifyUploadDone(response_code, report_id, it->second); | 312 NotifyUploadDone(response_code, report_id, it->second); |
| 310 upload_done_data_.erase(it); | 313 upload_done_data_.erase(it); |
| 311 } | 314 } |
| 312 | 315 |
| 313 delete source; | 316 delete source; |
| 314 } | 317 } |
| 315 | 318 |
| 316 void WebRtcLogUploader::OnURLFetchUploadProgress( | 319 void WebRtcLogUploader::OnURLFetchUploadProgress(const net::URLFetcher* source, |
| 317 const net::URLFetcher* source, int64 current, int64 total) { | 320 int64_t current, |
| 318 } | 321 int64_t total) {} |
| 319 | 322 |
| 320 void WebRtcLogUploader::SetupMultipart( | 323 void WebRtcLogUploader::SetupMultipart( |
| 321 std::string* post_data, | 324 std::string* post_data, |
| 322 const std::string& compressed_log, | 325 const std::string& compressed_log, |
| 323 const base::FilePath& incoming_rtp_dump, | 326 const base::FilePath& incoming_rtp_dump, |
| 324 const base::FilePath& outgoing_rtp_dump, | 327 const base::FilePath& outgoing_rtp_dump, |
| 325 const std::map<std::string, std::string>& meta_data) { | 328 const std::map<std::string, std::string>& meta_data) { |
| 326 #if defined(OS_WIN) | 329 #if defined(OS_WIN) |
| 327 const char product[] = "Chrome"; | 330 const char product[] = "Chrome"; |
| 328 #elif defined(OS_MACOSX) | 331 #elif defined(OS_MACOSX) |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 WebRtcLogBuffer* buffer) { | 380 WebRtcLogBuffer* buffer) { |
| 378 z_stream stream = {0}; | 381 z_stream stream = {0}; |
| 379 int result = deflateInit2(&stream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, | 382 int result = deflateInit2(&stream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, |
| 380 // windowBits = 15 is default, 16 is added to | 383 // windowBits = 15 is default, 16 is added to |
| 381 // produce a gzip header + trailer. | 384 // produce a gzip header + trailer. |
| 382 15 + 16, | 385 15 + 16, |
| 383 8, // memLevel = 8 is default. | 386 8, // memLevel = 8 is default. |
| 384 Z_DEFAULT_STRATEGY); | 387 Z_DEFAULT_STRATEGY); |
| 385 DCHECK_EQ(Z_OK, result); | 388 DCHECK_EQ(Z_OK, result); |
| 386 | 389 |
| 387 uint8 intermediate_buffer[kIntermediateCompressionBufferBytes] = {0}; | 390 uint8_t intermediate_buffer[kIntermediateCompressionBufferBytes] = {0}; |
| 388 ResizeForNextOutput(compressed_log, &stream); | 391 ResizeForNextOutput(compressed_log, &stream); |
| 389 uint32 read = 0; | 392 uint32_t read = 0; |
| 390 | 393 |
| 391 PartialCircularBuffer read_buffer(buffer->Read()); | 394 PartialCircularBuffer read_buffer(buffer->Read()); |
| 392 do { | 395 do { |
| 393 if (stream.avail_in == 0) { | 396 if (stream.avail_in == 0) { |
| 394 read = read_buffer.Read(&intermediate_buffer[0], | 397 read = read_buffer.Read(&intermediate_buffer[0], |
| 395 sizeof(intermediate_buffer)); | 398 sizeof(intermediate_buffer)); |
| 396 stream.next_in = &intermediate_buffer[0]; | 399 stream.next_in = &intermediate_buffer[0]; |
| 397 stream.avail_in = read; | 400 stream.avail_in = read; |
| 398 if (read != kIntermediateCompressionBufferBytes) | 401 if (read != kIntermediateCompressionBufferBytes) |
| 399 break; | 402 break; |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 std::string error_message; | 588 std::string error_message; |
| 586 if (!success) { | 589 if (!success) { |
| 587 error_message = "Uploading failed, response code: " + | 590 error_message = "Uploading failed, response code: " + |
| 588 base::IntToString(response_code); | 591 base::IntToString(response_code); |
| 589 } | 592 } |
| 590 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 593 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 591 base::Bind(upload_done_data.callback, success, | 594 base::Bind(upload_done_data.callback, success, |
| 592 report_id, error_message)); | 595 report_id, error_message)); |
| 593 } | 596 } |
| 594 } | 597 } |
| OLD | NEW |