#include "chrome/notification_helper/notification_helper_crash_reporter_client.h"
#include <memory>
#include "base/check.h"
#include "base/debug/leak_annotations.h"
#include "base/file_version_info.h"
#include "base/notreached.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/common/chrome_version.h"
#include "chrome/install_static/install_util.h"
#include "chrome/install_static/user_data_dir.h"
#include "components/crash/core/app/crashpad.h"
#include "components/version_info/channel.h"
NotificationHelperCrashReporterClient::NotificationHelperCrashReporterClient() =
default;
NotificationHelperCrashReporterClient::
~NotificationHelperCrashReporterClient() = default;
void NotificationHelperCrashReporterClient::
InitializeCrashReportingForProcessWithHandler(
const base::FilePath& exe_path) {
DCHECK(!exe_path.empty());
static NotificationHelperCrashReporterClient* instance = nullptr;
if (instance)
return;
instance = new NotificationHelperCrashReporterClient();
ANNOTATE_LEAKING_OBJECT_PTR(instance);
crash_reporter::SetCrashReporterClient(instance);
std::wstring user_data_dir;
install_static::GetUserDataDirectory(&user_data_dir, nullptr);
crash_reporter::InitializeCrashpadWithEmbeddedHandler(
true, "notification-helper", install_static::WideToUTF8(user_data_dir),
exe_path);
}
bool NotificationHelperCrashReporterClient::GetAlternativeCrashDumpLocation(
std::wstring* crash_dir) {
return false;
}
void NotificationHelperCrashReporterClient::GetProductNameAndVersion(
const std::wstring& exe_path,
std::wstring* product_name,
std::wstring* version,
std::wstring* special_build,
std::wstring* channel_name) {
*product_name = base::ASCIIToWide(PRODUCT_SHORTNAME_STRING);
std::unique_ptr<FileVersionInfo> version_info(
FileVersionInfo::CreateFileVersionInfo(base::FilePath(exe_path)));
if (version_info) {
*version = base::AsWString(version_info->product_version());
*special_build = base::AsWString(version_info->special_build());
} else {
*version = L"0.0.0.0-devel";
*special_build = std::wstring();
}
*channel_name =
install_static::GetChromeChannelName(true);
}
bool NotificationHelperCrashReporterClient::GetShouldDumpLargerDumps() {
return install_static::GetChromeChannel() != version_info::Channel::STABLE;
}
bool NotificationHelperCrashReporterClient::GetCrashDumpLocation(
std::wstring* crash_dir) {
*crash_dir = install_static::GetCrashDumpLocation();
return !crash_dir->empty();
}
bool NotificationHelperCrashReporterClient::GetCrashMetricsLocation(
std::wstring* metrics_dir) {
install_static::GetUserDataDirectory(metrics_dir, nullptr);
return !metrics_dir->empty();
}
bool NotificationHelperCrashReporterClient::IsRunningUnattended() {
return install_static::HasEnvironmentVariable(install_static::kHeadless);
}
bool NotificationHelperCrashReporterClient::GetCollectStatsConsent() {
return install_static::GetCollectStatsConsent();
}
bool NotificationHelperCrashReporterClient::GetCollectStatsInSample() {
return install_static::GetCollectStatsInSample();
}
bool NotificationHelperCrashReporterClient::ReportingIsEnforcedByPolicy(
bool* enabled) {
return install_static::ReportingIsEnforcedByPolicy(enabled);
}
bool NotificationHelperCrashReporterClient::
ShouldMonitorCrashHandlerExpensively() {
return false;
}
bool NotificationHelperCrashReporterClient::EnableBreakpadForProcess(
const std::string& process_type) {
NOTREACHED();
}