platform_util.cc 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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/bind.h"
  7. #include "base/task/thread_pool.h"
  8. #include "content/public/browser/browser_task_traits.h"
  9. #include "content/public/browser/browser_thread.h"
  10. #include "shell/common/platform_util_internal.h"
  11. namespace platform_util {
  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. void TrashItem(const base::FilePath& full_path,
  22. base::OnceCallback<void(bool, const std::string&)> callback) {
  23. // XXX: is continue_on_shutdown right?
  24. base::ThreadPool::PostTaskAndReplyWithResult(
  25. FROM_HERE,
  26. {base::MayBlock(), base::WithBaseSyncPrimitives(),
  27. base::TaskPriority::USER_BLOCKING,
  28. base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN},
  29. base::BindOnce(&TrashItemOnBlockingThread, full_path),
  30. base::BindOnce(
  31. [](base::OnceCallback<void(bool, const std::string&)> callback,
  32. TrashItemResult result) {
  33. std::move(callback).Run(result.success, result.error);
  34. },
  35. std::move(callback)));
  36. }
  37. } // namespace platform_util