Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(502)

Side by Side Diff: chrome/browser/tracing/crash_service_uploader.h

Issue 911153002: Moved the TraceUploader to chrome/ and abstracted it for alternative new upload destinations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_BROWSER_TRACING_TRACE_UPLOADER_H_ 5 #ifndef CHROME_BROWSER_TRACING_CRASH_SERVICE_UPLOADER_H_
6 #define CONTENT_BROWSER_TRACING_TRACE_UPLOADER_H_ 6 #define CHROME_BROWSER_TRACING_CRASH_SERVICE_UPLOADER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/callback.h"
14 #include "base/gtest_prod_util.h" 13 #include "base/gtest_prod_util.h"
15 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
16 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
17 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
18 #include "base/threading/thread_checker.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" 19 #include "net/url_request/url_fetcher_delegate.h"
20 20
21 namespace net { 21 namespace net {
22 class URLFetcher; 22 class URLFetcher;
23 class URLRequestContextGetter; 23 class URLRequestContextGetter;
24 } // namespace net 24 } // namespace net
25 25
26 namespace content {
27
28 namespace { 26 namespace {
29 27
30 // Allow up to 10MB for trace upload 28 // Allow up to 10MB for trace upload
31 const int kMaxUploadBytes = 10000000; 29 const int kMaxUploadBytes = 10000000;
32 30
33 } // namespace 31 } // namespace
34 32
35 // TraceUploader uploads traces. 33 // TraceCrashServiceUploader uploads traces to the Chrome crash service.
36 class TraceUploader : public net::URLFetcherDelegate { 34 class TraceCrashServiceUploader : public content::TraceUploader,
35 public net::URLFetcherDelegate {
37 public: 36 public:
38 typedef base::Callback<void(bool, const std::string&, const std::string&)> 37 explicit TraceCrashServiceUploader(
39 UploadDoneCallback; 38 net::URLRequestContextGetter* request_context);
40 typedef base::Callback<void(int64, int64)> UploadProgressCallback; 39 ~TraceCrashServiceUploader() override;
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 40
48 // net::URLFetcherDelegate implementation. 41 // net::URLFetcherDelegate implementation.
49 void OnURLFetchComplete(const net::URLFetcher* source) override; 42 void OnURLFetchComplete(const net::URLFetcher* source) override;
50 void OnURLFetchUploadProgress(const net::URLFetcher* source, 43 void OnURLFetchUploadProgress(const net::URLFetcher* source,
51 int64 current, 44 int64 current,
52 int64 total) override; 45 int64 total) override;
53 46
54 // Compresses and uploads the given file contents. 47 // content::TraceUploader
55 void DoUpload(const std::string& file_contents, 48 void DoUpload(const std::string& file_contents,
56 UploadProgressCallback progress_callback, 49 UploadProgressCallback progress_callback,
Lei Zhang 2015/02/10 22:28:16 General feedback, feel free to address this in a s
oystein (OOO til 10th of July) 2015/02/10 23:40:15 Done.
57 UploadDoneCallback done_callback); 50 UploadDoneCallback done_callback) override;
58 51
59 private: 52 private:
53 void DoUploadOnFileThread(const std::string& file_contents,
54 UploadProgressCallback progress_callback,
55 UploadDoneCallback done_callback);
60 // Sets up a multipart body to be uploaded. The body is produced according 56 // Sets up a multipart body to be uploaded. The body is produced according
61 // to RFC 2046. 57 // to RFC 2046.
62 void SetupMultipart(const std::string& trace_filename, 58 void SetupMultipart(const std::string& product,
59 const std::string& version,
60 const std::string& trace_filename,
63 const std::string& trace_contents, 61 const std::string& trace_contents,
64 std::string* post_data); 62 std::string* post_data);
65 void AddTraceFile(const std::string& trace_filename, 63 void AddTraceFile(const std::string& trace_filename,
66 const std::string& trace_contents, 64 const std::string& trace_contents,
67 std::string* post_data); 65 std::string* post_data);
68 // Compresses the input and returns whether compression was successful. 66 // Compresses the input and returns whether compression was successful.
69 bool Compress(std::string input, 67 bool Compress(std::string input,
70 int max_compressed_bytes, 68 int max_compressed_bytes,
71 char* compressed_contents, 69 char* compressed_contents,
72 int* compressed_bytes); 70 int* compressed_bytes);
73 void CreateAndStartURLFetcher(const std::string& post_data); 71 void CreateAndStartURLFetcher(const std::string& upload_url,
72 const std::string& post_data);
74 void OnUploadError(std::string error_message); 73 void OnUploadError(std::string error_message);
75 74
76 std::string product_;
77 std::string version_;
78
79 std::string upload_url_;
80
81 scoped_ptr<net::URLFetcher> url_fetcher_; 75 scoped_ptr<net::URLFetcher> url_fetcher_;
82 UploadProgressCallback progress_callback_; 76 UploadProgressCallback progress_callback_;
83 UploadDoneCallback done_callback_; 77 UploadDoneCallback done_callback_;
84 78
85 net::URLRequestContextGetter* request_context_; 79 net::URLRequestContextGetter* request_context_;
86 80
87 DISALLOW_COPY_AND_ASSIGN(TraceUploader); 81 DISALLOW_COPY_AND_ASSIGN(TraceCrashServiceUploader);
88 }; 82 };
89 83
90 } // namespace content 84 #endif // CHROME_BROWSER_TRACING_CRASH_SERVICE_UPLOADER_H_
91
92 #endif // CONTENT_BROWSER_TRACING_TRACE_UPLOADER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698