From c89debd19abf271cc074c7e08cfcfcbb39e837bf Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Fri, 23 Aug 2019 15:49:54 -0700 Subject: [PATCH] refactor: use Error util when only throwing errors (#19837) --- shell/browser/api/atom_api_app.cc | 36 ++++++++++++++------------- shell/browser/api/atom_api_app.h | 17 +++++++------ shell/browser/api/atom_api_app_mac.mm | 6 ++--- 3 files changed, 31 insertions(+), 28 deletions(-) diff --git a/shell/browser/api/atom_api_app.cc b/shell/browser/api/atom_api_app.cc index f20818729daf..a9661b3dc0cf 100644 --- a/shell/browser/api/atom_api_app.cc +++ b/shell/browser/api/atom_api_app.cc @@ -846,11 +846,11 @@ void App::SetAppPath(const base::FilePath& app_path) { } #if !defined(OS_MACOSX) -void App::SetAppLogsPath(base::Optional custom_path, - mate::Arguments* args) { +void App::SetAppLogsPath(util::ErrorThrower thrower, + base::Optional custom_path) { if (custom_path.has_value()) { if (!custom_path->IsAbsolute()) { - args->ThrowError("Path must be absolute"); + thrower.ThrowError("Path must be absolute"); return; } base::PathService::Override(DIR_APP_LOGS, custom_path.value()); @@ -865,7 +865,8 @@ void App::SetAppLogsPath(base::Optional custom_path, } #endif -base::FilePath App::GetPath(mate::Arguments* args, const std::string& name) { +base::FilePath App::GetPath(util::ErrorThrower thrower, + const std::string& name) { bool succeed = false; base::FilePath path; @@ -876,22 +877,22 @@ base::FilePath App::GetPath(mate::Arguments* args, const std::string& name) { // set the path to a sensible default and then try to get it again if (!succeed && name == "logs") { base::ThreadRestrictions::ScopedAllowIO allow_io; - SetAppLogsPath(base::Optional(), args); + SetAppLogsPath(thrower, base::Optional()); succeed = base::PathService::Get(key, &path); } } if (!succeed) - args->ThrowError("Failed to get '" + name + "' path"); + thrower.ThrowError("Failed to get '" + name + "' path"); return path; } -void App::SetPath(mate::Arguments* args, +void App::SetPath(util::ErrorThrower thrower, const std::string& name, const base::FilePath& path) { if (!path.IsAbsolute()) { - args->ThrowError("Path must be absolute"); + thrower.ThrowError("Path must be absolute"); return; } @@ -901,7 +902,7 @@ void App::SetPath(mate::Arguments* args, succeed = base::PathService::OverrideAndCreateIfNeeded(key, path, true, false); if (!succeed) - args->ThrowError("Failed to set path"); + thrower.ThrowError("Failed to set path"); } void App::SetDesktopName(const std::string& desktop_name) { @@ -1030,9 +1031,9 @@ bool App::Relaunch(mate::Arguments* js_args) { return relauncher::RelaunchApp(argv); } -void App::DisableHardwareAcceleration(mate::Arguments* args) { +void App::DisableHardwareAcceleration(util::ErrorThrower thrower) { if (Browser::Get()->is_ready()) { - args->ThrowError( + thrower.ThrowError( "app.disableHardwareAcceleration() can only be called " "before app is ready"); return; @@ -1040,9 +1041,9 @@ void App::DisableHardwareAcceleration(mate::Arguments* args) { content::GpuDataManager::GetInstance()->DisableHardwareAcceleration(); } -void App::DisableDomainBlockingFor3DAPIs(mate::Arguments* args) { +void App::DisableDomainBlockingFor3DAPIs(util::ErrorThrower thrower) { if (Browser::Get()->is_ready()) { - args->ThrowError( + thrower.ThrowError( "app.disableDomainBlockingFor3DAPIs() can only be called " "before app is ready"); return; @@ -1056,9 +1057,10 @@ bool App::IsAccessibilitySupportEnabled() { return ax_state->IsAccessibleBrowser(); } -void App::SetAccessibilitySupportEnabled(bool enabled, mate::Arguments* args) { +void App::SetAccessibilitySupportEnabled(util::ErrorThrower thrower, + bool enabled) { if (!Browser::Get()->is_ready()) { - args->ThrowError( + thrower.ThrowError( "app.setAccessibilitySupportEnabled() can only be called " "after app is ready"); return; @@ -1312,9 +1314,9 @@ static void RemoveNoSandboxSwitch(base::CommandLine* command_line) { } } -void App::EnableSandbox(mate::Arguments* args) { +void App::EnableSandbox(util::ErrorThrower thrower) { if (Browser::Get()->is_ready()) { - args->ThrowError( + thrower.ThrowError( "app.enableSandbox() can only be called " "before app is ready"); return; diff --git a/shell/browser/api/atom_api_app.h b/shell/browser/api/atom_api_app.h index 0376256114c1..ae4ab5fc0e1f 100644 --- a/shell/browser/api/atom_api_app.h +++ b/shell/browser/api/atom_api_app.h @@ -27,6 +27,7 @@ #include "shell/browser/atom_browser_client.h" #include "shell/browser/browser.h" #include "shell/browser/browser_observer.h" +#include "shell/common/error_util.h" #include "shell/common/native_mate_converters/callback.h" #include "shell/common/promise_util.h" @@ -164,12 +165,12 @@ class App : public AtomBrowserClient::Delegate, void ChildProcessLaunched(int process_type, base::ProcessHandle handle); void ChildProcessDisconnected(base::ProcessId pid); - void SetAppLogsPath(base::Optional custom_path, - mate::Arguments* args); + void SetAppLogsPath(util::ErrorThrower thrower, + base::Optional custom_path); // Get/Set the pre-defined path in PathService. - base::FilePath GetPath(mate::Arguments* args, const std::string& name); - void SetPath(mate::Arguments* args, + base::FilePath GetPath(util::ErrorThrower thrower, const std::string& name); + void SetPath(util::ErrorThrower thrower, const std::string& name, const base::FilePath& path); @@ -182,10 +183,10 @@ class App : public AtomBrowserClient::Delegate, bool RequestSingleInstanceLock(); void ReleaseSingleInstanceLock(); bool Relaunch(mate::Arguments* args); - void DisableHardwareAcceleration(mate::Arguments* args); - void DisableDomainBlockingFor3DAPIs(mate::Arguments* args); + void DisableHardwareAcceleration(util::ErrorThrower thrower); + void DisableDomainBlockingFor3DAPIs(util::ErrorThrower thrower); bool IsAccessibilitySupportEnabled(); - void SetAccessibilitySupportEnabled(bool enabled, mate::Arguments* args); + void SetAccessibilitySupportEnabled(util::ErrorThrower thrower, bool enabled); Browser::LoginItemSettings GetLoginItemSettings(mate::Arguments* args); #if defined(USE_NSS_CERTS) void ImportCertificate(const base::DictionaryValue& options, @@ -198,7 +199,7 @@ class App : public AtomBrowserClient::Delegate, v8::Local GetGPUFeatureStatus(v8::Isolate* isolate); v8::Local GetGPUInfo(v8::Isolate* isolate, const std::string& info_type); - void EnableSandbox(mate::Arguments* args); + void EnableSandbox(util::ErrorThrower thrower); void SetUserAgentFallback(const std::string& user_agent); std::string GetUserAgentFallback(); void SetBrowserClientCanUseCustomSiteInstance(bool should_disable); diff --git a/shell/browser/api/atom_api_app_mac.mm b/shell/browser/api/atom_api_app_mac.mm index 420f009d6e7f..48e4907179bf 100644 --- a/shell/browser/api/atom_api_app_mac.mm +++ b/shell/browser/api/atom_api_app_mac.mm @@ -13,11 +13,11 @@ namespace electron { namespace api { -void App::SetAppLogsPath(base::Optional custom_path, - mate::Arguments* args) { +void App::SetAppLogsPath(util::ErrorThrower thrower, + base::Optional custom_path) { if (custom_path.has_value()) { if (!custom_path->IsAbsolute()) { - args->ThrowError("Path must be absolute"); + thrower.ThrowError("Path must be absolute"); return; } base::PathService::Override(DIR_APP_LOGS, custom_path.value());