Index: components/webrtc_log_uploader/webrtc_log_uploader.h |
diff --git a/components/webrtc_log_uploader/webrtc_log_uploader.h b/components/webrtc_log_uploader/webrtc_log_uploader.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..26d7142a02cddb4cf17117431516bf89cae2a3ae |
--- /dev/null |
+++ b/components/webrtc_log_uploader/webrtc_log_uploader.h |
@@ -0,0 +1,79 @@ |
+// Copyright 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef COMPONENTS_WEBRTC_LOG_UPLOADER_WEBRTC_LOG_UPLOADER_H_ |
+#define COMPONENTS_WEBRTC_LOG_UPLOADER_WEBRTC_LOG_UPLOADER_H_ |
+ |
+#include <string> |
+#include <vector> |
+ |
+#include "base/basictypes.h" |
+#include "base/memory/ref_counted.h" |
+#include "base/platform_file.h" |
+#include "components/webrtc_log_uploader/webrtc_log_uploader_export.h" |
+#include "net/url_request/url_fetcher_delegate.h" |
+ |
+namespace base { |
+class SharedMemory; |
+} |
+ |
+namespace net { |
+class URLFetcher; |
+} |
+ |
+namespace components { |
+ |
+class WebRtcLogURLRequestContextGetter; |
+ |
+// WebRtcLogUploader uploads WebRTC logs, keeps count of how many logs have |
+// been started and denies further logs if a limit is reached. There must only |
+// be one object of this type. |
+class WEBRTC_LOG_UPLOADER_EXPORT WebRtcLogUploader |
+ : public net::URLFetcherDelegate { |
+ public: |
+ WebRtcLogUploader(); |
+ virtual ~WebRtcLogUploader(); |
+ |
+ // net::URLFetcherDelegate implementation. |
+ virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
+ virtual void OnURLFetchUploadProgress(const net::URLFetcher* source, |
+ int64 current, int64 total) OVERRIDE; |
+ |
+ // Returns true is number of logs limit is not reached yet. Increases log |
+ // count if true is returned. |
+ bool ApplyForStartLogging(); |
+ |
+ // Uploads log and decreases log count. |
+ void UploadLog(scoped_ptr<base::SharedMemory> shared_memory, uint32 length); |
vabr (Chromium)
2013/05/13 08:55:50
If the contract is that ApplyForStartLogging() nee
Henrik Grunell
2013/05/14 13:48:50
Done.
|
+ |
+ private: |
+ void SetupMultipartFile(uint8* log_buffer, uint32 log_buffer_length, |
+ const base::FilePath& upload_file_path); |
+ void AddPairString(const std::string& key, const std::string& value); |
+ void AddUrlChunks(); |
+ void AddLogData(uint8* log_buffer, uint32 log_buffer_length); |
+ void CompressLog(uint8* input, uint32 input_size, |
+ base::PlatformFile output_file); |
+ void AddMultipartValueForUpload(const std::string& value_name, |
+ const std::string& value, |
+ const std::string& mime_boundary, |
+ const std::string& content_type, |
+ std::string* post_data); |
+ void DecreaseLogCount(); |
+ |
+ int log_count_; |
+ |
+ std::vector<net::URLFetcher*> url_fetchers_; |
+ scoped_refptr<WebRtcLogURLRequestContextGetter> |
+ request_context_getter_; |
+ |
+ // TODO(grunell): Maybe don't need to be member. |
+ base::PlatformFile multipart_file_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(WebRtcLogUploader); |
+}; |
+ |
+} // namespace components |
+ |
+#endif // COMPONENTS_WEBRTC_LOG_UPLOADER_WEBRTC_LOG_UPLOADER_H_ |