Make sure local accounts can't initiate processing after suspendNetwork is called. Issue #1401

This commit is contained in:
Maurice Parker 2019-12-06 16:06:54 -07:00
parent 1e05238c54
commit d4722f766f
2 changed files with 12 additions and 5 deletions

View File

@ -202,7 +202,7 @@ final class LocalAccountDelegate: AccountDelegate {
// MARK: Suspend and Resume (for iOS) // MARK: Suspend and Resume (for iOS)
func suspendNetwork() { func suspendNetwork() {
refresher.cancelAll() refresher.suspend()
} }
func suspendDatabase() { func suspendDatabase() {
@ -210,6 +210,6 @@ final class LocalAccountDelegate: AccountDelegate {
} }
func resume() { func resume() {
// Nothing to do refresher.resume()
} }
} }

View File

@ -15,6 +15,7 @@ import Articles
final class LocalAccountRefresher { final class LocalAccountRefresher {
private var completion: (() -> Void)? private var completion: (() -> Void)?
private var isSuspended = false
private lazy var downloadSession: DownloadSession = { private lazy var downloadSession: DownloadSession = {
return DownloadSession(delegate: self) return DownloadSession(delegate: self)
@ -29,8 +30,13 @@ final class LocalAccountRefresher {
downloadSession.downloadObjects(feeds as NSSet) downloadSession.downloadObjects(feeds as NSSet)
} }
public func cancelAll() { public func suspend() {
downloadSession.cancelAll() downloadSession.cancelAll()
isSuspended = true
}
public func resume() {
isSuspended = false
} }
} }
@ -56,7 +62,7 @@ extension LocalAccountRefresher: DownloadSessionDelegate {
} }
func downloadSession(_ downloadSession: DownloadSession, downloadDidCompleteForRepresentedObject representedObject: AnyObject, response: URLResponse?, data: Data, error: NSError?) { func downloadSession(_ downloadSession: DownloadSession, downloadDidCompleteForRepresentedObject representedObject: AnyObject, response: URLResponse?, data: Data, error: NSError?) {
guard let feed = representedObject as? WebFeed, !data.isEmpty else { guard let feed = representedObject as? WebFeed, !data.isEmpty, !isSuspended else {
return return
} }
@ -86,13 +92,14 @@ extension LocalAccountRefresher: DownloadSessionDelegate {
} }
func downloadSession(_ downloadSession: DownloadSession, shouldContinueAfterReceivingData data: Data, representedObject: AnyObject) -> Bool { func downloadSession(_ downloadSession: DownloadSession, shouldContinueAfterReceivingData data: Data, representedObject: AnyObject) -> Bool {
guard let feed = representedObject as? WebFeed else { guard !isSuspended, let feed = representedObject as? WebFeed else {
return false return false
} }
if data.isEmpty { if data.isEmpty {
return true return true
} }
if data.isDefinitelyNotFeed() { if data.isDefinitelyNotFeed() {
return false return false
} }