camera_roll_manager.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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_MANAGER_H_
  5. #define ASH_COMPONENTS_PHONEHUB_CAMERA_ROLL_MANAGER_H_
  6. #include "ash/components/phonehub/proto/phonehub_api.pb.h"
  7. #include "ash/services/multidevice_setup/public/mojom/multidevice_setup.mojom.h"
  8. #include "base/observer_list.h"
  9. #include "base/observer_list_types.h"
  10. namespace ash {
  11. namespace phonehub {
  12. class CameraRollItem;
  13. // Manages camera roll items sent from the connected Android device.
  14. class CameraRollManager {
  15. public:
  16. class Observer : public base::CheckedObserver {
  17. public:
  18. ~Observer() override = default;
  19. // Notifies observers that camera view needs be refreshed,
  20. // the access state of camera roll feature is updated or current camera roll
  21. // items has changed.
  22. virtual void OnCameraRollViewUiStateUpdated();
  23. // Notifies observers that there was an error in the download process.
  24. enum class DownloadErrorType {
  25. kGenericError,
  26. kInsufficientStorage,
  27. kNetworkConnection,
  28. };
  29. virtual void OnCameraRollDownloadError(
  30. DownloadErrorType error_type,
  31. const proto::CameraRollItemMetadata& metadata);
  32. };
  33. enum class CameraRollUiState {
  34. // Feature is either not supported, or supported and enabled, but haven't
  35. // received any items yet
  36. SHOULD_HIDE,
  37. // Feature is enabled on phone, but can not be used because storage access
  38. // permissions have been rejected on the Android device. In this state the
  39. // UI is hidden but the settings toggle is shown in a grayed out state.
  40. NO_STORAGE_PERMISSION,
  41. // We have items that can be displayed
  42. ITEMS_VISIBLE,
  43. };
  44. CameraRollManager(const CameraRollManager&) = delete;
  45. CameraRollManager& operator=(const CameraRollManager&) = delete;
  46. virtual ~CameraRollManager();
  47. // Returns the set of current camera roll items in the order in which they
  48. // should be displayed
  49. const std::vector<CameraRollItem>& current_items() const {
  50. return current_items_;
  51. }
  52. void AddObserver(Observer* observer);
  53. void RemoveObserver(Observer* observer);
  54. CameraRollUiState ui_state();
  55. // Downloads a full-quality photo or video file from the connected Android
  56. // device specified by the |item_metadata| to the Downloads folder.
  57. virtual void DownloadItem(
  58. const proto::CameraRollItemMetadata& item_metadata) = 0;
  59. protected:
  60. CameraRollManager();
  61. CameraRollUiState ui_state_ = CameraRollUiState::SHOULD_HIDE;
  62. void SetCurrentItems(const std::vector<CameraRollItem>& items);
  63. void ClearCurrentItems();
  64. virtual void ComputeAndUpdateUiState() = 0;
  65. void NotifyCameraRollViewUiStateUpdated();
  66. void NotifyCameraRollDownloadError(
  67. Observer::DownloadErrorType error_type,
  68. const proto::CameraRollItemMetadata& metadata);
  69. private:
  70. std::vector<CameraRollItem> current_items_;
  71. base::ObserverList<Observer> observer_list_;
  72. };
  73. } // namespace phonehub
  74. } // namespace ash
  75. #endif // ASH_COMPONENTS_PHONEHUB_CAMERA_ROLL_MANAGER_H_