/* This file is part of Telegram Desktop, the official desktop application for the Telegram messaging service. For license and copyright information please follow this link: https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once #include "base/timer.h" class PhotoData; class DocumentData; namespace Media { namespace Streaming { class Reader; class Document; } // namespace Streaming } // namespace Media namespace Data { class Session; struct FileOrigin; class Streaming final { public: explicit Streaming(not_null owner); Streaming(const Streaming &other) = delete; Streaming &operator=(const Streaming &other) = delete; ~Streaming(); using Reader = ::Media::Streaming::Reader; using Document = ::Media::Streaming::Document; [[nodiscard]] std::shared_ptr sharedReader( not_null document, FileOrigin origin, bool forceRemoteLoader = false); [[nodiscard]] std::shared_ptr sharedDocument( not_null document, FileOrigin origin); [[nodiscard]] std::shared_ptr sharedReader( not_null photo, FileOrigin origin, bool forceRemoteLoader = false); [[nodiscard]] std::shared_ptr sharedDocument( not_null photo, FileOrigin origin); void keepAlive(not_null document); void keepAlive(not_null photo); private: void clearKeptAlive(); template [[nodiscard]] std::shared_ptr sharedReader( base::flat_map, std::weak_ptr> &readers, not_null data, FileOrigin origin, bool forceRemoteLoader = false); template [[nodiscard]] std::shared_ptr sharedDocument( base::flat_map, std::weak_ptr> &documents, base::flat_map, std::weak_ptr> &readers, not_null data, FileOrigin origin); template void keepAlive( base::flat_map, std::weak_ptr> &documents, not_null data); const not_null _owner; base::flat_map< not_null, std::weak_ptr> _fileReaders; base::flat_map< not_null, std::weak_ptr> _fileDocuments; base::flat_map, std::weak_ptr> _photoReaders; base::flat_map< not_null, std::weak_ptr> _photoDocuments; base::flat_map, crl::time> _keptAlive; base::Timer _keptAliveTimer; }; } // namespace Data