OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef COMPONENTS_WEBRTC_LOG_UPLOADER_WEBRTC_LOG_UPLOADER_H_ |
| 6 #define COMPONENTS_WEBRTC_LOG_UPLOADER_WEBRTC_LOG_UPLOADER_H_ |
| 7 |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/basictypes.h" |
| 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/platform_file.h" |
| 14 #include "components/webrtc_log_uploader/webrtc_log_uploader_export.h" |
| 15 #include "net/url_request/url_fetcher_delegate.h" |
| 16 |
| 17 namespace base { |
| 18 class SharedMemory; |
| 19 } |
| 20 |
| 21 namespace net { |
| 22 class URLFetcher; |
| 23 } |
| 24 |
| 25 namespace components { |
| 26 |
| 27 class WebRtcLogURLRequestContextGetter; |
| 28 |
| 29 // 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 // be one object of this type. |
| 32 class WEBRTC_LOG_UPLOADER_EXPORT WebRtcLogUploader |
| 33 : public net::URLFetcherDelegate { |
| 34 public: |
| 35 WebRtcLogUploader(); |
| 36 virtual ~WebRtcLogUploader(); |
| 37 |
| 38 // net::URLFetcherDelegate implementation. |
| 39 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 40 virtual void OnURLFetchUploadProgress(const net::URLFetcher* source, |
| 41 int64 current, int64 total) OVERRIDE; |
| 42 |
| 43 // Returns true is number of logs limit is not reached yet. Increases log |
| 44 // count if true is returned. Must be called before UploadLog(). |
| 45 bool ApplyForStartLogging(); |
| 46 |
| 47 // Uploads log and decreases log count. May only be called if permission to |
| 48 // to log has been granted by calling ApplyForStartLogging() and getting true |
| 49 // in return. After UploadLog has been called, a new permission must be |
| 50 // granted. |
| 51 void UploadLog(scoped_ptr<base::SharedMemory> shared_memory, uint32 length); |
| 52 |
| 53 private: |
| 54 // Sets up a multipart file to be uploaded. The body is produced according |
| 55 // to RFC 2046. |
| 56 void SetupMultipartFile(uint8* log_buffer, uint32 log_buffer_length, |
| 57 const base::FilePath& upload_file_path); |
| 58 |
| 59 void AddPairString(base::PlatformFile multipart_file, const std::string& key, |
| 60 const std::string& value); |
| 61 void AddUrlChunks(); |
| 62 void AddLogData(base::PlatformFile multipart_file, uint8* log_buffer, |
| 63 uint32 log_buffer_length); |
| 64 void CompressLog(uint8* input, uint32 input_size, |
| 65 base::PlatformFile output_file); |
| 66 void AddMultipartValueForUpload(const std::string& value_name, |
| 67 const std::string& value, |
| 68 const std::string& mime_boundary, |
| 69 const std::string& content_type, |
| 70 std::string* post_data); |
| 71 void DecreaseLogCount(); |
| 72 |
| 73 int log_count_; |
| 74 |
| 75 scoped_refptr<WebRtcLogURLRequestContextGetter> |
| 76 request_context_getter_; |
| 77 |
| 78 DISALLOW_COPY_AND_ASSIGN(WebRtcLogUploader); |
| 79 }; |
| 80 |
| 81 } // namespace components |
| 82 |
| 83 #endif // COMPONENTS_WEBRTC_LOG_UPLOADER_WEBRTC_LOG_UPLOADER_H_ |
OLD | NEW |