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 CHROME_BROWSER_MEDIA_WEBRTC_LOG_UPLOADER_H_ |
| 6 #define CHROME_BROWSER_MEDIA_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 "net/url_request/url_fetcher_delegate.h" |
| 15 |
| 16 namespace base { |
| 17 class SharedMemory; |
| 18 } |
| 19 |
| 20 namespace net { |
| 21 class URLFetcher; |
| 22 class URLRequestContextGetter; |
| 23 } |
| 24 |
| 25 typedef struct z_stream_s z_stream; |
| 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 WebRtcLogUploader : public net::URLFetcherDelegate { |
| 33 public: |
| 34 WebRtcLogUploader(); |
| 35 virtual ~WebRtcLogUploader(); |
| 36 |
| 37 // net::URLFetcherDelegate implementation. |
| 38 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 39 virtual void OnURLFetchUploadProgress(const net::URLFetcher* source, |
| 40 int64 current, int64 total) OVERRIDE; |
| 41 |
| 42 // Returns true is number of logs limit is not reached yet. Increases log |
| 43 // count if true is returned. Must be called before UploadLog(). |
| 44 bool ApplyForStartLogging(); |
| 45 |
| 46 // 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 |
| 48 // in return. After UploadLog has been called, a new permission must be |
| 49 // granted. |
| 50 void UploadLog(net::URLRequestContextGetter* request_context, |
| 51 scoped_ptr<base::SharedMemory> shared_memory, |
| 52 uint32 length, |
| 53 const std::string& app_session_id, |
| 54 const std::string& app_url); |
| 55 |
| 56 private: |
| 57 // Sets up a multipart body to be uploaded. The body is produced according |
| 58 // to RFC 2046. |
| 59 void SetupMultipart(std::string* post_data, uint8* log_buffer, |
| 60 uint32 log_buffer_length, |
| 61 const std::string& app_session_id, |
| 62 const std::string& app_url); |
| 63 |
| 64 void AddLogData(std::string* post_data, uint8* log_buffer, |
| 65 uint32 log_buffer_length); |
| 66 void CompressLog(std::string* post_data, uint8* input, uint32 input_size); |
| 67 void ResizeForNextOutput(std::string* post_data, z_stream* stream); |
| 68 void DecreaseLogCount(); |
| 69 |
| 70 int log_count_; |
| 71 |
| 72 DISALLOW_COPY_AND_ASSIGN(WebRtcLogUploader); |
| 73 }; |
| 74 |
| 75 #endif // CHROME_BROWSER_MEDIA_WEBRTC_LOG_UPLOADER_H_ |
OLD | NEW |