| 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 <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/gtest_prod_util.h" |
| 12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 13 #include "base/platform_file.h" | 14 #include "base/platform_file.h" |
| 14 #include "net/url_request/url_fetcher_delegate.h" | 15 #include "net/url_request/url_fetcher_delegate.h" |
| 15 | 16 |
| 16 namespace base { | 17 namespace base { |
| 17 class SharedMemory; | 18 class SharedMemory; |
| 18 } | 19 } |
| 19 | 20 |
| 20 namespace net { | 21 namespace net { |
| 21 class URLFetcher; | 22 class URLFetcher; |
| 22 class URLRequestContextGetter; | 23 class URLRequestContextGetter; |
| 23 } | 24 } |
| 24 | 25 |
| 25 typedef struct z_stream_s z_stream; | 26 typedef struct z_stream_s z_stream; |
| 26 | 27 |
| 27 class WebRtcLogURLRequestContextGetter; | 28 class WebRtcLogURLRequestContextGetter; |
| 28 | 29 |
| 29 // WebRtcLogUploader uploads WebRTC logs, keeps count of how many logs have | 30 // WebRtcLogUploader uploads WebRTC logs, keeps count of how many logs have |
| 30 // been started and denies further logs if a limit is reached. There must only | 31 // been started and denies further logs if a limit is reached. It also adds |
| 31 // be one object of this type. | 32 // the timestamp and report ID of the uploded log to a text file. There must |
| 33 // only be one object of this type. |
| 32 class WebRtcLogUploader : public net::URLFetcherDelegate { | 34 class WebRtcLogUploader : public net::URLFetcherDelegate { |
| 33 public: | 35 public: |
| 34 WebRtcLogUploader(); | 36 WebRtcLogUploader(); |
| 35 virtual ~WebRtcLogUploader(); | 37 virtual ~WebRtcLogUploader(); |
| 36 | 38 |
| 37 // net::URLFetcherDelegate implementation. | 39 // net::URLFetcherDelegate implementation. |
| 38 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 40 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 39 virtual void OnURLFetchUploadProgress(const net::URLFetcher* source, | 41 virtual void OnURLFetchUploadProgress(const net::URLFetcher* source, |
| 40 int64 current, int64 total) OVERRIDE; | 42 int64 current, int64 total) OVERRIDE; |
| 41 | 43 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 53 const std::string& app_session_id, | 55 const std::string& app_session_id, |
| 54 const std::string& app_url); | 56 const std::string& app_url); |
| 55 | 57 |
| 56 // For testing purposes. If called, the multipart will not be uploaded, but | 58 // For testing purposes. If called, the multipart will not be uploaded, but |
| 57 // written to |post_data_| instead. | 59 // written to |post_data_| instead. |
| 58 void OverrideUploadWithBufferForTesting(std::string* post_data) { | 60 void OverrideUploadWithBufferForTesting(std::string* post_data) { |
| 59 post_data_ = post_data; | 61 post_data_ = post_data; |
| 60 } | 62 } |
| 61 | 63 |
| 62 private: | 64 private: |
| 65 FRIEND_TEST_ALL_PREFIXES(WebRtcLogUploaderTest, |
| 66 AddUploadedLogInfoToUploadListFile); |
| 67 |
| 63 // Sets up a multipart body to be uploaded. The body is produced according | 68 // Sets up a multipart body to be uploaded. The body is produced according |
| 64 // to RFC 2046. | 69 // to RFC 2046. |
| 65 void SetupMultipart(std::string* post_data, uint8* log_buffer, | 70 void SetupMultipart(std::string* post_data, uint8* log_buffer, |
| 66 uint32 log_buffer_length, | 71 uint32 log_buffer_length, |
| 67 const std::string& app_session_id, | 72 const std::string& app_session_id, |
| 68 const std::string& app_url); | 73 const std::string& app_url); |
| 69 | 74 |
| 70 void AddLogData(std::string* post_data, uint8* log_buffer, | 75 void AddLogData(std::string* post_data, uint8* log_buffer, |
| 71 uint32 log_buffer_length); | 76 uint32 log_buffer_length); |
| 72 void CompressLog(std::string* post_data, uint8* input, uint32 input_size); | 77 void CompressLog(std::string* post_data, uint8* input, uint32 input_size); |
| 73 void ResizeForNextOutput(std::string* post_data, z_stream* stream); | 78 void ResizeForNextOutput(std::string* post_data, z_stream* stream); |
| 74 void DecreaseLogCount(); | 79 void DecreaseLogCount(); |
| 75 | 80 |
| 81 // Append information (time and report ID) about this uploaded log to a log |
| 82 // list file, limited to |kLogListLimitLines| entries. This list is used for |
| 83 // viewing the uploaded logs under chrome://webrtc-logs, see |
| 84 // WebRtcLogUploadList. The list has the format |
| 85 // time,id |
| 86 // time,id |
| 87 // etc. |
| 88 // where each line represents an uploaded log and "time" is Unix time. |
| 89 void AddUploadedLogInfoToUploadListFile(const std::string& report_id); |
| 90 |
| 91 void SetUploadPathForTesting(const base::FilePath& path) { |
| 92 upload_list_path_ = path; |
| 93 } |
| 94 |
| 76 int log_count_; | 95 int log_count_; |
| 96 base::FilePath upload_list_path_; |
| 77 | 97 |
| 78 // For testing purposes, see OverrideUploadWithBufferForTesting. Only accessed | 98 // For testing purposes, see OverrideUploadWithBufferForTesting. Only accessed |
| 79 // on the FILE thread. | 99 // on the FILE thread. |
| 80 std::string* post_data_; | 100 std::string* post_data_; |
| 81 | 101 |
| 82 DISALLOW_COPY_AND_ASSIGN(WebRtcLogUploader); | 102 DISALLOW_COPY_AND_ASSIGN(WebRtcLogUploader); |
| 83 }; | 103 }; |
| 84 | 104 |
| 85 #endif // CHROME_BROWSER_MEDIA_WEBRTC_LOG_UPLOADER_H_ | 105 #endif // CHROME_BROWSER_MEDIA_WEBRTC_LOG_UPLOADER_H_ |
| OLD | NEW |