camera_roll_thumbnail_decoder.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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_THUMBNAIL_DECODER_H_
  5. #define ASH_COMPONENTS_PHONEHUB_CAMERA_ROLL_THUMBNAIL_DECODER_H_
  6. #include "ash/components/phonehub/proto/phonehub_api.pb.h"
  7. #include "base/callback.h"
  8. namespace ash {
  9. namespace phonehub {
  10. class CameraRollItem;
  11. // Decodes camera roll item thumbnails received from
  12. // |FetchCameraRollItemsResponse| in batches, and converts decoded items into
  13. // |CameraRollItem| objects that can be displayed on the UI.
  14. class CameraRollThumbnailDecoder {
  15. public:
  16. // Result of a |BatchDecode| operation.
  17. enum class BatchDecodeResult {
  18. // All items in the batch have been completed.
  19. kCompleted = 0,
  20. // The decode requests for this batch has been cancelled.
  21. kCancelled = 1,
  22. kMaxValue = kCancelled
  23. };
  24. CameraRollThumbnailDecoder(const CameraRollThumbnailDecoder&) = delete;
  25. CameraRollThumbnailDecoder& operator=(const CameraRollThumbnailDecoder&) =
  26. delete;
  27. virtual ~CameraRollThumbnailDecoder() = default;
  28. // Loads thumbnails of the batch of camera roll items either using encoded
  29. // thumbnail bytes in the |FetchCameraRollItemsResponse|, or from existing
  30. // images in |current_items| if an item has not changed.
  31. //
  32. // Returns decoded items through |callback| if the full batch can be decoded;
  33. // otherwise an empty list will be returned with appropriate result code.
  34. virtual void BatchDecode(
  35. const proto::FetchCameraRollItemsResponse& response,
  36. const std::vector<CameraRollItem>& current_items,
  37. base::OnceCallback<void(BatchDecodeResult result,
  38. const std::vector<CameraRollItem>&)>
  39. callback) = 0;
  40. protected:
  41. CameraRollThumbnailDecoder() = default;
  42. };
  43. } // namespace phonehub
  44. } // namespace ash
  45. #endif // ASH_COMPONENTS_PHONEHUB_CAMERA_ROLL_THUMBNAIL_DECODER_H_