summaryrefslogtreecommitdiff
path: root/platform/default
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-01-08 13:53:44 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-01-13 13:38:12 -0800
commitea45075e4d8c3e5194d41d915b3660c85cc4ed2a (patch)
tree15340a8fbff7ff029a9c7bbb7cd1dfaf4ded762e /platform/default
parent6f9de6ae47f00ce33f07a05747f8fd3a8277bd2b (diff)
downloadqtlocation-mapboxgl-ea45075e4d8c3e5194d41d915b3660c85cc4ed2a.tar.gz
[core] Inline OnlineFileRequestImpl::checkResponseFreshness
Diffstat (limited to 'platform/default')
-rw-r--r--platform/default/online_file_source.cpp30
1 files changed, 11 insertions, 19 deletions
diff --git a/platform/default/online_file_source.cpp b/platform/default/online_file_source.cpp
index 668c466732..f9c1fdb912 100644
--- a/platform/default/online_file_source.cpp
+++ b/platform/default/online_file_source.cpp
@@ -75,10 +75,6 @@ private:
// a timeout at all.
Seconds getRetryTimeout() const;
- // Checks the currently stored response and replaces it with an idential one, except with the
- // stale flag set, if the response is expired.
- void checkResponseFreshness();
-
// Stores a set of all observing Request objects.
std::unordered_map<FileRequest*, Callback> observers;
@@ -229,9 +225,17 @@ OnlineFileRequestImpl::~OnlineFileRequestImpl() {
void OnlineFileRequestImpl::addObserver(FileRequest* req, Callback callback, OnlineFileSource::Impl& impl) {
if (response) {
// We've at least obtained a cache value, potentially we also got a final response.
- // Before returning the existing response, make sure that it is still fresh, or update the
- // `stale` flag.
- checkResponseFreshness();
+ // Before returning the existing response, update the `stale` flag if necessary.
+ if (!response->stale && response->isExpired()) {
+ // Create a new Response object with `stale = true`, but the same data, and
+ // replace the current request object we have.
+ // We're not immediately swapping the member variable because it's declared as `const`, and
+ // we first have to update the `stale` flag.
+ auto staleResponse = std::make_shared<Response>(*response);
+ staleResponse->stale = true;
+ response = staleResponse;
+ }
+
callback(*response);
if (response->stale && !realRequest) {
@@ -406,16 +410,4 @@ Seconds OnlineFileRequestImpl::getRetryTimeout() const {
return timeout;
}
-void OnlineFileRequestImpl::checkResponseFreshness() {
- if (response && !response->stale && response->isExpired()) {
- // Create a new Response object with `stale = true`, but the same data, and
- // replace the current request object we have.
- // We're not immediately swapping the member variable because it's declared as `const`, and
- // we first have to update the `stale` flag.
- auto staleResponse = std::make_shared<Response>(*response);
- staleResponse->stale = true;
- response = staleResponse;
- }
-}
-
} // namespace mbgl