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.
5 #include "chromecast/crash/cast_crashdump_uploader.h"
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"
14 namespace chromecast
{
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";
28 CastCrashdumpData::CastCrashdumpData() {
31 CastCrashdumpData::~CastCrashdumpData() {
34 CastCrashdumpUploader::CastCrashdumpUploader(const CastCrashdumpData
& data
)
35 : CastCrashdumpUploader(data
, new google_breakpad::LibcurlWrapper()) {
36 // This instance of libcurlwrapper will leak.
39 CastCrashdumpUploader::CastCrashdumpUploader(
40 const CastCrashdumpData
& data
,
41 google_breakpad::LibcurlWrapper
* http_layer
)
42 : http_layer_(http_layer
), data_(data
) {
46 CastCrashdumpUploader::~CastCrashdumpUploader() {
49 bool CastCrashdumpUploader::AddAttachment(const std::string
& label
,
50 const std::string
& filename
) {
51 attachments_
[label
] = filename
;
55 bool CastCrashdumpUploader::CheckRequiredParametersArePresent() {
56 return !(data_
.product
.empty() || data_
.version
.empty() ||
57 data_
.guid
.empty() || data_
.minidump_pathname
.empty());
60 bool CastCrashdumpUploader::Upload(std::string
* response
) {
61 if (!http_layer_
->Init()) {
62 LOG(ERROR
) << "http layer Init failed";
66 if (!CheckRequiredParametersArePresent()) {
67 LOG(ERROR
) << "Missing required parameters";
72 if (0 != stat(data_
.minidump_pathname
.c_str(), &st
)) {
73 LOG(ERROR
) << data_
.minidump_pathname
<< " does not exist.";
77 if (!http_layer_
->AddFile(data_
.minidump_pathname
, "upload_file_minidump")) {
78 LOG(ERROR
) << "Failed to add file: " << data_
.minidump_pathname
;
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
;
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";
100 if (!http_layer_
->AddFile(iter
->second
, iter
->first
)) {
101 LOG(ERROR
) << "Failed to add file: " << iter
->second
102 << " with label: " << iter
->first
;
107 LOG(INFO
) << "Sending request to " << data_
.crash_server
;
109 int http_status_code
;
110 std::string http_header_data
;
111 return http_layer_
->SendRequest(data_
.crash_server
,
118 void CastCrashdumpUploader::SetParameter(const std::string
& key
,
119 const std::string
& value
) {
120 parameters_
[key
] = value
;
123 } // namespace chromecast