async_file_util_adapter.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // Copyright (c) 2013 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 STORAGE_BROWSER_FILE_SYSTEM_ASYNC_FILE_UTIL_ADAPTER_H_
  5. #define STORAGE_BROWSER_FILE_SYSTEM_ASYNC_FILE_UTIL_ADAPTER_H_
  6. #include <stdint.h>
  7. #include <memory>
  8. #include "base/component_export.h"
  9. #include "base/memory/ptr_util.h"
  10. #include "storage/browser/file_system/async_file_util.h"
  11. namespace storage {
  12. class FileSystemFileUtil;
  13. // An adapter class for FileSystemFileUtil classes to provide asynchronous
  14. // interface.
  15. //
  16. // A filesystem can do either:
  17. // - implement a synchronous version of FileUtil by extending
  18. // FileSystemFileUtil and atach it to this adapter, or
  19. // - directly implement AsyncFileUtil.
  20. //
  21. // This instance (as thus this->sync_file_util_) is guaranteed to be alive
  22. // as far as FileSystemOperationContext given to each operation is kept alive.
  23. class COMPONENT_EXPORT(STORAGE_BROWSER) AsyncFileUtilAdapter
  24. : public AsyncFileUtil {
  25. public:
  26. explicit AsyncFileUtilAdapter(
  27. std::unique_ptr<FileSystemFileUtil> sync_file_util);
  28. AsyncFileUtilAdapter(const AsyncFileUtilAdapter&) = delete;
  29. AsyncFileUtilAdapter& operator=(const AsyncFileUtilAdapter&) = delete;
  30. ~AsyncFileUtilAdapter() override;
  31. FileSystemFileUtil* sync_file_util() { return sync_file_util_.get(); }
  32. // AsyncFileUtil overrides.
  33. void CreateOrOpen(std::unique_ptr<FileSystemOperationContext> context,
  34. const FileSystemURL& url,
  35. uint32_t file_flags,
  36. CreateOrOpenCallback callback) override;
  37. void EnsureFileExists(std::unique_ptr<FileSystemOperationContext> context,
  38. const FileSystemURL& url,
  39. EnsureFileExistsCallback callback) override;
  40. void CreateDirectory(std::unique_ptr<FileSystemOperationContext> context,
  41. const FileSystemURL& url,
  42. bool exclusive,
  43. bool recursive,
  44. StatusCallback callback) override;
  45. void GetFileInfo(std::unique_ptr<FileSystemOperationContext> context,
  46. const FileSystemURL& url,
  47. int fields,
  48. GetFileInfoCallback callback) override;
  49. void ReadDirectory(std::unique_ptr<FileSystemOperationContext> context,
  50. const FileSystemURL& url,
  51. ReadDirectoryCallback callback) override;
  52. void Touch(std::unique_ptr<FileSystemOperationContext> context,
  53. const FileSystemURL& url,
  54. const base::Time& last_access_time,
  55. const base::Time& last_modified_time,
  56. StatusCallback callback) override;
  57. void Truncate(std::unique_ptr<FileSystemOperationContext> context,
  58. const FileSystemURL& url,
  59. int64_t length,
  60. StatusCallback callback) override;
  61. void CopyFileLocal(std::unique_ptr<FileSystemOperationContext> context,
  62. const FileSystemURL& src_url,
  63. const FileSystemURL& dest_url,
  64. CopyOrMoveOptionSet options,
  65. CopyFileProgressCallback progress_callback,
  66. StatusCallback callback) override;
  67. void MoveFileLocal(std::unique_ptr<FileSystemOperationContext> context,
  68. const FileSystemURL& src_url,
  69. const FileSystemURL& dest_url,
  70. CopyOrMoveOptionSet options,
  71. StatusCallback callback) override;
  72. void CopyInForeignFile(std::unique_ptr<FileSystemOperationContext> context,
  73. const base::FilePath& src_file_path,
  74. const FileSystemURL& dest_url,
  75. StatusCallback callback) override;
  76. void DeleteFile(std::unique_ptr<FileSystemOperationContext> context,
  77. const FileSystemURL& url,
  78. StatusCallback callback) override;
  79. void DeleteDirectory(std::unique_ptr<FileSystemOperationContext> context,
  80. const FileSystemURL& url,
  81. StatusCallback callback) override;
  82. void DeleteRecursively(std::unique_ptr<FileSystemOperationContext> context,
  83. const FileSystemURL& url,
  84. StatusCallback callback) override;
  85. void CreateSnapshotFile(std::unique_ptr<FileSystemOperationContext> context,
  86. const FileSystemURL& url,
  87. CreateSnapshotFileCallback callback) override;
  88. private:
  89. std::unique_ptr<FileSystemFileUtil> sync_file_util_;
  90. };
  91. } // namespace storage
  92. #endif // STORAGE_BROWSER_FILE_SYSTEM_ASYNC_FILE_UTIL_ADAPTER_H_