forked from organicmaps/organicmaps
[guides on map] network requests cancelling is added
This commit is contained in:
parent
77ba73da2f
commit
8fe3dfd119
4 changed files with 22 additions and 7 deletions
|
@ -159,7 +159,7 @@ void GuidesManager::RequestGuides()
|
|||
mercator::ClampPoint(p);
|
||||
|
||||
auto const requestNumber = ++m_requestCounter;
|
||||
m_api.GetGuidesOnMap(
|
||||
auto const id = m_api.GetGuidesOnMap(
|
||||
corners, m_zoom,
|
||||
[this](guides_on_map::GuidesOnMap const & guides) {
|
||||
if (m_state == GuidesState::Disabled)
|
||||
|
@ -203,6 +203,14 @@ void GuidesManager::RequestGuides()
|
|||
if (requestNumber == m_requestCounter)
|
||||
RequestGuides();
|
||||
});
|
||||
|
||||
if (id != base::TaskLoop::kIncorrectId)
|
||||
{
|
||||
if (m_previousRequestsId != base::TaskLoop::kIncorrectId)
|
||||
GetPlatform().CancelTask(Platform::Thread::Network, m_previousRequestsId);
|
||||
|
||||
m_previousRequestsId = id;
|
||||
}
|
||||
}
|
||||
|
||||
void GuidesManager::Clear()
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
#include "geometry/rect2d.hpp"
|
||||
#include "geometry/screenbase.hpp"
|
||||
|
||||
#include "base/task_loop.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
@ -136,6 +138,7 @@ private:
|
|||
|
||||
uint64_t m_requestCounter = 0;
|
||||
uint8_t m_errorRequestsCount = 0;
|
||||
base::TaskLoop::TaskId m_previousRequestsId = base::TaskLoop::kIncorrectId;
|
||||
|
||||
guides_on_map::Api m_api;
|
||||
guides_on_map::GuidesOnMap m_guides;
|
||||
|
|
|
@ -123,18 +123,19 @@ void Api::SetDelegate(std::unique_ptr<Delegate> delegate)
|
|||
m_delegate = std::move(delegate);
|
||||
}
|
||||
|
||||
void Api::GetGuidesOnMap(m2::AnyRectD::Corners const & corners, uint8_t zoomLevel,
|
||||
GuidesOnMapCallback const & onSuccess, OnError const & onError) const
|
||||
base::TaskLoop::TaskId Api::GetGuidesOnMap(m2::AnyRectD::Corners const & corners, uint8_t zoomLevel,
|
||||
GuidesOnMapCallback const & onSuccess,
|
||||
OnError const & onError) const
|
||||
{
|
||||
auto const url = MakeGalleryUrl(m_baseUrl, corners, zoomLevel, languages::GetCurrentNorm());
|
||||
if (url.empty())
|
||||
{
|
||||
onSuccess({});
|
||||
return;
|
||||
return base::TaskLoop::kIncorrectId;
|
||||
}
|
||||
|
||||
auto const headers = m_delegate->GetHeaders();
|
||||
GetPlatform().RunTask(Platform::Thread::Network, [url, headers, onSuccess, onError]()
|
||||
return GetPlatform().RunTask(Platform::Thread::Network, [url, headers, onSuccess, onError]()
|
||||
{
|
||||
std::string httpResult;
|
||||
if (!GetGalleryRaw(url, headers, httpResult))
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
#include "geometry/any_rect2d.hpp"
|
||||
#include "geometry/point2d.hpp"
|
||||
|
||||
#include "base/task_loop.hpp"
|
||||
|
||||
#include "private.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
@ -59,8 +61,9 @@ public:
|
|||
|
||||
void SetDelegate(std::unique_ptr<Delegate> delegate);
|
||||
|
||||
void GetGuidesOnMap(m2::AnyRectD::Corners const & corners, uint8_t zoomLevel,
|
||||
GuidesOnMapCallback const & onSuccess, OnError const & onError) const;
|
||||
base::TaskLoop::TaskId GetGuidesOnMap(m2::AnyRectD::Corners const & corners, uint8_t zoomLevel,
|
||||
GuidesOnMapCallback const & onSuccess,
|
||||
OnError const & onError) const;
|
||||
|
||||
private:
|
||||
std::unique_ptr<Delegate> m_delegate;
|
||||
|
|
Loading…
Add table
Reference in a new issue