fixes #2350: remove iOS-specific SQLite cache wrapper
This commit is contained in:
@@ -25,8 +25,6 @@
|
||||
'../include/mbgl/ios/MGLMapView.h',
|
||||
'../include/mbgl/ios/MGLMapView+IBAdditions.h',
|
||||
'../platform/ios/MGLMapView.mm',
|
||||
'../platform/ios/MGLFileCache.h',
|
||||
'../platform/ios/MGLFileCache.mm',
|
||||
'../include/mbgl/ios/MGLAccountManager.h',
|
||||
'../platform/ios/MGLAccountManager_Private.h',
|
||||
'../platform/ios/MGLAccountManager.m',
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
#import "MGLTypes.h"
|
||||
|
||||
#include <mbgl/storage/sqlite_cache.hpp>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface MGLFileCache : NSObject
|
||||
|
||||
+ (mbgl::SQLiteCache *)obtainSharedCacheWithObject:(NSObject *)object;
|
||||
+ (void)releaseSharedCacheForObject:(NSObject *)object;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -1,83 +0,0 @@
|
||||
#import "MGLFileCache.h"
|
||||
|
||||
@interface MGLFileCache ()
|
||||
|
||||
@property (nonatomic) MGLFileCache *sharedInstance;
|
||||
@property (nonatomic) mbgl::SQLiteCache *sharedCache;
|
||||
@property (nonatomic) NSHashTable *retainers;
|
||||
|
||||
@end
|
||||
|
||||
@implementation MGLFileCache
|
||||
|
||||
const std::string &defaultCacheDatabasePath() {
|
||||
static const std::string path = []() -> std::string {
|
||||
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
|
||||
if ([paths count] == 0) {
|
||||
// Disable the cache if we don't have a location to write.
|
||||
return "";
|
||||
}
|
||||
|
||||
NSString *libraryDirectory = [paths objectAtIndex:0];
|
||||
return [[libraryDirectory stringByAppendingPathComponent:@"cache.db"] UTF8String];
|
||||
}();
|
||||
return path;
|
||||
}
|
||||
|
||||
- (instancetype)init {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_retainers = [NSHashTable weakObjectsHashTable];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
+ (instancetype)sharedInstance {
|
||||
static dispatch_once_t onceToken;
|
||||
static MGLFileCache *_sharedInstance;
|
||||
dispatch_once(&onceToken, ^{
|
||||
_sharedInstance = [[self alloc] init];
|
||||
});
|
||||
return _sharedInstance;
|
||||
}
|
||||
|
||||
- (void)teardown {
|
||||
if (self.sharedCache) {
|
||||
delete self.sharedCache;
|
||||
self.sharedCache = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[self.retainers removeAllObjects];
|
||||
[self teardown];
|
||||
}
|
||||
|
||||
+ (mbgl::SQLiteCache *)obtainSharedCacheWithObject:(NSObject *)object {
|
||||
return [[MGLFileCache sharedInstance] obtainSharedCacheWithObject:object];
|
||||
}
|
||||
|
||||
- (mbgl::SQLiteCache *)obtainSharedCacheWithObject:(NSObject *)object {
|
||||
assert([[NSThread currentThread] isMainThread]);
|
||||
if (!self.sharedCache) {
|
||||
self.sharedCache = new mbgl::SQLiteCache(defaultCacheDatabasePath());
|
||||
}
|
||||
[self.retainers addObject:object];
|
||||
return self.sharedCache;
|
||||
}
|
||||
|
||||
+ (void)releaseSharedCacheForObject:(NSObject *)object {
|
||||
return [[MGLFileCache sharedInstance] releaseSharedCacheForObject:object];
|
||||
}
|
||||
|
||||
- (void)releaseSharedCacheForObject:(NSObject *)object {
|
||||
assert([[NSThread currentThread] isMainThread]);
|
||||
if ([self.retainers containsObject:object]) {
|
||||
[self.retainers removeObject:object];
|
||||
}
|
||||
if ([self.retainers count] == 0) {
|
||||
[self teardown];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <mbgl/annotation/sprite_image.hpp>
|
||||
#include <mbgl/platform/platform.hpp>
|
||||
#include <mbgl/platform/darwin/reachability.h>
|
||||
#include <mbgl/storage/sqlite_cache.hpp>
|
||||
#include <mbgl/storage/default_file_source.hpp>
|
||||
#include <mbgl/storage/network_status.hpp>
|
||||
#include <mbgl/util/geo.hpp>
|
||||
@@ -28,7 +29,6 @@
|
||||
#import "NSException+MGLAdditions.h"
|
||||
#import "MGLUserLocationAnnotationView.h"
|
||||
#import "MGLUserLocation_Private.h"
|
||||
#import "MGLFileCache.h"
|
||||
#import "MGLAccountManager_Private.h"
|
||||
#import "MGLMapboxEvents.h"
|
||||
|
||||
@@ -112,12 +112,14 @@ mbgl::util::UnitBezier MGLUnitBezierForMediaTimingFunction(CAMediaTimingFunction
|
||||
{
|
||||
mbgl::Map *_mbglMap;
|
||||
MBGLView *_mbglView;
|
||||
std::shared_ptr<mbgl::SQLiteCache> _mbglFileCache;
|
||||
mbgl::DefaultFileSource *_mbglFileSource;
|
||||
BOOL _isWaitingForRedundantReachableNotification;
|
||||
|
||||
|
||||
NS_MUTABLE_ARRAY_OF(NSURL *) *_bundledStyleURLs;
|
||||
|
||||
BOOL _isWaitingForRedundantReachableNotification;
|
||||
BOOL _isTargetingInterfaceBuilder;
|
||||
|
||||
CLLocationDegrees _pendingLatitude;
|
||||
CLLocationDegrees _pendingLongitude;
|
||||
}
|
||||
@@ -225,14 +227,24 @@ std::chrono::steady_clock::duration secondsAsDuration(float duration)
|
||||
self.backgroundColor = [UIColor clearColor];
|
||||
self.clipsToBounds = YES;
|
||||
|
||||
// setup mbgl map
|
||||
//
|
||||
// setup mbgl view
|
||||
const float scaleFactor = [UIScreen instancesRespondToSelector:@selector(nativeScale)] ? [[UIScreen mainScreen] nativeScale] : [[UIScreen mainScreen] scale];
|
||||
_mbglView = new MBGLView(self, scaleFactor);
|
||||
_mbglFileSource = new mbgl::DefaultFileSource([MGLFileCache obtainSharedCacheWithObject:self]);
|
||||
|
||||
// Start paused
|
||||
// setup mbgl cache & file source
|
||||
NSString *fileCachePath = @"";
|
||||
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
|
||||
if ([paths count] != 0) {
|
||||
NSString *libraryDirectory = [paths objectAtIndex:0];
|
||||
fileCachePath = [libraryDirectory stringByAppendingPathComponent:@"cache.db"];
|
||||
}
|
||||
_mbglFileCache = mbgl::SharedSQLiteCache::get([fileCachePath UTF8String]);
|
||||
_mbglFileSource = new mbgl::DefaultFileSource(_mbglFileCache.get());
|
||||
|
||||
// setup mbgl map
|
||||
_mbglMap = new mbgl::Map(*_mbglView, *_mbglFileSource, mbgl::MapMode::Continuous);
|
||||
|
||||
// start paused if in IB
|
||||
if (_isTargetingInterfaceBuilder || background) {
|
||||
self.dormant = YES;
|
||||
_mbglMap->pause();
|
||||
@@ -465,8 +477,6 @@ std::chrono::steady_clock::duration secondsAsDuration(float duration)
|
||||
_mbglFileSource = nullptr;
|
||||
}
|
||||
|
||||
[MGLFileCache releaseSharedCacheForObject:self];
|
||||
|
||||
if (_mbglView)
|
||||
{
|
||||
delete _mbglView;
|
||||
|
||||
Reference in New Issue
Block a user