diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2016-01-11 12:52:41 -0800 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2016-01-13 13:40:31 -0800 |
commit | 86c8446d3a4390ff6577d070ac8b5fa3ad3c5cd1 (patch) | |
tree | ef10190d3fca34ff72b2473816901088b0b85ac2 /platform/default/online_file_source.cpp | |
parent | 2126e34e52dc5dd94c5a3907b240e62ee17d1e70 (diff) | |
download | qtlocation-mapboxgl-86c8446d3a4390ff6577d070ac8b5fa3ad3c5cd1.tar.gz |
[core] Simplify asset:// implementation
* Move asset:// URL handling to DefaultFileSource.
* AssetFileSource implements FileSource interface and follows familiar implementation patterns.
* Move default implementation to platform/default, zip implementation to platform/android.
* Don't bother with modified / expires / etag -- assets are not cached so it doesn't matter.
* Don't bother with interleaving individual IO calls on the implementation thread. That adds a lot of complexity for very little benefit.
Diffstat (limited to 'platform/default/online_file_source.cpp')
-rw-r--r-- | platform/default/online_file_source.cpp | 26 |
1 files changed, 7 insertions, 19 deletions
diff --git a/platform/default/online_file_source.cpp b/platform/default/online_file_source.cpp index 480d2a8276..84be64a22f 100644 --- a/platform/default/online_file_source.cpp +++ b/platform/default/online_file_source.cpp @@ -1,10 +1,8 @@ #include <mbgl/storage/online_file_source.hpp> -#include <mbgl/storage/asset_context_base.hpp> #include <mbgl/storage/http_context_base.hpp> #include <mbgl/storage/network_status.hpp> #include <mbgl/storage/response.hpp> -#include <mbgl/platform/platform.hpp> #include <mbgl/platform/log.hpp> #include <mbgl/util/thread.hpp> @@ -14,7 +12,6 @@ #include <mbgl/util/async_task.hpp> #include <mbgl/util/noncopyable.hpp> #include <mbgl/util/timer.hpp> -#include <mbgl/util/url.hpp> #include <algorithm> #include <cassert> @@ -83,7 +80,7 @@ class OnlineFileSource::Impl { public: using Callback = std::function<void (Response)>; - Impl(FileCache*, const std::string& = ""); + Impl(FileCache*); ~Impl(); void networkIsReachableAgain(); @@ -96,17 +93,14 @@ private: std::unordered_map<Resource, std::unique_ptr<OnlineFileRequestImpl>, Resource::Hash> pending; FileCache* const cache; - const std::string assetRoot; - const std::unique_ptr<AssetContextBase> assetContext; const std::unique_ptr<HTTPContextBase> httpContext; util::AsyncTask reachability; }; -OnlineFileSource::OnlineFileSource(FileCache* cache, const std::string& root) +OnlineFileSource::OnlineFileSource(FileCache* cache) : thread(std::make_unique<util::Thread<Impl>>( util::ThreadContext{ "OnlineFileSource", util::ThreadType::Unknown, util::ThreadPriority::Low }, - cache, - root)) { + cache)) { } OnlineFileSource::~OnlineFileSource() = default; @@ -152,10 +146,8 @@ void OnlineFileSource::cancel(const Resource& res, FileRequest* req) { // ----- Impl ----- -OnlineFileSource::Impl::Impl(FileCache* cache_, const std::string& root) +OnlineFileSource::Impl::Impl(FileCache* cache_) : cache(cache_), - assetRoot(root.empty() ? platform::assetRoot() : root), - assetContext(AssetContextBase::createContext()), httpContext(HTTPContextBase::createContext()), reachability(std::bind(&Impl::networkIsReachableAgain, this)) { // Subscribe to network status changes, but make sure that this async handle doesn't keep the @@ -242,7 +234,7 @@ void OnlineFileRequestImpl::addObserver(FileRequest* req, Callback callback, Onl } else if (!cacheRequest && !realRequest) { // There is no request in progress, and we don't have a response yet. This means we'll have // to start the request ourselves. - if (impl.cache && !util::isAssetURL(resource.url)) { + if (impl.cache) { scheduleCacheRequest(impl); } else { scheduleRealRequest(impl); @@ -330,7 +322,7 @@ void OnlineFileRequestImpl::scheduleRealRequest(OnlineFileSource::Impl& impl, bo // In particular, we don't want to write a Canceled request, or one that failed due to // connection errors to the cache. Server errors are hopefully also temporary, so we're not // caching them either. - if (impl.cache && !util::isAssetURL(resource.url) && + if (impl.cache && (!response_->error || (response_->error->reason == Response::Error::Reason::NotFound))) { // Store response in database. Make sure we only refresh the expires column if the data // didn't change. @@ -357,11 +349,7 @@ void OnlineFileRequestImpl::scheduleRealRequest(OnlineFileSource::Impl& impl, bo scheduleRealRequest(impl); }; - if (util::isAssetURL(resource.url)) { - realRequest = impl.assetContext->createRequest(resource.url, callback, impl.assetRoot); - } else { - realRequest = impl.httpContext->createRequest(resource.url, callback, response); - } + realRequest = impl.httpContext->createRequest(resource.url, callback, response); }); } |