From e65cac6ae8ce3a0a1d0a33610e6157fd29836dc7 Mon Sep 17 00:00:00 2001 From: Jeremy Apthorp Date: Mon, 20 Apr 2020 14:44:09 -0700 Subject: [PATCH] refactor: remove extra args from crashreporter init (#23144) --- lib/common/crash-reporter.js | 2 +- shell/common/crash_reporter/crash_reporter.cc | 57 +++++++++---------- shell/common/crash_reporter/crash_reporter.h | 20 +++---- .../crash_reporter/crash_reporter_linux.cc | 9 ++- .../crash_reporter/crash_reporter_linux.h | 7 ++- .../crash_reporter/crash_reporter_mac.h | 4 +- .../crash_reporter/crash_reporter_mac.mm | 4 +- .../crash_reporter/crash_reporter_win.cc | 4 +- .../crash_reporter/crash_reporter_win.h | 4 +- 9 files changed, 49 insertions(+), 62 deletions(-) diff --git a/lib/common/crash-reporter.js b/lib/common/crash-reporter.js index 893c09b848fb..3ef27736e5b6 100644 --- a/lib/common/crash-reporter.js +++ b/lib/common/crash-reporter.js @@ -41,7 +41,7 @@ class CrashReporter { if (extra._companyName == null) extra._companyName = companyName; if (extra._version == null) extra._version = ret.appVersion; - binding.start(ret.productName, companyName, submitURL, ret.crashesDirectory, uploadToServer, ignoreSystemCrashHandler, rateLimit, compress, extra); + binding.start(submitURL, ret.crashesDirectory, uploadToServer, ignoreSystemCrashHandler, rateLimit, compress, extra); } getLastCrashReport () { diff --git a/shell/common/crash_reporter/crash_reporter.cc b/shell/common/crash_reporter/crash_reporter.cc index da112e460254..57519f2d9d1d 100644 --- a/shell/common/crash_reporter/crash_reporter.cc +++ b/shell/common/crash_reporter/crash_reporter.cc @@ -46,9 +46,7 @@ bool CrashReporter::IsInitialized() { return is_initialized_; } -void CrashReporter::Start(const std::string& product_name, - const std::string& company_name, - const std::string& submit_url, +void CrashReporter::Start(const std::string& submit_url, const base::FilePath& crashes_dir, bool upload_to_server, bool skip_system_crash_handler, @@ -58,8 +56,8 @@ void CrashReporter::Start(const std::string& product_name, is_initialized_ = true; SetUploadParameters(extra_parameters); - Init(product_name, company_name, submit_url, crashes_dir, upload_to_server, - skip_system_crash_handler, rate_limit, compress); + Init(submit_url, crashes_dir, upload_to_server, skip_system_crash_handler, + rate_limit, compress); } void CrashReporter::SetUploadParameters(const StringMap& parameters) { @@ -73,12 +71,6 @@ void CrashReporter::SetUploadParameters(const StringMap& parameters) { SetUploadParameters(); } -void CrashReporter::SetUploadToServer(const bool upload_to_server) {} - -bool CrashReporter::GetUploadToServer() { - return true; -} - std::vector CrashReporter::GetUploadedReports(const base::FilePath& crashes_dir) { base::ThreadRestrictions::ScopedAllowIO allow_io; @@ -102,30 +94,33 @@ CrashReporter::GetUploadedReports(const base::FilePath& crashes_dir) { return result; } -void CrashReporter::Init(const std::string& product_name, - const std::string& company_name, - const std::string& submit_url, - const base::FilePath& crashes_dir, - bool auto_submit, - bool skip_system_crash_handler, - bool rate_limit, - bool compress) {} - -void CrashReporter::SetUploadParameters() {} - -void CrashReporter::AddExtraParameter(const std::string& key, - const std::string& value) {} - -void CrashReporter::RemoveExtraParameter(const std::string& key) {} - std::map CrashReporter::GetParameters() const { return upload_parameters_; } #if defined(OS_MACOSX) && defined(MAS_BUILD) +class DummyCrashReporter : public CrashReporter { + public: + ~DummyCrashReporter() override {} + + void SetUploadToServer(bool upload_to_server) override {} + bool GetUploadToServer() override { return false; } + void AddExtraParameter(const std::string& key, + const std::string& value) override {} + void RemoveExtraParameter(const std::string& key) override {} + + void Init(const std::string& submit_url, + const base::FilePath& crashes_dir, + bool upload_to_server, + bool skip_system_crash_handler, + bool rate_limit, + bool compress) override {} + void SetUploadParameters() override {} +}; + // static CrashReporter* CrashReporter::GetInstance() { - static CrashReporter crash_reporter; + static DummyCrashReporter crash_reporter; return &crash_reporter; } #endif @@ -156,9 +151,9 @@ void CrashReporter::StartInstance(const gin_helper::Dictionary& options) { bool upload_to_server = true; bool skip_system_crash_handler = false; - reporter->Start(product_name, company_name, submit_url, crashes_dir, - upload_to_server, skip_system_crash_handler, rate_limit, - compress, extra_parameters); + reporter->Start(submit_url, crashes_dir, upload_to_server, + skip_system_crash_handler, rate_limit, compress, + extra_parameters); } } // namespace crash_reporter diff --git a/shell/common/crash_reporter/crash_reporter.h b/shell/common/crash_reporter/crash_reporter.h index f3afabebf0b2..0884ba868bf8 100644 --- a/shell/common/crash_reporter/crash_reporter.h +++ b/shell/common/crash_reporter/crash_reporter.h @@ -34,9 +34,7 @@ class CrashReporter { static void StartInstance(const gin_helper::Dictionary& options); bool IsInitialized(); - void Start(const std::string& product_name, - const std::string& company_name, - const std::string& submit_url, + void Start(const std::string& submit_url, const base::FilePath& crashes_dir, bool upload_to_server, bool skip_system_crash_handler, @@ -47,26 +45,24 @@ class CrashReporter { virtual std::vector GetUploadedReports( const base::FilePath& crashes_dir); - virtual void SetUploadToServer(bool upload_to_server); - virtual bool GetUploadToServer(); + virtual void SetUploadToServer(bool upload_to_server) = 0; + virtual bool GetUploadToServer() = 0; virtual void AddExtraParameter(const std::string& key, - const std::string& value); - virtual void RemoveExtraParameter(const std::string& key); + const std::string& value) = 0; + virtual void RemoveExtraParameter(const std::string& key) = 0; virtual std::map GetParameters() const; protected: CrashReporter(); virtual ~CrashReporter(); - virtual void Init(const std::string& product_name, - const std::string& company_name, - const std::string& submit_url, + virtual void Init(const std::string& submit_url, const base::FilePath& crashes_dir, bool upload_to_server, bool skip_system_crash_handler, bool rate_limit, - bool compress); - virtual void SetUploadParameters(); + bool compress) = 0; + virtual void SetUploadParameters() = 0; StringMap upload_parameters_; std::string process_type_; diff --git a/shell/common/crash_reporter/crash_reporter_linux.cc b/shell/common/crash_reporter/crash_reporter_linux.cc index ccffddfd360a..6f91228d9dea 100644 --- a/shell/common/crash_reporter/crash_reporter_linux.cc +++ b/shell/common/crash_reporter/crash_reporter_linux.cc @@ -56,9 +56,7 @@ CrashReporterLinux::CrashReporterLinux() : pid_(getpid()) { CrashReporterLinux::~CrashReporterLinux() = default; -void CrashReporterLinux::Init(const std::string& product_name, - const std::string& company_name, - const std::string& submit_url, +void CrashReporterLinux::Init(const std::string& submit_url, const base::FilePath& crashes_dir, bool upload_to_server, bool skip_system_crash_handler, @@ -87,6 +85,11 @@ bool CrashReporterLinux::GetUploadToServer() { return upload_to_server_; } +void CrashReporterLinux::AddExtraParameter(const std::string& key, + const std::string& value) {} + +void CrashReporterLinux::RemoveExtraParameter(const std::string& key) {} + void CrashReporterLinux::EnableCrashDumping(const base::FilePath& crashes_dir) { { base::ThreadRestrictions::ScopedAllowIO allow_io; diff --git a/shell/common/crash_reporter/crash_reporter_linux.h b/shell/common/crash_reporter/crash_reporter_linux.h index 9013a70ff6c4..395007d49e1b 100644 --- a/shell/common/crash_reporter/crash_reporter_linux.h +++ b/shell/common/crash_reporter/crash_reporter_linux.h @@ -28,9 +28,7 @@ class CrashReporterLinux : public CrashReporter { public: static CrashReporterLinux* GetInstance(); - void Init(const std::string& product_name, - const std::string& company_name, - const std::string& submit_url, + void Init(const std::string& submit_url, const base::FilePath& crashes_dir, bool upload_to_server, bool skip_system_crash_handler, @@ -39,6 +37,9 @@ class CrashReporterLinux : public CrashReporter { void SetUploadToServer(bool upload_to_server) override; void SetUploadParameters() override; bool GetUploadToServer() override; + void AddExtraParameter(const std::string& key, + const std::string& value) override; + void RemoveExtraParameter(const std::string& key) override; private: friend struct base::DefaultSingletonTraits; diff --git a/shell/common/crash_reporter/crash_reporter_mac.h b/shell/common/crash_reporter/crash_reporter_mac.h index 92bab58743cd..5b684c384edd 100644 --- a/shell/common/crash_reporter/crash_reporter_mac.h +++ b/shell/common/crash_reporter/crash_reporter_mac.h @@ -21,9 +21,7 @@ class CrashReporterMac : public CrashReporterCrashpad { public: static CrashReporterMac* GetInstance(); - void Init(const std::string& product_name, - const std::string& company_name, - const std::string& submit_url, + void Init(const std::string& submit_url, const base::FilePath& crashes_dir, bool upload_to_server, bool skip_system_crash_handler, diff --git a/shell/common/crash_reporter/crash_reporter_mac.mm b/shell/common/crash_reporter/crash_reporter_mac.mm index cd14cc127764..8f253adc3bbd 100644 --- a/shell/common/crash_reporter/crash_reporter_mac.mm +++ b/shell/common/crash_reporter/crash_reporter_mac.mm @@ -22,9 +22,7 @@ CrashReporterMac::CrashReporterMac() {} CrashReporterMac::~CrashReporterMac() {} -void CrashReporterMac::Init(const std::string& product_name, - const std::string& company_name, - const std::string& submit_url, +void CrashReporterMac::Init(const std::string& submit_url, const base::FilePath& crashes_dir, bool upload_to_server, bool skip_system_crash_handler, diff --git a/shell/common/crash_reporter/crash_reporter_win.cc b/shell/common/crash_reporter/crash_reporter_win.cc index 833f7671465c..69f26bd1293a 100644 --- a/shell/common/crash_reporter/crash_reporter_win.cc +++ b/shell/common/crash_reporter/crash_reporter_win.cc @@ -57,9 +57,7 @@ void CrashReporterWin::SetUnhandledExceptionFilter() { } #endif -void CrashReporterWin::Init(const std::string& product_name, - const std::string& company_name, - const std::string& submit_url, +void CrashReporterWin::Init(const std::string& submit_url, const base::FilePath& crashes_dir, bool upload_to_server, bool skip_system_crash_handler, diff --git a/shell/common/crash_reporter/crash_reporter_win.h b/shell/common/crash_reporter/crash_reporter_win.h index f410d9cd55ee..e112d53f9b5c 100644 --- a/shell/common/crash_reporter/crash_reporter_win.h +++ b/shell/common/crash_reporter/crash_reporter_win.h @@ -25,9 +25,7 @@ class CrashReporterWin : public CrashReporterCrashpad { static void SetUnhandledExceptionFilter(); #endif - void Init(const std::string& product_name, - const std::string& company_name, - const std::string& submit_url, + void Init(const std::string& submit_url, const base::FilePath& crashes_dir, bool upload_to_server, bool skip_system_crash_handler,