1 #pragma once
2 
3 #include <mbgl/storage/response.hpp>
4 #include <mbgl/storage/resource.hpp>
5 
6 #include <mbgl/util/noncopyable.hpp>
7 #include <mbgl/util/async_request.hpp>
8 
9 #include <functional>
10 #include <memory>
11 
12 namespace mbgl {
13 
14 class FileSource : private util::noncopyable {
15 public:
16     virtual ~FileSource() = default;
17 
18     using Callback = std::function<void (Response)>;
19 
20     // Request a resource. The callback will be called asynchronously, in the same
21     // thread as the request was made. This thread must have an active RunLoop. The
22     // request may be cancelled before completion by releasing the returned AsyncRequest.
23     // If the request is cancelled before the callback is executed, the callback will
24     // not be executed.
25     virtual std::unique_ptr<AsyncRequest> request(const Resource&, Callback) = 0;
26 
27     // When a file source supports consulting a local cache only, it must return true.
28     // Cache-only requests are requests that aren't as urgent, but could be useful, e.g.
29     // to cover part of the map while loading. The FileSource should only do cheap actions to
30     // retrieve the data, e.g. load it from a cache, but not from the internet.
supportsCacheOnlyRequests() const31     virtual bool supportsCacheOnlyRequests() const {
32         return false;
33     }
34 };
35 
36 } // namespace mbgl
37