summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-01-11 17:20:07 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-01-14 13:46:03 -0800
commit7fb5e973edbf546046defb67dd28f1275326319b (patch)
tree39240ab154af6919e15e6b1ebf52ed44f6cd6b99
parentf9574e350c9634b5a4f9849fdfe66fbd84747b12 (diff)
downloadqtlocation-mapboxgl-7fb5e973edbf546046defb67dd28f1275326319b.tar.gz
[core] Eliminate FileCache interface
There is only one implementation and we're unlikely to add more.
-rw-r--r--include/mbgl/storage/file_cache.hpp28
-rw-r--r--include/mbgl/storage/online_file_source.hpp5
-rw-r--r--platform/default/online_file_source.cpp13
-rw-r--r--src/mbgl/storage/request_base.hpp1
-rw-r--r--src/mbgl/storage/sqlite_cache.hpp21
-rw-r--r--test/storage/cache_response.cpp6
6 files changed, 28 insertions, 46 deletions
diff --git a/include/mbgl/storage/file_cache.hpp b/include/mbgl/storage/file_cache.hpp
deleted file mode 100644
index 65d6dfbff0..0000000000
--- a/include/mbgl/storage/file_cache.hpp
+++ /dev/null
@@ -1,28 +0,0 @@
-#ifndef MBGL_STORAGE_FILE_CACHE
-#define MBGL_STORAGE_FILE_CACHE
-
-#include <mbgl/util/noncopyable.hpp>
-
-#include <functional>
-#include <memory>
-
-namespace mbgl {
-
-struct Resource;
-class Response;
-class WorkRequest;
-
-class FileCache : private util::noncopyable {
-public:
- virtual ~FileCache() = default;
-
- enum class Hint : bool { Full, Refresh };
- using Callback = std::function<void(std::unique_ptr<Response>)>;
-
- virtual std::unique_ptr<WorkRequest> get(const Resource &resource, Callback callback) = 0;
- virtual void put(const Resource &resource, std::shared_ptr<const Response> response, Hint hint) = 0;
-};
-
-} // namespace mbgl
-
-#endif
diff --git a/include/mbgl/storage/online_file_source.hpp b/include/mbgl/storage/online_file_source.hpp
index e5253bc3fe..bdf14c7b34 100644
--- a/include/mbgl/storage/online_file_source.hpp
+++ b/include/mbgl/storage/online_file_source.hpp
@@ -2,17 +2,18 @@
#define MBGL_STORAGE_ONLINE_FILE_SOURCE
#include <mbgl/storage/file_source.hpp>
-#include <mbgl/storage/file_cache.hpp>
namespace mbgl {
+class SQLiteCache;
+
namespace util {
template <typename T> class Thread;
} // namespace util
class OnlineFileSource : public FileSource {
public:
- OnlineFileSource(FileCache*);
+ OnlineFileSource(SQLiteCache*);
~OnlineFileSource() override;
void setAccessToken(const std::string& t) { accessToken = t; }
diff --git a/platform/default/online_file_source.cpp b/platform/default/online_file_source.cpp
index 330ecba091..30f3701d2d 100644
--- a/platform/default/online_file_source.cpp
+++ b/platform/default/online_file_source.cpp
@@ -1,6 +1,7 @@
#include <mbgl/storage/online_file_source.hpp>
#include <mbgl/storage/http_context_base.hpp>
#include <mbgl/storage/network_status.hpp>
+#include <mbgl/storage/sqlite_cache.hpp>
#include <mbgl/storage/response.hpp>
#include <mbgl/platform/log.hpp>
@@ -68,7 +69,7 @@ class OnlineFileSource::Impl {
public:
using Callback = std::function<void (Response)>;
- Impl(FileCache*);
+ Impl(SQLiteCache*);
~Impl();
void networkIsReachableAgain();
@@ -80,12 +81,12 @@ private:
friend OnlineFileRequestImpl;
std::unordered_map<FileRequest*, std::unique_ptr<OnlineFileRequestImpl>> pending;
- FileCache* const cache;
+ SQLiteCache* const cache;
const std::unique_ptr<HTTPContextBase> httpContext;
util::AsyncTask reachability;
};
-OnlineFileSource::OnlineFileSource(FileCache* cache)
+OnlineFileSource::OnlineFileSource(SQLiteCache* cache)
: thread(std::make_unique<util::Thread<Impl>>(
util::ThreadContext{ "OnlineFileSource", util::ThreadType::Unknown, util::ThreadPriority::Low },
cache)) {
@@ -134,7 +135,7 @@ void OnlineFileSource::cancel(FileRequest* req) {
// ----- Impl -----
-OnlineFileSource::Impl::Impl(FileCache* cache_)
+OnlineFileSource::Impl::Impl(SQLiteCache* cache_)
: cache(cache_),
httpContext(HTTPContextBase::createContext()),
reachability(std::bind(&Impl::networkIsReachableAgain, this)) {
@@ -251,9 +252,9 @@ void OnlineFileRequestImpl::scheduleRealRequest(OnlineFileSource::Impl& impl, bo
(!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.
- FileCache::Hint hint = FileCache::Hint::Full;
+ SQLiteCache::Hint hint = SQLiteCache::Hint::Full;
if (response && response_->data == response->data) {
- hint = FileCache::Hint::Refresh;
+ hint = SQLiteCache::Hint::Refresh;
}
impl.cache->put(resource, response_, hint);
}
diff --git a/src/mbgl/storage/request_base.hpp b/src/mbgl/storage/request_base.hpp
index a0476d49bf..e3d33571d4 100644
--- a/src/mbgl/storage/request_base.hpp
+++ b/src/mbgl/storage/request_base.hpp
@@ -2,7 +2,6 @@
#define MBGL_STORAGE_REQUEST_BASE
#include <mbgl/util/noncopyable.hpp>
-#include <mbgl/storage/file_cache.hpp>
#include <memory>
#include <functional>
diff --git a/src/mbgl/storage/sqlite_cache.hpp b/src/mbgl/storage/sqlite_cache.hpp
index 6e79d44a33..ed94dfbc8c 100644
--- a/src/mbgl/storage/sqlite_cache.hpp
+++ b/src/mbgl/storage/sqlite_cache.hpp
@@ -1,27 +1,36 @@
#ifndef MBGL_STORAGE_DEFAULT_SQLITE_CACHE
#define MBGL_STORAGE_DEFAULT_SQLITE_CACHE
-#include <mbgl/storage/file_cache.hpp>
+#include <mbgl/util/noncopyable.hpp>
+#include <mbgl/util/chrono.hpp>
+#include <functional>
+#include <memory>
#include <string>
namespace mbgl {
+struct Resource;
+class Response;
+class WorkRequest;
+
namespace util {
template <typename T> class Thread;
} // namespace util
-class SQLiteCache : public FileCache {
+class SQLiteCache : private util::noncopyable {
public:
SQLiteCache(const std::string &path = ":memory:");
- ~SQLiteCache() override;
+ ~SQLiteCache();
void setMaximumCacheSize(uint64_t size);
void setMaximumCacheEntrySize(uint64_t size);
- // FileCache API
- std::unique_ptr<WorkRequest> get(const Resource &resource, Callback callback) override;
- void put(const Resource &resource, std::shared_ptr<const Response> response, Hint hint) override;
+ enum class Hint : bool { Full, Refresh };
+ using Callback = std::function<void(std::unique_ptr<Response>)>;
+
+ std::unique_ptr<WorkRequest> get(const Resource&, Callback);
+ void put(const Resource&, std::shared_ptr<const Response> response, Hint hint);
class Impl;
diff --git a/test/storage/cache_response.cpp b/test/storage/cache_response.cpp
index b27f1caa9c..4f68edf0c4 100644
--- a/test/storage/cache_response.cpp
+++ b/test/storage/cache_response.cpp
@@ -66,7 +66,7 @@ TEST_F(Storage, CacheNotFound) {
// Insert existing data into the cache that will be marked as stale.
auto response = std::make_shared<Response>();
response->data = std::make_shared<const std::string>("existing data");
- cache.put(resource, response, FileCache::Hint::Full);
+ cache.put(resource, response, SQLiteCache::Hint::Full);
std::unique_ptr<FileRequest> req1;
std::unique_ptr<WorkRequest> req2;
@@ -124,7 +124,7 @@ TEST_F(Storage, DontCacheConnectionErrors) {
// Insert existing data into the cache that will be marked as stale.
auto response = std::make_shared<Response>();
response->data = std::make_shared<const std::string>("existing data");
- cache.put(resource, response, FileCache::Hint::Full);
+ cache.put(resource, response, SQLiteCache::Hint::Full);
std::unique_ptr<FileRequest> req1;
std::unique_ptr<WorkRequest> req2;
@@ -180,7 +180,7 @@ TEST_F(Storage, DontCacheServerErrors) {
// Insert existing data into the cache that will be marked as stale.
auto response = std::make_shared<Response>();
response->data = std::make_shared<const std::string>("existing data");
- cache.put(resource, response, FileCache::Hint::Full);
+ cache.put(resource, response, SQLiteCache::Hint::Full);
std::unique_ptr<FileRequest> req1;
std::unique_ptr<WorkRequest> req2;