Skip to content

Commit

Permalink
Merge pull request #86 from supervacuus/feat/handler_http_proxy_support
Browse files Browse the repository at this point in the history
feat: handler http-proxy support
  • Loading branch information
supervacuus authored May 27, 2023
2 parents 3b82866 + 7041349 commit 3cdef1c
Show file tree
Hide file tree
Showing 16 changed files with 260 additions and 66 deletions.
5 changes: 5 additions & 0 deletions client/client_argv_handling.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ std::vector<std::string> BuildHandlerArgvStrings(
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 All @@ -54,6 +55,10 @@ std::vector<std::string> BuildHandlerArgvStrings(
argv_strings.push_back(FormatArgumentString("url", url));
}

if (!http_proxy.empty()) {
argv_strings.push_back(FormatArgumentString("http-proxy", http_proxy));
}

for (const auto& kv : annotations) {
argv_strings.push_back(
FormatArgumentString("annotation", kv.first + '=' + kv.second));
Expand Down
1 change: 1 addition & 0 deletions client/client_argv_handling.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ std::vector<std::string> BuildHandlerArgvStrings(
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
7 changes: 7 additions & 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 Expand Up @@ -363,6 +364,8 @@ class CrashpadClient {
//! path as its `--metrics-dir` argument.
//! \param[in] url The URL of an upload server. The handler will be started
//! with this URL as its `--url` argument.
//! \param[in] http_proxy The URL of an HTTP proxy. The handler will be started
//! with this URL as its `--http-proxy` argument.
//! \param[in] annotations Process annotations to set in each crash report.
//! The handler will be started with an `--annotation` argument for each
//! element in this map.
Expand All @@ -377,6 +380,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,
const std::vector<base::FilePath>& attachments = {});
Expand All @@ -394,6 +398,8 @@ class CrashpadClient {
//! path as its `--metrics-dir` argument.
//! \param[in] url The URL of an upload server. The handler will be started
//! with this URL as its `--url` argument.
//! \param[in] http_proxy The URL of an HTTP proxy. The handler will be started
//! with this URL as its `--http-proxy` argument.
//! \param[in] annotations Process annotations to set in each crash report.
//! The handler will be started with an `--annotation` argument for each
//! element in this map.
Expand All @@ -410,6 +416,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,
int socket);
Expand Down
9 changes: 6 additions & 3 deletions client/crashpad_client_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ bool CrashpadClient::StartHandler(
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 @@ -457,7 +458,7 @@ bool CrashpadClient::StartHandler(
}

std::vector<std::string> argv = BuildHandlerArgvStrings(
handler, database, metrics_dir, url, annotations, arguments, attachments);
handler, database, metrics_dir, url, http_proxy, annotations, arguments, attachments);

argv.push_back(FormatArgumentInt("initial-client-fd", handler_sock.get()));
argv.push_back("--shared-client-connection");
Expand Down Expand Up @@ -676,11 +677,12 @@ bool CrashpadClient::StartHandlerAtCrash(
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) {
std::vector<std::string> argv = BuildHandlerArgvStrings(
handler, database, metrics_dir, url, annotations, arguments, attachments);
handler, database, metrics_dir, url, http_proxy, annotations, arguments, attachments);

auto signal_handler = LaunchAtCrashHandler::Get();
return signal_handler->Initialize(&argv, nullptr, &unhandled_signals_);
Expand All @@ -692,11 +694,12 @@ bool CrashpadClient::StartHandlerForClient(
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,
int socket) {
std::vector<std::string> argv = BuildHandlerArgvStrings(
handler, database, metrics_dir, url, annotations, arguments);
handler, database, metrics_dir, url, http_proxy, annotations, arguments);

argv.push_back(FormatArgumentInt("initial-client-fd", socket));

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: 10 additions & 0 deletions client/crashpad_client_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ struct BackgroundHandlerStartThreadData {
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 All @@ -340,6 +341,7 @@ struct BackgroundHandlerStartThreadData {
database(database),
metrics_dir(metrics_dir),
url(url),
http_proxy(http_proxy),
annotations(annotations),
arguments(arguments),
attachments(attachments),
Expand All @@ -350,6 +352,7 @@ struct BackgroundHandlerStartThreadData {
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 Down Expand Up @@ -405,6 +408,11 @@ bool StartHandlerProcess(
FormatArgumentString("url", base::UTF8ToWide(data->url)),
&command_line);
}
if (!data->http_proxy.empty()) {
AppendCommandLineArgument(
FormatArgumentString("http-proxy", base::UTF8ToWide(data->http_proxy)),
&command_line);
}
for (const auto& kv : data->annotations) {
AppendCommandLineArgument(
FormatArgumentString("annotation",
Expand Down Expand Up @@ -629,6 +637,7 @@ bool CrashpadClient::StartHandler(
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 Expand Up @@ -661,6 +670,7 @@ bool CrashpadClient::StartHandler(
database,
metrics_dir,
url,
http_proxy,
annotations,
arguments,
attachments,
Expand Down
2 changes: 1 addition & 1 deletion client/ios_handler/in_process_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ bool InProcessHandler::Initialize(
upload_thread_options.identify_client_via_url = true;

upload_thread_.reset(new CrashReportUploadThread(
database_.get(), url, upload_thread_options, callback));
database_.get(), url, "", upload_thread_options, callback));
}

if (!CreateDirectory(database))
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
Loading

0 comments on commit 3cdef1c

Please sign in to comment.