summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-01-07 21:35:14 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-01-08 12:29:11 -0800
commit0a8fef1f516a2d230c34980b31d8e46d891941e1 (patch)
treece41204760dd545b1ca6963b7c32a4354b4d71bd
parentadf3dea4e58f0fcd59899937ed050e7174aebd42 (diff)
downloadqtlocation-mapboxgl-0a8fef1f516a2d230c34980b31d8e46d891941e1.tar.gz
[core] Merge OnlineFileRequestImpl::notify into OnlineFileRequestImpl::setResponse
In every case where setResponse is called, notify was called soon after. In one case immediately, in another, after intervening functions which are safe to reorder after notifications. The null-check of response is safe to eliminate because response must not be null inside setResponse.
-rw-r--r--platform/default/online_file_source.cpp25
1 files changed, 8 insertions, 17 deletions
diff --git a/platform/default/online_file_source.cpp b/platform/default/online_file_source.cpp
index 4d9a13bd83..970929c1ed 100644
--- a/platform/default/online_file_source.cpp
+++ b/platform/default/online_file_source.cpp
@@ -62,8 +62,10 @@ public:
void removeObserver(FileRequest*);
bool hasObservers() const;
- // Updates/gets the response of this request object.
+ // Set the response of this request object and notify all observers.
void setResponse(const std::shared_ptr<const Response>&);
+
+ // Get the response of this request object.
const std::shared_ptr<const Response>& getResponse() const;
// Returns the seconds we have to wait until we need to redo this request. A value of 0
@@ -75,10 +77,6 @@ public:
// stale flag set, if the response is expired.
void checkResponseFreshness();
- // Notifies all observers.
- void notify();
-
-
private:
// Stores a set of all observing Request objects.
std::unordered_map<FileRequest*, Callback> observers;
@@ -258,9 +256,6 @@ void OnlineFileSource::Impl::startCacheRequest(OnlineFileRequestImpl& request) {
startRealRequest(request);
}
- // Notify in all cases; requestors can decide whether they want to use stale responses.
- request.notify();
-
reschedule(request);
});
}
@@ -290,7 +285,6 @@ void OnlineFileSource::Impl::startRealRequest(OnlineFileRequestImpl& request) {
}
request.setResponse(response);
- request.notify();
reschedule(request);
};
@@ -364,14 +358,6 @@ bool OnlineFileRequestImpl::hasObservers() const {
return !observers.empty();
}
-void OnlineFileRequestImpl::notify() {
- if (response) {
- for (auto& req : observers) {
- req.second(*response);
- }
- }
-}
-
void OnlineFileRequestImpl::setResponse(const std::shared_ptr<const Response>& response_) {
response = response_;
@@ -381,6 +367,11 @@ void OnlineFileRequestImpl::setResponse(const std::shared_ptr<const Response>& r
// 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);
+ }
}
const std::shared_ptr<const Response>& OnlineFileRequestImpl::getResponse() const {