Commit 0b94e98e authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

flatpak: reuse the cancellable instances where it makes sense

It's not very useful to create the cancellable when we won't be able to
use it. Pass the one from the backend so we can cancel jobs upon closing
at least.
parent c3a286b1
......@@ -480,7 +480,7 @@ FlatpakResource * FlatpakBackend::addAppFromFlatpakRef(const QUrl &url)
}
fw->deleteLater();
});
fw->setFuture(QtConcurrent::run(&m_threadPool, &FlatpakRunnables::fetchMetadata, installation, resource));
fw->setFuture(QtConcurrent::run(&m_threadPool, &FlatpakRunnables::fetchMetadata, installation, resource, m_cancellable));
} else {
addResource(resource);
}
......@@ -980,7 +980,7 @@ bool FlatpakBackend::updateAppMetadata(FlatpakInstallation* flatpakInstallation,
onFetchMetadataFinished(flatpakInstallation, resource, metadata);
fw->deleteLater();
});
fw->setFuture(QtConcurrent::run(&m_threadPool, &FlatpakRunnables::fetchMetadata, flatpakInstallation, resource));
fw->setFuture(QtConcurrent::run(&m_threadPool, &FlatpakRunnables::fetchMetadata, flatpakInstallation, resource, m_cancellable));
// Return false to indicate we cannot continue (right now used only in updateAppSize())
return false;
......@@ -1101,7 +1101,7 @@ bool FlatpakBackend::updateAppSizeFromRemote(FlatpakInstallation *flatpakInstall
resource->setPropertyState(FlatpakResource::DownloadSize, FlatpakResource::Fetching);
resource->setPropertyState(FlatpakResource::InstalledSize, FlatpakResource::Fetching);
futureWatcher->setFuture(QtConcurrent::run(&m_threadPool, &FlatpakRunnables::fetchFlatpakSize, flatpakInstallation, resource));
futureWatcher->setFuture(QtConcurrent::run(&m_threadPool, &FlatpakRunnables::fetchFlatpakSize, flatpakInstallation, resource, m_cancellable));
}
return true;
......
......@@ -27,9 +27,8 @@ static FlatpakRef * createFakeRef(FlatpakResource *resource)
namespace FlatpakRunnables
{
QByteArray fetchMetadata(FlatpakInstallation *installation, FlatpakResource *app)
QByteArray fetchMetadata(FlatpakInstallation *installation, FlatpakResource *app, GCancellable* cancellable)
{
g_autoptr(GCancellable) cancellable = g_cancellable_new();
g_autoptr(GError) localError = nullptr;
if (app->origin().isEmpty()) {
......@@ -61,9 +60,8 @@ QByteArray fetchMetadata(FlatpakInstallation *installation, FlatpakResource *app
return metadataContent;
}
SizeInformation fetchFlatpakSize(FlatpakInstallation *installation, FlatpakResource *app)
SizeInformation fetchFlatpakSize(FlatpakInstallation *installation, FlatpakResource *app, GCancellable* cancellable)
{
g_autoptr(GCancellable) cancellable = g_cancellable_new();
g_autoptr(GError) localError = nullptr;
SizeInformation ret;
......
......@@ -23,9 +23,9 @@ namespace FlatpakRunnables
guint64 installedSize;
};
SizeInformation fetchFlatpakSize(FlatpakInstallation *installation, FlatpakResource *app);
SizeInformation fetchFlatpakSize(FlatpakInstallation *installation, FlatpakResource *app, GCancellable* cancellable);
QByteArray fetchMetadata(FlatpakInstallation *installation, FlatpakResource *app);
QByteArray fetchMetadata(FlatpakInstallation *installation, FlatpakResource *app, GCancellable* cancellable);
}
#endif // FLATPAKFETCHDATAJOB_H
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment