Skip to content

Commit

Permalink
Initial e2e implementation macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
supervacuus committed May 20, 2023
1 parent 3b82866 commit dc77935
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 61 deletions.
1 change: 1 addition & 0 deletions client/crashpad_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ class CrashpadClient {
const base::FilePath& database,
const base::FilePath& metrics_dir,
const std::string& url,
const std::string& http_proxy,
const std::map<std::string, std::string>& annotations,
const std::vector<std::string>& arguments,
bool restartable,
Expand Down
38 changes: 26 additions & 12 deletions client/crashpad_client_mac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ bool SetCrashExceptionPorts(exception_handler_t exception_handler) {
class ScopedPthreadAttrDestroy {
public:
explicit ScopedPthreadAttrDestroy(pthread_attr_t* pthread_attr)
: pthread_attr_(pthread_attr) {
}
: pthread_attr_(pthread_attr) {}

ScopedPthreadAttrDestroy(const ScopedPthreadAttrDestroy&) = delete;
ScopedPthreadAttrDestroy& operator=(const ScopedPthreadAttrDestroy&) = delete;
Expand Down Expand Up @@ -127,6 +126,7 @@ class HandlerStarter final : public NotifyServer::DefaultInterface {
const base::FilePath& database,
const base::FilePath& metrics_dir,
const std::string& url,
const std::string& http_proxy,
const std::map<std::string, std::string>& annotations,
const std::vector<std::string>& arguments,
const std::vector<base::FilePath>& attachments,
Expand Down Expand Up @@ -167,6 +167,7 @@ class HandlerStarter final : public NotifyServer::DefaultInterface {
database,
metrics_dir,
url,
http_proxy,
annotations,
arguments,
attachments,
Expand All @@ -177,8 +178,14 @@ class HandlerStarter final : public NotifyServer::DefaultInterface {
}

if (handler_restarter &&
handler_restarter->StartRestartThread(
handler, database, metrics_dir, url, annotations, arguments, attachments)) {
handler_restarter->StartRestartThread(handler,
database,
metrics_dir,
url,
http_proxy,
annotations,
arguments,
attachments)) {
// The thread owns the object now.
std::ignore = handler_restarter.release();
}
Expand Down Expand Up @@ -211,6 +218,7 @@ class HandlerStarter final : public NotifyServer::DefaultInterface {
database_,
metrics_dir_,
url_,
http_proxy_,
annotations_,
arguments_,
attachments_,
Expand All @@ -232,8 +240,7 @@ class HandlerStarter final : public NotifyServer::DefaultInterface {
arguments_(),
attachments_(),
notify_port_(NewMachPort(MACH_PORT_RIGHT_RECEIVE)),
last_start_time_(0) {
}
last_start_time_(0) {}

//! \brief Starts a Crashpad handler.
//!
Expand All @@ -258,6 +265,7 @@ class HandlerStarter final : public NotifyServer::DefaultInterface {
const base::FilePath& database,
const base::FilePath& metrics_dir,
const std::string& url,
const std::string& http_proxy,
const std::map<std::string, std::string>& annotations,
const std::vector<std::string>& arguments,
const std::vector<base::FilePath>& attachments,
Expand Down Expand Up @@ -337,6 +345,9 @@ class HandlerStarter final : public NotifyServer::DefaultInterface {
if (!url.empty()) {
argv.push_back(FormatArgumentString("url", url));
}
if (!http_proxy.empty()) {
argv.push_back(FormatArgumentString("http-proxy", http_proxy));
}
for (const auto& kv : annotations) {
argv.push_back(
FormatArgumentString("annotation", kv.first + '=' + kv.second));
Expand Down Expand Up @@ -380,13 +391,15 @@ class HandlerStarter final : public NotifyServer::DefaultInterface {
const base::FilePath& database,
const base::FilePath& metrics_dir,
const std::string& url,
const std::string& http_proxy,
const std::map<std::string, std::string>& annotations,
const std::vector<std::string>& arguments,
const std::vector<base::FilePath>& attachments) {
handler_ = handler;
database_ = database;
metrics_dir_ = metrics_dir;
url_ = url;
http_proxy_ = http_proxy;
annotations_ = annotations;
arguments_ = arguments;
attachments_ = attachments;
Expand Down Expand Up @@ -440,6 +453,7 @@ class HandlerStarter final : public NotifyServer::DefaultInterface {
base::FilePath database_;
base::FilePath metrics_dir_;
std::string url_;
std::string http_proxy_;
std::map<std::string, std::string> annotations_;
std::vector<std::string> arguments_;
std::vector<base::FilePath> attachments_;
Expand All @@ -449,17 +463,16 @@ class HandlerStarter final : public NotifyServer::DefaultInterface {

} // namespace

CrashpadClient::CrashpadClient() : exception_port_(MACH_PORT_NULL) {
}
CrashpadClient::CrashpadClient() : exception_port_(MACH_PORT_NULL) {}

CrashpadClient::~CrashpadClient() {
}
CrashpadClient::~CrashpadClient() {}

bool CrashpadClient::StartHandler(
const base::FilePath& handler,
const base::FilePath& database,
const base::FilePath& metrics_dir,
const std::string& url,
const std::string& http_proxy,
const std::map<std::string, std::string>& annotations,
const std::vector<std::string>& arguments,
bool restartable,
Expand All @@ -473,6 +486,7 @@ bool CrashpadClient::StartHandler(
database,
metrics_dir,
url,
http_proxy,
annotations,
arguments,
attachments,
Expand Down Expand Up @@ -538,8 +552,8 @@ base::mac::ScopedMachSendRight CrashpadClient::GetHandlerMachPort() const {

// static
void CrashpadClient::UseSystemDefaultHandler() {
base::mac::ScopedMachSendRight
system_crash_reporter_handler(SystemCrashReporterHandler());
base::mac::ScopedMachSendRight system_crash_reporter_handler(
SystemCrashReporterHandler());

// Proceed even if SystemCrashReporterHandler() failed, setting MACH_PORT_NULL
// to clear the current exception ports.
Expand Down
10 changes: 7 additions & 3 deletions handler/crash_report_upload_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <algorithm>
#include <map>
#include <memory>
#include <utility>
#include <vector>

#include "base/logging.h"
Expand Down Expand Up @@ -88,12 +89,14 @@ class ScopedFunctionInvoker final {

CrashReportUploadThread::CrashReportUploadThread(
CrashReportDatabase* database,
const std::string& url,
std::string url,
std::string http_proxy,
const Options& options,
ProcessPendingReportsObservationCallback callback)
: options_(options),
callback_(callback),
url_(url),
callback_(std::move(callback)),
url_(std::move(url)),
http_proxy_(std::move(http_proxy)),
// When watching for pending reports, check every 15 minutes, even in the
// absence of a signal from the handler thread. This allows for failed
// uploads to be retried periodically, and for pending reports written by
Expand Down Expand Up @@ -365,6 +368,7 @@ CrashReportUploadThread::UploadResult CrashReportUploadThread::UploadReport(
}
}
http_transport->SetURL(url);
http_transport->SetHTTPProxy(http_proxy_);

if (!http_transport->ExecuteSynchronously(response_body)) {
return UploadResult::kRetry;
Expand Down
4 changes: 3 additions & 1 deletion handler/crash_report_upload_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ class CrashReportUploadThread : public WorkerThread::Delegate,
//! processing and attempting to upload on-disk crash reports.
//! If this callback is empty, it is not invoked.
CrashReportUploadThread(CrashReportDatabase* database,
const std::string& url,
std::string url,
std::string http_proxy,
const Options& options,
ProcessPendingReportsObservationCallback callback);

Expand Down Expand Up @@ -226,6 +227,7 @@ class CrashReportUploadThread : public WorkerThread::Delegate,
const Options options_;
const ProcessPendingReportsObservationCallback callback_;
const std::string url_;
const std::string http_proxy_;
WorkerThread thread_;
ThreadSafeVector<UUID> known_pending_report_uuids_;
#if BUILDFLAG(IS_IOS)
Expand Down
9 changes: 9 additions & 0 deletions handler/handler_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ struct Options {
std::map<std::string, std::string> annotations;
std::map<std::string, std::string> monitor_self_annotations;
std::string url;
std::string http_proxy;
base::FilePath database;
base::FilePath metrics_dir;
std::vector<std::string> monitor_self_arguments;
Expand Down Expand Up @@ -515,6 +516,7 @@ void MonitorSelf(const Options& options) {
options.database,
base::FilePath(),
options.url,
options.http_proxy,
options.annotations,
extra_arguments,
true,
Expand Down Expand Up @@ -621,6 +623,7 @@ int HandlerMain(int argc,
kOptionTraceParentWithException,
#endif
kOptionURL,
kOptionHttpProxy,
#if BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(IS_CHROMEOS_LACROS)
kOptionUseCrosCrashReporter,
kOptionMinidumpDirForTests,
Expand Down Expand Up @@ -705,6 +708,7 @@ int HandlerMain(int argc,
#endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) ||
// BUILDFLAG(IS_ANDROID)
{"url", required_argument, nullptr, kOptionURL},
{"http-proxy", optional_argument, nullptr, kOptionHttpProxy},
#if BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(IS_CHROMEOS_LACROS)
{"use-cros-crash-reporter",
no_argument,
Expand Down Expand Up @@ -878,6 +882,10 @@ int HandlerMain(int argc,
options.url = optarg;
break;
}
case kOptionHttpProxy: {
options.http_proxy = optarg;
break;
}
#if BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(IS_CHROMEOS_LACROS)
case kOptionUseCrosCrashReporter: {
options.use_cros_crash_reporter = true;
Expand Down Expand Up @@ -1030,6 +1038,7 @@ int HandlerMain(int argc,
upload_thread.Reset(new CrashReportUploadThread(
database.get(),
options.url,
options.http_proxy,
upload_thread_options,
CrashReportUploadThread::ProcessPendingReportsObservationCallback()));
upload_thread.Get()->Start();
Expand Down
4 changes: 4 additions & 0 deletions util/net/http_transport.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ void HTTPTransport::SetURL(const std::string& url) {
url_ = url;
}

void HTTPTransport::SetHTTPProxy(const std::string& http_proxy) {
http_proxy_ = http_proxy;
}

void HTTPTransport::SetMethod(const std::string& method) {
method_ = method;
}
Expand Down
7 changes: 7 additions & 0 deletions util/net/http_transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ class HTTPTransport {
//! \param[in] url The request URL.
void SetURL(const std::string& url);

//! \brief Sets the optional HTTP proxy through which to send the request
//!
//! \param[in] http_proxy the fully specified URL
void SetHTTPProxy(const std::string& http_proxy);

//! \brief Sets the HTTP method to execute. E.g., GET, POST, etc. The default
//! method is `"POST"`.
//!
Expand Down Expand Up @@ -99,6 +104,7 @@ class HTTPTransport {
HTTPTransport();

const std::string& url() const { return url_; }
const std::string& http_proxy() const { return http_proxy_; }
const std::string& method() const { return method_; }
const HTTPHeaders& headers() const { return headers_; }
HTTPBodyStream* body_stream() const { return body_stream_.get(); }
Expand All @@ -109,6 +115,7 @@ class HTTPTransport {

private:
std::string url_;
std::string http_proxy_;
std::string method_;
base::FilePath root_ca_certificate_path_;
HTTPHeaders headers_;
Expand Down
3 changes: 3 additions & 0 deletions util/net/http_transport_libcurl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,9 @@ bool HTTPTransportLibcurl::ExecuteSynchronously(std::string* response_body) {
TRY_CURL_EASY_SETOPT(curl.get(), CURLOPT_READDATA, this);
TRY_CURL_EASY_SETOPT(curl.get(), CURLOPT_WRITEFUNCTION, WriteResponseBody);
TRY_CURL_EASY_SETOPT(curl.get(), CURLOPT_WRITEDATA, response_body);
if (!http_proxy().empty()) {
TRY_CURL_EASY_SETOPT(curl.get(), CURLOPT_PROXY, http_proxy());
}

#undef TRY_CURL_EASY_SETOPT
#undef TRY_CURL_SLIST_APPEND
Expand Down
Loading

0 comments on commit dc77935

Please sign in to comment.