platform_util.cc 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright (c) 2020 Slack Technologies, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #include "shell/common/platform_util.h"
  5. #include <utility>
  6. #include "base/functional/bind.h"
  7. #include "base/task/thread_pool.h"
  8. #include "content/public/browser/browser_task_traits.h"
  9. #include "shell/common/platform_util_internal.h"
  10. namespace platform_util {
  11. namespace {
  12. struct TrashItemResult {
  13. bool success;
  14. std::string error;
  15. };
  16. TrashItemResult TrashItemOnBlockingThread(const base::FilePath& full_path) {
  17. std::string error;
  18. bool success = internal::PlatformTrashItem(full_path, &error);
  19. return {success, error};
  20. }
  21. } // namespace
  22. void TrashItem(const base::FilePath& full_path,
  23. base::OnceCallback<void(bool, const std::string&)> callback) {
  24. // XXX: is continue_on_shutdown right?
  25. base::ThreadPool::PostTaskAndReplyWithResult(
  26. FROM_HERE,
  27. {base::MayBlock(), base::WithBaseSyncPrimitives(),
  28. base::TaskPriority::USER_BLOCKING,
  29. base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN},
  30. base::BindOnce(&TrashItemOnBlockingThread, full_path),
  31. base::BindOnce(
  32. [](base::OnceCallback<void(bool, const std::string&)> callback,
  33. TrashItemResult result) {
  34. std::move(callback).Run(result.success, result.error);
  35. },
  36. std::move(callback)));
  37. }
  38. } // namespace platform_util