Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / chrome / browser / tracing / crash_service_uploader.h
blob23cf556ae1fb3dd6250d779bcb0e183e4be102f5
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 // net::URLFetcherDelegate implementation.
42 void OnURLFetchComplete(const net::URLFetcher* source) override;
43 void OnURLFetchUploadProgress(const net::URLFetcher* source,
44 int64 current,
45 int64 total) override;
47 // content::TraceUploader
48 void DoUpload(const std::string& file_contents,
49 const UploadProgressCallback& progress_callback,
50 const UploadDoneCallback& done_callback) override;
52 private:
53 void DoUploadOnFileThread(const std::string& file_contents,
54 const UploadProgressCallback& progress_callback,
55 const UploadDoneCallback& done_callback);
56 // Sets up a multipart body to be uploaded. The body is produced according
57 // to RFC 2046.
58 void SetupMultipart(const std::string& product,
59 const std::string& version,
60 const std::string& trace_filename,
61 const std::string& trace_contents,
62 std::string* post_data);
63 void AddTraceFile(const std::string& trace_filename,
64 const std::string& trace_contents,
65 std::string* post_data);
66 // Compresses the input and returns whether compression was successful.
67 bool Compress(std::string input,
68 int max_compressed_bytes,
69 char* compressed_contents,
70 int* compressed_bytes);
71 void CreateAndStartURLFetcher(const std::string& upload_url,
72 const std::string& post_data);
73 void OnUploadError(std::string error_message);
75 scoped_ptr<net::URLFetcher> url_fetcher_;
76 UploadProgressCallback progress_callback_;
77 UploadDoneCallback done_callback_;
79 net::URLRequestContextGetter* request_context_;
81 DISALLOW_COPY_AND_ASSIGN(TraceCrashServiceUploader);
84 #endif // CHROME_BROWSER_TRACING_CRASH_SERVICE_UPLOADER_H_