summaryrefslogtreecommitdiff
path: root/platform/default/include/mbgl/storage/offline_database.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'platform/default/include/mbgl/storage/offline_database.hpp')
-rw-r--r--platform/default/include/mbgl/storage/offline_database.hpp37
1 files changed, 34 insertions, 3 deletions
diff --git a/platform/default/include/mbgl/storage/offline_database.hpp b/platform/default/include/mbgl/storage/offline_database.hpp
index 62a82f3a25..7eb546b3f6 100644
--- a/platform/default/include/mbgl/storage/offline_database.hpp
+++ b/platform/default/include/mbgl/storage/offline_database.hpp
@@ -3,7 +3,6 @@
#include <mbgl/storage/resource.hpp>
#include <mbgl/storage/offline.hpp>
#include <mbgl/util/exception.hpp>
-#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/optional.hpp>
#include <mbgl/util/constants.hpp>
#include <mbgl/util/mapbox.hpp>
@@ -36,7 +35,7 @@ struct MapboxTileLimitExceededException : util::Exception {
MapboxTileLimitExceededException() : util::Exception("Mapbox tile limit exceeded") {}
};
-class OfflineDatabase : private util::noncopyable {
+class OfflineDatabase {
public:
OfflineDatabase(std::string path);
~OfflineDatabase();
@@ -97,6 +96,8 @@ public:
void reopenDatabaseReadOnly(bool readOnly);
private:
+ class DatabaseSizeChangeStats;
+
void initialize();
void handleError(const mapbox::sqlite::Exception&, const char* action);
void handleError(const util::IOException&, const char* action);
@@ -150,7 +151,37 @@ private:
optional<uint64_t> offlineMapboxTileCount;
- bool evict(uint64_t neededFreeSize);
+ bool evict(uint64_t neededFreeSize, DatabaseSizeChangeStats& stats);
+
+ class DatabaseSizeChangeStats {
+ public:
+ explicit DatabaseSizeChangeStats(OfflineDatabase*);
+
+ // Returns difference between current database size and
+ // database size at the time of creation of this object.
+ int64_t diff() const;
+
+ // Returns how many bytes were released comparing to a database
+ // size at the time of creation of this object.
+ uint64_t bytesReleased() const;
+
+ // Returns page size for the database.
+ uint64_t pageSize() const;
+
+ private:
+ uint64_t pageSize_ = 0u;
+ uint64_t pageCount_ = 0u;
+ uint64_t initialSize_ = 0u;
+ OfflineDatabase* db = nullptr;
+ };
+
+ friend class DatabaseSizeChangeStats;
+
+ // Lazily initializes currentAmbientCacheSize.
+ std::exception_ptr initAmbientCacheSize();
+ optional<uint64_t> currentAmbientCacheSize;
+ void updateAmbientCacheSize(DatabaseSizeChangeStats&);
+
bool autopack = true;
bool readOnly = false;
};