From 7681def0debec00027585d5e28b50a668fc69011 Mon Sep 17 00:00:00 2001 From: Tim van der Meij Date: Sun, 1 Nov 2015 15:45:12 +0100 Subject: [PATCH 1/2] Move VIEW_HISTORY_MEMORY constant to `view_history.js` Currently this constant is present in `viewer.js`, but it is not used there at all. Instead, it is used in `view_history.js` where we have a global for it. We might as well move the constant to `view_history.js` as that is the only place where it is used, thereby removing a global and an unused constant from `viewer.js`. --- web/view_history.js | 4 +++- web/viewer.js | 1 - 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/web/view_history.js b/web/view_history.js index cb21153b6..d4f65f2bc 100644 --- a/web/view_history.js +++ b/web/view_history.js @@ -14,10 +14,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* globals PDFJS, VIEW_HISTORY_MEMORY, Promise */ +/* globals PDFJS, Promise */ 'use strict'; +var VIEW_HISTORY_MEMORY = 20; + /** * View History - This is a utility for saving various view parameters for * recently opened files. diff --git a/web/viewer.js b/web/viewer.js index bbe1f6696..b1730695f 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -31,7 +31,6 @@ var DEFAULT_URL = 'compressed.tracemonkey-pldi-09.pdf'; var DEFAULT_SCALE_DELTA = 1.1; var MIN_SCALE = 0.25; var MAX_SCALE = 10.0; -var VIEW_HISTORY_MEMORY = 20; var SCALE_SELECT_CONTAINER_PADDING = 8; var SCALE_SELECT_PADDING = 22; var PAGE_NUMBER_LOADING_INDICATOR = 'visiblePageIsLoading'; From 55870788e5585df6a26e0b019420a99173e86ef8 Mon Sep 17 00:00:00 2001 From: Tim van der Meij Date: Mon, 2 Nov 2015 14:56:50 +0100 Subject: [PATCH 2/2] Make the view history cache size configurable during initialization --- web/view_history.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/web/view_history.js b/web/view_history.js index d4f65f2bc..a05482102 100644 --- a/web/view_history.js +++ b/web/view_history.js @@ -18,7 +18,7 @@ 'use strict'; -var VIEW_HISTORY_MEMORY = 20; +var DEFAULT_VIEW_HISTORY_CACHE_SIZE = 20; /** * View History - This is a utility for saving various view parameters for @@ -30,8 +30,9 @@ var VIEW_HISTORY_MEMORY = 20; * - GENERIC or CHROME - uses localStorage, if it is available. */ var ViewHistory = (function ViewHistoryClosure() { - function ViewHistory(fingerprint) { + function ViewHistory(fingerprint, cacheSize) { this.fingerprint = fingerprint; + this.cacheSize = cacheSize || DEFAULT_VIEW_HISTORY_CACHE_SIZE; this.isInitializedPromiseResolved = false; this.initializedPromise = this._readFromStorage().then(function (databaseStr) { @@ -41,7 +42,7 @@ var ViewHistory = (function ViewHistoryClosure() { if (!('files' in database)) { database.files = []; } - if (database.files.length >= VIEW_HISTORY_MEMORY) { + if (database.files.length >= this.cacheSize) { database.files.shift(); } var index;