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_
11 #include "base/basictypes.h"
12 #include "base/gtest_prod_util.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h"
16 #include "base/threading/thread_checker.h"
17 #include "content/public/browser/trace_uploader.h"
18 #include "net/url_request/url_fetcher_delegate.h"
22 class URLRequestContextGetter
;
27 // Allow up to 10MB for trace upload
28 const int kMaxUploadBytes
= 10000000;
32 // TraceCrashServiceUploader uploads traces to the Chrome crash service.
33 class TraceCrashServiceUploader
: public content::TraceUploader
,
34 public net::URLFetcherDelegate
{
36 explicit TraceCrashServiceUploader(
37 net::URLRequestContextGetter
* request_context
);
38 ~TraceCrashServiceUploader() override
;
40 void SetUploadURL(const std::string
& url
);
42 // net::URLFetcherDelegate implementation.
43 void OnURLFetchComplete(const net::URLFetcher
* source
) override
;
44 void OnURLFetchUploadProgress(const net::URLFetcher
* source
,
46 int64 total
) override
;
48 // content::TraceUploader
49 void DoUpload(const std::string
& file_contents
,
50 UploadMode upload_mode
,
51 scoped_ptr
<base::DictionaryValue
> metadata
,
52 const UploadProgressCallback
& progress_callback
,
53 const UploadDoneCallback
& done_callback
) override
;
56 void DoUploadOnFileThread(const std::string
& file_contents
,
57 UploadMode upload_mode
,
58 const std::string
& upload_url
,
59 scoped_ptr
<base::DictionaryValue
> metadata
,
60 const UploadProgressCallback
& progress_callback
,
61 const UploadDoneCallback
& done_callback
);
62 // Sets up a multipart body to be uploaded. The body is produced according
64 void SetupMultipart(const std::string
& product
,
65 const std::string
& version
,
66 scoped_ptr
<base::DictionaryValue
> metadata
,
67 const std::string
& trace_filename
,
68 const std::string
& trace_contents
,
69 std::string
* post_data
);
70 void AddTraceFile(const std::string
& trace_filename
,
71 const std::string
& trace_contents
,
72 std::string
* post_data
);
73 // Compresses the input and returns whether compression was successful.
74 bool Compress(std::string input
,
75 int max_compressed_bytes
,
76 char* compressed_contents
,
77 int* compressed_bytes
);
78 void CreateAndStartURLFetcher(const std::string
& upload_url
,
79 const std::string
& post_data
);
80 void OnUploadError(std::string error_message
);
82 scoped_ptr
<net::URLFetcher
> url_fetcher_
;
83 UploadProgressCallback progress_callback_
;
84 UploadDoneCallback done_callback_
;
86 net::URLRequestContextGetter
* request_context_
;
88 std::string upload_url_
;
90 DISALLOW_COPY_AND_ASSIGN(TraceCrashServiceUploader
);
93 #endif // CHROME_BROWSER_TRACING_CRASH_SERVICE_UPLOADER_H_