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> |
no longer working on chromium
2013/10/01 08:41:42
include what you are using:
include <map>
Henrik Grunell
2013/10/02 12:47:18
Done.
| |
9 #include <vector> | |
10 | 9 |
11 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
12 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
13 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
14 #include "base/platform_file.h" | 13 #include "base/platform_file.h" |
14 #include "chrome/browser/media/webrtc_logging_handler_host.h" | |
15 #include "net/url_request/url_fetcher_delegate.h" | 15 #include "net/url_request/url_fetcher_delegate.h" |
16 | 16 |
17 namespace base { | 17 namespace base { |
18 class SharedMemory; | 18 class SharedMemory; |
19 } | 19 } |
20 | 20 |
21 namespace net { | 21 namespace net { |
22 class URLFetcher; | 22 class URLFetcher; |
23 class URLRequestContextGetter; | 23 class URLRequestContextGetter; |
24 } | 24 } |
25 | 25 |
26 typedef struct z_stream_s z_stream; | 26 typedef struct z_stream_s z_stream; |
27 | 27 |
28 // Used when uploading is done to inform about that it's done. | |
29 typedef struct { | |
30 WebRtcLoggingHandlerHost::UploadDoneCallback callback; | |
31 scoped_refptr<WebRtcLoggingHandlerHost> host; | |
32 } WebRtcLogUploadDoneData; | |
33 | |
28 class WebRtcLogURLRequestContextGetter; | 34 class WebRtcLogURLRequestContextGetter; |
29 | 35 |
30 // WebRtcLogUploader uploads WebRTC logs, keeps count of how many logs have | 36 // WebRtcLogUploader uploads WebRTC logs, keeps count of how many logs have |
31 // been started and denies further logs if a limit is reached. It also adds | 37 // been started and denies further logs if a limit is reached. It also adds |
32 // the timestamp and report ID of the uploded log to a text file. There must | 38 // the timestamp and report ID of the uploded log to a text file. There must |
33 // only be one object of this type. | 39 // only be one object of this type. |
34 class WebRtcLogUploader : public net::URLFetcherDelegate { | 40 class WebRtcLogUploader : public net::URLFetcherDelegate { |
35 public: | 41 public: |
36 WebRtcLogUploader(); | 42 WebRtcLogUploader(); |
37 virtual ~WebRtcLogUploader(); | 43 virtual ~WebRtcLogUploader(); |
38 | 44 |
39 // net::URLFetcherDelegate implementation. | 45 // net::URLFetcherDelegate implementation. |
40 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 46 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
41 virtual void OnURLFetchUploadProgress(const net::URLFetcher* source, | 47 virtual void OnURLFetchUploadProgress(const net::URLFetcher* source, |
42 int64 current, int64 total) OVERRIDE; | 48 int64 current, int64 total) OVERRIDE; |
43 | 49 |
44 // Returns true is number of logs limit is not reached yet. Increases log | 50 // Returns true is number of logs limit is not reached yet. Increases log |
45 // count if true is returned. Must be called before UploadLog(). | 51 // count if true is returned. Must be called before UploadLog(). |
46 bool ApplyForStartLogging(); | 52 bool ApplyForStartLogging(); |
47 | 53 |
48 // Uploads log and decreases log count. May only be called if permission to | 54 // Notifies that that logging has stopped and that the log should not be |
55 // uploaded. Decreases log count. May only be called if permission to | |
Jói
2013/09/27 14:39:53
"to to" (one at the end of this line, one at start
Henrik Grunell
2013/10/02 12:47:18
Done.
| |
49 // to log has been granted by calling ApplyForStartLogging() and getting true | 56 // to log has been granted by calling ApplyForStartLogging() and getting true |
50 // in return. After UploadLog has been called, a new permission must be | 57 // in return. After this function has been called, a new permission must be |
51 // granted. | 58 // granted. Call either this function or LoggingStoppedDoUpload(). |
52 void UploadLog(net::URLRequestContextGetter* request_context, | 59 void LoggingStoppedDontUpload(); |
53 scoped_ptr<base::SharedMemory> shared_memory, | 60 |
54 uint32 length, | 61 // Notifies that that logging has stopped and that the log should be uploaded. |
55 const std::string& app_session_id, | 62 // Decreases log count. May only be called if permission to |
Jói
2013/09/27 14:39:53
"to to"
Henrik Grunell
2013/10/02 12:47:18
Done.
| |
56 const std::string& app_url); | 63 // to log has been granted by calling ApplyForStartLogging() and getting true |
64 // in return. After this function has been called, a new permission must be | |
65 // granted. Call either this function or LoggingStoppedDontUpload(). | |
66 void LoggingStoppedDoUpload( | |
67 net::URLRequestContextGetter* request_context, | |
68 scoped_ptr<base::SharedMemory> shared_memory, | |
69 uint32 length, | |
70 const std::map<std::string, std::string>& meta_data, | |
71 const std::string& app_url, | |
72 const WebRtcLogUploadDoneData& upload_done_data); | |
57 | 73 |
58 // For testing purposes. If called, the multipart will not be uploaded, but | 74 // For testing purposes. If called, the multipart will not be uploaded, but |
59 // written to |post_data_| instead. | 75 // written to |post_data_| instead. |
60 void OverrideUploadWithBufferForTesting(std::string* post_data) { | 76 void OverrideUploadWithBufferForTesting(std::string* post_data) { |
61 post_data_ = post_data; | 77 post_data_ = post_data; |
62 } | 78 } |
63 | 79 |
64 private: | 80 private: |
65 FRIEND_TEST_ALL_PREFIXES(WebRtcLogUploaderTest, | 81 FRIEND_TEST_ALL_PREFIXES(WebRtcLogUploaderTest, |
66 AddUploadedLogInfoToUploadListFile); | 82 AddUploadedLogInfoToUploadListFile); |
67 | 83 |
68 // Sets up a multipart body to be uploaded. The body is produced according | 84 // Sets up a multipart body to be uploaded. The body is produced according |
69 // to RFC 2046. | 85 // to RFC 2046. |
70 void SetupMultipart(std::string* post_data, uint8* log_buffer, | 86 void SetupMultipart(std::string* post_data, uint8* log_buffer, |
71 uint32 log_buffer_length, | 87 uint32 log_buffer_length, |
72 const std::string& app_session_id, | 88 const std::map<std::string, std::string>& meta_data, |
73 const std::string& app_url); | 89 const std::string& app_url); |
74 | 90 |
75 void AddLogData(std::string* post_data, uint8* log_buffer, | 91 void AddLogData(std::string* post_data, uint8* log_buffer, |
76 uint32 log_buffer_length); | 92 uint32 log_buffer_length); |
77 void CompressLog(std::string* post_data, uint8* input, uint32 input_size); | 93 void CompressLog(std::string* post_data, uint8* input, uint32 input_size); |
78 void ResizeForNextOutput(std::string* post_data, z_stream* stream); | 94 void ResizeForNextOutput(std::string* post_data, z_stream* stream); |
79 void DecreaseLogCount(); | 95 void DecreaseLogCount(); |
80 | 96 |
81 // Append information (time and report ID) about this uploaded log to a log | 97 // 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 | 98 // list file, limited to |kLogListLimitLines| entries. This list is used for |
83 // viewing the uploaded logs under chrome://webrtc-logs, see | 99 // viewing the uploaded logs under chrome://webrtc-logs, see |
84 // WebRtcLogUploadList. The list has the format | 100 // WebRtcLogUploadList. The list has the format |
85 // time,id | 101 // time,id |
86 // time,id | 102 // time,id |
87 // etc. | 103 // etc. |
88 // where each line represents an uploaded log and "time" is Unix time. | 104 // where each line represents an uploaded log and "time" is Unix time. |
89 void AddUploadedLogInfoToUploadListFile(const std::string& report_id); | 105 void AddUploadedLogInfoToUploadListFile(const std::string& report_id); |
90 | 106 |
91 void SetUploadPathForTesting(const base::FilePath& path) { | 107 void SetUploadPathForTesting(const base::FilePath& path) { |
92 upload_list_path_ = path; | 108 upload_list_path_ = path; |
93 } | 109 } |
94 | 110 |
95 int log_count_; | 111 int log_count_; |
96 base::FilePath upload_list_path_; | 112 base::FilePath upload_list_path_; |
97 | 113 |
98 // For testing purposes, see OverrideUploadWithBufferForTesting. Only accessed | 114 // For testing purposes, see OverrideUploadWithBufferForTesting. Only accessed |
99 // on the FILE thread. | 115 // on the FILE thread. |
100 std::string* post_data_; | 116 std::string* post_data_; |
101 | 117 |
118 typedef std::map<const net::URLFetcher*, WebRtcLogUploadDoneData> | |
119 UploadDoneDataMap; | |
120 UploadDoneDataMap upload_done_data_; | |
121 | |
102 DISALLOW_COPY_AND_ASSIGN(WebRtcLogUploader); | 122 DISALLOW_COPY_AND_ASSIGN(WebRtcLogUploader); |
103 }; | 123 }; |
104 | 124 |
105 #endif // CHROME_BROWSER_MEDIA_WEBRTC_LOG_UPLOADER_H_ | 125 #endif // CHROME_BROWSER_MEDIA_WEBRTC_LOG_UPLOADER_H_ |
OLD | NEW |