| Index: chromecast/crash/cast_crashdump_uploader.cc
|
| diff --git a/chromecast/crash/cast_crashdump_uploader.cc b/chromecast/crash/cast_crashdump_uploader.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..3f697a3ffbec355599f6db83e94ca988ea9ce32b
|
| --- /dev/null
|
| +++ b/chromecast/crash/cast_crashdump_uploader.cc
|
| @@ -0,0 +1,121 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chromecast/crash/cast_crashdump_uploader.h"
|
| +
|
| +#include <sys/stat.h>
|
| +
|
| +#include "base/logging.h"
|
| +#include "breakpad/src/common/linux/libcurl_wrapper.h"
|
| +
|
| +namespace chromecast {
|
| +
|
| +CastCrashdumpData::CastCrashdumpData() {
|
| +}
|
| +
|
| +CastCrashdumpData::~CastCrashdumpData() {
|
| +}
|
| +
|
| +CastCrashdumpUploader::CastCrashdumpUploader(const CastCrashdumpData& data)
|
| + : CastCrashdumpUploader(data, new google_breakpad::LibcurlWrapper()) {
|
| + http_layer_created_internally_ = true;
|
| +}
|
| +
|
| +CastCrashdumpUploader::CastCrashdumpUploader(
|
| + const CastCrashdumpData& data,
|
| + google_breakpad::LibcurlWrapper* http_layer)
|
| + : http_layer_(nullptr), http_layer_created_internally_(false) {
|
| + DCHECK(http_layer);
|
| + Init(data, http_layer);
|
| +}
|
| +
|
| +CastCrashdumpUploader::~CastCrashdumpUploader() {
|
| + if (http_layer_created_internally_) {
|
| + // Note that calling delete on |http_layer_| will cause a build error when
|
| + // compiling with -Wdelete-non-virtual-dtor. |http_layer_| will leak in this
|
| + // case.
|
| + }
|
| +}
|
| +
|
| +void CastCrashdumpUploader::Init(const CastCrashdumpData& data,
|
| + google_breakpad::LibcurlWrapper* http_layer) {
|
| + data_ = data;
|
| + http_layer_ = http_layer;
|
| +}
|
| +
|
| +bool CastCrashdumpUploader::AddAttachment(const std::string& label,
|
| + const std::string& filename) {
|
| + attachments_[label] = filename;
|
| + return true;
|
| +}
|
| +
|
| +bool CastCrashdumpUploader::CheckRequiredParametersArePresent() {
|
| + return !(data_.product.empty() || data_.version.empty() ||
|
| + data_.guid.empty() || data_.minidump_pathname.empty());
|
| +}
|
| +
|
| +bool CastCrashdumpUploader::Upload(std::string* response) {
|
| + if (http_layer_->Init()) {
|
| + LOG(ERROR) << "http layer Init failed";
|
| + return false;
|
| + }
|
| +
|
| + if (!CheckRequiredParametersArePresent()) {
|
| + LOG(ERROR) << "Missing required parameters";
|
| + return false;
|
| + }
|
| +
|
| + struct stat st;
|
| + if (0 != stat(data_.minidump_pathname.c_str(), &st)) {
|
| + LOG(ERROR) << data_.minidump_pathname << " does not exist.";
|
| + return false;
|
| + }
|
| +
|
| + if (!http_layer_->AddFile(data_.minidump_pathname, "upload_file_minidump")) {
|
| + LOG(ERROR) << "Failed to add file: " << data_.minidump_pathname;
|
| + return false;
|
| + }
|
| +
|
| + // Populate |parameters_|.
|
| + parameters_["prod"] = data_.product;
|
| + parameters_["ver"] = data_.version;
|
| + parameters_["guid"] = data_.guid;
|
| + parameters_["ptime"] = data_.ptime;
|
| + parameters_["ctime"] = data_.ctime;
|
| + parameters_["email"] = data_.email;
|
| + parameters_["comments"] = data_.comments;
|
| +
|
| + // Add each attachement in |attachments_|.
|
| + for (auto iter = attachments_.begin(); iter != attachments_.end(); ++iter) {
|
| + // Search for the attachment.
|
| + if (0 != stat(iter->second.c_str(), &st)) {
|
| + LOG(ERROR) << iter->second << " could not be found";
|
| + return false;
|
| + }
|
| +
|
| + // Add the attachment
|
| + if (!http_layer_->AddFile(iter->second, iter->first)) {
|
| + LOG(ERROR) << "Failed to add file: " << iter->second
|
| + << " with label: " << iter->first;
|
| + return false;
|
| + }
|
| + }
|
| +
|
| + LOG(INFO) << "Sending request to " << data_.crash_server;
|
| +
|
| + int http_status_code;
|
| + std::string http_header_data;
|
| + return http_layer_->SendRequest(data_.crash_server,
|
| + parameters_,
|
| + &http_status_code,
|
| + &http_header_data,
|
| + response);
|
| +}
|
| +
|
| +void CastCrashdumpUploader::SetParameter(const std::string& key,
|
| + const std::string& value) {
|
| + parameters_[key] = value;
|
| +}
|
| +
|
| +} // namespace chromecast
|
|
|