Audacity 3.2.0
CrashpadConfigurer.cpp
Go to the documentation of this file.
2
3#include <client/crashpad_client.h>
4#include <client/crash_report_database.h>
5#include <client/settings.h>
6
7#include "internal/Util.h"
8
10{
11 mHandlerPath = handlerPath;
12 return *this;
13}
14
16{
17 mDatabasePath = database;
18 return *this;
19}
20
22{
23 mMetricsDir = metricsDir;
24 return *this;
25}
26
28{
29 mURL = url;
30 return *this;
31}
32
33CrashpadConfigurer& CrashpadConfigurer::SetArguments(const std::vector<std::string>& arguments)
34{
35 mArguments = arguments;
36 return *this;
37}
38
39CrashpadConfigurer& CrashpadConfigurer::SetAnnotations(const std::map<std::string, std::string>& annotations)
40{
41 mAnnotations = annotations;
42 return *this;
43}
44
45CrashpadConfigurer& CrashpadConfigurer::SetAttachmentsUTF8(const std::vector<std::string>& attachments)
46{
47 mAttachments = attachments;
48 return *this;
49}
50
52{
54 return *this;
55}
56
58{
59 base::FilePath databasePath(makeFilePath<base::FilePath::StringType>(mDatabasePath));
60
61 auto database = crashpad::CrashReportDatabase::Initialize(databasePath);
62 if (database == nullptr)
63 {
64 throw std::runtime_error("Crash report database error");
65 }
66 auto dbSettings = database->GetSettings();
67 if (dbSettings == nullptr)
68 {
69 throw std::runtime_error("Cannot access crash report database settings");
70 }
71 dbSettings->SetUploadsEnabled(mDatabaseUploadsEnabled);
72
73 base::FilePath metricsDir(makeFilePath<base::FilePath::StringType>(mMetricsDir));
74 base::FilePath handlerPath(makeFilePath<base::FilePath::StringType>(mHandlerPath));
75 std::vector<base::FilePath> attachments;
76 std::transform(mAttachments.begin(), mAttachments.end(), std::back_inserter(attachments), [](const std::string& path) {
77 return base::FilePath(makeFilePath<base::FilePath::StringType>(path));
78 });
79
80 crashpad::CrashpadClient client;
81
82 auto success = client.StartHandler(
83 handlerPath,
84 databasePath,
85 metricsDir,
86 mURL,
89 true,
90 false,
91 attachments);
92
93 if (!success)
94 {
95 throw std::runtime_error("Cannot start crashpad handler");
96 }
97}
wxString FilePath
Definition: Project.h:21
CrashpadConfigurer & SetMetricsDirUTF8(const std::string &metricsDir)
CrashpadConfigurer & SetDatabasePathUTF8(const std::string &database)
CrashpadConfigurer & SetHandlerPathUTF8(const std::string &handlerPath)
CrashpadConfigurer & SetDatabaseUploadEnabled(bool enabled)
CrashpadConfigurer & SetAttachmentsUTF8(const std::vector< std::string > &attachments)
CrashpadConfigurer & SetURL(const std::string &)
std::vector< std::string > mArguments
CrashpadConfigurer & SetAnnotations(const std::map< std::string, std::string > &annotations)
CrashpadConfigurer & SetArguments(const std::vector< std::string > &arguments)
std::string mHandlerPath
std::vector< std::string > mAttachments
std::map< std::string, std::string > mAnnotations