Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cd3880e

Browse files
committedJun 27, 2018
[core] harden OfflineDatabase
1 parent 30ece0d commit cd3880e

15 files changed

+1126
-354
lines changed
 

‎cmake/test-files.cmake

+2
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ set(MBGL_TEST_FILES
102102
test/src/mbgl/test/fixture_log_observer.hpp
103103
test/src/mbgl/test/getrss.cpp
104104
test/src/mbgl/test/getrss.hpp
105+
test/src/mbgl/test/sqlite3_test_fs.cpp
106+
test/src/mbgl/test/sqlite3_test_fs.hpp
105107
test/src/mbgl/test/stub_file_source.cpp
106108
test/src/mbgl/test/stub_file_source.hpp
107109
test/src/mbgl/test/stub_geometry_tile_feature.hpp

‎platform/default/default_file_source.cpp

+19-9
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ class DefaultFileSource::Impl {
7979
}
8080

8181
void getRegionStatus(int64_t regionID, std::function<void (std::exception_ptr, optional<OfflineRegionStatus>)> callback) {
82-
try {
83-
callback({}, getDownload(regionID).getStatus());
84-
} catch (...) {
82+
if (auto download = getDownload(regionID)) {
83+
callback({}, download->getStatus());
84+
} else {
8585
callback(std::current_exception(), {});
8686
}
8787
}
@@ -97,11 +97,15 @@ class DefaultFileSource::Impl {
9797
}
9898

9999
void setRegionObserver(int64_t regionID, std::unique_ptr<OfflineRegionObserver> observer) {
100-
getDownload(regionID).setObserver(std::move(observer));
100+
if (auto download = getDownload(regionID)) {
101+
download->setObserver(std::move(observer));
102+
}
101103
}
102104

103105
void setRegionDownloadState(int64_t regionID, OfflineRegionDownloadState state) {
104-
getDownload(regionID).setState(state);
106+
if (auto download = getDownload(regionID)) {
107+
download->setState(state);
108+
}
105109
}
106110

107111
void request(AsyncRequest* req, Resource resource, ActorRef<FileSourceRequest> ref) {
@@ -186,13 +190,19 @@ class DefaultFileSource::Impl {
186190
}
187191

188192
private:
189-
OfflineDownload& getDownload(int64_t regionID) {
193+
OfflineDownload* getDownload(int64_t regionID) {
190194
auto it = downloads.find(regionID);
191195
if (it != downloads.end()) {
192-
return *it->second;
196+
return it->second.get();
197+
}
198+
auto definition = offlineDatabase->getRegionDefinition(regionID);
199+
if (!definition) {
200+
return nullptr;
193201
}
194-
return *downloads.emplace(regionID,
195-
std::make_unique<OfflineDownload>(regionID, offlineDatabase->getRegionDefinition(regionID), *offlineDatabase, onlineFileSource)).first->second;
202+
203+
auto download = std::make_unique<OfflineDownload>(regionID, std::move(*definition),
204+
*offlineDatabase, onlineFileSource);
205+
return downloads.emplace(regionID, std::move(download)).first->second.get();
196206
}
197207

198208
// shared so that destruction is done on the creating thread

0 commit comments

Comments
 (0)
This repository has been archived.