icon_decoder_impl.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright 2022 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_ICON_DECODER_IMPL_H_
  5. #define ASH_COMPONENTS_PHONEHUB_ICON_DECODER_IMPL_H_
  6. #include "ash/components/phonehub/icon_decoder.h"
  7. #include "ash/components/phonehub/proto/phonehub_api.pb.h"
  8. #include "ash/components/phonehub/recent_apps_interaction_handler.h"
  9. #include "base/callback.h"
  10. #include "base/memory/weak_ptr.h"
  11. #include "services/data_decoder/public/cpp/data_decoder.h"
  12. #include "services/data_decoder/public/cpp/decode_image.h"
  13. #include "ui/gfx/image/image.h"
  14. namespace ash {
  15. namespace phonehub {
  16. class IconDecoderImpl : public IconDecoder {
  17. public:
  18. IconDecoderImpl();
  19. ~IconDecoderImpl() override;
  20. void BatchDecode(
  21. std::unique_ptr<std::vector<DecodingData>> decode_items,
  22. base::OnceCallback<void(std::unique_ptr<std::vector<DecodingData>>)>
  23. finished_callback) override;
  24. private:
  25. friend class IconDecoderImplTest;
  26. friend class TestDecoderDelegate;
  27. friend class RecentAppsInteractionHandlerTest;
  28. // Delegate class that decodes icons. Can be overridden in tests.
  29. class DecoderDelegate {
  30. public:
  31. DecoderDelegate();
  32. virtual ~DecoderDelegate();
  33. virtual void Decode(const DecodingData& data,
  34. data_decoder::DecodeImageCallback callback);
  35. private:
  36. // The instance of DataDecoder to decode thumbnail images. The underlying
  37. // service instance is started lazily when needed and torn down when not in
  38. // use.
  39. data_decoder::DataDecoder data_decoder_;
  40. };
  41. void OnIconDecoded(DecodingData& decoding_data, const SkBitmap& result);
  42. void OnAllIconsDecoded(
  43. base::OnceCallback<void(std::unique_ptr<std::vector<DecodingData>>)>
  44. finished_callback);
  45. void CancelPendingRequests();
  46. std::unique_ptr<DecoderDelegate> decoder_delegate_;
  47. std::unique_ptr<std::vector<DecodingData>> pending_items_;
  48. base::RepeatingClosure barrier_closure_;
  49. // Contains weak pointers to callbacks passed to the |DecoderDelegate|.
  50. base::WeakPtrFactory<IconDecoderImpl> weak_ptr_factory_{this};
  51. };
  52. } // namespace phonehub
  53. } // namespace ash
  54. #endif // ASH_COMPONENTS_PHONEHUB_ICON_DECODER_IMPL_H_