mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
fix: shell.trashItem crash when called in renderer (#28788)
* fix: shell.trashItem crash when called in renderer * Update api-shell-spec.ts * Update spec-main/api-shell-spec.ts Co-authored-by: Jeremy Rose <nornagon@nornagon.net> Co-authored-by: Jeremy Rose <jeremya@chromium.org>
This commit is contained in:
@@ -14,24 +14,32 @@
|
||||
|
||||
namespace platform_util {
|
||||
|
||||
void TrashItemOnBlockingThread(
|
||||
const base::FilePath& full_path,
|
||||
base::OnceCallback<void(bool, const std::string&)> callback) {
|
||||
struct TrashItemResult {
|
||||
bool success;
|
||||
std::string error;
|
||||
};
|
||||
|
||||
TrashItemResult TrashItemOnBlockingThread(const base::FilePath& full_path) {
|
||||
std::string error;
|
||||
bool success = internal::PlatformTrashItem(full_path, &error);
|
||||
content::GetUIThreadTaskRunner({})->PostTask(
|
||||
FROM_HERE, base::BindOnce(std::move(callback), success, error));
|
||||
return {success, error};
|
||||
}
|
||||
|
||||
void TrashItem(const base::FilePath& full_path,
|
||||
base::OnceCallback<void(bool, const std::string&)> callback) {
|
||||
// XXX: is continue_on_shutdown right?
|
||||
base::ThreadPool::PostTask(FROM_HERE,
|
||||
{base::MayBlock(), base::WithBaseSyncPrimitives(),
|
||||
base::TaskPriority::USER_BLOCKING,
|
||||
base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN},
|
||||
base::BindOnce(&TrashItemOnBlockingThread,
|
||||
full_path, std::move(callback)));
|
||||
base::ThreadPool::PostTaskAndReplyWithResult(
|
||||
FROM_HERE,
|
||||
{base::MayBlock(), base::WithBaseSyncPrimitives(),
|
||||
base::TaskPriority::USER_BLOCKING,
|
||||
base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN},
|
||||
base::BindOnce(&TrashItemOnBlockingThread, full_path),
|
||||
base::BindOnce(
|
||||
[](base::OnceCallback<void(bool, const std::string&)> callback,
|
||||
TrashItemResult result) {
|
||||
std::move(callback).Run(result.success, result.error);
|
||||
},
|
||||
std::move(callback)));
|
||||
}
|
||||
|
||||
} // namespace platform_util
|
||||
|
||||
Reference in New Issue
Block a user