camera_roll_download_manager.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright 2021 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 ASH_COMPONENTS_PHONEHUB_CAMERA_ROLL_DOWNLOAD_MANAGER_H_
  5. #define ASH_COMPONENTS_PHONEHUB_CAMERA_ROLL_DOWNLOAD_MANAGER_H_
  6. #include "ash/components/phonehub/proto/phonehub_api.pb.h"
  7. #include "ash/services/secure_channel/public/mojom/secure_channel_types.mojom.h"
  8. #include "base/callback.h"
  9. #include "third_party/abseil-cpp/absl/types/optional.h"
  10. namespace ash {
  11. namespace phonehub {
  12. // Manages photo and videos files downloaded via Camera Roll. Files will be
  13. // created under the Downloads folder and added to the Holding Space tray.
  14. class CameraRollDownloadManager {
  15. public:
  16. CameraRollDownloadManager(const CameraRollDownloadManager&) = delete;
  17. CameraRollDownloadManager& operator=(const CameraRollDownloadManager&) =
  18. delete;
  19. virtual ~CameraRollDownloadManager() = default;
  20. enum class CreatePayloadFilesResult {
  21. // The payload files are created successfully.
  22. kSuccess,
  23. // The payload files cannot be created because the file name provided was
  24. // invalid.
  25. kInvalidFileName,
  26. // The payload files cannot be created because they have already been
  27. // created for the provided payload ID.
  28. kPayloadAlreadyExists,
  29. // The payload files cannot be created because there is not enough free disk
  30. // space for the item requested.
  31. kInsufficientDiskSpace,
  32. // The payload files cannot be created because a file already exists at the
  33. // target path, likely a result of some race conditions.
  34. kNotUniqueFilePath,
  35. };
  36. // Creates payload files that can be used to receive an incoming file transfer
  37. // for the given |payload_id|. The file will be created under the Downloads
  38. // folder with the file name provided in the |item_metadata|. If the file
  39. // creation succeeds, the file will be passed back via
  40. // |payload_files_callback| with the result code |kSuccess|. Otherwise an
  41. // empty optional will be passed back along with a result code indicating the
  42. // error.
  43. using CreatePayloadFilesCallback = base::OnceCallback<void(
  44. CreatePayloadFilesResult,
  45. absl::optional<secure_channel::mojom::PayloadFilesPtr>)>;
  46. virtual void CreatePayloadFiles(
  47. int64_t payload_id,
  48. const proto::CameraRollItemMetadata& item_metadata,
  49. CreatePayloadFilesCallback payload_files_callback) = 0;
  50. // Updates the download progress for the file transfer associated with the
  51. // |update| in the Holding Space tray. The backfile file will be deleted if
  52. // the transfer was canceled or has failed.
  53. virtual void UpdateDownloadProgress(
  54. secure_channel::mojom::FileTransferUpdatePtr update) = 0;
  55. // Deletes the file created for the given |payload_id|.
  56. virtual void DeleteFile(int64_t payload_id) = 0;
  57. protected:
  58. CameraRollDownloadManager() = default;
  59. };
  60. } // namespace phonehub
  61. } // namespace ash
  62. #endif // ASH_COMPONENTS_PHONEHUB_CAMERA_ROLL_DOWNLOAD_MANAGER_H_