| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 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 CONTENT_BROWSER_TRACING_TRACE_UPLOADER_H_ | |
| 6 #define CONTENT_BROWSER_TRACING_TRACE_UPLOADER_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <string> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/basictypes.h" | |
| 13 #include "base/callback.h" | |
| 14 #include "base/gtest_prod_util.h" | |
| 15 #include "base/memory/ref_counted.h" | |
| 16 #include "base/memory/scoped_ptr.h" | |
| 17 #include "base/memory/weak_ptr.h" | |
| 18 #include "base/threading/thread_checker.h" | |
| 19 #include "net/url_request/url_fetcher_delegate.h" | |
| 20 | |
| 21 namespace net { | |
| 22 class URLFetcher; | |
| 23 class URLRequestContextGetter; | |
| 24 } // namespace net | |
| 25 | |
| 26 namespace content { | |
| 27 | |
| 28 namespace { | |
| 29 | |
| 30 // Allow up to 10MB for trace upload | |
| 31 const int kMaxUploadBytes = 10000000; | |
| 32 | |
| 33 } // namespace | |
| 34 | |
| 35 // TraceUploader uploads traces. | |
| 36 class TraceUploader : public net::URLFetcherDelegate { | |
| 37 public: | |
| 38 typedef base::Callback<void(bool, const std::string&, const std::string&)> | |
| 39 UploadDoneCallback; | |
| 40 typedef base::Callback<void(int64, int64)> UploadProgressCallback; | |
| 41 | |
| 42 TraceUploader(const std::string& product, | |
| 43 const std::string& version, | |
| 44 const std::string& upload_url, | |
| 45 net::URLRequestContextGetter* request_context); | |
| 46 ~TraceUploader() override; | |
| 47 | |
| 48 // net::URLFetcherDelegate implementation. | |
| 49 void OnURLFetchComplete(const net::URLFetcher* source) override; | |
| 50 void OnURLFetchUploadProgress(const net::URLFetcher* source, | |
| 51 int64 current, | |
| 52 int64 total) override; | |
| 53 | |
| 54 // Compresses and uploads the given file contents. | |
| 55 void DoUpload(const std::string& file_contents, | |
| 56 UploadProgressCallback progress_callback, | |
| 57 UploadDoneCallback done_callback); | |
| 58 | |
| 59 private: | |
| 60 // Sets up a multipart body to be uploaded. The body is produced according | |
| 61 // to RFC 2046. | |
| 62 void SetupMultipart(const std::string& trace_filename, | |
| 63 const std::string& trace_contents, | |
| 64 std::string* post_data); | |
| 65 void AddTraceFile(const std::string& trace_filename, | |
| 66 const std::string& trace_contents, | |
| 67 std::string* post_data); | |
| 68 // Compresses the input and returns whether compression was successful. | |
| 69 bool Compress(std::string input, | |
| 70 int max_compressed_bytes, | |
| 71 char* compressed_contents, | |
| 72 int* compressed_bytes); | |
| 73 void CreateAndStartURLFetcher(const std::string& post_data); | |
| 74 void OnUploadError(std::string error_message); | |
| 75 | |
| 76 std::string product_; | |
| 77 std::string version_; | |
| 78 | |
| 79 std::string upload_url_; | |
| 80 | |
| 81 scoped_ptr<net::URLFetcher> url_fetcher_; | |
| 82 UploadProgressCallback progress_callback_; | |
| 83 UploadDoneCallback done_callback_; | |
| 84 | |
| 85 net::URLRequestContextGetter* request_context_; | |
| 86 | |
| 87 DISALLOW_COPY_AND_ASSIGN(TraceUploader); | |
| 88 }; | |
| 89 | |
| 90 } // namespace content | |
| 91 | |
| 92 #endif // CONTENT_BROWSER_TRACING_TRACE_UPLOADER_H_ | |
| OLD | NEW |