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

Side by Side Diff: chromecast/crash/cast_crashdump_uploader.cc

Issue 1154383006: Adding crash utilities to chromecast/crash. (Closed) Base URL: https://eureka-internal.googlesource.com/chromium/src@master
Patch Set: Linux-specific utils moved to linux/ Created 5 years, 6 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
(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 #include "breakpad/src/common/linux/libcurl_wrapper.h"
11
12 namespace chromecast {
13
14 CastCrashdumpData::CastCrashdumpData() {
15 }
16
17 CastCrashdumpData::~CastCrashdumpData() {
18 }
19
20 CastCrashdumpUploader::CastCrashdumpUploader(const CastCrashdumpData& data)
21 : CastCrashdumpUploader(data, new google_breakpad::LibcurlWrapper()) {
22 http_layer_created_internally_ = true;
23 }
24
25 CastCrashdumpUploader::CastCrashdumpUploader(
26 const CastCrashdumpData& data,
27 google_breakpad::LibcurlWrapper* http_layer)
28 : http_layer_(nullptr), http_layer_created_internally_(false) {
29 DCHECK(http_layer);
30 Init(data, http_layer);
31 }
32
33 CastCrashdumpUploader::~CastCrashdumpUploader() {
34 if (http_layer_created_internally_) {
35 // Note that calling delete on |http_layer_| will cause a build error when
36 // compiling with -Wdelete-non-virtual-dtor. |http_layer_| will leak in this
37 // case.
38 }
39 }
40
41 void CastCrashdumpUploader::Init(const CastCrashdumpData& data,
42 google_breakpad::LibcurlWrapper* http_layer) {
43 data_ = data;
44 http_layer_ = http_layer;
45 }
46
47 bool CastCrashdumpUploader::AddAttachment(const std::string& label,
48 const std::string& filename) {
49 attachments_[label] = filename;
50 return true;
51 }
52
53 bool CastCrashdumpUploader::CheckRequiredParametersArePresent() {
54 return !(data_.product.empty() || data_.version.empty() ||
55 data_.guid.empty() || data_.minidump_pathname.empty());
56 }
57
58 bool CastCrashdumpUploader::Upload(std::string* response) {
59 if (http_layer_->Init()) {
60 LOG(ERROR) << "http layer Init failed";
61 return false;
62 }
63
64 if (!CheckRequiredParametersArePresent()) {
65 LOG(ERROR) << "Missing required parameters";
66 return false;
67 }
68
69 struct stat st;
70 if (0 != stat(data_.minidump_pathname.c_str(), &st)) {
71 LOG(ERROR) << data_.minidump_pathname << " does not exist.";
72 return false;
73 }
74
75 if (!http_layer_->AddFile(data_.minidump_pathname, "upload_file_minidump")) {
76 LOG(ERROR) << "Failed to add file: " << data_.minidump_pathname;
77 return false;
78 }
79
80 // Populate |parameters_|.
81 parameters_["prod"] = data_.product;
82 parameters_["ver"] = data_.version;
83 parameters_["guid"] = data_.guid;
84 parameters_["ptime"] = data_.ptime;
85 parameters_["ctime"] = data_.ctime;
86 parameters_["email"] = data_.email;
87 parameters_["comments"] = data_.comments;
88
89 // Add each attachement in |attachments_|.
90 for (auto iter = attachments_.begin(); iter != attachments_.end(); ++iter) {
91 // Search for the attachment.
92 if (0 != stat(iter->second.c_str(), &st)) {
93 LOG(ERROR) << iter->second << " could not be found";
94 return false;
95 }
96
97 // Add the attachment
98 if (!http_layer_->AddFile(iter->second, iter->first)) {
99 LOG(ERROR) << "Failed to add file: " << iter->second
100 << " with label: " << iter->first;
101 return false;
102 }
103 }
104
105 LOG(INFO) << "Sending request to " << data_.crash_server;
106
107 int http_status_code;
108 std::string http_header_data;
109 return http_layer_->SendRequest(data_.crash_server,
110 parameters_,
111 &http_status_code,
112 &http_header_data,
113 response);
114 }
115
116 void CastCrashdumpUploader::SetParameter(const std::string& key,
117 const std::string& value) {
118 parameters_[key] = value;
119 }
120
121 } // namespace chromecast
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698