mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 06:26:18 +00:00
Register streaming loaders in Storage::Downloader.
This commit is contained in:
@@ -36,8 +36,9 @@ constexpr auto kMaxWebFileQueries = 8;
|
||||
|
||||
} // namespace
|
||||
|
||||
Downloader::Downloader()
|
||||
: _killDownloadSessionsTimer([=] { killDownloadSessions(); })
|
||||
Downloader::Downloader(not_null<ApiWrap*> api)
|
||||
: _api(api)
|
||||
, _killDownloadSessionsTimer([=] { killDownloadSessions(); })
|
||||
, _queueForWeb(kMaxWebFileQueries) {
|
||||
}
|
||||
|
||||
@@ -48,14 +49,16 @@ void Downloader::clearPriorities() {
|
||||
void Downloader::requestedAmountIncrement(MTP::DcId dcId, int index, int amount) {
|
||||
Expects(index >= 0 && index < MTP::kDownloadSessionsCount);
|
||||
|
||||
using namespace rpl::mappers;
|
||||
|
||||
auto it = _requestedBytesAmount.find(dcId);
|
||||
if (it == _requestedBytesAmount.cend()) {
|
||||
it = _requestedBytesAmount.emplace(dcId, RequestedInDc { { 0 } }).first;
|
||||
}
|
||||
it->second[index] += amount;
|
||||
if (it->second[index]) {
|
||||
if (amount > 0) {
|
||||
killDownloadSessionsStop(dcId);
|
||||
} else {
|
||||
} else if (ranges::find_if(it->second, _1 > 0) == end(it->second)) {
|
||||
killDownloadSessionsStart(dcId);
|
||||
}
|
||||
}
|
||||
|
@@ -12,6 +12,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "base/binary_guard.h"
|
||||
#include "data/data_file_origin.h"
|
||||
|
||||
class ApiWrap;
|
||||
|
||||
namespace Storage {
|
||||
namespace Cache {
|
||||
struct Key;
|
||||
@@ -35,9 +37,13 @@ public:
|
||||
FileLoader *end = nullptr;
|
||||
};
|
||||
|
||||
Downloader();
|
||||
explicit Downloader(not_null<ApiWrap*> api);
|
||||
~Downloader();
|
||||
|
||||
ApiWrap &api() const {
|
||||
return *_api;
|
||||
}
|
||||
|
||||
int currentPriority() const {
|
||||
return _priority;
|
||||
}
|
||||
@@ -58,6 +64,8 @@ private:
|
||||
void killDownloadSessionsStop(MTP::DcId dcId);
|
||||
void killDownloadSessions();
|
||||
|
||||
not_null<ApiWrap*> _api;
|
||||
|
||||
base::Observable<void> _taskFinishedObservable;
|
||||
int _priority = 1;
|
||||
|
||||
|
@@ -140,7 +140,8 @@ const QString &Uploader::File::filename() const {
|
||||
return file ? file->filename : media.filename;
|
||||
}
|
||||
|
||||
Uploader::Uploader() {
|
||||
Uploader::Uploader(not_null<ApiWrap*> api)
|
||||
: _api(api) {
|
||||
nextTimer.setSingleShot(true);
|
||||
connect(&nextTimer, SIGNAL(timeout()), this, SLOT(sendNext()));
|
||||
stopSessionsTimer.setSingleShot(true);
|
||||
|
@@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
|
||||
struct FileLoadResult;
|
||||
struct SendMediaReady;
|
||||
class ApiWrap;
|
||||
|
||||
namespace Storage {
|
||||
|
||||
@@ -53,7 +54,9 @@ class Uploader : public QObject, public RPCSender {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Uploader();
|
||||
explicit Uploader(not_null<ApiWrap*> api);
|
||||
~Uploader();
|
||||
|
||||
void uploadMedia(const FullMsgId &msgId, const SendMediaReady &image);
|
||||
void upload(
|
||||
const FullMsgId &msgId,
|
||||
@@ -96,8 +99,6 @@ public:
|
||||
return _secureFailed.events();
|
||||
}
|
||||
|
||||
~Uploader();
|
||||
|
||||
public slots:
|
||||
void unpause();
|
||||
void sendNext();
|
||||
@@ -111,6 +112,7 @@ private:
|
||||
|
||||
void currentFailed();
|
||||
|
||||
not_null<ApiWrap*> _api;
|
||||
base::flat_map<mtpRequestId, QByteArray> requestsSent;
|
||||
base::flat_map<mtpRequestId, int32> docRequestsSent;
|
||||
base::flat_map<mtpRequestId, int32> dcMap;
|
||||
|
@@ -125,11 +125,6 @@ bool StreamedFileDownloader::loadPart() {
|
||||
_nextPartIndex = index + 1;
|
||||
_reader->loadForDownloader(this, index * kPartSize);
|
||||
|
||||
AssertIsDebug();
|
||||
//_downloader->requestedAmountIncrement(
|
||||
// requestData.dcId,
|
||||
// requestData.dcIndex,
|
||||
// kPartSize);
|
||||
++_partsRequested;
|
||||
++_queue->queriesCount;
|
||||
|
||||
@@ -154,11 +149,6 @@ void StreamedFileDownloader::savePart(const LoadedPart &part) {
|
||||
++_partsSaved;
|
||||
|
||||
if (index < _nextPartIndex) {
|
||||
AssertIsDebug();
|
||||
//_downloader->requestedAmountIncrement(
|
||||
// requestData.dcId,
|
||||
// requestData.dcIndex,
|
||||
// -kPartSize);
|
||||
--_partsRequested;
|
||||
--_queue->queriesCount;
|
||||
}
|
||||
|
Reference in New Issue
Block a user