Move StartsWith[ASCII] to base namespace.
[chromium-blink-merge.git] / chrome / browser / tracing / crash_service_uploader.h
blob5211f4303adc7e740f145dc13d499b1ec7999e0a
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 CHROME_BROWSER_TRACING_CRASH_SERVICE_UPLOADER_H_
6 #define CHROME_BROWSER_TRACING_CRASH_SERVICE_UPLOADER_H_
8 #include <map>
9 #include <string>
10 #include <vector>
12 #include "base/basictypes.h"
13 #include "base/gtest_prod_util.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/weak_ptr.h"
17 #include "base/threading/thread_checker.h"
18 #include "content/public/browser/trace_uploader.h"
19 #include "net/url_request/url_fetcher_delegate.h"
21 namespace net {
22 class URLFetcher;
23 class URLRequestContextGetter;
24 } // namespace net
26 namespace {
28 // Allow up to 10MB for trace upload
29 const int kMaxUploadBytes = 10000000;
31 } // namespace
33 // TraceCrashServiceUploader uploads traces to the Chrome crash service.
34 class TraceCrashServiceUploader : public content::TraceUploader,
35 public net::URLFetcherDelegate {
36 public:
37 explicit TraceCrashServiceUploader(
38 net::URLRequestContextGetter* request_context);
39 ~TraceCrashServiceUploader() override;
41 void SetUploadURL(const std::string& url);
43 // net::URLFetcherDelegate implementation.
44 void OnURLFetchComplete(const net::URLFetcher* source) override;
45 void OnURLFetchUploadProgress(const net::URLFetcher* source,
46 int64 current,
47 int64 total) override;
49 // content::TraceUploader
50 void DoUpload(const std::string& file_contents,
51 const UploadProgressCallback& progress_callback,
52 const UploadDoneCallback& done_callback) override;
54 private:
55 void DoUploadOnFileThread(const std::string& file_contents,
56 const std::string& upload_url,
57 const UploadProgressCallback& progress_callback,
58 const UploadDoneCallback& done_callback);
59 // Sets up a multipart body to be uploaded. The body is produced according
60 // to RFC 2046.
61 void SetupMultipart(const std::string& product,
62 const std::string& version,
63 const std::string& trace_filename,
64 const std::string& trace_contents,
65 std::string* post_data);
66 void AddTraceFile(const std::string& trace_filename,
67 const std::string& trace_contents,
68 std::string* post_data);
69 // Compresses the input and returns whether compression was successful.
70 bool Compress(std::string input,
71 int max_compressed_bytes,
72 char* compressed_contents,
73 int* compressed_bytes);
74 void CreateAndStartURLFetcher(const std::string& upload_url,
75 const std::string& post_data);
76 void OnUploadError(std::string error_message);
78 scoped_ptr<net::URLFetcher> url_fetcher_;
79 UploadProgressCallback progress_callback_;
80 UploadDoneCallback done_callback_;
82 net::URLRequestContextGetter* request_context_;
84 std::string upload_url_;
86 DISALLOW_COPY_AND_ASSIGN(TraceCrashServiceUploader);
89 #endif // CHROME_BROWSER_TRACING_CRASH_SERVICE_UPLOADER_H_