#include <map>
#include <string>
#include <vector>
#include "client/crashpad_client.h"
#include "client/settings.h"
#include "client/crash_report_database.h"
using crashpad::CrashReportDatabase;
using crashpad::CrashpadClient;
#if defined(__APPLE__) || defined(__linux__)
#define _convert(input) input
#elif defined(_MSC_VER)
#include <stringapiset.h>
#define _convert(input) s2ws(input)
std::wstring s2ws(char* str)
{
int len = strlen(str);
int size_needed = MultiByteToWideChar(CP_UTF8, 0, str, len, NULL, 0);
std::wstring wstrTo(size_needed, 0);
MultiByteToWideChar(CP_UTF8, 0, str, len, &wstrTo[0], size_needed);
return wstrTo;
}
#endif
extern "C" {
bool start_crashpad(char* raw_handler,
char* raw_datadir,
char* raw_url) {
base::FilePath handler(_convert(raw_handler));
base::FilePath database(_convert(raw_datadir));
std::string url(raw_url);
std::map<std::string, std::string> annotations;
std::vector<std::string> arguments;
std::unique_ptr<CrashReportDatabase> db = CrashReportDatabase::Initialize(database);
if (db == nullptr || db->GetSettings() == nullptr) {
return false;
}
db->GetSettings()->SetUploadsEnabled(true);
arguments.push_back(std::string("--no-rate-limit"));
CrashpadClient client;
bool success = client.StartHandler(
handler,
database,
database,
url,
annotations,
arguments,
true, false );
if (success == false) {
return false;
}
return true;
}
}