mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-31 14:45:14 +00:00
All mtproto downloads using DownloadMtprotoTask.
This commit is contained in:
@@ -10,12 +10,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "base/observer.h"
|
||||
#include "base/timer.h"
|
||||
#include "base/binary_guard.h"
|
||||
#include "data/data_file_origin.h"
|
||||
#include "mtproto/facade.h"
|
||||
|
||||
#include <QtNetwork/QNetworkReply>
|
||||
|
||||
class ApiWrap;
|
||||
namespace Data {
|
||||
struct FileOrigin;
|
||||
} // namespace Data
|
||||
|
||||
namespace Main {
|
||||
class Session;
|
||||
@@ -26,88 +26,22 @@ namespace Cache {
|
||||
struct Key;
|
||||
} // namespace Cache
|
||||
|
||||
// 10 MB max file could be hold in memory
|
||||
// This value is used in local cache database settings!
|
||||
constexpr auto kMaxFileInMemory = 10 * 1024 * 1024; // 10 MB max file could be hold in memory
|
||||
constexpr auto kMaxFileInMemory = 10 * 1024 * 1024;
|
||||
|
||||
constexpr auto kMaxVoiceInMemory = 2 * 1024 * 1024; // 2 MB audio is hold in memory and auto loaded
|
||||
constexpr auto kMaxStickerInMemory = 2 * 1024 * 1024; // 2 MB stickers hold in memory, auto loaded and displayed inline
|
||||
// 2 MB audio is hold in memory and auto loaded
|
||||
constexpr auto kMaxVoiceInMemory = 2 * 1024 * 1024;
|
||||
|
||||
// 2 MB stickers hold in memory, auto loaded and displayed inline
|
||||
constexpr auto kMaxStickerInMemory = 2 * 1024 * 1024;
|
||||
|
||||
// 10 MB GIF and mp4 animations held in memory while playing
|
||||
constexpr auto kMaxWallPaperInMemory = kMaxFileInMemory;
|
||||
constexpr auto kMaxAnimationInMemory = kMaxFileInMemory; // 10 MB gif and mp4 animations held in memory while playing
|
||||
constexpr auto kMaxWallPaperDimension = 4096; // 4096x4096 is max area.
|
||||
constexpr auto kMaxAnimationInMemory = kMaxFileInMemory;
|
||||
|
||||
// Different part sizes are not supported for now :(
|
||||
// Because we start downloading with some part size
|
||||
// and then we get a cdn-redirect where we support only
|
||||
// fixed part size download for hash checking.
|
||||
constexpr auto kDownloadPartSize = 128 * 1024;
|
||||
|
||||
class Downloader {
|
||||
public:
|
||||
virtual ~Downloader() = default;
|
||||
|
||||
[[nodiscard]] virtual MTP::DcId dcId() const = 0;
|
||||
[[nodiscard]] virtual bool readyToRequest() const = 0;
|
||||
virtual void loadPart(int dcIndex) = 0;
|
||||
|
||||
};
|
||||
|
||||
class DownloadManager final : public base::has_weak_ptr {
|
||||
public:
|
||||
explicit DownloadManager(not_null<ApiWrap*> api);
|
||||
~DownloadManager();
|
||||
|
||||
[[nodiscard]] ApiWrap &api() const {
|
||||
return *_api;
|
||||
}
|
||||
|
||||
void enqueue(not_null<Downloader*> loader);
|
||||
void remove(not_null<Downloader*> loader);
|
||||
|
||||
[[nodiscard]] base::Observable<void> &taskFinished() {
|
||||
return _taskFinishedObservable;
|
||||
}
|
||||
|
||||
// dcId == 0 is for web requests.
|
||||
void requestedAmountIncrement(MTP::DcId dcId, int index, int amount);
|
||||
[[nodiscard]] int chooseDcIndexForRequest(MTP::DcId dcId);
|
||||
|
||||
private:
|
||||
class Queue final {
|
||||
public:
|
||||
void enqueue(not_null<Downloader*> loader);
|
||||
void remove(not_null<Downloader*> loader);
|
||||
void resetGeneration();
|
||||
[[nodiscard]] bool empty() const;
|
||||
[[nodiscard]] Downloader *nextLoader() const;
|
||||
|
||||
private:
|
||||
std::vector<not_null<Downloader*>> _loaders;
|
||||
std::vector<not_null<Downloader*>> _previousGeneration;
|
||||
|
||||
};
|
||||
|
||||
void checkSendNext();
|
||||
|
||||
void killDownloadSessionsStart(MTP::DcId dcId);
|
||||
void killDownloadSessionsStop(MTP::DcId dcId);
|
||||
void killDownloadSessions();
|
||||
|
||||
void resetGeneration();
|
||||
|
||||
const not_null<ApiWrap*> _api;
|
||||
|
||||
base::Observable<void> _taskFinishedObservable;
|
||||
|
||||
base::flat_map<MTP::DcId, std::vector<int>> _requestedBytesAmount;
|
||||
base::Timer _resetGenerationTimer;
|
||||
|
||||
base::flat_map<MTP::DcId, crl::time> _killDownloadSessionTimes;
|
||||
base::Timer _killDownloadSessionsTimer;
|
||||
|
||||
base::flat_map<MTP::DcId, Queue> _mtprotoLoaders;
|
||||
Queue _webLoaders;
|
||||
|
||||
};
|
||||
// 4096x4096 is max area.
|
||||
constexpr auto kMaxWallPaperDimension = 4096;
|
||||
|
||||
} // namespace Storage
|
||||
|
||||
@@ -132,8 +66,9 @@ public:
|
||||
LoadFromCloudSetting fromCloud,
|
||||
bool autoLoading,
|
||||
uint8 cacheTag);
|
||||
virtual ~FileLoader();
|
||||
|
||||
Main::Session &session() const;
|
||||
[[nodiscard]] Main::Session &session() const;
|
||||
|
||||
bool finished() const {
|
||||
return _finished;
|
||||
@@ -153,7 +88,8 @@ public:
|
||||
QString fileName() const {
|
||||
return _filename;
|
||||
}
|
||||
virtual Data::FileOrigin fileOrigin() const;
|
||||
// Used in MainWidget::documentLoadFailed.
|
||||
[[nodiscard]] virtual Data::FileOrigin fileOrigin() const;
|
||||
float64 currentProgress() const;
|
||||
virtual int currentOffset() const;
|
||||
int fullSize() const;
|
||||
@@ -171,10 +107,6 @@ public:
|
||||
return _autoLoading;
|
||||
}
|
||||
|
||||
virtual void stop() {
|
||||
}
|
||||
virtual ~FileLoader();
|
||||
|
||||
void localLoaded(
|
||||
const StorageImageSaved &result,
|
||||
const QByteArray &imageFormat,
|
||||
@@ -198,7 +130,7 @@ protected:
|
||||
void loadLocal(const Storage::Cache::Key &key);
|
||||
virtual Storage::Cache::Key cacheKey() const = 0;
|
||||
virtual std::optional<MediaKey> fileLocationKey() const = 0;
|
||||
virtual void cancelRequests() = 0;
|
||||
virtual void cancelHook() = 0;
|
||||
virtual void startLoading() = 0;
|
||||
|
||||
void cancel(bool failed);
|
||||
|
Reference in New Issue
Block a user