From be44c34cf9cb5b69a50d2218f00d97a1efc944a1 Mon Sep 17 00:00:00 2001 From: "r.kuznetsov" Date: Thu, 4 Jul 2019 10:10:03 +0300 Subject: [PATCH] Review fixes --- .../maps/bookmarks/data/BookmarkManager.cpp | 6 +++--- map/bookmark_catalog.cpp | 10 ++++------ map/bookmark_manager.cpp | 11 ++++++----- map/bookmark_manager.hpp | 6 ++++++ 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/android/jni/com/mapswithme/maps/bookmarks/data/BookmarkManager.cpp b/android/jni/com/mapswithme/maps/bookmarks/data/BookmarkManager.cpp index 9f31ed6299..708c4b702b 100644 --- a/android/jni/com/mapswithme/maps/bookmarks/data/BookmarkManager.cpp +++ b/android/jni/com/mapswithme/maps/bookmarks/data/BookmarkManager.cpp @@ -954,7 +954,7 @@ Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativePingBookmarkCatalo JNIEXPORT void JNICALL Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeCheckInvalidCategories(JNIEnv * env, - jobject) + jobject) { frm()->GetBookmarkManager().CheckInvalidCategories(Purchase::GetDeviceId(), [env](bool hasInvalidCategories) @@ -965,14 +965,14 @@ Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeCheckInvalidCatego JNIEXPORT void JNICALL Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeDeleteInvalidCategories(JNIEnv * env, - jobject) + jobject) { frm()->GetBookmarkManager().DeleteInvalidCategories(); } JNIEXPORT void JNICALL Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeResetInvalidCategories(JNIEnv * env, - jobject) + jobject) { frm()->GetBookmarkManager().ResetInvalidCategories(); } diff --git a/map/bookmark_catalog.cpp b/map/bookmark_catalog.cpp index a76c42a83c..5209bc7bf9 100644 --- a/map/bookmark_catalog.cpp +++ b/map/bookmark_catalog.cpp @@ -698,7 +698,7 @@ void BookmarkCatalog::RequestBookmarksToDelete(std::string const & accessToken, if (request.RunHttpRequest()) { auto const resultCode = request.ErrorCode(); - if (callback && resultCode >= 200 && resultCode < 300) + if (resultCode >= 200 && resultCode < 300) { DeleteRequestResponseData responseData; try @@ -708,9 +708,8 @@ void BookmarkCatalog::RequestBookmarksToDelete(std::string const & accessToken, } catch (coding::DeserializerJson::Exception const & ex) { - LOG(LWARNING, ("Bookmarks-to-delete request deserialization error:", ex.Msg())); - if (callback) - callback({}); + LOG(LERROR, ("Bookmarks-to-delete request deserialization error:", ex.Msg())); + callback({}); return; } @@ -718,8 +717,7 @@ void BookmarkCatalog::RequestBookmarksToDelete(std::string const & accessToken, return; } } - if (callback) - callback({}); + callback({}); }); } diff --git a/map/bookmark_manager.cpp b/map/bookmark_manager.cpp index 85812a8bd0..8db8e7e161 100644 --- a/map/bookmark_manager.cpp +++ b/map/bookmark_manager.cpp @@ -2522,10 +2522,8 @@ void BookmarkManager::CheckInvalidCategories(std::string const & deviceId, CheckInvalidCategoriesHandler && handler) { CHECK_THREAD_CHECKER(m_threadChecker, ()); - m_bookmarkCatalog.RequestBookmarksToDelete(m_user.GetAccessToken(), m_user.GetUserId(), deviceId, - GetAllPaidCategoriesIds(), - [this, handler = std::move(handler)]( - std::vector const & serverIds) + + auto f = [this, handler = std::move(handler)](std::vector const & serverIds) { CHECK_THREAD_CHECKER(m_threadChecker, ()); m_invalidCategories.clear(); @@ -2539,7 +2537,10 @@ void BookmarkManager::CheckInvalidCategories(std::string const & deviceId, } if (handler) handler(!m_invalidCategories.empty()); - }); + }; + + m_bookmarkCatalog.RequestBookmarksToDelete(m_user.GetAccessToken(), m_user.GetUserId(), + deviceId, GetAllPaidCategoriesIds(), f); } void BookmarkManager::DeleteInvalidCategories() diff --git a/map/bookmark_manager.hpp b/map/bookmark_manager.hpp index d9418c78d9..11b8460414 100644 --- a/map/bookmark_manager.hpp +++ b/map/bookmark_manager.hpp @@ -330,8 +330,14 @@ public: bool IsMyCategory(kml::MarkGroupId categoryId) const; + // CheckInvalidCategories checks invalid categories asynchronously, it prepares a state for following + // functions calls. using CheckInvalidCategoriesHandler = std::function; void CheckInvalidCategories(std::string const & deviceId, CheckInvalidCategoriesHandler && handler); + + // The following 2 functions allow to delete invalid categories or forget about them. + // These functions are stateful, so they must be called after finishing CheckInvalidCategoriesHandler. + // ResetInvalidCategories resets internal state. void DeleteInvalidCategories(); void ResetInvalidCategories();