diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2016-01-08 14:22:14 -0800 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2016-01-13 13:38:12 -0800 |
commit | 96781c0a8df89caaeffdb4267de38613a935fe25 (patch) | |
tree | 25b57953a18f5d91f1f8c856b1e3c048bfcd3b2b /platform/default/online_file_source.cpp | |
parent | 601e3d9d45c1800f29e363f0e35addfefc97bff7 (diff) | |
download | qtlocation-mapboxgl-96781c0a8df89caaeffdb4267de38613a935fe25.tar.gz |
[core] Inline OnlineFileRequestImpl::setResponse
In the cache response case, we don't want the failedRequests logic; cached errors, should they occur, shouldn't affect the scheduling behavior for real requests.
Diffstat (limited to 'platform/default/online_file_source.cpp')
-rw-r--r-- | platform/default/online_file_source.cpp | 53 |
1 files changed, 24 insertions, 29 deletions
diff --git a/platform/default/online_file_source.cpp b/platform/default/online_file_source.cpp index 8347b7969a..54ed6c51b3 100644 --- a/platform/default/online_file_source.cpp +++ b/platform/default/online_file_source.cpp @@ -66,9 +66,6 @@ private: RequestBase* realRequest = nullptr; util::Timer realRequestTimer; - // Set the response of this request object and notify all observers. - void setResponse(const std::shared_ptr<const Response>&); - // Stores a set of all observing Request objects. std::unordered_map<FileRequest*, Callback> observers; @@ -268,17 +265,19 @@ bool OnlineFileRequestImpl::hasObservers() const { void OnlineFileRequestImpl::scheduleCacheRequest(OnlineFileSource::Impl& impl) { // Check the cache for existing data so that we can potentially // revalidate the information without having to redownload everything. - cacheRequest = - impl.cache->get(resource, [this, &impl](std::shared_ptr<Response> response_) { - cacheRequest = nullptr; - - if (response_) { - response_->stale = response_->isExpired(); - setResponse(response_); + cacheRequest = impl.cache->get(resource, [this, &impl](std::shared_ptr<Response> response_) { + cacheRequest = nullptr; + + if (response_) { + response_->stale = response_->isExpired(); + response = response_; + for (auto& req : observers) { + req.second(*response); } + } - scheduleRealRequest(impl); - }); + scheduleRealRequest(impl); + }); } void OnlineFileRequestImpl::scheduleRealRequest(OnlineFileSource::Impl& impl, bool forceImmediate) { @@ -350,7 +349,19 @@ void OnlineFileRequestImpl::scheduleRealRequest(OnlineFileSource::Impl& impl, bo impl.cache->put(resource, response_, hint); } - setResponse(response_); + response = response_; + + if (response->error) { + failedRequests++; + } else { + // Reset the number of subsequent failed requests after we got a successful one. + failedRequests = 0; + } + + for (auto& req : observers) { + req.second(*response); + } + scheduleRealRequest(impl); }; @@ -370,20 +381,4 @@ void OnlineFileRequestImpl::networkIsReachableAgain(OnlineFileSource::Impl& impl } } -void OnlineFileRequestImpl::setResponse(const std::shared_ptr<const Response>& response_) { - response = response_; - - if (response->error) { - failedRequests++; - } else { - // Reset the number of subsequent failed requests after we got a successful one. - failedRequests = 0; - } - - // Notify in all cases; requestors can decide whether they want to use stale responses. - for (auto& req : observers) { - req.second(*response); - } -} - } // namespace mbgl |