camera_roll_manager_impl.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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_IMPL_H_
  5. #define ASH_COMPONENTS_PHONEHUB_CAMERA_ROLL_MANAGER_IMPL_H_
  6. #include <memory>
  7. #include "ash/components/phonehub/camera_roll_download_manager.h"
  8. #include "ash/components/phonehub/camera_roll_manager.h"
  9. #include "ash/components/phonehub/camera_roll_thumbnail_decoder.h"
  10. #include "ash/components/phonehub/message_receiver.h"
  11. #include "ash/components/phonehub/proto/phonehub_api.pb.h"
  12. #include "ash/services/multidevice_setup/public/cpp/multidevice_setup_client.h"
  13. #include "ash/services/multidevice_setup/public/mojom/multidevice_setup.mojom.h"
  14. #include "ash/services/secure_channel/public/cpp/client/connection_manager.h"
  15. #include "ash/services/secure_channel/public/mojom/secure_channel_types.mojom.h"
  16. #include "base/memory/weak_ptr.h"
  17. #include "base/observer_list.h"
  18. #include "base/observer_list_types.h"
  19. #include "base/time/time.h"
  20. #include "third_party/abseil-cpp/absl/types/optional.h"
  21. namespace ash {
  22. namespace phonehub {
  23. class CameraRollDownloadManager;
  24. class CameraRollItem;
  25. class MessageSender;
  26. // Manages camera roll items sent from the connected Android device.
  27. class CameraRollManagerImpl
  28. : public CameraRollManager,
  29. public MessageReceiver::Observer,
  30. public multidevice_setup::MultiDeviceSetupClient::Observer,
  31. public secure_channel::ConnectionManager::Observer {
  32. public:
  33. CameraRollManagerImpl(
  34. MessageReceiver* message_receiver,
  35. MessageSender* message_sender,
  36. multidevice_setup::MultiDeviceSetupClient* multidevice_setup_client,
  37. secure_channel::ConnectionManager* connection_manager,
  38. std::unique_ptr<CameraRollDownloadManager> camera_roll_download_manager);
  39. ~CameraRollManagerImpl() override;
  40. private:
  41. friend class CameraRollManagerImplTest;
  42. // CameraRollManager:
  43. void DownloadItem(
  44. const proto::CameraRollItemMetadata& item_metadata) override;
  45. // MessageReceiver::Observer
  46. void OnPhoneStatusSnapshotReceived(
  47. proto::PhoneStatusSnapshot phone_status_snapshot) override;
  48. void OnPhoneStatusUpdateReceived(
  49. proto::PhoneStatusUpdate phone_status_update) override;
  50. void OnFetchCameraRollItemsResponseReceived(
  51. const proto::FetchCameraRollItemsResponse& response) override;
  52. void OnFetchCameraRollItemDataResponseReceived(
  53. const proto::FetchCameraRollItemDataResponse& response) override;
  54. // MultiDeviceSetupClient::Observer:
  55. void OnFeatureStatesChanged(
  56. const multidevice_setup::MultiDeviceSetupClient::FeatureStatesMap&
  57. feature_states_map) override;
  58. // ConnectionManager::Observer:
  59. void OnConnectionStatusChanged() override;
  60. void SendFetchCameraRollItemsRequest();
  61. void OnItemThumbnailsDecoded(
  62. CameraRollThumbnailDecoder::BatchDecodeResult result,
  63. const std::vector<CameraRollItem>& items);
  64. void CancelPendingThumbnailRequests();
  65. void OnPayloadFilesCreated(
  66. const proto::FetchCameraRollItemDataResponse& response,
  67. CameraRollDownloadManager::CreatePayloadFilesResult result,
  68. absl::optional<secure_channel::mojom::PayloadFilesPtr> payload_files);
  69. void OnPayloadFileRegistered(const proto::CameraRollItemMetadata& metadata,
  70. int64_t payload_id,
  71. bool success);
  72. void OnFileTransferUpdate(
  73. const proto::CameraRollItemMetadata& metadata,
  74. secure_channel::mojom::FileTransferUpdatePtr update);
  75. bool IsCameraRollSettingEnabled();
  76. void UpdateCameraRollAccessStateAndNotifyIfNeeded(
  77. const proto::CameraRollAccessState& access_state);
  78. void ComputeAndUpdateUiState() override;
  79. bool is_android_feature_enabled_ = false;
  80. bool is_android_storage_granted_ = false;
  81. absl::optional<base::TimeTicks> fetch_items_request_start_timestamp_;
  82. MessageReceiver* message_receiver_;
  83. MessageSender* message_sender_;
  84. multidevice_setup::MultiDeviceSetupClient* multidevice_setup_client_;
  85. secure_channel::ConnectionManager* connection_manager_;
  86. std::unique_ptr<CameraRollDownloadManager> camera_roll_download_manager_;
  87. std::unique_ptr<CameraRollThumbnailDecoder> thumbnail_decoder_;
  88. base::WeakPtrFactory<CameraRollManagerImpl> weak_ptr_factory_{this};
  89. // WeakPtrFactory dedicated to thumbanil decoder callbacks that need to be
  90. // invalidated when the current item set updates.
  91. base::WeakPtrFactory<CameraRollManagerImpl>
  92. thumbnail_decoder_weak_ptr_factory_{this};
  93. };
  94. } // namespace phonehub
  95. } // namespace ash
  96. #endif // ASH_COMPONENTS_PHONEHUB_CAMERA_ROLL_MANAGER_IMPL_H_