mojo_backend_file_operations.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright 2022 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. #ifndef SERVICES_NETWORK_DISK_CACHE_MOJO_BACKEND_FILE_OPERATIONS_H_
  5. #define SERVICES_NETWORK_DISK_CACHE_MOJO_BACKEND_FILE_OPERATIONS_H_
  6. #include "base/component_export.h"
  7. #include "base/memory/ref_counted.h"
  8. #include "base/task/sequenced_task_runner.h"
  9. #include "mojo/public/cpp/bindings/pending_remote.h"
  10. #include "mojo/public/cpp/bindings/remote.h"
  11. #include "net/disk_cache/disk_cache.h"
  12. #include "services/network/public/mojom/http_cache_backend_file_operations.mojom.h"
  13. namespace network {
  14. // A BackendFileOperations that provides file operations with brokering them
  15. // via mojo.
  16. class MojoBackendFileOperations final
  17. : public disk_cache::BackendFileOperations {
  18. public:
  19. MojoBackendFileOperations(
  20. mojo::PendingRemote<mojom::HttpCacheBackendFileOperations> pending_remote,
  21. scoped_refptr<base::SequencedTaskRunner> task_runner);
  22. ~MojoBackendFileOperations() override;
  23. // disk_cache::BackendFileOperations implementation:
  24. bool CreateDirectory(const base::FilePath& path) override;
  25. bool PathExists(const base::FilePath& path) override;
  26. bool DirectoryExists(const base::FilePath& path) override;
  27. base::File OpenFile(const base::FilePath& path, uint32_t flags) override;
  28. bool DeleteFile(const base::FilePath& path, DeleteFileMode mode) override;
  29. bool ReplaceFile(const base::FilePath& from_path,
  30. const base::FilePath& to_path,
  31. base::File::Error* error) override;
  32. absl::optional<base::File::Info> GetFileInfo(
  33. const base::FilePath& path) override;
  34. std::unique_ptr<disk_cache::BackendFileOperations::FileEnumerator>
  35. EnumerateFiles(const base::FilePath& path) override;
  36. void CleanupDirectory(const base::FilePath& path,
  37. base::OnceCallback<void(bool)> callback) override;
  38. std::unique_ptr<disk_cache::UnboundBackendFileOperations> Unbind() override;
  39. private:
  40. mojo::Remote<mojom::HttpCacheBackendFileOperations> remote_;
  41. };
  42. class UnboundMojoBackendFileOperations final
  43. : public disk_cache::UnboundBackendFileOperations {
  44. public:
  45. explicit UnboundMojoBackendFileOperations(
  46. mojo::PendingRemote<mojom::HttpCacheBackendFileOperations>
  47. pending_remote);
  48. ~UnboundMojoBackendFileOperations() override;
  49. std::unique_ptr<disk_cache::BackendFileOperations> Bind(
  50. scoped_refptr<base::SequencedTaskRunner> task_runner) override;
  51. private:
  52. mojo::PendingRemote<mojom::HttpCacheBackendFileOperations> pending_remote_;
  53. };
  54. } // namespace network
  55. #endif // SERVICES_NETWORK_DISK_CACHE_MOJO_BACKEND_FILE_OPERATIONS_H_