OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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. | |
4 | |
5 #include "chromecast/crash/cast_crashdump_uploader.h" | |
6 | |
7 #include <sys/stat.h> | |
8 | |
9 #include "base/logging.h" | |
10 // TODO(slan): Find a replacement for LibcurlWrapper in Chromium to remove the | |
11 // breakpad dependency. | |
12 #include "breakpad/src/common/linux/libcurl_wrapper.h" | |
13 | |
14 namespace chromecast { | |
15 namespace { | |
16 | |
17 // Keep these in sync with "//breakpad/src/client/mac/sender/uploader.mm" | |
18 const char kProdKey[] = "prod"; | |
19 const char kVerKey[] = "ver"; | |
20 const char kGuidKey[] = "guid"; | |
21 const char kPtimeKey[] = "ptime"; | |
22 const char kCtimeKey[] = "ctime"; | |
23 const char kEmailKey[] = "email"; | |
24 const char kCommentsKey[] = "comments"; | |
25 | |
26 } // namespace | |
27 | |
28 CastCrashdumpData::CastCrashdumpData() { | |
alokp
2015/06/15 17:51:48
Do you need constructor/destructor for this struct
slan
2015/06/16 14:57:49
This is enforced by chromium-style for anything co
| |
29 } | |
30 | |
31 CastCrashdumpData::~CastCrashdumpData() { | |
32 } | |
33 | |
34 CastCrashdumpUploader::CastCrashdumpUploader(const CastCrashdumpData& data) | |
35 : CastCrashdumpUploader(data, new google_breakpad::LibcurlWrapper()) { | |
36 // This instance of libcurlwrapper will leak. | |
37 } | |
38 | |
39 CastCrashdumpUploader::CastCrashdumpUploader( | |
40 const CastCrashdumpData& data, | |
41 google_breakpad::LibcurlWrapper* http_layer) | |
42 : http_layer_(http_layer), data_(data) { | |
43 DCHECK(http_layer_); | |
44 } | |
45 | |
46 CastCrashdumpUploader::~CastCrashdumpUploader() { | |
47 } | |
48 | |
49 bool CastCrashdumpUploader::AddAttachment(const std::string& label, | |
50 const std::string& filename) { | |
51 attachments_[label] = filename; | |
52 return true; | |
53 } | |
54 | |
55 bool CastCrashdumpUploader::CheckRequiredParametersArePresent() { | |
56 return !(data_.product.empty() || data_.version.empty() || | |
57 data_.guid.empty() || data_.minidump_pathname.empty()); | |
58 } | |
59 | |
60 bool CastCrashdumpUploader::Upload(std::string* response) { | |
61 if (http_layer_->Init()) { | |
62 LOG(ERROR) << "http layer Init failed"; | |
63 return false; | |
64 } | |
65 | |
66 if (!CheckRequiredParametersArePresent()) { | |
67 LOG(ERROR) << "Missing required parameters"; | |
68 return false; | |
69 } | |
70 | |
71 struct stat st; | |
72 if (0 != stat(data_.minidump_pathname.c_str(), &st)) { | |
73 LOG(ERROR) << data_.minidump_pathname << " does not exist."; | |
74 return false; | |
75 } | |
76 | |
77 if (!http_layer_->AddFile(data_.minidump_pathname, "upload_file_minidump")) { | |
78 LOG(ERROR) << "Failed to add file: " << data_.minidump_pathname; | |
79 return false; | |
80 } | |
81 | |
82 // Populate |parameters_|. | |
83 parameters_[kProdKey] = data_.product; | |
84 parameters_[kVerKey] = data_.version; | |
85 parameters_[kGuidKey] = data_.guid; | |
86 parameters_[kPtimeKey] = data_.ptime; | |
87 parameters_[kCtimeKey] = data_.ctime; | |
88 parameters_[kEmailKey] = data_.email; | |
89 parameters_[kCommentsKey] = data_.comments; | |
90 | |
91 // Add each attachement in |attachments_|. | |
92 for (auto iter = attachments_.begin(); iter != attachments_.end(); ++iter) { | |
93 // Search for the attachment. | |
94 if (0 != stat(iter->second.c_str(), &st)) { | |
95 LOG(ERROR) << iter->second << " could not be found"; | |
96 return false; | |
97 } | |
98 | |
99 // Add the attachment | |
100 if (!http_layer_->AddFile(iter->second, iter->first)) { | |
101 LOG(ERROR) << "Failed to add file: " << iter->second | |
102 << " with label: " << iter->first; | |
103 return false; | |
104 } | |
105 } | |
106 | |
107 LOG(INFO) << "Sending request to " << data_.crash_server; | |
alokp
2015/06/15 17:51:48
VLOG?
I am not sure what convention we follow in
gunsch
2015/06/15 18:16:12
In general we stick with LOG(INFO) for things we w
slan
2015/06/16 14:57:49
Acknowledged.
| |
108 | |
109 int http_status_code; | |
110 std::string http_header_data; | |
111 return http_layer_->SendRequest(data_.crash_server, | |
112 parameters_, | |
113 &http_status_code, | |
114 &http_header_data, | |
115 response); | |
116 } | |
117 | |
118 void CastCrashdumpUploader::SetParameter(const std::string& key, | |
119 const std::string& value) { | |
120 parameters_[key] = value; | |
121 } | |
122 | |
123 } // namespace chromecast | |
OLD | NEW |