fake_camera_roll_download_manager.cc 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. #include "ash/components/phonehub/fake_camera_roll_download_manager.h"
  5. #include <utility>
  6. #include <vector>
  7. #include "ash/components/phonehub/camera_roll_download_manager.h"
  8. #include "ash/components/phonehub/proto/phonehub_api.pb.h"
  9. #include "ash/services/secure_channel/public/mojom/secure_channel_types.mojom.h"
  10. #include "base/containers/flat_map.h"
  11. #include "third_party/abseil-cpp/absl/types/optional.h"
  12. namespace ash {
  13. namespace phonehub {
  14. FakeCameraRollDownloadManager::FakeCameraRollDownloadManager() = default;
  15. FakeCameraRollDownloadManager::~FakeCameraRollDownloadManager() = default;
  16. void FakeCameraRollDownloadManager::CreatePayloadFiles(
  17. int64_t payload_id,
  18. const phonehub::proto::CameraRollItemMetadata& item_metadata,
  19. CreatePayloadFilesCallback payload_files_callback) {
  20. absl::optional<secure_channel::mojom::PayloadFilesPtr> payload_files;
  21. if (expected_create_payload_files_result_ ==
  22. CreatePayloadFilesResult::kSuccess) {
  23. payload_files =
  24. absl::make_optional(secure_channel::mojom::PayloadFiles::New());
  25. payload_update_map_.emplace(
  26. payload_id,
  27. std::vector<secure_channel::mojom::FileTransferUpdatePtr>());
  28. } else {
  29. payload_files = absl::nullopt;
  30. }
  31. std::move(payload_files_callback)
  32. .Run(expected_create_payload_files_result_, std::move(payload_files));
  33. }
  34. void FakeCameraRollDownloadManager::UpdateDownloadProgress(
  35. secure_channel::mojom::FileTransferUpdatePtr update) {
  36. payload_update_map_.at(update->payload_id).push_back(std::move(update));
  37. }
  38. void FakeCameraRollDownloadManager::DeleteFile(int64_t payload_id) {
  39. payload_update_map_.erase(payload_id);
  40. }
  41. const std::vector<secure_channel::mojom::FileTransferUpdatePtr>&
  42. FakeCameraRollDownloadManager::GetFileTransferUpdates(
  43. int64_t payload_id) const {
  44. return payload_update_map_.at(payload_id);
  45. }
  46. } // namespace phonehub
  47. } // namespace ash