Skip to content

Commit

Permalink
Revert "Revert "Fix MythDownloadManger after 997f7aa. It was possible…
Browse files Browse the repository at this point in the history
… for queue and cancel requests to be handled out of order resulting in newly queued downloads being cancelled almost immediately. We avoid this by removing any cancelled downloads from the download queue to a new cancellation queue, then we clean up the cancelled downloads later without affecting new additions.""

This reverts commit eb3a338.
  • Loading branch information
jyavenard committed Aug 12, 2013
1 parent a95a760 commit fd132e6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 29 deletions.
58 changes: 30 additions & 28 deletions mythtv/libs/libmythbase/mythdownloadmanager.cpp
Expand Up @@ -862,12 +862,6 @@ bool MythDownloadManager::downloadNow(MythDownloadInfo *dlInfo, bool deleteInfo)
* \param url for download to cancel
*/
void MythDownloadManager::cancelDownload(const QString &url)
{
QMetaObject::invokeMethod(this, "downloadCanceled",
Qt::QueuedConnection, Q_ARG(const QString&, url));
}

void MythDownloadManager::downloadCanceled(const QString &url)
{
QMutexLocker locker(m_infoLock);
MythDownloadInfo *dlInfo;
Expand All @@ -879,41 +873,49 @@ void MythDownloadManager::downloadCanceled(const QString &url)
dlInfo = lit.value();
if (dlInfo->m_url == url)
{
// this shouldn't happen
if (dlInfo->m_reply)
{
LOG(VB_FILE, LOG_DEBUG,
LOC + QString("Aborting download - user request"));
dlInfo->m_reply->abort();
}
m_cancellationQueue.append(dlInfo);
lit.remove();
if (dlInfo->IsDone())
continue;
dlInfo->m_lock.lock();
dlInfo->m_errorCode = QNetworkReply::OperationCanceledError;
dlInfo->m_done = true;
dlInfo->m_lock.unlock();
}
}

if (m_downloadInfos.contains(url))
{
dlInfo = m_downloadInfos[url];
if (dlInfo->m_reply)
m_downloadReplies.remove(dlInfo->m_reply);

m_cancellationQueue.append(dlInfo);
m_downloadInfos.remove(url);
}

QMetaObject::invokeMethod(this, "downloadCanceled",
Qt::QueuedConnection);
}

void MythDownloadManager::downloadCanceled()
{
QMutexLocker locker(m_infoLock);
MythDownloadInfo *dlInfo;

QMutableListIterator<MythDownloadInfo*> lit(m_cancellationQueue);
while (lit.hasNext())
{
lit.next();
dlInfo = lit.value();
// this shouldn't happen
if (dlInfo->m_reply)
{
LOG(VB_FILE, LOG_DEBUG,
LOC + QString("Aborting download - user request"));
m_downloadReplies.remove(dlInfo->m_reply);
dlInfo->m_reply->abort();
}
m_downloadInfos.remove(url);
if (!dlInfo->IsDone())
{
dlInfo->m_lock.lock();
dlInfo->m_errorCode = QNetworkReply::OperationCanceledError;
dlInfo->m_done = true;
dlInfo->m_lock.unlock();
}
lit.remove();
if (dlInfo->IsDone())
continue;
dlInfo->m_lock.lock();
dlInfo->m_errorCode = QNetworkReply::OperationCanceledError;
dlInfo->m_done = true;
dlInfo->m_lock.unlock();
}
}

Expand Down
3 changes: 2 additions & 1 deletion mythtv/libs/libmythbase/mythdownloadmanager.h
Expand Up @@ -97,7 +97,7 @@ class MBASE_PUBLIC MythDownloadManager : public QObject, public MThread
void downloadError(QNetworkReply::NetworkError errorCode);
void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);

void downloadCanceled(const QString &url);
void downloadCanceled();

private:
// Notification from RemoteFile downloads
Expand Down Expand Up @@ -140,6 +140,7 @@ class MBASE_PUBLIC MythDownloadManager : public QObject, public MThread
QMap <QString, MythDownloadInfo*> m_downloadInfos;
QMap <QNetworkReply*, MythDownloadInfo*> m_downloadReplies;
QList <MythDownloadInfo*> m_downloadQueue;
QList <MythDownloadInfo*> m_cancellationQueue;

QThread *m_queueThread;

Expand Down

0 comments on commit fd132e6

Please sign in to comment.