summaryrefslogtreecommitdiff
path: root/platform/darwin
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2016-08-27 15:56:19 -0700
committerMinh Nguyễn <mxn@1ec5.org>2016-09-20 22:34:54 -0700
commit3b546b964609d0f596dac32e155b1489bb85645e (patch)
tree194683f1e98d191f973384bb48967a6e5e86d31e /platform/darwin
parent7df9a21f415aa269e7ae435d1500f4a3c7d607e1 (diff)
downloadqtlocation-mapboxgl-3b546b964609d0f596dac32e155b1489bb85645e.tar.gz
[ios, macos] Ignore progress updates after suspending
-suspend and -resume are now presumed to be synchronous, even if technically they remain asynchronous under the hood.
Diffstat (limited to 'platform/darwin')
-rw-r--r--platform/darwin/src/MGLOfflinePack.h12
-rw-r--r--platform/darwin/src/MGLOfflinePack.mm20
2 files changed, 21 insertions, 11 deletions
diff --git a/platform/darwin/src/MGLOfflinePack.h b/platform/darwin/src/MGLOfflinePack.h
index 3d4422da33..a14d001d0f 100644
--- a/platform/darwin/src/MGLOfflinePack.h
+++ b/platform/darwin/src/MGLOfflinePack.h
@@ -144,11 +144,6 @@ typedef struct MGLOfflinePackProgress {
/**
Resumes downloading if the pack is inactive.
- A pack resumes asynchronously. To get notified when this pack resumes, observe
- KVO change notifications on this pack’s `state` key path. Alternatively, you
- can add an observer for `MGLOfflinePackProgressChangedNotification`s about this
- pack that come from the default notification center.
-
When a pack resumes after being suspended, it may begin by iterating over the
already downloaded resources. As a result, the `progress` structure’s
`countOfResourcesCompleted` field may revert to 0 before rapidly returning to
@@ -161,10 +156,9 @@ typedef struct MGLOfflinePackProgress {
/**
Temporarily stops downloading if the pack is active.
- A pack suspends asynchronously. To get notified when this pack resumes, observe
- KVO change notifications on this pack’s `state` key path. Alternatively, you
- can add an observer for `MGLOfflinePackProgressChangedNotification` about this
- pack that come from the default notification center.
+ A pack suspends asynchronously, so some network requests may be sent after this
+ method is called. Regardless, the `progress` property will not be updated until
+ `-resume` is called.
If the pack previously reached a higher level of progress before being
suspended, it may wait to suspend until it returns to that level.
diff --git a/platform/darwin/src/MGLOfflinePack.mm b/platform/darwin/src/MGLOfflinePack.mm
index 59406074e6..1f2fd95f2b 100644
--- a/platform/darwin/src/MGLOfflinePack.mm
+++ b/platform/darwin/src/MGLOfflinePack.mm
@@ -43,7 +43,9 @@ private:
@end
-@implementation MGLOfflinePack
+@implementation MGLOfflinePack {
+ BOOL _isSuspending;
+}
- (instancetype)init {
if (self = [super init]) {
@@ -86,6 +88,8 @@ private:
- (void)resume {
MGLAssertOfflinePackIsValid();
+ self.state = MGLOfflinePackStateActive;
+
mbgl::DefaultFileSource *mbglFileSource = [[MGLOfflineStorage sharedOfflineStorage] mbglFileSource];
mbglFileSource->setOfflineRegionDownloadState(*_mbglOfflineRegion, mbgl::OfflineRegionDownloadState::Active);
}
@@ -93,6 +97,11 @@ private:
- (void)suspend {
MGLAssertOfflinePackIsValid();
+ if (self.state == MGLOfflinePackStateActive) {
+ self.state = MGLOfflinePackStateInactive;
+ _isSuspending = YES;
+ }
+
mbgl::DefaultFileSource *mbglFileSource = [[MGLOfflineStorage sharedOfflineStorage] mbglFileSource];
mbglFileSource->setOfflineRegionDownloadState(*_mbglOfflineRegion, mbgl::OfflineRegionDownloadState::Inactive);
}
@@ -117,7 +126,10 @@ private:
NSAssert(_state != MGLOfflinePackStateInvalid, @"Cannot change the state of an invalid offline pack.");
- _state = state;
+ if (!_isSuspending || state != MGLOfflinePackStateActive) {
+ _isSuspending = NO;
+ _state = state;
+ }
}
- (void)requestProgress {
@@ -150,6 +162,10 @@ private:
break;
}
+ if (_isSuspending) {
+ return;
+ }
+
MGLOfflinePackProgress progress;
progress.countOfResourcesCompleted = status.completedResourceCount;
progress.countOfBytesCompleted = status.completedResourceSize;