From ca7217cff7d046b741f59777647a03b4c525afda Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Mon, 16 Sep 2019 01:08:18 -0400 Subject: [PATCH] Add HTTP cancellation support to sync runner --- chrome/content/zotero/xpcom/sync/syncAPIClient.js | 2 ++ chrome/content/zotero/xpcom/sync/syncRunner.js | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/chrome/content/zotero/xpcom/sync/syncAPIClient.js b/chrome/content/zotero/xpcom/sync/syncAPIClient.js index 5c223e6bd7..9fd6bca200 100644 --- a/chrome/content/zotero/xpcom/sync/syncAPIClient.js +++ b/chrome/content/zotero/xpcom/sync/syncAPIClient.js @@ -37,6 +37,7 @@ Zotero.Sync.APIClient = function (options) { this.apiKey = options.apiKey; this.caller = options.caller; this.debugUploadPolicy = Zotero.Prefs.get('sync.debugUploadPolicy'); + this.cancellerReceiver = options.cancellerReceiver; this.rateDelayIntervals = [30, 60, 300]; this.rateDelayPosition = 0; @@ -647,6 +648,7 @@ Zotero.Sync.APIClient.prototype = { && Zotero.Prefs.get('sync.server.compressData')) { opts.compressBody = true; } + opts.cancellerReceiver = this.cancellerReceiver; var tries = 0; while (true) { diff --git a/chrome/content/zotero/xpcom/sync/syncRunner.js b/chrome/content/zotero/xpcom/sync/syncRunner.js index 4dd71064bc..682bac2e1e 100644 --- a/chrome/content/zotero/xpcom/sync/syncRunner.js +++ b/chrome/content/zotero/xpcom/sync/syncRunner.js @@ -75,6 +75,7 @@ Zotero.Sync.Runner_Module = function (options = {}) { var _firstInSession = true; var _syncInProgress = false; var _stopping = false; + var _canceller; var _manualSyncRequired = false; // TODO: make public? var _currentEngine = null; @@ -92,7 +93,8 @@ Zotero.Sync.Runner_Module = function (options = {}) { baseURL: this.baseURL, apiVersion: this.apiVersion, apiKey: options.apiKey, - caller: this.caller + caller: this.caller, + cancellerReceiver: _cancellerReceiver, }); } @@ -282,7 +284,8 @@ Zotero.Sync.Runner_Module = function (options = {}) { _errors = []; } - if (e instanceof Zotero.Sync.UserCancelledException) { + if (e instanceof Zotero.Sync.UserCancelledException + || e instanceof Zotero.HTTP.CancelledException) { Zotero.debug("Sync was cancelled"); } else if (options.onError) { @@ -867,6 +870,9 @@ Zotero.Sync.Runner_Module = function (options = {}) { if (_currentEngine) { _currentEngine.stop(); } + if (_canceller) { + _canceller(); + } } @@ -1571,4 +1577,9 @@ Zotero.Sync.Runner_Module = function (options = {}) { throw new Zotero.Sync.UserCancelledException; } } + + + function _cancellerReceiver(canceller) { + _canceller = canceller; + } }