@@ -74,9 +74,9 @@ class DefaultFileSource::Impl {
74
74
}
75
75
76
76
void getRegionStatus (int64_t regionID, std::function<void (std::exception_ptr, optional<OfflineRegionStatus>)> callback) {
77
- try {
78
- callback ({}, getDownload (regionID). getStatus ());
79
- } catch (...) {
77
+ if ( auto download = getDownload (regionID)) {
78
+ callback ({}, download-> getStatus ());
79
+ } else {
80
80
callback (std::current_exception (), {});
81
81
}
82
82
}
@@ -92,11 +92,15 @@ class DefaultFileSource::Impl {
92
92
}
93
93
94
94
void setRegionObserver (int64_t regionID, std::unique_ptr<OfflineRegionObserver> observer) {
95
- getDownload (regionID).setObserver (std::move (observer));
95
+ if (auto download = getDownload (regionID)) {
96
+ download->setObserver (std::move (observer));
97
+ }
96
98
}
97
99
98
100
void setRegionDownloadState (int64_t regionID, OfflineRegionDownloadState state) {
99
- getDownload (regionID).setState (state);
101
+ if (auto download = getDownload (regionID)) {
102
+ download->setState (state);
103
+ }
100
104
}
101
105
102
106
void request (AsyncRequest* req, Resource resource, ActorRef<FileSourceRequest> ref) {
@@ -181,13 +185,19 @@ class DefaultFileSource::Impl {
181
185
}
182
186
183
187
private:
184
- OfflineDownload& getDownload (int64_t regionID) {
188
+ OfflineDownload* getDownload (int64_t regionID) {
185
189
auto it = downloads.find (regionID);
186
190
if (it != downloads.end ()) {
187
- return *it->second ;
191
+ return it->second .get ();
192
+ }
193
+ auto definition = offlineDatabase->getRegionDefinition (regionID);
194
+ if (!definition) {
195
+ return nullptr ;
188
196
}
189
- return *downloads.emplace (regionID,
190
- std::make_unique<OfflineDownload>(regionID, offlineDatabase->getRegionDefinition (regionID), *offlineDatabase, onlineFileSource)).first ->second ;
197
+
198
+ auto download = std::make_unique<OfflineDownload>(regionID, std::move (*definition),
199
+ *offlineDatabase, onlineFileSource);
200
+ return downloads.emplace (regionID, std::move (download)).first ->second .get ();
191
201
}
192
202
193
203
// shared so that destruction is done on the creating thread
0 commit comments