@@ -79,9 +79,9 @@ class DefaultFileSource::Impl {
79
79
}
80
80
81
81
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 {
85
85
callback (std::current_exception (), {});
86
86
}
87
87
}
@@ -97,11 +97,15 @@ class DefaultFileSource::Impl {
97
97
}
98
98
99
99
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
+ }
101
103
}
102
104
103
105
void setRegionDownloadState (int64_t regionID, OfflineRegionDownloadState state) {
104
- getDownload (regionID).setState (state);
106
+ if (auto download = getDownload (regionID)) {
107
+ download->setState (state);
108
+ }
105
109
}
106
110
107
111
void request (AsyncRequest* req, Resource resource, ActorRef<FileSourceRequest> ref) {
@@ -186,13 +190,19 @@ class DefaultFileSource::Impl {
186
190
}
187
191
188
192
private:
189
- OfflineDownload& getDownload (int64_t regionID) {
193
+ OfflineDownload* getDownload (int64_t regionID) {
190
194
auto it = downloads.find (regionID);
191
195
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 ;
193
201
}
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 ();
196
206
}
197
207
198
208
// shared so that destruction is done on the creating thread
0 commit comments