Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/map
diff options
context:
space:
mode:
authorr.kuznetsov <r.kuznetsov@corp.mail.ru>2018-08-20 17:04:47 +0300
committerDaria Volvenkova <d.volvenkova@corp.mail.ru>2018-08-20 18:03:00 +0300
commitecd47090ebfbbba80b1cca18b2621021ff75db50 (patch)
tree9e401a6445dabd232344366b5fd9fac96287404e /map
parent850a23b09e22b92cd3fce63322b5cc886911d2dc (diff)
Added caching sensitive info for bookmarks restoring
Diffstat (limited to 'map')
-rw-r--r--map/bookmark.cpp9
-rw-r--r--map/bookmark.hpp1
-rw-r--r--map/bookmark_manager.cpp30
-rw-r--r--map/bookmark_manager.hpp7
4 files changed, 46 insertions, 1 deletions
diff --git a/map/bookmark.cpp b/map/bookmark.cpp
index 3d373e7177..2bb7863e8e 100644
--- a/map/bookmark.cpp
+++ b/map/bookmark.cpp
@@ -276,6 +276,15 @@ void BookmarkCategory::SetAuthor(std::string const & name, std::string const & i
m_data.m_authorId = id;
}
+void BookmarkCategory::SetAccessRules(kml::AccessRules accessRules)
+{
+ if (m_data.m_accessRules == accessRules)
+ return;
+
+ SetDirty();
+ m_data.m_accessRules = accessRules;
+}
+
// static
kml::PredefinedColor BookmarkCategory::GetDefaultColor()
{
diff --git a/map/bookmark.hpp b/map/bookmark.hpp
index 86b95b210a..d8f275e9e7 100644
--- a/map/bookmark.hpp
+++ b/map/bookmark.hpp
@@ -89,6 +89,7 @@ public:
std::string GetCatalogDeeplink() const;
void SetAuthor(std::string const & name, std::string const & id);
+ void SetAccessRules(kml::AccessRules accessRules);
private:
void SetDirty() override;
diff --git a/map/bookmark_manager.cpp b/map/bookmark_manager.cpp
index cf8f093b6d..512b2d895f 100644
--- a/map/bookmark_manager.cpp
+++ b/map/bookmark_manager.cpp
@@ -1536,6 +1536,17 @@ void BookmarkManager::CreateCategories(KMLDataCollection && dataCollection, bool
group->SetFileName(fileName);
group->SetServerId(fileData.m_serverId);
+ // Restore sensitive info from the cache.
+ auto const cacheIt = m_restoringCache.find(fileName);
+ if (cacheIt != m_restoringCache.end() &&
+ (group->GetServerId().empty() || group->GetServerId() == cacheIt->second.m_serverId) &&
+ cacheIt->second.m_accessRules != group->GetCategoryData().m_accessRules)
+ {
+ group->SetServerId(cacheIt->second.m_serverId);
+ group->SetAccessRules(cacheIt->second.m_accessRules);
+ group->EnableAutoSave(autoSave);
+ }
+
for (auto & bmData : fileData.m_bookmarksData)
{
auto * bm = CreateBookmark(std::move(bmData));
@@ -1552,6 +1563,7 @@ void BookmarkManager::CreateCategories(KMLDataCollection && dataCollection, bool
UserMarkIdStorage::Instance().EnableSaving(true);
}
+ m_restoringCache.clear();
NotifyChanges();
@@ -2010,7 +2022,23 @@ void BookmarkManager::OnRestoreRequested(Cloud::RestoringRequestResult result,
void BookmarkManager::OnRestoredFilesPrepared()
{
- // This method is always called from UI-thread.
+ CHECK_THREAD_CHECKER(m_threadChecker, ());
+
+ // Here we save some sensitive info, which must not be lost after restoring.
+ for (auto groupId : m_bmGroupsIdList)
+ {
+ auto * group = GetBmCategory(groupId);
+ auto const & data = group->GetCategoryData();
+ if (m_user.GetUserId() == data.m_authorId && !group->GetServerId().empty() &&
+ data.m_accessRules != kml::AccessRules::Local)
+ {
+ RestoringCache cache;
+ cache.m_serverId = group->GetServerId();
+ cache.m_accessRules = data.m_accessRules;
+ m_restoringCache.insert({group->GetFileName(), std::move(cache)});
+ }
+ }
+
ClearCategories();
CheckAndResetLastIds();
diff --git a/map/bookmark_manager.hpp b/map/bookmark_manager.hpp
index 4bddc2652e..e6351b2ccf 100644
--- a/map/bookmark_manager.hpp
+++ b/map/bookmark_manager.hpp
@@ -541,6 +541,13 @@ private:
OnCatalogImportStartedHandler m_onCatalogImportStarted;
OnCatalogImportFinishedHandler m_onCatalogImportFinished;
+ struct RestoringCache
+ {
+ std::string m_serverId;
+ kml::AccessRules m_accessRules;
+ };
+ std::map<std::string, RestoringCache> m_restoringCache;
+
bool m_testModeEnabled = false;
DISALLOW_COPY_AND_MOVE(BookmarkManager);