Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/prefs.js

Issue 29621569: Issue 6050 - Use localStorage for blocked_total preference on Gecko (Closed)
Patch Set: Use parseInt instead of JSON.parse Created Nov. 27, 2017, 6:51 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/prefs.js
diff --git a/lib/prefs.js b/lib/prefs.js
index 7686f83f462e7f19f406583e3bea424c144a3f43..d0b0d899754ac6c417b2c2e4d43e0a8f27d3edf1 100644
--- a/lib/prefs.js
+++ b/lib/prefs.js
@@ -259,32 +259,17 @@ function savePref(pref)
let customSave = new Map();
if (require("info").platform == "gecko")
{
- // Saving one storage value causes all others to be saved as well on Gecko.
- // Make sure that updating ad counter doesn't cause the filters data to be
- // saved frequently as a side-effect.
- const MIN_UPDATE_INTERVAL = 60 * 1000;
- let lastUpdate = -MIN_UPDATE_INTERVAL;
- let updateScheduled = false;
+ // Saving one browser.storage value causes all others to be saved as well on
+ // Gecko. Until that is rectified[1] we need to avoid saving the ad counter
+ // using browser.storage too often, since the filters data is saved as a
+ // side-effect. We do this by using localStorage instead, only updating the
+ // value saved in browser.storage when the extension first initializes.
+ // Note: This workaround is sub-optimal since if the user clears browser data
+ // localStorage is cleared.
+ // [1] - https://bugzilla.mozilla.org/show_bug.cgi?id=1277612
customSave.set("blocked_total", pref =>
{
- if (updateScheduled)
- return;
-
- let callback = () =>
- {
- lastUpdate = performance.now();
- updateScheduled = false;
- savePref(pref);
- };
-
- let timeElapsed = performance.now() - lastUpdate;
- if (timeElapsed < MIN_UPDATE_INTERVAL)
- {
- setTimeout(callback, MIN_UPDATE_INTERVAL - timeElapsed);
- updateScheduled = true;
- }
- else
- callback();
+ window.localStorage.setItem("blocked_total", overrides.blocked_total);
});
}
@@ -326,6 +311,20 @@ function init()
for (let key in items)
overrides[keyToPref(key)] = items[key];
+ if (require("info").platform == "gecko")
+ {
+ let blockedTotal = window.localStorage.getItem("blocked_total");
+ if (typeof blockedTotal == "string")
+ {
+ blockedTotal = parseInt(blockedTotal, 10);
+ if (blockedTotal > overrides.blocked_total)
+ {
+ overrides.blocked_total = blockedTotal;
+ savePref("blocked_total");
+ }
+ }
+ }
+
resolve();
});
});
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld