summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-01-13 16:31:54 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-01-14 13:46:03 -0800
commit2ee1fe41786742332d190b01e28ba88a72c59f43 (patch)
tree031003b2a5a1ca2b06f6e819696e9931e9732321
parent7fb5e973edbf546046defb67dd28f1275326319b (diff)
downloadqtlocation-mapboxgl-2ee1fe41786742332d190b01e28ba88a72c59f43.tar.gz
[core] std::shared_ptr<const Response> ⇢ const Response&
-rw-r--r--platform/default/online_file_source.cpp2
-rw-r--r--platform/default/sqlite_cache.cpp30
-rw-r--r--platform/default/sqlite_cache_impl.hpp4
-rw-r--r--src/mbgl/storage/sqlite_cache.hpp2
-rw-r--r--test/storage/cache_response.cpp12
-rw-r--r--test/storage/cache_size.cpp16
-rw-r--r--test/storage/database.cpp31
7 files changed, 46 insertions, 51 deletions
diff --git a/platform/default/online_file_source.cpp b/platform/default/online_file_source.cpp
index 30f3701d2d..634a6710a7 100644
--- a/platform/default/online_file_source.cpp
+++ b/platform/default/online_file_source.cpp
@@ -256,7 +256,7 @@ void OnlineFileRequestImpl::scheduleRealRequest(OnlineFileSource::Impl& impl, bo
if (response && response_->data == response->data) {
hint = SQLiteCache::Hint::Refresh;
}
- impl.cache->put(resource, response_, hint);
+ impl.cache->put(resource, *response_, hint);
}
response = response_;
diff --git a/platform/default/sqlite_cache.cpp b/platform/default/sqlite_cache.cpp
index e346cb0f87..53f2c10c23 100644
--- a/platform/default/sqlite_cache.cpp
+++ b/platform/default/sqlite_cache.cpp
@@ -367,24 +367,24 @@ void SQLiteCache::Impl::get(const Resource &resource, Callback callback) {
}
}
-void SQLiteCache::put(const Resource &resource, std::shared_ptr<const Response> response, Hint hint) {
+void SQLiteCache::put(const Resource &resource, const Response& response, Hint hint) {
// Can be called from any thread, but most likely from the file source thread. We are either
// storing a new response or updating the currently stored response, potentially setting a new
// expiry date.
if (hint == Hint::Full) {
thread->invoke(&Impl::put, resource, response);
} else if (hint == Hint::Refresh) {
- thread->invoke(&Impl::refresh, resource, response->expires);
+ thread->invoke(&Impl::refresh, resource, response.expires);
}
}
-void SQLiteCache::Impl::put(const Resource& resource, std::shared_ptr<const Response> response) {
+void SQLiteCache::Impl::put(const Resource& resource, const Response& response) {
try {
initializeDatabase();
pruneEntries();
- if (response->data) {
- auto entrySize = response->data->size();
+ if (response.data) {
+ auto entrySize = response.data->size();
if (entrySize > maximumCacheEntrySize) {
Log::Warning(Event::Database, "Entry too big for caching.");
@@ -408,30 +408,30 @@ void SQLiteCache::Impl::put(const Resource& resource, std::shared_ptr<const Resp
const auto canonicalURL = util::mapbox::canonicalURL(resource.url);
putStmt->bind(1 /* url */, canonicalURL.c_str());
- if (response->error) {
- putStmt->bind(2 /* status */, int(response->error->reason));
+ if (response.error) {
+ putStmt->bind(2 /* status */, int(response.error->reason));
} else {
putStmt->bind(2 /* status */, 1 /* success */);
}
putStmt->bind(3 /* kind */, int(resource.kind));
- putStmt->bind(4 /* modified */, int64_t(response->modified.count()));
- putStmt->bind(5 /* etag */, response->etag.c_str());
- putStmt->bind(6 /* expires */, int64_t(response->expires.count()));
+ putStmt->bind(4 /* modified */, int64_t(response.modified.count()));
+ putStmt->bind(5 /* etag */, response.etag.c_str());
+ putStmt->bind(6 /* expires */, int64_t(response.expires.count()));
putStmt->bind(7 /* accessed */, int64_t(toSeconds(SystemClock::now()).count()));
std::string data;
- if (resource.kind != Resource::SpriteImage && response->data) {
+ if (resource.kind != Resource::SpriteImage && response.data) {
// Do not compress images, since they are typically compressed already.
- data = util::compress(*response->data);
+ data = util::compress(*response.data);
}
- if (!data.empty() && data.size() < response->data->size()) {
+ if (!data.empty() && data.size() < response.data->size()) {
// Store the compressed data when it is smaller than the original
// uncompressed data.
putStmt->bind(8 /* data */, data, false); // do not retain the string internally.
putStmt->bind(9 /* compressed */, true);
- } else if (response->data) {
- putStmt->bind(8 /* data */, *response->data, false); // do not retain the string internally.
+ } else if (response.data) {
+ putStmt->bind(8 /* data */, *response.data, false); // do not retain the string internally.
putStmt->bind(9 /* compressed */, false);
} else {
putStmt->bind(8 /* data */, "", false);
diff --git a/platform/default/sqlite_cache_impl.hpp b/platform/default/sqlite_cache_impl.hpp
index 8ad22d79fc..aef91efec9 100644
--- a/platform/default/sqlite_cache_impl.hpp
+++ b/platform/default/sqlite_cache_impl.hpp
@@ -22,8 +22,8 @@ public:
void setMaximumCacheEntrySize(uint64_t size);
void get(const Resource&, Callback);
- void put(const Resource& resource, std::shared_ptr<const Response> response);
- void refresh(const Resource& resource, Seconds expires);
+ void put(const Resource&, const Response&);
+ void refresh(const Resource&, Seconds expires);
private:
void initializeDatabase();
diff --git a/src/mbgl/storage/sqlite_cache.hpp b/src/mbgl/storage/sqlite_cache.hpp
index ed94dfbc8c..76e7aed440 100644
--- a/src/mbgl/storage/sqlite_cache.hpp
+++ b/src/mbgl/storage/sqlite_cache.hpp
@@ -30,7 +30,7 @@ public:
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);
+ void put(const Resource&, const Response&, Hint hint);
class Impl;
diff --git a/test/storage/cache_response.cpp b/test/storage/cache_response.cpp
index 4f68edf0c4..df895ab7b4 100644
--- a/test/storage/cache_response.cpp
+++ b/test/storage/cache_response.cpp
@@ -64,8 +64,8 @@ TEST_F(Storage, CacheNotFound) {
const Resource resource{ Resource::Unknown, "http://127.0.0.1:3000/not-found" };
// 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");
+ Response response;
+ response.data = std::make_shared<const std::string>("existing data");
cache.put(resource, response, SQLiteCache::Hint::Full);
std::unique_ptr<FileRequest> req1;
@@ -122,8 +122,8 @@ TEST_F(Storage, DontCacheConnectionErrors) {
const Resource resource{ Resource::Unknown, "http://127.0.0.1:3001" };
// 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");
+ Response response;
+ response.data = std::make_shared<const std::string>("existing data");
cache.put(resource, response, SQLiteCache::Hint::Full);
std::unique_ptr<FileRequest> req1;
@@ -178,8 +178,8 @@ TEST_F(Storage, DontCacheServerErrors) {
const Resource resource{ Resource::Unknown, "http://127.0.0.1:3000/permanent-error" };
// 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");
+ Response response;
+ response.data = std::make_shared<const std::string>("existing data");
cache.put(resource, response, SQLiteCache::Hint::Full);
std::unique_ptr<FileRequest> req1;
diff --git a/test/storage/cache_size.cpp b/test/storage/cache_size.cpp
index f94c52d234..7cea572139 100644
--- a/test/storage/cache_size.cpp
+++ b/test/storage/cache_size.cpp
@@ -38,10 +38,10 @@ void insertTile(mbgl::SQLiteCache* cache, unsigned id, uint64_t size) {
auto url = std::string("http://tile") + mbgl::util::toString(id);
- auto response = std::make_shared<Response>();
- response->modified = toSeconds(SystemClock::now());
- response->expires = toSeconds(SystemClock::now()) + Seconds(5000);
- response->etag = url;
+ Response response;
+ response.modified = toSeconds(SystemClock::now());
+ response.expires = toSeconds(SystemClock::now()) + Seconds(5000);
+ response.etag = url;
auto data = std::make_shared<std::string>(size, 0);
@@ -50,7 +50,7 @@ void insertTile(mbgl::SQLiteCache* cache, unsigned id, uint64_t size) {
static std::mt19937 generator;
std::generate_n(data->begin(), size, generator);
- response->data = data;
+ response.data = data;
Resource resource{ Resource::Kind::Tile, url };
cache->put(resource, response, SQLiteCache::Hint::Full);
@@ -61,9 +61,9 @@ void refreshTile(mbgl::SQLiteCache* cache, unsigned id) {
auto url = std::string("http://tile") + mbgl::util::toString(id);
- auto response = std::make_shared<Response>();
- response->modified = toSeconds(SystemClock::now());
- response->expires = toSeconds(SystemClock::now()) + Seconds(5000);
+ Response response;
+ response.modified = toSeconds(SystemClock::now());
+ response.expires = toSeconds(SystemClock::now()) + Seconds(5000);
Resource resource{ Resource::Kind::Tile, url };
cache->put(resource, response, SQLiteCache::Hint::Refresh);
diff --git a/test/storage/database.cpp b/test/storage/database.cpp
index 82a0296cc1..700b58ed24 100644
--- a/test/storage/database.cpp
+++ b/test/storage/database.cpp
@@ -75,9 +75,7 @@ TEST_F(Storage, DatabaseVersion) {
{
SQLiteCache::Impl cache(path);
-
- auto response = std::make_shared<Response>();
- cache.put({ Resource::Unknown, "mapbox://test" }, response);
+ cache.put({ Resource::Unknown, "mapbox://test" }, Response());
}
sqlite3* db;
@@ -193,8 +191,7 @@ TEST_F(Storage, DatabaseLockedWrite) {
// Adds a file (which should fail).
Log::setObserver(std::make_unique<FixtureLogObserver>());
- auto response = std::make_shared<Response>();
- cache.put({ Resource::Unknown, "mapbox://test" }, response);
+ cache.put({ Resource::Unknown, "mapbox://test" }, Response());
cache.get({ Resource::Unknown, "mapbox://test" }, [] (std::unique_ptr<Response> res) {
EXPECT_EQ(nullptr, res.get());
});
@@ -211,8 +208,8 @@ TEST_F(Storage, DatabaseLockedWrite) {
// Then, set a file and obtain it again.
Log::setObserver(std::make_unique<FixtureLogObserver>());
- auto response = std::make_shared<Response>();
- response->data = std::make_shared<std::string>("Demo");
+ Response response;
+ response.data = std::make_shared<std::string>("Demo");
cache.put({ Resource::Unknown, "mapbox://test" }, response);
cache.get({ Resource::Unknown, "mapbox://test" }, [] (std::unique_ptr<Response> res) {
ASSERT_NE(nullptr, res.get());
@@ -244,8 +241,8 @@ TEST_F(Storage, DatabaseLockedRefresh) {
// Adds a file.
Log::setObserver(std::make_unique<FixtureLogObserver>());
- auto response = std::make_shared<Response>();
- response->data = std::make_shared<std::string>("Demo");
+ Response response;
+ response.data = std::make_shared<std::string>("Demo");
cache.put({ Resource::Unknown, "mapbox://test" }, response);
cache.get({ Resource::Unknown, "mapbox://test" }, [] (std::unique_ptr<Response> res) {
EXPECT_EQ(nullptr, res.get());
@@ -260,9 +257,7 @@ TEST_F(Storage, DatabaseLockedRefresh) {
// Then, try to refresh it.
Log::setObserver(std::make_unique<FixtureLogObserver>());
- auto response = std::make_shared<Response>();
- response->data = std::make_shared<std::string>("Demo");
- cache.refresh({ Resource::Unknown, "mapbox://test" }, response->expires);
+ cache.refresh({ Resource::Unknown, "mapbox://test" }, Seconds::zero());
cache.get({ Resource::Unknown, "mapbox://test" }, [] (std::unique_ptr<Response> res) {
EXPECT_EQ(nullptr, res.get());
});
@@ -289,8 +284,8 @@ TEST_F(Storage, DatabaseDeleted) {
// Adds a file.
Log::setObserver(std::make_unique<FixtureLogObserver>());
- auto response = std::make_shared<Response>();
- response->data = std::make_shared<std::string>("Demo");
+ Response response;
+ response.data = std::make_shared<std::string>("Demo");
cache.put({ Resource::Unknown, "mapbox://test" }, response);
cache.get({ Resource::Unknown, "mapbox://test" }, [] (std::unique_ptr<Response> res) {
ASSERT_NE(nullptr, res.get());
@@ -307,8 +302,8 @@ TEST_F(Storage, DatabaseDeleted) {
// Adds a file.
Log::setObserver(std::make_unique<FixtureLogObserver>());
- auto response = std::make_shared<Response>();
- response->data = std::make_shared<std::string>("Demo");
+ Response response;
+ response.data = std::make_shared<std::string>("Demo");
cache.put({ Resource::Unknown, "mapbox://test" }, response);
cache.get({ Resource::Unknown, "mapbox://test" }, [] (std::unique_ptr<Response> res) {
ASSERT_NE(nullptr, res.get());
@@ -338,8 +333,8 @@ TEST_F(Storage, DatabaseInvalid) {
// Adds a file.
Log::setObserver(std::make_unique<FixtureLogObserver>());
- auto response = std::make_shared<Response>();
- response->data = std::make_shared<std::string>("Demo");
+ Response response;
+ response.data = std::make_shared<std::string>("Demo");
cache.put({ Resource::Unknown, "mapbox://test" }, response);
cache.get({ Resource::Unknown, "mapbox://test" }, [] (std::unique_ptr<Response> res) {
ASSERT_NE(nullptr, res.get());