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
This commit is contained in:
loc 2020-04-21 12:28:01 -07:00 committed by GitHub
parent 07654c47ec
commit cd0dda0125
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 6 deletions

View file

@ -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<base::FilePath>());
succeed = base::PathService::Get(key, &path);
}

View file

@ -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]));
}
}
}