fake_file_chooser.cc 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "remoting/host/file_transfer/fake_file_chooser.h"
  5. #include "base/bind.h"
  6. #include "base/no_destructor.h"
  7. #include "base/task/sequenced_task_runner.h"
  8. #include "base/threading/sequenced_task_runner_handle.h"
  9. #include "remoting/protocol/file_transfer_helpers.h"
  10. namespace remoting {
  11. namespace {
  12. FileChooser::Result& StaticResult() {
  13. static base::NoDestructor<FileChooser::Result> result(
  14. protocol::MakeFileTransferError(
  15. FROM_HERE, protocol::FileTransfer_Error_Type_CANCELED));
  16. return *result;
  17. }
  18. } // namespace
  19. std::unique_ptr<FileChooser> FileChooser::Create(
  20. scoped_refptr<base::SequencedTaskRunner> ui_task_runner,
  21. ResultCallback callback) {
  22. return std::make_unique<FakeFileChooser>(std::move(callback));
  23. }
  24. FakeFileChooser::FakeFileChooser(FileChooser::ResultCallback callback)
  25. : callback_(std::move(callback)) {}
  26. FakeFileChooser::~FakeFileChooser() = default;
  27. void FakeFileChooser::Show() {
  28. base::SequencedTaskRunnerHandle::Get()->PostTask(
  29. FROM_HERE, base::BindOnce(std::move(callback_), StaticResult()));
  30. }
  31. void FakeFileChooser::SetResult(FileChooser::Result result) {
  32. StaticResult() = std::move(result);
  33. }
  34. } // namespace remoting