platform_util.cc 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. struct TrashItemResult {
  12. bool success;
  13. std::string error;
  14. };
  15. TrashItemResult TrashItemOnBlockingThread(const base::FilePath& full_path) {
  16. std::string error;
  17. bool success = internal::PlatformTrashItem(full_path, &error);
  18. return {success, error};
  19. }
  20. void TrashItem(const base::FilePath& full_path,
  21. base::OnceCallback<void(bool, const std::string&)> callback) {
  22. // XXX: is continue_on_shutdown right?
  23. base::ThreadPool::PostTaskAndReplyWithResult(
  24. FROM_HERE,
  25. {base::MayBlock(), base::WithBaseSyncPrimitives(),
  26. base::TaskPriority::USER_BLOCKING,
  27. base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN},
  28. base::BindOnce(&TrashItemOnBlockingThread, full_path),
  29. base::BindOnce(
  30. [](base::OnceCallback<void(bool, const std::string&)> callback,
  31. TrashItemResult result) {
  32. std::move(callback).Run(result.success, result.error);
  33. },
  34. std::move(callback)));
  35. }
  36. } // namespace platform_util