Keep observers encapsulated
This commit is contained in:
@@ -184,22 +184,14 @@ void DefaultFileSource::Impl::abort(const Environment& env) {
|
||||
}
|
||||
|
||||
void DefaultFileSource::Impl::notify(SharedRequestBase *sharedRequest,
|
||||
const std::set<Request *> &observers,
|
||||
std::shared_ptr<const Response> response, FileCache::Hint hint) {
|
||||
// First, remove the request, since it might be destructed at any point now.
|
||||
assert(find(sharedRequest->resource) == sharedRequest);
|
||||
pending.erase(sharedRequest->resource);
|
||||
|
||||
if (response) {
|
||||
if (cache) {
|
||||
// Store response in database
|
||||
cache->put(sharedRequest->resource, response, hint);
|
||||
}
|
||||
|
||||
// Notify all observers.
|
||||
for (auto req : observers) {
|
||||
req->notify(response);
|
||||
}
|
||||
if (response && cache) {
|
||||
// Store response in database
|
||||
cache->put(sharedRequest->resource, response, hint);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ class DefaultFileSource::Impl {
|
||||
public:
|
||||
Impl(FileCache *cache, const std::string &root = "");
|
||||
|
||||
void notify(SharedRequestBase *sharedRequest, const std::set<Request *> &observers,
|
||||
void notify(SharedRequestBase *sharedRequest,
|
||||
std::shared_ptr<const Response> response, FileCache::Hint hint);
|
||||
SharedRequestBase *find(const Resource &resource);
|
||||
|
||||
|
||||
@@ -35,7 +35,14 @@ public:
|
||||
void notify(std::shared_ptr<const Response> response, FileCache::Hint hint) {
|
||||
MBGL_VERIFY_THREAD(tid);
|
||||
|
||||
source.notify(this, observers, response, hint);
|
||||
source.notify(this, response, hint);
|
||||
|
||||
if (response) {
|
||||
// Notify all observers.
|
||||
for (auto req : observers) {
|
||||
req->notify(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void subscribe(Request *request) {
|
||||
@@ -52,7 +59,7 @@ public:
|
||||
if (abandoned()) {
|
||||
// There are no observers anymore. We are initiating cancelation.
|
||||
// First, remove this SharedRequestBase from the source.
|
||||
source.notify(this, observers, nullptr, FileCache::Hint::No);
|
||||
source.notify(this, nullptr, FileCache::Hint::No);
|
||||
|
||||
// Then, initiate cancelation of this request
|
||||
cancel();
|
||||
|
||||
Reference in New Issue
Block a user