From cd0dda0125ee87b5d8f6f310bd1912f34fa0d0c5 Mon Sep 17 00:00:00 2001 From: loc Date: Tue, 21 Apr 2020 12:28:01 -0700 Subject: [PATCH] fix: allow blocking IO for setAppLogsPath to avoid DCHECK (#23111) * fix: let setAppLogsPath write to disk on UI thread Otherwise, the DCHECK in thread_restrictions will fire. * scope the io allowance more tightly * oops, scope it tightly in the mac version too --- shell/browser/api/electron_api_app.cc | 11 ++++++++--- shell/browser/api/electron_api_app_mac.mm | 12 +++++++++--- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/shell/browser/api/electron_api_app.cc b/shell/browser/api/electron_api_app.cc index 1d0d70620df..702dc902fa0 100644 --- a/shell/browser/api/electron_api_app.cc +++ b/shell/browser/api/electron_api_app.cc @@ -851,13 +851,19 @@ void App::SetAppLogsPath(gin_helper::ErrorThrower thrower, thrower.ThrowError("Path must be absolute"); return; } - base::PathService::Override(DIR_APP_LOGS, custom_path.value()); + { + base::ThreadRestrictions::ScopedAllowIO allow_io; + base::PathService::Override(DIR_APP_LOGS, custom_path.value()); + } } else { base::FilePath path; if (base::PathService::Get(DIR_USER_DATA, &path)) { path = path.Append(base::FilePath::FromUTF8Unsafe(GetApplicationName())); path = path.Append(base::FilePath::FromUTF8Unsafe("logs")); - base::PathService::Override(DIR_APP_LOGS, path); + { + base::ThreadRestrictions::ScopedAllowIO allow_io; + base::PathService::Override(DIR_APP_LOGS, path); + } } } } @@ -874,7 +880,6 @@ base::FilePath App::GetPath(gin_helper::ErrorThrower thrower, // If users try to get the logs path before setting a logs path, // set the path to a sensible default and then try to get it again if (!succeed && name == "logs") { - base::ThreadRestrictions::ScopedAllowIO allow_io; SetAppLogsPath(thrower, base::Optional()); succeed = base::PathService::Get(key, &path); } diff --git a/shell/browser/api/electron_api_app_mac.mm b/shell/browser/api/electron_api_app_mac.mm index 2678153acd9..4d6bc27377d 100644 --- a/shell/browser/api/electron_api_app_mac.mm +++ b/shell/browser/api/electron_api_app_mac.mm @@ -21,7 +21,10 @@ void App::SetAppLogsPath(gin_helper::ErrorThrower thrower, thrower.ThrowError("Path must be absolute"); return; } - base::PathService::Override(DIR_APP_LOGS, custom_path.value()); + { + base::ThreadRestrictions::ScopedAllowIO allow_io; + base::PathService::Override(DIR_APP_LOGS, custom_path.value()); + } } else { NSString* bundle_name = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"]; @@ -29,8 +32,11 @@ void App::SetAppLogsPath(gin_helper::ErrorThrower thrower, [NSString stringWithFormat:@"Library/Logs/%@", bundle_name]; NSString* library_path = [NSHomeDirectory() stringByAppendingPathComponent:logs_path]; - base::PathService::Override(DIR_APP_LOGS, - base::FilePath([library_path UTF8String])); + { + base::ThreadRestrictions::ScopedAllowIO allow_io; + base::PathService::Override(DIR_APP_LOGS, + base::FilePath([library_path UTF8String])); + } } }