From f10fb2971424c867e364c6a21e999aaef83267b0 Mon Sep 17 00:00:00 2001 From: gorhill Date: Wed, 27 Sep 2017 08:42:27 -0400 Subject: [PATCH] fine tune fix #3006 --- platform/chromium/vapi-background.js | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/platform/chromium/vapi-background.js b/platform/chromium/vapi-background.js index c3c35c8bb..c60462bfd 100644 --- a/platform/chromium/vapi-background.js +++ b/platform/chromium/vapi-background.js @@ -1136,12 +1136,7 @@ vAPI.cloud = (function() { var maxChunkCountPerItem = Math.floor(512 * 0.75) & ~(chunkCountPerFetch - 1); // Mind chrome.storage.sync.QUOTA_BYTES_PER_ITEM (8192 at time of writing) - // https://github.com/gorhill/uBlock/issues/3006 - // For Firefox, we will use a higher ratio to allow for more overhead for - // the infrastructure. Unfortunately this leads to less usable space for - // actual data, but all of this is provided for free by browser vendors, - // so we need to accept and deal with these limitations. - var maxChunkSize = Math.floor(chrome.storage.sync.QUOTA_BYTES_PER_ITEM * 0.75 || 5120); + var maxChunkSize = chrome.storage.sync.QUOTA_BYTES_PER_ITEM || 8192; // Mind chrome.storage.sync.QUOTA_BYTES (128 kB at time of writing) // Firefox: @@ -1149,6 +1144,19 @@ vAPI.cloud = (function() { // > You can store up to 100KB of data using this API/ var maxStorageSize = chrome.storage.sync.QUOTA_BYTES || 102400; + // Flavor-specific handling needs to be done here. Reason: to allow time + // for vAPI.webextFlavor to be properly set. + // https://github.com/gorhill/uBlock/issues/3006 + // For Firefox, we will use a lower ratio to allow for more overhead for + // the infrastructure. Unfortunately this leads to less usable space for + // actual data, but all of this is provided for free by browser vendors, + // so we need to accept and deal with these limitations. + var initialize = function() { + var ratio = vAPI.webextFlavor.startsWith('Mozilla-Firefox-') ? 0.5 : 0.75; + maxChunkSize = Math.floor(maxChunkSize * ratio); + initialize = function(){}; + }; + var options = { defaultDeviceName: window.navigator.platform, deviceName: vAPI.localStorage.getItem('deviceName') || '' @@ -1205,6 +1213,8 @@ vAPI.cloud = (function() { }; var push = function(dataKey, data, callback) { + initialize(); + var bin = { 'source': options.deviceName || options.defaultDeviceName, 'tstamp': Date.now(), @@ -1239,6 +1249,8 @@ vAPI.cloud = (function() { }; var pull = function(dataKey, callback) { + initialize(); + var assembleChunks = function(bin) { if ( chrome.runtime.lastError ) { callback(null, chrome.runtime.lastError.message);