Clear language pack info when all language pack managers are closed.

GitOrigin-RevId: 2c08722e00ae6209fb90f912b9265ce30bc3aad6
This commit is contained in:
levlam 2018-07-19 01:14:20 +03:00
parent f25bcd8d70
commit 6ca79487e2
2 changed files with 15 additions and 0 deletions

View File

@ -21,6 +21,8 @@
namespace td { namespace td {
void LanguagePackManager::start_up() { void LanguagePackManager::start_up() {
std::lock_guard<std::mutex> lock(language_packs_mutex_);
manager_count_++;
language_pack_ = G()->shared_config().get_option_string("language_pack"); language_pack_ = G()->shared_config().get_option_string("language_pack");
language_code_ = G()->shared_config().get_option_string("language_code"); language_code_ = G()->shared_config().get_option_string("language_code");
LOG(INFO) << "Use language pack " << language_pack_ << " with language " << language_code_; LOG(INFO) << "Use language pack " << language_pack_ << " with language " << language_code_;
@ -28,6 +30,15 @@ void LanguagePackManager::start_up() {
// TODO load language_pack_version from database // TODO load language_pack_version from database
} }
void LanguagePackManager::tear_down() {
std::lock_guard<std::mutex> lock(language_packs_mutex_);
manager_count_--;
if (manager_count_ == 0) {
LOG(INFO) << "Clear language packs";
language_packs_.clear();
}
}
void LanguagePackManager::on_language_pack_changed() { void LanguagePackManager::on_language_pack_changed() {
auto new_language_pack = G()->shared_config().get_option_string("language_pack"); auto new_language_pack = G()->shared_config().get_option_string("language_pack");
if (new_language_pack == language_pack_) { if (new_language_pack == language_pack_) {
@ -427,6 +438,7 @@ void LanguagePackManager::hangup() {
stop(); stop();
} }
int32 LanguagePackManager::manager_count_ = 0;
std::mutex LanguagePackManager::language_packs_mutex_; std::mutex LanguagePackManager::language_packs_mutex_;
std::unordered_map<string, std::unique_ptr<LanguagePackManager::LanguagePack>> LanguagePackManager::language_packs_; std::unordered_map<string, std::unique_ptr<LanguagePackManager::LanguagePack>> LanguagePackManager::language_packs_;

View File

@ -72,6 +72,8 @@ class LanguagePackManager : public NetQueryCallback {
string language_code_; string language_code_;
uint32 generation_ = 0; uint32 generation_ = 0;
static int32 manager_count_;
static std::mutex language_packs_mutex_; static std::mutex language_packs_mutex_;
static std::unordered_map<string, std::unique_ptr<LanguagePack>> language_packs_; static std::unordered_map<string, std::unique_ptr<LanguagePack>> language_packs_;
@ -104,6 +106,7 @@ class LanguagePackManager : public NetQueryCallback {
void start_up() override; void start_up() override;
void hangup() override; void hangup() override;
void tear_down() override;
Container<Promise<NetQueryPtr>> container_; Container<Promise<NetQueryPtr>> container_;
void send_with_promise(NetQueryPtr query, Promise<NetQueryPtr> promise); void send_with_promise(NetQueryPtr query, Promise<NetQueryPtr> promise);