| OLD | NEW |
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-present eyeo GmbH | 3 * Copyright (C) 2006-present eyeo GmbH |
| 4 * | 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
| 8 * | 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 { | 293 { |
| 294 return browser.storage.local.set({[prefToKey(pref)]: overrides[pref]}); | 294 return browser.storage.local.set({[prefToKey(pref)]: overrides[pref]}); |
| 295 } | 295 } |
| 296 | 296 |
| 297 let customSave = new Map(); | 297 let customSave = new Map(); |
| 298 if (require("info").platform == "gecko") | 298 if (require("info").platform == "gecko") |
| 299 { | 299 { |
| 300 // Saving one storage value causes all others to be saved as well on Gecko. | 300 // Saving one storage value causes all others to be saved as well on Gecko. |
| 301 // Make sure that updating ad counter doesn't cause the filters data to be | 301 // Make sure that updating ad counter doesn't cause the filters data to be |
| 302 // saved frequently as a side-effect. | 302 // saved frequently as a side-effect. |
| 303 const MIN_UPDATE_INTERVAL = 60 * 1000; | |
| 304 let lastUpdate = -MIN_UPDATE_INTERVAL; | |
| 305 let promise = null; | 303 let promise = null; |
| 306 customSave.set("blocked_total", pref => | 304 customSave.set("blocked_total", pref => |
| 307 { | 305 { |
| 308 if (!promise) | 306 if (!promise) |
| 309 { | 307 { |
| 310 promise = new Promise((resolve, reject) => | 308 promise = new Promise((resolve, reject) => |
| 311 { | 309 { |
| 312 setTimeout( | 310 setTimeout( |
| 313 () => | 311 () => |
| 314 { | 312 { |
| 315 lastUpdate = performance.now(); | |
| 316 promise = null; | 313 promise = null; |
| 317 savePref(pref).then(resolve, reject); | 314 savePref(pref).then(resolve, reject); |
| 318 }, | 315 }, |
| 319 lastUpdate + MIN_UPDATE_INTERVAL - performance.now() | 316 60 * 1000 |
| 320 ); | 317 ); |
| 321 }); | 318 }); |
| 322 } | 319 } |
| 323 return promise; | 320 return promise; |
| 324 }); | 321 }); |
| 325 } | 322 } |
| 326 | 323 |
| 327 function addPreference(pref) | 324 function addPreference(pref) |
| 328 { | 325 { |
| 329 Object.defineProperty(Prefs, pref, { | 326 Object.defineProperty(Prefs, pref, { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 eventEmitter.emit(pref); | 384 eventEmitter.emit(pref); |
| 388 } | 385 } |
| 389 } | 386 } |
| 390 }); | 387 }); |
| 391 } | 388 } |
| 392 | 389 |
| 393 Prefs.untilLoaded = Promise.all([localLoaded, managedLoaded]).then(onLoaded); | 390 Prefs.untilLoaded = Promise.all([localLoaded, managedLoaded]).then(onLoaded); |
| 394 } | 391 } |
| 395 | 392 |
| 396 init(); | 393 init(); |
| OLD | NEW |