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

Delta Between Two Patch Sets: lib/prefs.js

Issue 29760565: Issue 6599 - Detect data corruption of storage.local (Closed)
Left Patch Set: Rebased Created April 25, 2018, 2:38 p.m.
Right Patch Set: Fixed blocked_total optimization logic Created April 27, 2018, 4:55 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « dependencies ('k') | lib/subscriptionInit.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 } 290 }
291 291
292 let customSave = new Map(); 292 let customSave = new Map();
293 if (require("../buildtools/info").platform == "gecko") 293 if (require("../buildtools/info").platform == "gecko")
294 { 294 {
295 // Saving one storage value causes all others to be saved as well on Gecko. 295 // Saving one storage value causes all others to be saved as well on Gecko.
296 // Make sure that updating ad counter doesn't cause the filters data to be 296 // Make sure that updating ad counter doesn't cause the filters data to be
297 // saved frequently as a side-effect. 297 // saved frequently as a side-effect.
298 const MIN_UPDATE_INTERVAL = 60 * 1000; 298 const MIN_UPDATE_INTERVAL = 60 * 1000;
299 let lastUpdate = -MIN_UPDATE_INTERVAL; 299 let lastUpdate = -MIN_UPDATE_INTERVAL;
300 let updateScheduled = false; 300 let promise = null;
301 customSave.set("blocked_total", pref => 301 customSave.set("blocked_total", pref =>
302 { 302 {
303 if (!updateScheduled) 303 if (!promise)
304 { 304 {
305 let callback = () => 305 promise = new Promise((resolve, reject) =>
306 { 306 {
307 lastUpdate = performance.now(); 307 setTimeout(
308 updateScheduled = false; 308 () =>
309 savePref(pref); 309 {
310 }; 310 lastUpdate = performance.now();
311 311 promise = null;
312 let timeElapsed = performance.now() - lastUpdate; 312 savePref(pref).then(resolve, reject);
313 if (timeElapsed < MIN_UPDATE_INTERVAL) 313 },
314 { 314 lastUpdate + MIN_UPDATE_INTERVAL - performance.now()
315 setTimeout(callback, MIN_UPDATE_INTERVAL - timeElapsed); 315 );
316 updateScheduled = true; 316 });
317 }
318 else
319 callback();
320 } 317 }
321 return Promise.resolve(); 318 return promise;
322 }); 319 });
323 } 320 }
324 321
325 function addPreference(pref) 322 function addPreference(pref)
326 { 323 {
327 Object.defineProperty(Prefs, pref, { 324 Object.defineProperty(Prefs, pref, {
328 get() { return (pref in overrides ? overrides : defaults)[pref]; }, 325 get() { return (pref in overrides ? overrides : defaults)[pref]; },
329 set(value) 326 set(value)
330 { 327 {
331 Prefs.set(pref, value); 328 Prefs.set(pref, value);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 eventEmitter.emit(pref); 382 eventEmitter.emit(pref);
386 } 383 }
387 } 384 }
388 }); 385 });
389 } 386 }
390 387
391 Prefs.untilLoaded = Promise.all([localLoaded, managedLoaded]).then(onLoaded); 388 Prefs.untilLoaded = Promise.all([localLoaded, managedLoaded]).then(onLoaded);
392 } 389 }
393 390
394 init(); 391 init();
LEFTRIGHT

Powered by Google App Engine
This is Rietveld