Commit f7b5d81c authored by Paweł Wegner's avatar Paweł Wegner

cloudbrowser: use other thread pool for context operations.

parent ec97b696
......@@ -98,6 +98,7 @@ CloudContext::CloudContext(QObject* parent)
IHttpServerFactory::create())),
http_(IHttp::create()),
thread_pool_(IThreadPool::create(1)),
context_thread_pool_(IThreadPool::create(1)),
cache_size_(updatedCacheSize()) {
util::log_stream(util::make_unique<std::ostream>(&debug_stream_));
std::lock_guard<std::mutex> lock(mutex_);
......@@ -129,8 +130,6 @@ CloudContext::CloudContext(QObject* parent)
}
CloudContext::~CloudContext() {
save();
thread_pool_ = nullptr;
util::log_stream(util::make_unique<std::ostream>(std::cerr.rdbuf()));
}
......@@ -178,12 +177,11 @@ void CloudContext::saveCachedDirectories() {
file.write(QJsonDocument(json).toBinaryData());
}
void CloudContext::save() {
thread_pool_->schedule([this] {
void CloudContext::saveProviders() {
schedule([this] {
std::lock_guard<std::mutex> lock(mutex_);
QSettings settings;
settings.setValue("providers", user_provider_model_.dump());
saveCachedDirectories();
});
}
......@@ -234,7 +232,7 @@ void CloudContext::removeProvider(QVariant provider) {
std::lock_guard<std::mutex> lock(mutex_);
user_provider_model_.remove(provider);
}
save();
saveProviders();
}
QString CloudContext::pretty(QString provider) const {
......@@ -352,7 +350,7 @@ IItem::List CloudContext::cachedDirectory(ListDirectoryCacheKey key) {
}
void CloudContext::schedule(std::function<void()> f) {
thread_pool_->schedule(f);
context_thread_pool_->schedule(f);
}
void CloudContext::receivedCode(std::string provider, std::string code) {
......@@ -377,7 +375,7 @@ void CloudContext::receivedCode(std::string provider, std::string code) {
{d.right()->username_,
this->provider(provider, d.right()->username_, *e.right())});
}
save();
saveProviders();
}));
});
pool_.add(std::move(p), std::move(r));
......
......@@ -55,11 +55,6 @@ class CloudContext : public QObject {
CloudContext(QObject* parent = nullptr);
~CloudContext();
void loadCachedDirectories();
void saveCachedDirectories();
void save();
QStringList providers() const;
ProviderListModel* userProviders();
bool includeAds() const;
......@@ -135,6 +130,9 @@ class CloudContext : public QObject {
QString current_line_;
};
void loadCachedDirectories();
void saveCachedDirectories();
void saveProviders();
void receivedCode(std::string provider, std::string code);
cloudstorage::ICloudProvider::Pointer provider(
const std::string& name, const std::string& label,
......@@ -149,6 +147,7 @@ class CloudContext : public QObject {
std::vector<std::shared_ptr<cloudstorage::IHttpServer>> auth_server_;
std::shared_ptr<cloudstorage::IHttp> http_;
std::shared_ptr<cloudstorage::IThreadPool> thread_pool_;
cloudstorage::IThreadPool::Pointer context_thread_pool_;
RequestPool pool_;
std::unordered_map<ListDirectoryCacheKey,
std::vector<cloudstorage::IItem::Pointer>>
......
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