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 // |upload_list_path| is the text file to add the uploaded log info to. It is |
37 // intended for testing. If empty the default path will be used. | |
38 explicit WebRtcLogUploader(base::FilePath& upload_list_path); | |
tommi (sloooow) - chröme
2013/07/01 12:01:01
instead of changing the constructor and add a File
Henrik Grunell
2013/07/01 13:26:22
Done.
| |
35 virtual ~WebRtcLogUploader(); | 39 virtual ~WebRtcLogUploader(); |
36 | 40 |
37 // net::URLFetcherDelegate implementation. | 41 // net::URLFetcherDelegate implementation. |
38 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 42 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
39 virtual void OnURLFetchUploadProgress(const net::URLFetcher* source, | 43 virtual void OnURLFetchUploadProgress(const net::URLFetcher* source, |
40 int64 current, int64 total) OVERRIDE; | 44 int64 current, int64 total) OVERRIDE; |
41 | 45 |
42 // Returns true is number of logs limit is not reached yet. Increases log | 46 // Returns true is number of logs limit is not reached yet. Increases log |
43 // count if true is returned. Must be called before UploadLog(). | 47 // count if true is returned. Must be called before UploadLog(). |
44 bool ApplyForStartLogging(); | 48 bool ApplyForStartLogging(); |
45 | 49 |
46 // Uploads log and decreases log count. May only be called if permission to | 50 // Uploads log and decreases log count. May only be called if permission to |
47 // to log has been granted by calling ApplyForStartLogging() and getting true | 51 // to log has been granted by calling ApplyForStartLogging() and getting true |
48 // in return. After UploadLog has been called, a new permission must be | 52 // in return. After UploadLog has been called, a new permission must be |
49 // granted. | 53 // granted. |
50 void UploadLog(net::URLRequestContextGetter* request_context, | 54 void UploadLog(net::URLRequestContextGetter* request_context, |
51 scoped_ptr<base::SharedMemory> shared_memory, | 55 scoped_ptr<base::SharedMemory> shared_memory, |
52 uint32 length, | 56 uint32 length, |
53 const std::string& app_session_id, | 57 const std::string& app_session_id, |
54 const std::string& app_url); | 58 const std::string& app_url); |
55 | 59 |
56 private: | 60 private: |
61 FRIEND_TEST_ALL_PREFIXES(WebRtcLogUploaderTest, Basic); | |
62 | |
57 // Sets up a multipart body to be uploaded. The body is produced according | 63 // Sets up a multipart body to be uploaded. The body is produced according |
58 // to RFC 2046. | 64 // to RFC 2046. |
59 void SetupMultipart(std::string* post_data, uint8* log_buffer, | 65 void SetupMultipart(std::string* post_data, uint8* log_buffer, |
60 uint32 log_buffer_length, | 66 uint32 log_buffer_length, |
61 const std::string& app_session_id, | 67 const std::string& app_session_id, |
62 const std::string& app_url); | 68 const std::string& app_url); |
63 | 69 |
64 void AddLogData(std::string* post_data, uint8* log_buffer, | 70 void AddLogData(std::string* post_data, uint8* log_buffer, |
65 uint32 log_buffer_length); | 71 uint32 log_buffer_length); |
66 void CompressLog(std::string* post_data, uint8* input, uint32 input_size); | 72 void CompressLog(std::string* post_data, uint8* input, uint32 input_size); |
67 void ResizeForNextOutput(std::string* post_data, z_stream* stream); | 73 void ResizeForNextOutput(std::string* post_data, z_stream* stream); |
68 void DecreaseLogCount(); | 74 void DecreaseLogCount(); |
69 | 75 |
76 // Append information (time and report ID) about this uploaded log to a log | |
77 // list file, limited to |kLogListLimitLines| entries. This list is used for | |
78 // viewing the uploaded logs under chrome://webrtc-logs, see | |
79 // WebRtcLogUploadList. The list has the format | |
80 // time,id | |
81 // time,id | |
82 // etc. | |
83 // where each line represents an uploaded log and "time" is Unix time. | |
84 void AddUploadedLogInfoToUploadListFile(const std::string& report_id); | |
85 | |
70 int log_count_; | 86 int log_count_; |
87 base::FilePath upload_list_path_; | |
71 | 88 |
72 DISALLOW_COPY_AND_ASSIGN(WebRtcLogUploader); | 89 DISALLOW_COPY_AND_ASSIGN(WebRtcLogUploader); |
73 }; | 90 }; |
74 | 91 |
75 #endif // CHROME_BROWSER_MEDIA_WEBRTC_LOG_UPLOADER_H_ | 92 #endif // CHROME_BROWSER_MEDIA_WEBRTC_LOG_UPLOADER_H_ |
OLD | NEW |