From 96781c0a8df89caaeffdb4267de38613a935fe25 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 8 Jan 2016 14:22:14 -0800 Subject: [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. --- platform/default/online_file_source.cpp | 53 +++++++++++++++------------------ 1 file changed, 24 insertions(+), 29 deletions(-) (limited to 'platform/default/online_file_source.cpp') 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&); - // Stores a set of all observing Request objects. std::unordered_map 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_) { - cacheRequest = nullptr; - - if (response_) { - response_->stale = response_->isExpired(); - setResponse(response_); + cacheRequest = impl.cache->get(resource, [this, &impl](std::shared_ptr 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& 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 -- cgit v1.2.1