Disable PDF tests that are failing after combining PDF plugin into chrome.
[chromium-blink-merge.git] / content / browser / tracing / trace_uploader.h
blob323a4c54668b12f6f6fabbb7f98c6919fa09a259
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.
5 #ifndef CONTENT_BROWSER_TRACING_TRACE_UPLOADER_H_
6 #define CONTENT_BROWSER_TRACING_TRACE_UPLOADER_H_
8 #include <map>
9 #include <string>
10 #include <vector>
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"
21 namespace net {
22 class URLFetcher;
23 class URLRequestContextGetter;
24 } // namespace net
26 namespace content {
28 namespace {
30 // Allow up to 10MB for trace upload
31 const int kMaxUploadBytes = 10000000;
33 } // namespace
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;
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;
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;
54 // Compresses and uploads the given file contents.
55 void DoUpload(const std::string& file_contents,
56 UploadProgressCallback progress_callback,
57 UploadDoneCallback done_callback);
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);
76 std::string product_;
77 std::string version_;
79 std::string upload_url_;
81 scoped_ptr<net::URLFetcher> url_fetcher_;
82 UploadProgressCallback progress_callback_;
83 UploadDoneCallback done_callback_;
85 net::URLRequestContextGetter* request_context_;
87 DISALLOW_COPY_AND_ASSIGN(TraceUploader);
90 } // namespace content
92 #endif // CONTENT_BROWSER_TRACING_TRACE_UPLOADER_H_