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
diff options
context:
space:
mode:
authorr.kuznetsov <r.kuznetsov@corp.mail.ru>2018-05-07 18:31:35 +0300
committerDaria Volvenkova <d.volvenkova@corp.mail.ru>2018-05-08 13:09:47 +0300
commit1f8e343a84d112ea619e310cc6e32e0e35cda628 (patch)
treed842701c19955e2e4bbbf49225b10f27f95e1d4a
parentd0a762cbaa11f1a312f421d60979877e69f40687 (diff)
Fixed false asserts in cloud
-rw-r--r--map/cloud.cpp79
1 files changed, 56 insertions, 23 deletions
diff --git a/map/cloud.cpp b/map/cloud.cpp
index 9aef1158ba..6b249049e3 100644
--- a/map/cloud.cpp
+++ b/map/cloud.cpp
@@ -698,16 +698,17 @@ void Cloud::ScheduleUploadingTask(EntryPtr const & entry, uint32_t timeout,
{
std::string entryName;
std::string entryHash;
+ bool isInvalidToken;
{
std::lock_guard<std::mutex> lock(m_mutex);
- #ifdef DEBUG
- ASSERT(m_state == State::Enabled, ());
- ASSERT(!m_accessToken.empty(), ());
- ASSERT(m_uploadingStarted, ());
+ // Uploading has finished.
+ if (!m_uploadingStarted)
+ return;
+
ASSERT(entry->m_isOutdated, ());
- #endif
entryName = entry->m_name;
entryHash = entry->m_hash;
+ isInvalidToken = m_accessToken.empty();
}
if (kServerUrl.empty())
@@ -716,6 +717,13 @@ void Cloud::ScheduleUploadingTask(EntryPtr const & entry, uint32_t timeout,
return;
}
+ // Access token may become invalid between tasks.
+ if (isInvalidToken)
+ {
+ FinishUploading(SynchronizationResult::AuthError, "Access token is empty");
+ return;
+ }
+
// Prepare file to uploading.
auto const uploadedName = PrepareFileToUploading(entryName);
auto deleteAfterUploading = [uploadedName]() {
@@ -818,15 +826,17 @@ void Cloud::CreateSnapshotTask(uint32_t timeout, uint32_t attemptIndex,
[this, timeout, attemptIndex, files = std::move(files),
handler = std::move(handler)]() mutable
{
- #ifdef DEBUG
+ ASSERT(!files.empty(), ());
+
+ bool isInvalidToken;
{
+ // Uploading has finished.
std::lock_guard<std::mutex> lock(m_mutex);
- ASSERT(m_state == State::Enabled, ());
- ASSERT(!m_accessToken.empty(), ());
- ASSERT(m_uploadingStarted, ());
- ASSERT(!files.empty(), ());
+ if (!m_uploadingStarted)
+ return;
+
+ isInvalidToken = m_accessToken.empty();
}
- #endif
if (kServerUrl.empty())
{
@@ -834,6 +844,13 @@ void Cloud::CreateSnapshotTask(uint32_t timeout, uint32_t attemptIndex,
return;
}
+ // Access token may become invalid between tasks.
+ if (isInvalidToken)
+ {
+ FinishUploading(SynchronizationResult::AuthError, "Access token is empty");
+ return;
+ }
+
auto const result = CreateSnapshot(files);
if (result.m_status == RequestStatus::NetworkError)
{
@@ -865,14 +882,15 @@ void Cloud::FinishSnapshotTask(uint32_t timeout, uint32_t attemptIndex)
GetPlatform().RunDelayedTask(Platform::Thread::Network, seconds(timeout),
[this, timeout, attemptIndex]()
{
- #ifdef DEBUG
+ bool isInvalidToken;
{
+ // Uploading has finished.
std::lock_guard<std::mutex> lock(m_mutex);
- ASSERT(m_state == State::Enabled, ());
- ASSERT(!m_accessToken.empty(), ());
- ASSERT(m_uploadingStarted, ());
+ if (!m_uploadingStarted)
+ return;
+
+ isInvalidToken = m_accessToken.empty();
}
- #endif
if (kServerUrl.empty())
{
@@ -880,6 +898,13 @@ void Cloud::FinishSnapshotTask(uint32_t timeout, uint32_t attemptIndex)
return;
}
+ // Access token may become invalid between tasks.
+ if (isInvalidToken)
+ {
+ FinishUploading(SynchronizationResult::AuthError, "Access token is empty");
+ return;
+ }
+
auto const result = FinishSnapshot();
if (result.m_status == RequestStatus::Ok)
{
@@ -1201,14 +1226,15 @@ void Cloud::GetBestSnapshotTask(uint32_t timeout, uint32_t attemptIndex)
GetPlatform().RunDelayedTask(Platform::Thread::Network, seconds(timeout),
[this, timeout, attemptIndex]()
{
- #ifdef DEBUG
+ bool isInvalidToken;
{
+ // Restoring state may be changed between tasks.
std::lock_guard<std::mutex> lock(m_mutex);
- ASSERT(m_state == State::Enabled, ());
- ASSERT(!m_accessToken.empty(), ());
- ASSERT_EQUAL(m_restoringState, RestoringState::Requested, ());
+ if (m_restoringState != RestoringState::Requested)
+ return;
+
+ isInvalidToken = m_accessToken.empty();
}
- #endif
if (kServerUrl.empty())
{
@@ -1216,6 +1242,13 @@ void Cloud::GetBestSnapshotTask(uint32_t timeout, uint32_t attemptIndex)
return;
}
+ // Access token may become invalid between tasks.
+ if (isInvalidToken)
+ {
+ FinishRestoring(SynchronizationResult::AuthError, "Access token is empty");
+ return;
+ }
+
auto const result = GetBestSnapshot();
if (result.m_isMalformed)
{
@@ -1270,11 +1303,11 @@ void Cloud::ProcessSuccessfulSnapshot(SnapshotResult const & result)
}
// Save snapshot data.
- bool isInterrupted = false;
+ bool isInterrupted;
{
std::lock_guard<std::mutex> lock(m_mutex);
m_bestSnapshotData = result.m_response;
- isInterrupted = m_restoringState != RestoringState::Requested;
+ isInterrupted = (m_restoringState != RestoringState::Requested);
}
if (!isInterrupted)
{